org.norther.tammi.core.base
Class DefaultFactory

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.base.DefaultContainer<ObjectFactory<?>>
          extended by org.norther.tammi.core.base.DefaultFactory
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Container<ObjectFactory<?>>, Factory, Manageable, MBeanDelegate, ObjectFactory<Object>

public class DefaultFactory
extends DefaultContainer<ObjectFactory<?>>
implements Factory

A default implementation of Factory. This implementation forwards complicated instantiations to class specific factories, but can itself instantiate any available classes with one or more public constructors.

Version:
$Id: DefaultFactory.java,v 1.16 2009/09/28 15:08:42 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
DefaultFactory()
          Constructs a new factory.
 
Method Summary
 void clear()
          Clears all MBeans from this registry.
 ObjectFactory<?> get(String className)
          Gets the referent of the MBean in this registry.
 Object getInstance(String className)
          Gets an instance of a named class.
 Object getInstance(String className, Object[] params, String[] signature)
          Gets an instance of a named class.
 Object getInstance(String className, ObjectName loader)
          Gets an instance of a named class using a specified class loader.
 Object getInstance(String className, ObjectName loader, Object[] params, String[] signature)
          Gets an instance of a named class using a specified class loader.
 MBeanReference<ObjectFactory<?>> getMBean(String className)
          Gets a reference to the MBean in this registry.
protected  MBeanHandle<ObjectFactory<?>> getMBeanHandle(String key)
          Gets a reference to a mapped MBean.
 ObjectName getObjectName(String className)
          Gets the object name of the MBean in this registry, which is also registered in the MBean server.
 Set<ObjectName> getObjectNames(String className)
          Gets a set of object names registered in the MBean server with names matching the query pattern of the MBean in this registry.
 ObjectName getQueryPattern(String className)
          Gets the query pattern, with which the MBean is registered in this registry.
 boolean isLoaderSupported(String className)
          Checks if specified class loaders are supported for a named class.
 void postmanaged()
          This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.
 void remove(String className)
          Removes an MBean from this registry.
 void setQueryPattern(String className, ObjectName name)
          Sets the object name of a registry MBean.
 void setQueryPattern(String className, String ifname, ObjectName name)
          Sets the interface and object name of a registry MBean.
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 
Methods inherited from class org.norther.tammi.core.base.DefaultContainer
containsKey, getContainerKey, getContainerKey, getContainerKey, getMBeanHandles, getMBeanInterface, getMBeanInterface, registryKeySet, registryKeySet, registryKeySet, registryKeySet, registryMap, registrySize, setMBeanInterface
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.base.Container
containsKey, getContainerKey, getContainerKey, getContainerKey, getMBeanInterface, getMBeanInterface, registryKeySet, registryKeySet, registryKeySet, registryKeySet, registryMap, registrySize, setMBeanInterface
 

Constructor Detail

DefaultFactory

public DefaultFactory()
Constructs a new factory.

Method Detail

postmanaged

public void postmanaged()
Description copied from interface: Manageable
This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.

Specified by:
postmanaged in interface Manageable
Overrides:
postmanaged in class Adaptee

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class Adaptee
Throws:
Exception - if the adaptee refused to be unmanaged.

getInstance

public Object getInstance(String className)
                   throws ConstructionException
Description copied from interface: ObjectFactory
Gets an instance of a named class.

Specified by:
getInstance in interface ObjectFactory<Object>
Parameters:
className - the name of the class.
Returns:
the instance.
Throws:
ConstructionException - if construction fails.

getInstance

public Object getInstance(String className,
                          ObjectName loader)
                   throws ConstructionException
Description copied from interface: ObjectFactory
Gets an instance of a named class using a specified class loader.

Class loaders are supported only if the isLoaderSupported method returns true. Otherwise the loader parameter is ignored.

Specified by:
getInstance in interface ObjectFactory<Object>
Parameters:
className - the name of the class.
loader - the class loader.
Returns:
the instance.
Throws:
ConstructionException - if construction fails.

getInstance

public Object getInstance(String className,
                          Object[] params,
                          String[] signature)
                   throws ConstructionException
Description copied from interface: ObjectFactory
Gets an instance of a named class. Parameters for its constructor are given as an array of objects, primitive types must be wrapped with a corresponding class.

Specified by:
getInstance in interface ObjectFactory<Object>
Parameters:
className - the name of the class.
params - an array containing the parameters of the constructor.
signature - an array containing the signature of the constructor.
Returns:
the instance.
Throws:
ConstructionException - if construction fails.

getInstance

public Object getInstance(String className,
                          ObjectName loader,
                          Object[] params,
                          String[] signature)
                   throws ConstructionException
