org.progeeks.meta
Class AbstractMetaObject

java.lang.Object
  extended by org.progeeks.util.beans.BeanChangeSupport
      extended by org.progeeks.meta.AbstractMetaObject
All Implemented Interfaces:
MetaObject, StandardBean
Direct Known Subclasses:
BeanMetaObject, DbfMetaObject, GraphMetaObject, MapMetaObject, MBeanMetaObject, MetaObjectProxy, PreferencesMetaObject, ResultSetMetaObjectIterator

public abstract class AbstractMetaObject
extends BeanChangeSupport
implements MetaObject

An abstract meta-object implementation making it easier to create kit-specific meta-object adapters. Hooks are provided to allow subclasses to override specific functionality that may be important to a meta-kit implementation. Subclasses must provide, at the minimum, getPropertyValue() and setPropertyValue() methods.

Version:
$Revision: 1.27 $
Author:
Paul Speed

Nested Class Summary
protected  class AbstractMetaObject.BaseListMutator
          Overridden to provide access to a firePropertyChange() method.
 
Constructor Summary
protected AbstractMetaObject()
          So that subclasses can be serializable without this class having to be.
protected AbstractMetaObject(MetaClass metaClass, MetaKit metaKit)
          Creates a meta-object that will use the specified meta-kit and meta-class.
protected AbstractMetaObject(MetaKit metaKit)
          Creates a meta-object that will use the specified meta-kit.
 
Method Summary
protected  void cacheWrapper(java.lang.String name, java.lang.Object value)
          Sticks a wrapped value into the wrapper cache.
protected  ListMutator createListMutator(java.lang.String name, ListPropertyType type)
          Creates a ListMutator for the specified property.
protected  PropertyMutator createPropertyMutator(java.lang.String name)
          Creates a PropertyMutator for the specified property.
protected  java.lang.Object getCachedWrapper(java.lang.String name)
          Retrieves a wrapped value from the wrapper cache.
 MetaClass getMetaClass()
          Returns the meta-class associated with this object.
 MetaKit getMetaKit()
          Returns the meta-kit for this meta-object's implementation layer.
 java.lang.Object getProperty(java.lang.String name)
          Returns the value of the specified property.
 PropertyMutator getPropertyMutator(java.lang.String name)
          Returns a mutator for the specified property.
protected abstract  java.lang.Object getPropertyValue(java.lang.String name)
          Overridden by subclasses to provide implementation-specific field-level access.
protected  MetaClass readMetaClass(java.io.ObjectInputStream stream)
          Can be used by subclasses to read a meta-class in a way specified by the current serialization policy configuration.
protected  java.lang.Object readResolve()
           
 void release()
          Releases any internal resources that may be held by the underlying implementation.
protected  void setMetaClass(MetaClass metaClass)
          Called by subclasses to set the meta-class when setting it on the constructor is not possible.
protected  void setMetaKit(MetaKit metaKit)
          Called by subclasses to set the meta-kit when setting it on the constructor is not possible.
 void setProperty(java.lang.String name, java.lang.Object value)
          Sets the value of the specified property.
protected abstract  java.lang.Object setPropertyValue(java.lang.String name, java.lang.Object value)
          Overridden by subclasses to provide implementation-specific field-level access.
protected  java.lang.Object unwrapPropertyValue(java.lang.String name, java.lang.Object value, PropertyType type)
          Unwraps the object as appropriate to pass to the internal setPropertyValue() method or returns the original value if no unwrapping is needed.
protected  java.lang.Object wrapPropertyValue(java.lang.String name, PropertyType type, java.lang.Object value)
          Wraps the object as appropriate to return to a caller or returns the original value if no wrapping is needed.
protected  void writeMetaClass(java.io.ObjectOutputStream stream)
          Can be used by subclasses to write this object's meta-class in a way specified by the current serialization policy configuration.
protected  java.lang.Object writeReplace()
          Stores an instance of this object in the context MetaObjectCache for later retrieval.
 
Methods inherited from class org.progeeks.util.beans.BeanChangeSupport
addPropertyChangeListener, addPropertyChangeListener, clearAllListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, hasListeners, hasListeners, removePropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.progeeks.meta.MetaObject
addPropertyChangeListener, addPropertyChangeListener, clearAllListeners, hasListeners, hasListeners, removePropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

AbstractMetaObject

protected AbstractMetaObject()
So that subclasses can be serializable without this class having to be. They will need to set the metaClass and metaKit themselves.


AbstractMetaObject

protected AbstractMetaObject(MetaClass metaClass,
                             MetaKit metaKit)
Creates a meta-object that will use the specified meta-kit and meta-class.


AbstractMetaObject

protected AbstractMetaObject(MetaKit metaKit)
Creates a meta-object that will use the specified meta-kit. The metaClass must be set by subclasses by calling the setMetaClass() method before any other local methods are accessed.

