/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* <p>
* This helper class provides a utility implementation of the
* java.beans.beancontext.BeanContextServices interface.
* </p>
* <p>
* Since this class directly implements the BeanContextServices interface,
* the class can, and is intended to be used either by subclassing this
* implementation, or via delegation of an instance of this class
* from another through the BeanContextProxy interface.
* </p>
*
* @author Laurence P. G. Cable
* @since 1.2
*/
implements BeanContextServices {
/**
* <p>
* Construct a BeanContextServicesSupport instance
* </p>
*
* @param peer The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
* @param lcle The current Locale for this BeanContext.
* @param dTime The initial state, true if in design mode, false if runtime.
* @param visible The initial visibility.
*
*/
public BeanContextServicesSupport(BeanContextServices peer, Locale lcle, boolean dTime, boolean visible) {
}
/**
* Create an instance using the specified Locale and design mode.
*
* @param peer The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
* @param lcle The current Locale for this BeanContext.
* @param dtime The initial state, true if in design mode, false if runtime.
*/
}
/**
* Create an instance using the specified locale
*
* @param peer The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
* @param lcle The current Locale for this BeanContext.
*/
}
/**
* Create an instance with a peer
*
* @param peer The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
*/
}
/**
* Create an instance that is not a delegate of another object
*/
public BeanContextServicesSupport() {
}
/**
* called by BeanContextSupport superclass during construction and
* deserialization to initialize subclass transient state.
*
* subclasses may envelope this method, but should not override it or
* call it directly.
*/
public void initialize() {
super.initialize();
}
/**
* Gets the <tt>BeanContextServices</tt> associated with this
* <tt>BeanContextServicesSupport</tt>.
*
* @return the instance of <tt>BeanContext</tt>
* this object is providing the implementation for.
*/
return (BeanContextServices)getBeanContextChildPeer();
}
/************************************************************************/
/*
* protected nested class containing per child information, an instance
* of which is associated with each child in the "children" hashtable.
* subclasses can extend this class to include their own per-child state.
*
* Note that this 'value' is serialized with the corresponding child 'key'
* when the BeanContextSupport is serialized.
*/
/*
* private nested class to map serviceClass to Provider and requestors
* listeners.
*/
class BCSSCServiceClassRef {
// create an instance of a service ref
super();
serviceClass = sc;
if (delegated)
else
}
// add a requestor and assoc listener
void addRequestor(Object requestor, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
BeanContextServiceRevokedListener cbcsrl = (BeanContextServiceRevokedListener)requestors.get(requestor);
throw new TooManyListenersException();
}
// remove a requestor
}
// check a requestors listener
void verifyRequestor(Object requestor, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
BeanContextServiceRevokedListener cbcsrl = (BeanContextServiceRevokedListener)requestors.get(requestor);
throw new TooManyListenersException();
}
if (isDelegated) { // the provider is delegated
return;
}
} else { // the provider is registered with this BCS
return;
}
}
throw new UnsupportedOperationException("existing service reference obtained from different BeanContextServiceProvider not supported");
}
}
return serviceProvider;
}
return delegateProvider;
}
if (delegated) {
delegateRefs++;
} else {
serviceRefs++;
}
}
if (delegated) {
if (--delegateRefs == 0) {
}
} else {
if (--serviceRefs <= 0) {
}
}
}
/*
* fields
*/
int serviceRefs;
int delegateRefs;
}
/*
* per service reference info ...
*/
class BCSSCServiceRef {
}
/*
* fields
*/
boolean delegated = false;
}
// note usage of service per requestor, per service
synchronized void usingService(Object requestor, Object service, Class serviceClass, BeanContextServiceProvider bcsp, boolean isDelegated, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException, UnsupportedOperationException {
// first, process mapping from serviceClass to requestor(s)
if (serviceClasses == null)
else
} else { // existing service ...
}
// now handle mapping from requestor to service(s)
if (serviceRequestors == null) {
} else {
}
} else
if (serviceRef == null) {
} else {
serviceRef.addRef();
}
}
// release a service reference
if (serviceRequestors == null) return;
BeanContextServiceProvider bcsp = isDelegated ? serviceClassRef.getDelegateProvider() : serviceClassRef.getServiceProvider();
bcsp.releaseService(BeanContextServicesSupport.this.getBeanContextServicesPeer(), requestor, service);
}
if (serviceRequestors.isEmpty()) {
}
if (serviceClassRef.isEmpty()) {
}
if (serviceClasses.isEmpty())
}
}
// revoke a service
if (serviceClasses == null) return;
if (serviceClassRef == null) return;
BeanContextServiceRevokedEvent bcsre = new BeanContextServiceRevokedEvent(BeanContextServicesSupport.this.getBeanContextServicesPeer(), serviceClass, revokeNow);
boolean noMoreRefs = false;
if (revokeNow) {
if (serviceRef.getServiceClassRef().equals(serviceClassRef) && isDelegated == serviceRef.isDelegated()) {
}
}
}
}
}
}
if (serviceClassRef.isEmpty())
if (serviceClasses.isEmpty())
}
}
// release all references for this child since it has been unnested.
void cleanupReferences() {
if (serviceRequestors == null) return;
while(requestors.hasNext()) {
requestors.remove();
BeanContextServiceProvider bcsp = sref.isDelegated() ? scref.getDelegateProvider() : scref.getServiceProvider();
bcsp.releaseService(BeanContextServicesSupport.this.getBeanContextServicesPeer(), requestor, service);
}
}
}
}
void revokeAllDelegatedServicesNow() {
if (serviceClasses == null) return;
while (serviceClassRefs.hasNext()) {
if (!serviceClassRef.isDelegated()) continue;
BeanContextServiceRevokedEvent bcsre = new BeanContextServiceRevokedEvent(BeanContextServicesSupport.this.getBeanContextServicesPeer(), serviceClassRef.getServiceClass(), true);
boolean noMoreRefs = false;
while (i.hasNext()) {
}
}
}
}
if (serviceClassRef.isEmpty())
}
}
}
/*
* fields
*/
}
/**
* <p>
* Subclasses can override this method to insert their own subclass
* of Child without having to override add() or the other Collection
* methods that add children to the set.
* </p>
*
* @param targetChild the child to create the Child on behalf of
* @param peer the peer if the targetChild and peer are related by BeanContextProxy
*/
}
/************************************************************************/
/**
* subclasses may subclass this nested class to add behaviors for
* each BeanContextServicesProvider.
*/
super();
}
return serviceProvider;
}
/*
* fields
*/
}
/**
* subclasses can override this method to create new subclasses of
* BCSSServiceProvider without having to overrride addService() in
* order to instantiate.
*/
protected BCSSServiceProvider createBCSSServiceProvider(Class sc, BeanContextServiceProvider bcsp) {
}
/************************************************************************/
/**
* add a BeanContextServicesListener
*
* @throws NullPointerException
*/
synchronized(bcsListeners) {
return;
else
}
}
/**
* remove a BeanContextServicesListener
*/
synchronized(bcsListeners) {
return;
else
}
}
/**
* add a service
*/
}
/**
* add a service
*/
protected boolean addService(Class serviceClass, BeanContextServiceProvider bcsp, boolean fireEvent) {
synchronized(BeanContext.globalHierarchyLock) {
return false;
else {
if (!fireEvent) return true;
BeanContextServiceAvailableEvent bcssae = new BeanContextServiceAvailableEvent(getBeanContextServicesPeer(), serviceClass);
synchronized(children) {
while (i.hasNext()) {
if (c instanceof BeanContextServices) {
}
}
}
return true;
}
}
}
/**
* remove a service
*/
public void revokeService(Class serviceClass, BeanContextServiceProvider bcsp, boolean revokeCurrentServicesNow) {
synchronized(BeanContext.globalHierarchyLock) {
throw new IllegalArgumentException("service provider mismatch");
while (i.hasNext()) {
}
}
}
/**
* has a service, which may be delegated
*/
synchronized(BeanContext.globalHierarchyLock) {
try {
} catch (ClassCastException cce) {
return false;
}
}
}
/************************************************************************/
/*
* a nested subclass used to represent a proxy for serviceClasses delegated
* to an enclosing BeanContext.
*/
protected class BCSSProxyServiceProvider implements BeanContextServiceProvider, BeanContextServiceRevokedListener {
super();
nestingCtxt = bcs;
}
public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) {
try {
} catch (TooManyListenersException tmle) {
return null;
}
return service;
}
}
}
while (i.hasNext()) {
((BCSSChild)i.next()).revokeService(bcsre.getServiceClass(), true, bcsre.isCurrentServiceInvalidNow());
}
}
/*
* fields
*/
}
/************************************************************************/
/**
* obtain a service which may be delegated
*/
public Object getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
synchronized(BeanContext.globalHierarchyLock) {
if (bcsc == null) throw new IllegalArgumentException("not a child of this context"); // not a child ...
try {
} catch (TooManyListenersException tmle) {
throw tmle;
} catch (UnsupportedOperationException uope) {
throw uope; // unchecked rt exception
}
return service;
}
}
// try to delegate ...
try {
} catch (TooManyListenersException tmle) {
throw tmle;
} catch (UnsupportedOperationException uope) {
throw uope; // unchecked rt exception
}
return service;
}
}
}
return null;
}
/**
* release a service
*/
synchronized(BeanContext.globalHierarchyLock) {
else
throw new IllegalArgumentException("child actual is not a child of this BeanContext");
}
}
/**
* @return an iterator for all the currently registered service classes.
*/
}
/**
* @return an iterator for all the currently available service selectors
* (if any) available for the specified service.
*/
return bcsssp != null ? new BCSIterator(bcsssp.getServiceProvider().getCurrentServiceSelectors(getBeanContextServicesPeer(), serviceClass)) : null;
}
/**
* BeanContextServicesListener callback, propagates event to all
* currently registered listeners and BeanContextServices children,
* if this BeanContextService does not already implement this service
* itself.
*
* subclasses may override or envelope this method to implement their
* own propagation semantics.
*/
synchronized(BeanContext.globalHierarchyLock) {
Iterator i;
synchronized(children) {
}
while (i.hasNext()) {
if (c instanceof BeanContextServices) {
}
}
}
}
/**
* BeanContextServicesListener callback, propagates event to all
* currently registered listeners and BeanContextServices children,
* if this BeanContextService does not already implement this service
* itself.
*
* subclasses may override or envelope this method to implement their
* own propagation semantics.
*/
synchronized(BeanContext.globalHierarchyLock) {
Iterator i;
synchronized(children) {
}
while (i.hasNext()) {
if (c instanceof BeanContextServices) {
}
}
}
}
/**
* Gets the <tt>BeanContextServicesListener</tt> (if any) of the specified
* child.
*
* @param child the specified child
* @return the BeanContextServicesListener (if any) of the specified child
*/
protected static final BeanContextServicesListener getChildBeanContextServicesListener(Object child) {
try {
return (BeanContextServicesListener)child;
} catch (ClassCastException cce) {
return null;
}
}
/**
* called from superclass child removal operations after a child
* has been successfully removed. called with child synchronized.
*
* This subclass uses this hook to immediately revoke any services
* being used by this child if it is a BeanContextChild.
*
* subclasses may envelope this method in order to implement their
* own child removal side-effects.
*/
}
/**
* called from setBeanContext to notify a BeanContextChild
* to release resources obtained from the nesting BeanContext.
*
* This method revokes any services obtained from its parent.
*
* subclasses may envelope this method to implement their own semantics.
*/
protected synchronized void releaseBeanContextResources() {
super.releaseBeanContextResources();
synchronized(children) {
}
}
}
/**
* called from setBeanContext to notify a BeanContextChild
* to allocate resources obtained from the nesting BeanContext.
*
* subclasses may envelope this method to implement their own semantics.
*/
protected synchronized void initializeBeanContextResources() {
super.initializeBeanContextResources();
try {
} catch (ClassCastException cce) {
// do nothing ...
}
}
/**
* Fires a <tt>BeanContextServiceEvent</tt> notifying of a new service.
*/
BeanContextServiceAvailableEvent bcssae = new BeanContextServiceAvailableEvent(getBeanContextServicesPeer(), serviceClass);
}
/**
* Fires a <tt>BeanContextServiceAvailableEvent</tt> indicating that a new
* service has become available.
*
* @param bcssae the <tt>BeanContextServiceAvailableEvent</tt>
*/
}
}
/**
* Fires a <tt>BeanContextServiceEvent</tt> notifying of a service being revoked.
*
* @param bcsre the <tt>BeanContextServiceRevokedEvent</tt>
*/
}
}
/**
* Fires a <tt>BeanContextServiceRevokedEvent</tt>
* indicating that a particular service is
* no longer available.
*/
BeanContextServiceRevokedEvent bcsre = new BeanContextServiceRevokedEvent(getBeanContextServicesPeer(), serviceClass, revokeNow);
}
}
/**
* called from BeanContextSupport writeObject before it serializes the
* children ...
*
* This class will serialize any Serializable BeanContextServiceProviders
* herein.
*
* subclasses may envelope this method to insert their own serialization
* processing that has to occur prior to serialization of the children
*/
if (serializable <= 0) return;
int count = 0;
try {
} catch (ClassCastException cce) {
continue;
}
count++;
}
}
if (count != serializable)
throw new IOException("wrote different number of service providers than expected");
}
/**
* called from BeanContextSupport readObject before it deserializes the
* children ...
*
* This class will deserialize any Serializable BeanContextServiceProviders
* serialized earlier thus making them available to the children when they
* deserialized.
*
* subclasses may envelope this method to insert their own serialization
* processing that has to occur prior to serialization of the children
*/
protected synchronized void bcsPreDeserializationHook(ObjectInputStream ois) throws IOException, ClassNotFoundException {
int count = serializable;
while (count > 0) {
count--;
}
}
/**
* serialize the instance
*/
}
/**
* deserialize the instance
*/
private synchronized void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
}
/*
* fields
*/
/**
* all accesses to the <code> protected transient HashMap services </code>
* field should be synchronized on that object
*/
/**
* The number of instances of a serializable <tt>BeanContextServceProvider</tt>.
*/
/**
* Delegate for the <tt>BeanContextServiceProvider</tt>.
*/
/**
* List of <tt>BeanContextServicesListener</tt> objects.
*/
}