Description copied from interface: ObjectFactory
Gets an instance of a named class using a specified class loader. Parameters for its constructor are given as an array of objects, primitive types must be wrapped with a corresponding class.

Class loaders are supported only if the isLoaderSupported method returns true. Otherwise the loader parameter is ignored.

Specified by:
getInstance in interface ObjectFactory<Object>
Parameters:
className - the name of the class.
loader - the class loader.
params - an array containing the parameters of the constructor.
signature - an array containing the signature of the constructor.
Returns:
the instance.
Throws:
ConstructionException - if construction fails.

isLoaderSupported

public boolean isLoaderSupported(String className)
Description copied from interface: ObjectFactory
Checks if specified class loaders are supported for a named class.

Specified by:
isLoaderSupported in interface ObjectFactory<Object>
Parameters:
className - the name of the class.
Returns:
true if class loaders are supported, false otherwise.

get

public ObjectFactory<?> get(String className)
Description copied from interface: Container
Gets the referent of the MBean in this registry.

Specified by:
get in interface Container<ObjectFactory<?>>
Overrides:
get in class DefaultContainer<ObjectFactory<?>>
Parameters:
className - the registry key.
Returns:
the referent or null.

getMBean

public MBeanReference<ObjectFactory<?>> getMBean(String className)
Description copied from interface: Container
Gets a reference to the MBean in this registry.

Specified by:
getMBean in interface Container<ObjectFactory<?>>
Overrides:
getMBean in class DefaultContainer<ObjectFactory<?>>
Parameters:
className - the registry key.
Returns:
the reference or null.

getQueryPattern

public ObjectName getQueryPattern(String className)
Description copied from interface: Container
Gets the query pattern, with which the MBean is registered in this registry. The MBean registration is not checked from the MBean server.

Specified by:
getQueryPattern in interface Container<ObjectFactory<?>>
Overrides:
getQueryPattern in class DefaultContainer<ObjectFactory<?>>
Parameters:
className - the registry key.
Returns:
the pattern or null if not registered.

setQueryPattern

public void setQueryPattern(String className,
                            ObjectName name)
Description copied from interface: Container
Sets the object name of a registry MBean.

Specified by:
setQueryPattern in interface Container<ObjectFactory<?>>
Overrides:
setQueryPattern in class DefaultContainer<ObjectFactory<?>>
Parameters:
className - the registry key.
name - the object name or query pattern.

setQueryPattern

public void setQueryPattern(String className,
                            String ifname,
                            ObjectName name)
Description copied from interface: Container
Sets the interface and object name of a registry MBean. If the registry is already configured for a specific interface, the interface name must correspond to it.

Specified by:
setQueryPattern in interface Container<ObjectFactory<?>>
Overrides:
setQueryPattern in class DefaultContainer<ObjectFactory<?>>
Parameters:
className - the registry key.
ifname - the class or interface name.
name - the object name or query pattern.

getObjectName

public ObjectName getObjectName(String className)
Description copied from interface: Container
Gets the object name of the MBean in this registry, which is also registered in the MBean server.

Specified by:
getObjectName in interface Container<ObjectFactory<?>>
Overrides:
getObjectName in class DefaultContainer<ObjectFactory<?>>
Parameters:
className - the registry key.
Returns:
the name or null if not in registered.

getObjectNames

public Set<ObjectName> getObjectNames(String className)
Description copied from interface: Container
Gets a set of object names registered in the MBean server with names matching the query pattern of the MBean in this registry.

Specified by:
getObjectNames in interface Container<ObjectFactory<?>>
Overrides:
getObjectNames in class DefaultContainer<ObjectFactory<?>>
Parameters:
className - the registry key.
Returns:
a set of object names or an empty set.

remove

public void remove(String className)
Description copied from interface: Container
Removes an MBean from this registry.

Specified by:
remove in interface Container<ObjectFactory<?>>
Overrides:
remove in class DefaultContainer<ObjectFactory<?>>
Parameters:
className - the registry key.

clear

public void clear()
Description copied from interface: Container
Clears all MBeans from this registry.

Specified by:
clear in interface Container<ObjectFactory<?>>
Overrides:
clear in class DefaultContainer<ObjectFactory<?>>

getMBeanHandle

protected MBeanHandle<ObjectFactory<?>> getMBeanHandle(String key)
Description copied from class: DefaultContainer
Gets a reference to a mapped MBean.

Note that the reference is meant for internal use only.

Overrides:
getMBeanHandle in class DefaultContainer<ObjectFactory<?>>
Parameters:
key - the key to the MBean.
Returns:
the reference or null.


Copyright © 2004 The Norther Organization. All rights reserved.