Method Detail

release

public void release()
Releases any internal resources that may be held by the underlying implementation. This implementation clears the listener list, sets the meta-class and meta-kit values to null, and releases any cached wrappers.

Specified by:
release in interface MetaObject

setMetaClass

protected void setMetaClass(MetaClass metaClass)
Called by subclasses to set the meta-class when setting it on the constructor is not possible. The meta-class can only be set once or a RuntimeException will be thrown.


setMetaKit

protected void setMetaKit(MetaKit metaKit)
Called by subclasses to set the meta-kit when setting it on the constructor is not possible. The meta-kit can only be set once or a RuntimeException will be thrown.


setPropertyValue

protected abstract java.lang.Object setPropertyValue(java.lang.String name,
                                                     java.lang.Object value)
Overridden by subclasses to provide implementation-specific field-level access.


getPropertyValue

protected abstract java.lang.Object getPropertyValue(java.lang.String name)
Overridden by subclasses to provide implementation-specific field-level access.


cacheWrapper

protected void cacheWrapper(java.lang.String name,
                            java.lang.Object value)
Sticks a wrapped value into the wrapper cache.


getCachedWrapper

protected java.lang.Object getCachedWrapper(java.lang.String name)
Retrieves a wrapped value from the wrapper cache.


wrapPropertyValue

protected java.lang.Object wrapPropertyValue(java.lang.String name,
                                             PropertyType type,
                                             java.lang.Object value)
Wraps the object as appropriate to return to a caller or returns the original value if no wrapping is needed. This implementation checks the property type and wraps objects in meta-objects or MetaObjectListAdapters if needed. Wrapped values are cached in an internal HashMap to speed later retrievals and reuse meta-objects as much as possible. Objects are wrapped using the local MetaKit.


unwrapPropertyValue

protected java.lang.Object unwrapPropertyValue(java.lang.String name,
                                               java.lang.Object value,
                                               PropertyType type)
Unwraps the object as appropriate to pass to the internal setPropertyValue() method or returns the original value if no unwrapping is needed. This implementation currently only checks for MetaObjectListAdapter values and returns the internal list. MetaObjects that can from a different meta-kit are not properly unwrapped yet. This is because technically a local meta-kit version of the meta-object created and the properties copied. This will be easier at a future time and is unnecessary for most users.


setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
Sets the value of the specified property. The default implementation does some initial type checking, unwraps the value as needed by calling unwrapPropertyValue() and then calls setPropertyValue() before firing a change event.

Specified by:
setProperty in interface MetaObject

getProperty

public java.lang.Object getProperty(java.lang.String name)
Returns the value of the specified property. The default version calls getPropertyValue() to retrieve the property value and then wraps the value as needed by calling wrapPropertyValue() before returning it.

Specified by:
getProperty in interface MetaObject

getPropertyMutator

public PropertyMutator getPropertyMutator(java.lang.String name)
Returns a mutator for the specified property. This implementation calls createListMutator() or createPropertyMutator() as is appropriate based on the PropertyInfo class.

Specified by:
getPropertyMutator in interface MetaObject

getMetaClass

public MetaClass getMetaClass()
Returns the meta-class associated with this object.

Specified by:
getMetaClass in interface MetaObject

getMetaKit

public MetaKit getMetaKit()
Returns the meta-kit for this meta-object's implementation layer.

Specified by:
getMetaKit in interface MetaObject

writeReplace

protected java.lang.Object writeReplace()
                                 throws java.io.ObjectStreamException
Stores an instance of this object in the context MetaObjectCache for later retrieval. Subclasses can override this method to return themselves if they don't support this feature. FIXME - should probably have a more fine-grained way of turning this off. Right now it can only be done by subclassing or by nulling out the context cache.

Throws:
java.io.ObjectStreamException

readResolve

protected java.lang.Object readResolve()
                                throws java.io.ObjectStreamException
Throws:
java.io.ObjectStreamException

writeMetaClass

protected void writeMetaClass(java.io.ObjectOutputStream stream)
                       throws java.io.IOException
Can be used by subclasses to write this object's meta-class in a way specified by the current serialization policy configuration.

Throws:
java.io.IOException

readMetaClass

protected MetaClass readMetaClass(java.io.ObjectInputStream stream)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException
Can be used by subclasses to read a meta-class in a way specified by the current serialization policy configuration.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

createPropertyMutator

protected PropertyMutator createPropertyMutator(java.lang.String name)
Creates a PropertyMutator for the specified property. The default implementation creates a DefaultPropertyMutator.


createListMutator

protected ListMutator createListMutator(java.lang.String name,
                                        ListPropertyType type)
Creates a ListMutator for the specified property. The default implementation creates an instance of the inner class BaseListMutator which is derived from DefaultListMutator.



Copyright © 2002-2003 Paul Speed. All Rights Reserved.