|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjaxx.compiler.tags.DefaultObjectHandler
public class DefaultObjectHandler
Default handler for class tags. Class tags are tags which represent instances of Java classes,
such as <JButton label='Close'/>. DefaultObjectHandler
provides support for attributes and events which adhere to JavaBeans naming conventions as
well as basic JAXX features like the id attribute and data binding by means of
curly braces.
"getDocument") and the word "property" refers to the JavaBeans-style simple
name of a property (e.g. "document").
| Nested Class Summary | |
|---|---|
static class |
DefaultObjectHandler.ProxyEventInfo
Encapsulates information about a "proxy event handler", which is an event handler that fires PropertyChangeEvents when it is triggered. |
| Field Summary | |
|---|---|
static java.lang.String |
ABSTRACT_ATTRIBUTE
|
static java.lang.String |
CONSTRAINTS_ATTRIBUTE
|
static java.lang.String |
CONSTRUCTOR_PARAMS_ATTRIBUTE
|
static java.lang.String |
DECORATOR_ATTRIBUTE
|
static java.lang.String |
DISPLAYED_MNEMONIC_ATTRIBUTE
|
static java.lang.String |
DISPLAYED_MNEMONIC_INDEX_ATTRIBUTE
|
static java.lang.String |
GENERICTYPE_ATTRIBUTE
|
static java.lang.String |
ID_ATTRIBUTE
|
static java.lang.String |
IMPLEMENTS_ATTRIBUTE
|
static java.lang.String |
INITIALIZER_ATTRIBUTE
|
static java.lang.String |
JAVA_BEAN_ATTRIBUTE
|
protected JAXXBeanInfo |
jaxxBeanInfo
The JAXXBeanInfo for the beanClass. |
static java.lang.String |
LAYOUT_ATTRIBUTE
|
static java.lang.String |
MNEMONIC_ATTRIBUTE
|
protected static java.util.Map<org.w3c.dom.Element,CompiledObject> |
objectMap
Maps XML tags to the CompiledObjects created from them. |
static java.lang.String |
STYLE_CLASS_ATTRIBUTE
|
static java.lang.String |
SUPER_GENERIC_TYPE_ATTRIBUTE
|
| Fields inherited from interface jaxx.compiler.tags.TagHandler |
|---|
XMLNS_ATTRIBUTE |
| Constructor Summary | |
|---|---|
DefaultObjectHandler(ClassDescriptor beanClass)
Creates a new DefaultObjectHandler which provides support for the specified class. |
|
| Method Summary | |
|---|---|
void |
addEventHandler(CompiledObject object,
java.lang.String name,
java.lang.String value,
JAXXCompiler compiler)
Adds the necessary Java code to a CompiledObject to add an event listener at runtime. |
void |
addProxyEventInfo(java.lang.String memberName,
java.lang.Class<?> listenerClass)
Configures a proxy event handler which fires PropertyChangeEvents when a non-bound
member is updated. |
void |
addProxyEventInfo(java.lang.String memberName,
java.lang.Class<?> listenerClass,
java.lang.String modelName)
Configures a proxy event handler which fires PropertyChangeEvents when a non-bound
member is updated. |
void |
addProxyEventInfo(java.lang.String memberName,
java.lang.Class<?> listenerClass,
java.lang.String modelName,
java.lang.String addMethod,
java.lang.String removeMethod)
|
void |
addProxyEventInfo(java.lang.String memberName,
ClassDescriptor listenerClass,
java.lang.String modelName,
java.lang.String addMethod,
java.lang.String removeMethod)
Configures a proxy event handler which fires PropertyChangeEvents when a non-bound
member is updated. |
void |
applyStylesheets(CompiledObject object,
JAXXCompiler compiler)
|
protected void |
compileChildrenFirstPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
Compiles the child tags of the current tag. |
protected void |
compileChildrenSecondPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
Compiles the child tags of the current tag. |
protected void |
compileChildTagFirstPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
Compiles a child of the current tag. |
protected void |
compileChildTagSecondPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
Compiles a child of the current tag. |
void |
compileFirstPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
Performs the first pass of compilation on an XML tag from a JAXX source file. |
void |
compileSecondPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
Performs the second pass of compilation on an XML tag from a JAXX source file. |
protected void |
configureProxyEventInfo()
Configures the event handling for members which do not fire PropertyChangeEvent when
modified. |
protected int |
constantValue(java.lang.String key,
java.lang.String value)
Maps string values onto integers, so that int-valued enumeration properties can be specified by strings. |
protected java.lang.Object |
convertFromString(java.lang.String key,
java.lang.String value,
java.lang.Class<?> type)
As TypeManager.convertFromString(String, Class), except that it additionally supports constant names
for int-valued types. |
protected CompiledObject |
createCompiledObject(java.lang.String id,
JAXXCompiler compiler)
Creates the CompiledObject which will represent the object
created by this TagHandler. |
protected java.util.Comparator<org.w3c.dom.Attr> |
getAttributeComparator()
Returns a Comparator which defines the ordering in which the tag's attributes should be processed. |
protected int |
getAttributeOrdering(org.w3c.dom.Attr attr)
Returns the priority with which a particular attribute should be processed. |
ClassDescriptor |
getBeanClass()
|
static ClassDescriptor |
getEventClass(ClassDescriptor listenerClass)
|
DefaultObjectHandler.ProxyEventInfo |
getEventInfo(java.lang.String memberName)
|
java.lang.String |
getGetPropertyCode(java.lang.String javaCode,
java.lang.String name,
JAXXCompiler compiler)
Returns a snippet of Java code which will retrieve an object property at runtime. |
JAXXBeanInfo |
getJAXXBeanInfo()
|
static JAXXBeanInfo |
getJAXXBeanInfo(ClassDescriptor beanClass)
Returns the JAXXBeanInfo for the specified class. |
ClassDescriptor |
getPropertyType(CompiledObject object,
java.lang.String propertyName,
JAXXCompiler compiler)
Returns the type of the named property. |
java.lang.String |
getSetPropertyCode(java.lang.String javaCode,
java.lang.String name,
java.lang.String valueCode,
JAXXCompiler compiler)
Returns a snippet of Java code which will set an object property at runtime. |
protected void |
init()
Performs introspection on the beanClass and stores the results. |
boolean |
isEventHandlerName(java.lang.String name)
|
boolean |
isMemberBound(java.lang.String name)
|
boolean |
isPropertyInherited(java.lang.String property)
|
void |
registerCompiledObject(org.w3c.dom.Element tag,
JAXXCompiler compiler)
|
protected void |
safeInit()
|
protected void |
scanAttributesForDependencies(org.w3c.dom.Element tag,
JAXXCompiler compiler)
Scans all attributes for any dependency classes and adds them to the current compilation set. |
void |
setAttribute(CompiledObject object,
java.lang.String propertyName,
java.lang.String stringValue,
boolean inline,
JAXXCompiler compiler)
Set a single property on an object. |
void |
setAttributes(CompiledObject object,
org.w3c.dom.Element tag,
JAXXCompiler compiler)
Processes the attributes of an XML tag. |
protected void |
setDefaults(CompiledObject object,
org.w3c.dom.Element tag,
JAXXCompiler compiler)
Initializes the default settings of the object, prior to setting its attribute values. |
void |
setProperty(CompiledObject object,
java.lang.String name,
java.lang.Object value,
JAXXCompiler compiler)
Appends Java code to a CompiledObject in order to implement a property assignment. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String ABSTRACT_ATTRIBUTE
public static final java.lang.String CONSTRAINTS_ATTRIBUTE
public static final java.lang.String CONSTRUCTOR_PARAMS_ATTRIBUTE
public static final java.lang.String DECORATOR_ATTRIBUTE
public static final java.lang.String DISPLAYED_MNEMONIC_ATTRIBUTE
public static final java.lang.String DISPLAYED_MNEMONIC_INDEX_ATTRIBUTE
public static final java.lang.String GENERICTYPE_ATTRIBUTE
public static final java.lang.String ID_ATTRIBUTE
public static final java.lang.String IMPLEMENTS_ATTRIBUTE
public static final java.lang.String INITIALIZER_ATTRIBUTE
public static final java.lang.String JAVA_BEAN_ATTRIBUTE
public static final java.lang.String LAYOUT_ATTRIBUTE
public static final java.lang.String MNEMONIC_ATTRIBUTE
public static final java.lang.String STYLE_CLASS_ATTRIBUTE
public static final java.lang.String SUPER_GENERIC_TYPE_ATTRIBUTE
protected JAXXBeanInfo jaxxBeanInfo
protected static java.util.Map<org.w3c.dom.Element,CompiledObject> objectMap
| Constructor Detail |
|---|
public DefaultObjectHandler(ClassDescriptor beanClass)
DefaultObjectHandler which provides support for the specified class. The
class is not actually introspected until the compileFirstPass(org.w3c.dom.Element, jaxx.compiler.JAXXCompiler) method is invoked.
beanClass - the class which this handler supports| Method Detail |
|---|
public DefaultObjectHandler.ProxyEventInfo getEventInfo(java.lang.String memberName)
protected void init()
throws java.beans.IntrospectionException
java.beans.IntrospectionException - if any pbpublic ClassDescriptor getBeanClass()
DefaultObjectHandler supports.public JAXXBeanInfo getJAXXBeanInfo()
JAXXBeanInfo for the class which this DefaultObjectHandler
supports.
public static JAXXBeanInfo getJAXXBeanInfo(ClassDescriptor beanClass)
throws java.beans.IntrospectionException
JAXXBeanInfo for the specified class.
beanClass - the bean class for which to retrieve JAXXBeanInfo
JAXXBeanInfo
java.beans.IntrospectionException - if any pb
public ClassDescriptor getPropertyType(CompiledObject object,
java.lang.String propertyName,
JAXXCompiler compiler)
get method;
for instance JLabel's text property is a String.
object - the object being compiledpropertyName - the simple JavaBeans-style name of the propertycompiler - the current JAXXCompiler
CompilerException - if the type cannot be determined
public boolean isMemberBound(java.lang.String name)
throws UnsupportedAttributeException
name - name of the property
true if the named member is bound (fires PropertyChangeEvent
when modified). Members are either fields (represented by the simple name of the field) or get/is
methods (represented by the simple name of the method, not the simplified JavaBeans-style name).
Methods which are not actually bound in their native class, but for which proxy events have been
configured (such as JTextField.getText, return true.
UnsupportedAttributeException - if attribute is not supportedpublic static ClassDescriptor getEventClass(ClassDescriptor listenerClass)
protected void configureProxyEventInfo()
PropertyChangeEvent when
modified. The default implementation does nothing. Subclasses should override this method to call
addProxyEventInfo for each member which requires special handling.
public void addProxyEventInfo(java.lang.String memberName,
java.lang.Class<?> listenerClass)
PropertyChangeEvents when a non-bound
member is updated. This is necessary for all fields (which cannot be bound) and for methods that are
not bound property get methods. The proxy event handler will attach the specified kind
of listener to the class and fire a PropertyChangeEvent whenever the listener receives
any kind of event.
Even though this method can theoretically be applied to fields (in addition to methods), it would be an
unusual situation in which that would actually work -- as fields cannot fire events when modified, it would
be difficult to have a listener that was always notified when a field value changed.
memberName - the name of the field or method being proxiedlistenerClass - the type of listener which receives events when the field or method is updated
public void addProxyEventInfo(java.lang.String memberName,
java.lang.Class<?> listenerClass,
java.lang.String modelName)
PropertyChangeEvents when a non-bound
member is updated. This is necessary for all fields (which cannot be bound) and for methods that are
not bound property get methods. This variant attaches a listener to a property of the
object (such as model) and not the object itself, which is useful when there is a model
that is the "real" container of the information. The proxy event handler will attach the specified kind
of listener to the property's value (retrieved using the property's get method) and fire
a PropertyChangeEvent whenever the listener receives any kind of event.
If the property is itself bound (typically the case with models), any updates to the property's value will
cause the listener to be removed from the old property value and reattached to the new property value,
as well as cause a PropertyChangeEvent to be fired.
Even though this method can theoretically be applied to fields (in addition to methods), it would be an
unusual situation in which that would actually work -- as fields cannot fire events when modified, it would
be difficult to have a listener that was always notified when a field value changed.
memberName - the name of the field or method being proxiedlistenerClass - the type of listener which receives events when the field or method is updatedmodelName - the JavaBeans-style name of the model property
public void addProxyEventInfo(java.lang.String memberName,
java.lang.Class<?> listenerClass,
java.lang.String modelName,
java.lang.String addMethod,
java.lang.String removeMethod)
public void addProxyEventInfo(java.lang.String memberName,
ClassDescriptor listenerClass,
java.lang.String modelName,
java.lang.String addMethod,
java.lang.String removeMethod)
PropertyChangeEvents when a non-bound
member is updated. This is necessary for all fields (which cannot be bound) and for methods that are
not bound property get methods. This variant attaches a listener to a property of the
object (such as model) and not the object itself, which is useful when there is a model
that is the "real" container of the information. The proxy event handler will attach the specified kind
of listener to the property's value (retrieved using the property's get method) and fire
a PropertyChangeEvent whenever the listener receives any kind of event.
If the property is itself bound (typically the case with models), any updates to the property's value will
cause the listener to be removed from the old property value and reattached to the new property value,
as well as cause a PropertyChangeEvent to be fired.
This variant of addProxyEventInfo allows the names of the methods that add and remove
the event listener to be specified, in cases where the names are not simply add<listenerClassName>
and remove<listenerClassName>.
Even though this method can theoretically be applied to fields (in addition to methods), it would be an
unusual situation in which that would actually work -- as fields cannot fire events when modified, it would
be difficult to have a listener that was always notified when a field value changed.
memberName - the name of the field or method being proxiedlistenerClass - the type of listener which receives events when the field or method is updatedmodelName - the JavaBeans-style name of the model propertyaddMethod - add method nameremoveMethod - remove method name
public void compileFirstPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
throws CompilerException,
java.io.IOException
TagHandlerTagHandler implementations affect the generated .java
file by calling methods in the JAXXCompiler.
compileFirstPass in interface TagHandlertag - the XML tag to compilecompiler - the active JAXXCompiler
CompilerException - if a compilation error occurs
java.io.IOException - if an I/O error occurs
public void compileSecondPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
throws CompilerException,
java.io.IOException
TagHandlerTagHandler implementations affect the generated .java
file by calling methods in the JAXXCompiler.
compileSecondPass in interface TagHandlertag - the XML tag to compilecompiler - the active JAXXCompiler
CompilerException - if a compilation error occurs
java.io.IOException - if an I/O error occurs
public void registerCompiledObject(org.w3c.dom.Element tag,
JAXXCompiler compiler)
protected CompiledObject createCompiledObject(java.lang.String id,
JAXXCompiler compiler)
CompiledObject which will represent the object
created by this TagHandler.
id - the CompiledObject's ID.compiler - compiler to use
CompiledObject to use
protected void setDefaults(CompiledObject object,
org.w3c.dom.Element tag,
JAXXCompiler compiler)
object - the object to initializetag - the tag being compiledcompiler - the current JAXXCompiler
public boolean isPropertyInherited(java.lang.String property)
throws UnsupportedAttributeException
property - property name to test
true if the specified property should be inherited by child components when specified
via CSS.
UnsupportedAttributeException - if attribute is not supportedpublic boolean isEventHandlerName(java.lang.String name)
name - name of event
true if the specified name has the form of an event handler attribute
(e.g. "onActionPerformed").
protected void scanAttributesForDependencies(org.w3c.dom.Element tag,
JAXXCompiler compiler)
compileFirstPass() (it is an error to add dependencies after
pass 1 is complete).
tag - tag to scancompiler - compiler to use
public void setAttributes(CompiledObject object,
org.w3c.dom.Element tag,
JAXXCompiler compiler)
convertFromString(java.lang.String, java.lang.String, java.lang.Class>)), data binding expressions (attributes containing curly-brace
pairs), event listeners (attributes starting with 'on', such as 'onActionPerformed'), and JAXX-defined properties
such as 'id'.
object - the object to be modifiedtag - the tag from which to pull attributescompiler - the current JAXXCompilerprotected java.util.Comparator<org.w3c.dom.Attr> getAttributeComparator()
Comparator which defines the ordering in which the tag's attributes should be processed. The
default implementation sorts the attributes according to the order defined by the getAttributeOrdering(org.w3c.dom.Attr) method.
Comparator defining the order of attribute processingprotected int getAttributeOrdering(org.w3c.dom.Attr attr)
getAttributeComparator() method to define the sort ordering.
attr - the attribute to treate
public void setAttribute(CompiledObject object,
java.lang.String propertyName,
java.lang.String stringValue,
boolean inline,
JAXXCompiler compiler)
convertFromString(java.lang.String, java.lang.String, java.lang.Class>).
object - the object on which to set the propertypropertyName - the name of the property to setstringValue - the raw string value of the property from the XMLinline - true if the value was directly specified as an inline class tag attribute, false otherwise (a default value, specified in CSS, etc.)compiler - the current JAXXCompiler
public void applyStylesheets(CompiledObject object,
JAXXCompiler compiler)
public void addEventHandler(CompiledObject object,
java.lang.String name,
java.lang.String value,
JAXXCompiler compiler)
CompiledObject to add an event listener at runtime.
object - the CompiledObject to which the event listener should be addedname - the name of the event listener, such as "actionPerformed"value - the Java code snippet to execute when the event is firedcompiler - the current JAXXCompiler
public java.lang.String getGetPropertyCode(java.lang.String javaCode,
java.lang.String name,
JAXXCompiler compiler)
get method, but it can be arbitrarily complex.
javaCode - Java code for the object whose property is being retrievedname - the name of the property to retrievecompiler - the current JAXXCompiler
CompilerException - if a compilation error occurs
public java.lang.String getSetPropertyCode(java.lang.String javaCode,
java.lang.String name,
java.lang.String valueCode,
JAXXCompiler compiler)
set method, but it can be arbitrarily complex.
javaCode - Java code for the object whose property is being setname - the name of the property to setvalueCode - Java expression representing the value to set the property tocompiler - the current JAXXCompiler
CompilerException - if a compilation error occurs
public void setProperty(CompiledObject object,
java.lang.String name,
java.lang.Object value,
JAXXCompiler compiler)
CompiledObject in order to implement a property assignment.
setProperty is invoked in response to most XML attributes (those which are not more
complicated cases, like data bindings or event handlers).
By the time it reaches this method, the value has already been converted from its XML
string representation to the appropriate destination type for the property (i.e. if
JLabel.foreground is being set, value will be a Color).
object - the object being modifiedname - the name of the property to setvalue - the value to set the property tocompiler - the current JAXXCompiler
CompilerException - if a compilation error occurs
protected int constantValue(java.lang.String key,
java.lang.String value)
convertFromString(java.lang.String, java.lang.String, java.lang.Class>) when an
int-valued property has a value which is not a valid number. By default, this method looks at the
enumerationValues value of the JAXXPropertyDescriptor.
key - the name of the int-typed propertyvalue - the non-numeric value that was specified for the property
java.lang.IllegalArgumentException - if the property is an enumeration, but the value is not valid
java.lang.NumberFormatException - if the property is not an enumeration
protected java.lang.Object convertFromString(java.lang.String key,
java.lang.String value,
java.lang.Class<?> type)
TypeManager.convertFromString(String, Class), except that it additionally supports constant names
for int-valued types.
key - the name of the property whose value is being convertedvalue - the raw string value of the property as it appears in the XMLtype - the datatype to convert the string into
constantValue(java.lang.String, java.lang.String)
protected void compileChildrenFirstPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
throws CompilerException,
java.io.IOException
compileChildTagFirstPass(org.w3c.dom.Element, jaxx.compiler.JAXXCompiler)
for each child tag.
tag - the tag whose children to runcompiler - the current JAXXCompiler
CompilerException - if a compilation error occurs
java.io.IOException - if an I/O error occurs
protected void compileChildrenSecondPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
throws CompilerException,
java.io.IOException
compileChildTagFirstPass(org.w3c.dom.Element, jaxx.compiler.JAXXCompiler)
for each child tag.
tag - the tag whose children to runcompiler - the current JAXXCompiler
CompilerException - if a compilation error occurs
java.io.IOException - if an I/O error occurs
protected void compileChildTagFirstPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
throws CompilerException,
java.io.IOException
JAXXCompiler.compileFirstPass.
tag - the child tag to runcompiler - the current JAXXCompiler
CompilerException - if a compilation error occurs
java.io.IOException - if an I/O error occurs
protected void compileChildTagSecondPass(org.w3c.dom.Element tag,
JAXXCompiler compiler)
throws CompilerException,
java.io.IOException
JAXXCompiler.compileSecondPass.
tag - the child tag to runcompiler - the current JAXXCompiler
CompilerException - if a compilation error occurs
java.io.IOException - if an I/O error occurspublic java.lang.String toString()
toString in class java.lang.Objectprotected void safeInit()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||