public class DefaultObjectHandler extends Object implements TagHandler
<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.
Throughout this class, the word "member" refers to the name of a field or method (e.g.
"getDocument") and the word "property" refers to the JavaBeans-style simple
name of a property (e.g. "document").
| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultObjectHandler.ProxyEventInfo
Encapsulates information about a "proxy event handler", which is an event handler that
fires PropertyChangeEvents when it is triggered.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
ABSTRACT_ATTRIBUTE |
static String |
BORDER_LAYOUT_PREFIX |
static String |
COMPUTE_I18N_ATTRIBUTE |
static String |
CONSTRAINTS_ATTRIBUTE |
static String |
CONSTRUCTOR_PARAMS_ATTRIBUTE |
static String |
DECORATOR_ATTRIBUTE |
static String |
DISPLAYED_MNEMONIC_ATTRIBUTE |
static String |
DISPLAYED_MNEMONIC_INDEX_ATTRIBUTE |
static String |
GENERIC_TYPE_ATTRIBUTE |
static String |
GRID_LAYOUT_PREFIX |
static String |
HANDLER_ATTRIBUTE |
static String |
I18N_FORMAT_ATTRIBUTE |
static String |
ID_ATTRIBUTE |
static String |
IMPLEMENTS_ATTRIBUTE |
static String |
INITIALIZER_ATTRIBUTE |
static String |
JAVA_BEAN_ATTRIBUTE |
protected JAXXBeanInfo |
jaxxBeanInfo
The JAXXBeanInfo for the beanClass.
|
static String |
LAYOUT_ATTRIBUTE |
static String |
MNEMONIC_ATTRIBUTE |
protected static Map<Element,CompiledObject> |
objectMap
Maps XML tags to the CompiledObjects created from them.
|
static String |
STYLE_CLASS_ATTRIBUTE |
static String |
SUPER_GENERIC_TYPE_ATTRIBUTE |
XMLNS_ATTRIBUTE| Constructor and Description |
|---|
DefaultObjectHandler(ClassDescriptor beanClass)
Creates a new
DefaultObjectHandler which provides support for the specified class. |
| Modifier and Type | Method and Description |
|---|---|
void |
addEventHandler(CompiledObject object,
String name,
String value,
JAXXCompiler compiler)
Adds the necessary Java code to a
CompiledObject to add an event listener at runtime. |
void |
addProxyEventInfo(String memberName,
Class<?> listenerClass)
Configures a proxy event handler which fires
PropertyChangeEvents when a non-bound
member is updated. |
void |
addProxyEventInfo(String memberName,
Class<?> listenerClass,
String modelName)
Configures a proxy event handler which fires
PropertyChangeEvents when a non-bound
member is updated. |
void |
addProxyEventInfo(String memberName,
Class<?> listenerClass,
String modelName,
String addMethod,
String removeMethod) |
void |
addProxyEventInfo(String memberName,
ClassDescriptor listenerClass,
String modelName,
String addMethod,
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(Element tag,
JAXXCompiler compiler)
Compiles the child tags of the current tag.
|
protected void |
compileChildrenSecondPass(Element tag,
JAXXCompiler compiler)
Compiles the child tags of the current tag.
|
protected void |
compileChildTagFirstPass(Element tag,
JAXXCompiler compiler)
Compiles a child of the current tag.
|
protected void |
compileChildTagSecondPass(Element tag,
JAXXCompiler compiler)
Compiles a child of the current tag.
|
void |
compileFirstPass(Element tag,
JAXXCompiler compiler)
Performs the first pass of compilation on an XML tag from a JAXX source file.
|
void |
compileSecondPass(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(String key,
String value)
Maps string values onto integers, so that int-valued enumeration properties can be specified by strings.
|
protected Object |
convertFromString(String key,
String value,
Class<?> type)
As
TypeManager.convertFromString(String, Class), except that it additionally supports constant names
for int-valued types. |
protected CompiledObject |
createCompiledObject(String id,
JAXXCompiler compiler)
Creates the
CompiledObject which will represent the object
created by this TagHandler. |
protected Comparator<Attr> |
getAttributeComparator()
Returns a
Comparator which defines the ordering in which the tag's attributes should be processed. |
protected int |
getAttributeOrdering(Attr attr)
Returns the priority with which a particular attribute should be processed.
|
ClassDescriptor |
getBeanClass() |
static ClassDescriptor |
getEventClass(ClassDescriptor listenerClass) |
DefaultObjectHandler.ProxyEventInfo |
getEventInfo(String memberName) |
String |
getGetPropertyCode(String javaCode,
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,
String propertyName,
JAXXCompiler compiler)
Returns the type of the named property.
|
String |
getSetPropertyCode(String javaCode,
String name,
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(String name) |
boolean |
isMemberBound(String name) |
boolean |
isPropertyInherited(String property) |
void |
registerCompiledObject(Element tag,
JAXXCompiler compiler) |
protected void |
safeInit() |
protected void |
scanAttributesForDependencies(Element tag,
JAXXCompiler compiler)
Scans all attributes for any dependency classes and adds them to the current compilation
set.
|
void |
setAttribute(CompiledObject object,
String propertyName,
String stringValue,
boolean inline,
JAXXCompiler compiler)
Set a single property on an object.
|
void |
setAttributeFromCss(CompiledObject object,
String propertyName,
String stringValue,
JAXXCompiler compiler)
Set a single property on an object.
|
void |
setAttributes(CompiledObject object,
Element tag,
JAXXCompiler compiler)
Processes the attributes of an XML tag.
|
protected void |
setDefaults(CompiledObject object,
Element tag,
JAXXCompiler compiler)
Initializes the default settings of the object, prior to setting its
attribute values.
|
void |
setProperty(CompiledObject object,
String name,
Object value,
JAXXCompiler compiler)
Appends Java code to a
CompiledObject in order to implement a property assignment. |
String |
toString() |
public static final String HANDLER_ATTRIBUTE
public static final String ABSTRACT_ATTRIBUTE
public static final String CONSTRAINTS_ATTRIBUTE
public static final String CONSTRUCTOR_PARAMS_ATTRIBUTE
public static final String DECORATOR_ATTRIBUTE
public static final String DISPLAYED_MNEMONIC_ATTRIBUTE
public static final String DISPLAYED_MNEMONIC_INDEX_ATTRIBUTE
public static final String GENERIC_TYPE_ATTRIBUTE
public static final String ID_ATTRIBUTE
public static final String IMPLEMENTS_ATTRIBUTE
public static final String INITIALIZER_ATTRIBUTE
public static final String JAVA_BEAN_ATTRIBUTE
public static final String LAYOUT_ATTRIBUTE
public static final String MNEMONIC_ATTRIBUTE
public static final String STYLE_CLASS_ATTRIBUTE
public static final String SUPER_GENERIC_TYPE_ATTRIBUTE
public static final String I18N_FORMAT_ATTRIBUTE
public static final String COMPUTE_I18N_ATTRIBUTE
public static final String GRID_LAYOUT_PREFIX
public static final String BORDER_LAYOUT_PREFIX
protected static final Map<Element,CompiledObject> objectMap
protected JAXXBeanInfo jaxxBeanInfo
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, org.nuiton.jaxx.compiler.JAXXCompiler) method is invoked.beanClass - the class which this handler supportspublic static JAXXBeanInfo getJAXXBeanInfo(ClassDescriptor beanClass)
JAXXBeanInfo for the specified class.beanClass - the bean class for which to retrieve JAXXBeanInfoJAXXBeanInfoIntrospectionException - if any pbpublic static ClassDescriptor getEventClass(ClassDescriptor listenerClass)
public DefaultObjectHandler.ProxyEventInfo getEventInfo(String memberName)
protected void init()
throws IntrospectionException
IntrospectionException - if any pbpublic ClassDescriptor getBeanClass()
DefaultObjectHandler supports.public JAXXBeanInfo getJAXXBeanInfo()
JAXXBeanInfo for the class which this DefaultObjectHandler
supports.public ClassDescriptor getPropertyType(CompiledObject object, 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 JAXXCompilerCompilerException - if the type cannot be determinedpublic boolean isMemberBound(String name) throws UnsupportedAttributeException
name - name of the propertytrue 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 supportedprotected 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(String memberName, 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 updatedpublic void addProxyEventInfo(String memberName, Class<?> listenerClass, 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 propertypublic void addProxyEventInfo(String memberName, Class<?> listenerClass, String modelName, String addMethod, String removeMethod)
public void addProxyEventInfo(String memberName, ClassDescriptor listenerClass, String modelName, String addMethod, 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 namepublic void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, 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 JAXXCompilerCompilerException - if a compilation error occursIOException - if an I/O error occurspublic void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, 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 JAXXCompilerCompilerException - if a compilation error occursIOException - if an I/O error occurspublic void registerCompiledObject(Element tag, JAXXCompiler compiler)
protected CompiledObject createCompiledObject(String id, JAXXCompiler compiler)
CompiledObject which will represent the object
created by this TagHandler.id - the CompiledObject's ID.compiler - compiler to useCompiledObject to useprotected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler)
object - the object to initializetag - the tag being compiledcompiler - the current JAXXCompilerpublic boolean isPropertyInherited(String property) throws UnsupportedAttributeException
property - property name to testtrue if the specified property should be inherited by child components when specified
via CSS.UnsupportedAttributeException - if attribute is not supportedpublic boolean isEventHandlerName(String name)
name - name of eventtrue if the specified name has the form of an event handler attribute
(e.g. "onActionPerformed").protected void scanAttributesForDependencies(Element tag, JAXXCompiler compiler)
compileFirstPass() (it is an error to add dependencies after
pass 1 is complete).tag - tag to scancompiler - compiler to usepublic void setAttributes(CompiledObject object, 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 Comparator<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(Attr attr)
getAttributeComparator() method to define the sort ordering.attr - the attribute to treatepublic void setAttributeFromCss(CompiledObject object, String propertyName, String stringValue, JAXXCompiler compiler)
convertFromString(String, String, 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 XMLcompiler - the current JAXXCompilerpublic void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler)
convertFromString(String, String, 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 JAXXCompilerpublic void applyStylesheets(CompiledObject object, JAXXCompiler compiler)
public void addEventHandler(CompiledObject object, String name, 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 JAXXCompilerpublic String getGetPropertyCode(String javaCode, 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 JAXXCompilerCompilerException - if a compilation error occurspublic String getSetPropertyCode(String javaCode, String name, 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 JAXXCompilerCompilerException - if a compilation error occurspublic void setProperty(CompiledObject object, String name, 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 JAXXCompilerCompilerException - if a compilation error occursprotected int constantValue(String key, String value)
You do not normally need to call this method yourself; it is invoked by 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 propertyIllegalArgumentException - if the property is an enumeration, but the value is not validNumberFormatException - if the property is not an enumerationprotected Object convertFromString(String key, String value, 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 intoconstantValue(java.lang.String, java.lang.String)protected void compileChildrenFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException
compileChildTagFirstPass(org.w3c.dom.Element, org.nuiton.jaxx.compiler.JAXXCompiler)
for each child tag.tag - the tag whose children to runcompiler - the current JAXXCompilerCompilerException - if a compilation error occursIOException - if an I/O error occursprotected void compileChildrenSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException
compileChildTagFirstPass(org.w3c.dom.Element, org.nuiton.jaxx.compiler.JAXXCompiler)
for each child tag.tag - the tag whose children to runcompiler - the current JAXXCompilerCompilerException - if a compilation error occursIOException - if an I/O error occursprotected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException
JAXXCompiler.compileFirstPass.tag - the child tag to runcompiler - the current JAXXCompilerCompilerException - if a compilation error occursIOException - if an I/O error occursprotected void compileChildTagSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException
JAXXCompiler.compileSecondPass.tag - the child tag to runcompiler - the current JAXXCompilerCompilerException - if a compilation error occursIOException - if an I/O error occursprotected void safeInit()
Copyright © 2008–2017 Ultreia.io. All rights reserved.