org.apache.uima.resource.metadata.impl
Class MetaDataObject_impl

java.lang.Object
  extended by org.apache.uima.resource.metadata.impl.MetaDataObject_impl
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, MetaDataObject, XMLizable
Direct Known Subclasses:
AllowedValue_impl, Attribute_impl, Capability_impl, CapabilityLanguageFlow_impl, CasProcessorCpeObject, CasProcessorDeploymentParamImpl, CasProcessorDeploymentParamsImpl, CasProcessorErrorHandlingImpl, CasProcessorErrorRateThresholdImpl, CasProcessorExecArgImpl, CasProcessorExecutableImpl, CasProcessorFilterImpl, CasProcessorMaxRestartsImpl, CasProcessorRunInSeperateProcessImpl, CasProcessorRuntimeEnvParamImpl, CasProcessorTimeoutImpl, ConfigurableDataResourceSpecifier_impl, ConfigurationGroup_impl, ConfigurationParameter_impl, ConfigurationParameterDeclarations_impl, ConfigurationParameterSettings_impl, CpeCasProcessorsImpl, CpeCheckpointImpl, CpeCollectionReaderCasInitializerImpl, CpeCollectionReaderImpl, CpeCollectionReaderIteratorImpl, CpeComponentDescriptorImpl, CpeConfigurationImpl, CpeDescriptionImpl, CpeIncludeImpl, CpeResourceManagerConfigurationImpl, CpeSofaMappingImpl, CpeSofaMappingsImpl, CustomResourceSpecifier_impl, ExternalResourceBinding_impl, ExternalResourceDependency_impl, ExternalResourceDescription_impl, FeatureDescription_impl, FileLanguageResourceSpecifier_impl, FileResourceSpecifier_impl, Filter_impl, FixedFlow_impl, FlowControllerDeclaration_impl, FsIndexCollection_impl, FsIndexDescription_impl, FsIndexKeyDescription_impl, Import_impl, IndexBuildItem_impl, IndexBuildSpecification_impl, IndexRule_impl, Mapping_impl, NameValuePair_impl, OperationalProperties_impl, OutputQueue_impl, Parameter_impl, PearSpecifier_impl, ResourceCreationSpecifier_impl, ResourceManagerConfiguration_impl, ResourceMetaData_impl, ResultSpecification_impl, SimplePrecondition_impl, SofaMapping_impl, Style_impl, TypeDescription_impl, TypeOrFeature_impl, TypePriorities_impl, TypePriorityList_impl, TypeSystemDescription_impl, URISpecifier_impl

public abstract class MetaDataObject_impl
extends java.lang.Object
implements MetaDataObject

Abstract base class for all MetaDataObjects in the reference implementation. Provides basic support for getting and setting property values given their names, by storing all attribute values in a HashMap keyed on attribute name.

Also provides the ability to write objects to XML and build objects from their DOM representation, as required to implement the XMLizable interface, which is a superinterface of MetaDataObject. In future versions, this could be replaced by a non-proprietary XML binding solution such as JAXB or EMF.

The implementation for getting and setting property values uses the JavaBeans introspection API. Therefore subclasses of this class must be valid JavaBeans and either use the standard naming conventions for getters and setters or else provide a BeanInfo class. See The Java Beans Tutorial for more information.

See Also:
Serialized Form

Constructor Summary
MetaDataObject_impl()
          Creates a new MetaDataObject_impl with null attribute values
 
Method Summary
 void buildFromXMLElement(org.w3c.dom.Element aElement, XMLParser aParser)
          Initializes this object from its XML DOM representation.
 void buildFromXMLElement(org.w3c.dom.Element aElement, XMLParser aParser, XMLParser.ParsingOptions aOptions)
          Initializes this object from its XML DOM representation.
 java.lang.Object clone()
          Creates a clone of this MetaDataObject.
 boolean equals(java.lang.Object aObj)
          Determines if this object is equal to another.
 java.lang.Class getAttributeClass(java.lang.String aName)
          Gets the Class of the given attribue's value.
 java.lang.Object getAttributeValue(java.lang.String aName)
          Retrieves the value of an attribute of this MetaDataObject.
protected  java.beans.PropertyDescriptor[] getPropertyDescriptors()
          Utility method that introspects this bean and returns a list of PropertyDescriptors for its properties.
protected  PropertyXmlInfo getPropertyXmlInfo(java.lang.String aXmlElementName)
          Looks in this class's XmlizationInfo for a property with the given XML element name.
 java.net.URL getRelativePathBase()
          Gets the relative path base used to resolve imports.
 java.net.URL getSourceUrl()
          Gets the URL from which this object was parsed.
 java.lang.String getSourceUrlString()
          If the sourceURL of this object is non-null, returns its string representation.
protected  java.lang.Class getWrapperClass(java.lang.Class aPrimitiveType)
          Gets the wrapper class corresponding to the given primitive type.
protected  org.xml.sax.helpers.AttributesImpl getXMLAttributes()
          Called by the toXML(Writer,String) method to get the XML attributes that will be written as part of the element's tag.
protected abstract  XmlizationInfo getXmlizationInfo()
          To be implemented by subclasses to return information describing how to represent this object in XML.
 int hashCode()
          Gets the hash code for this object.
 boolean isModifiable()
          Returns whether this object is modifiable.
 java.util.List<NameClassPair> listAttributes()
          Returns a list of NameClassPair objects indicating the attributes of this object and the Classes of the attributes' values.
protected  void readArrayPropertyValueFromXMLElement(PropertyXmlInfo aPropXmlInfo, java.lang.Class aPropClass, org.w3c.dom.Element aElement, XMLParser aParser, XMLParser.ParsingOptions aOptions)
          Utility method to read an array property's value from its DOM representation.
protected  void readMapPropertyFromXml(java.lang.String aPropName, org.w3c.dom.Element aElement, java.lang.String aKeyXmlAttribute, java.lang.String aValueTagName, XMLParser aParser, XMLParser.ParsingOptions aOptions, boolean aValueIsArray)
          Utility method for reading from XML an attribute whose value is a Map with String keys and XMLizable values.
protected  void readPropertyValueFromXMLElement(PropertyXmlInfo aPropXmlInfo, org.w3c.dom.Element aElement, XMLParser aParser, XMLParser.ParsingOptions aOptions)
          Utility method to read an attribute's value from its DOM representation.
protected  void readUnknownPropertyValueFromXMLElement(org.w3c.dom.Element aElement, XMLParser aParser, XMLParser.ParsingOptions aOptions, java.util.List<java.lang.String> aKnownPropertyNames)
          Utility method that attempts to read a property value from an XML element even though it is not known to which property the value should be assigned.
 void setAttributeValue(java.lang.String aName, java.lang.Object aValue)
          Sets the value of an attribute of this MetaDataObject.
 void setSourceUrl(java.net.URL aUrl)
          Sets the URL from which this object was parsed.
 void setSourceUrlIfNull(java.net.URL aUrl)
          Sets the source URL of this object, only if that URL is currently set to null.
 java.lang.String toString()
          Dump this metadata object's attributes and values to a String.
 void toXML(org.xml.sax.ContentHandler aContentHandler)
          Writes this object's XML representation by making calls on a SAX ContentHandler.
 void toXML(org.xml.sax.ContentHandler aContentHandler, boolean aWriteDefaultNamespaceAttribute)
          Writes this object's XML representation by making calls on a SAX ContentHandler.
 void toXML(java.io.OutputStream aOutputStream)
          Writes out this object's XML representation.
 void toXML(java.io.Writer aWriter)
          Writes out this object's XML representation.
protected  void writeArrayPropertyAsElement(java.lang.String aPropName, java.lang.Class aPropClass, java.lang.Object aValue, java.lang.String aArrayElementTagName, java.lang.String aNamespace, org.xml.sax.ContentHandler aContentHandler)
          Utility method used to write an array property out as an XML element.
protected  void writeMapPropertyToXml(java.lang.String aPropName, java.lang.String aXmlElementName, java.lang.String aKeyXmlAttribute, java.lang.String aValueTagName, boolean aOmitIfNull, java.lang.String aNamespace, org.xml.sax.ContentHandler aContentHandler)
          Utility method for writing to XML an property whose value is a Map with String keys and XMLizable values.
protected  void writePropertyAsElement(PropertyXmlInfo aPropInfo, java.lang.String aNamespace, org.xml.sax.ContentHandler aContentHandler)
          Utility method used to write a property out as an XML element.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MetaDataObject_impl

public MetaDataObject_impl()
Creates a new MetaDataObject_impl with null attribute values

Method Detail

listAttributes

public java.util.List<NameClassPair> listAttributes()
Returns a list of NameClassPair objects indicating the attributes of this object and the Classes of the attributes' values. For primitive types, the wrapper classes will be returned (e.g. java.lang.Integer instead of int).

Specified by:
listAttributes in interface MetaDataObject
Returns:
a List containing NameClassPair objects, each of which contains the name of a parameter and the Class of its value. For primitive types, the wrapper classes will be returned (e.g. java.lang.Integer instead of int).
See Also:
org.apache.uima.resource.MetaDataObject#listAttributes()

getAttributeValue

public java.lang.Object getAttributeValue(java.lang.String aName)
Description copied from interface: MetaDataObject
Retrieves the value of an attribute of this MetaDataObject.

Specified by:
getAttributeValue in interface MetaDataObject
Parameters:
aName - the name of the parameter to get
Returns:
the value of the parameter named aName. Returns null if there is no attribute with that name.
See Also:
org.apache.uima.resource.MetaDataObject#getAttributeValue(String)

getAttributeClass

public java.lang.Class getAttributeClass(java.lang.String aName)
Gets the Class of the given attribue's value. For primitive types, the wrapper classes will be returned (e.g. java.lang.Integer instead of int).

Parameters:
aName - name of an attribute
Returns:
Class of value that may be assigned to the named attribute. Returns null if there is no attribute with the given name.

isModifiable

public boolean isModifiable()
Returns whether this object is modifiable. MetaDataObjects are modifiable by default.

Specified by:
isModifiable in interface MetaDataObject
Returns:
true if and only if this object's attributes may be modified.
See Also:
org.apache.uima.resource.MetaDataObject#isModifiable()

setAttributeValue

public void setAttributeValue(java.lang.String aName,
                              java.lang.Object aValue)
Description copied from interface: MetaDataObject
Sets the value of an attribute of this MetaDataObject. Applications should first check the MetaDataObject.isModifiable() method; calling MetaDataObject.setAttributeValue(String, Object) on an unmodifiable MetaDataObject will result in an exception.

Specified by:
setAttributeValue in interface MetaDataObject
Parameters:
aName - the name of the parameter to set
aValue - the value to assign to the parameter
See Also:
org.apache.uima.resource.MetaDataObject#setAttributeValue(String, Object)

getRelativePathBase

public java.net.URL getRelativePathBase()
Gets the relative path base used to resolve imports. This is equal to the sourceUrl of this object, if known (i.e. if the object was parsed from an XML file or if setSourceUrl was explicitly called). If the source URL is not known, the value of the user.dir System property is returned.

Returns:
the base URL for resolving relative paths in this object

getSourceUrl

public java.net.URL getSourceUrl()
Gets the URL from which this object was parsed. When this object is parsed from an XML file, this is set by the parser to the URL of the source file XML file. If the object has been created by some other method, the source URL will not be known, and this method will return null.

This setting is used to resolve imports and is also included in exception messages to indicate the source of the problem.

Specified by:
getSourceUrl in interface MetaDataObject
Returns:
the source URL from which this object was parsed

getSourceUrlString

public java.lang.String getSourceUrlString()
If the sourceURL of this object is non-null, returns its string representation. If it is null, returns "<unknown>". Useful for error messages.

Specified by:
getSourceUrlString in interface MetaDataObject
Returns:
the source URL as a string, or "<unknown>"

setSourceUrlIfNull

public void setSourceUrlIfNull(java.net.URL aUrl)
Sets the source URL of this object, only if that URL is currently set to null. This is used internally to update null relative base paths before doing import resolution, without overriding user-specified settings.

Parameters:
aUrl - the location of the XML file from which this object was parsed

setSourceUrl

public void setSourceUrl(java.net.URL aUrl)
Sets the URL from which this object was parsed. Typically only the XML parser sets this. This recursively sets the source URL of all descendants of this object.

Specified by:
setSourceUrl in interface MetaDataObject
Parameters:
aUrl - the location of the XML file from which this object was parsed

clone

public java.lang.Object clone()
Description copied from interface: MetaDataObject
Creates a clone of this MetaDataObject. This performs a "deep" copy by cloning all attribute values that are also MetaDataObjects.

Specified by:
clone in interface MetaDataObject
Overrides:
clone in class java.lang.Object
Returns:
a clone of this MetaDataObject
See Also:
org.apache.uima.resource.MetaDataObject#clone()

toString

public java.lang.String toString()
Dump this metadata object's attributes and values to a String. This is useful for debugging.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object aObj)
Determines if this object is equal to another. Two MetaDataObjects are equivalent if they share the same attributes and the same values for those attributes.

Specified by:
equals in interface MetaDataObject
Overrides:
equals in class java.lang.Object
Parameters:
aObj - object with which to compare this object
Returns:
true if and only if this object is equal to aObj

hashCode

public int hashCode()
Gets the hash code for this object. The hash codes of two NameClassPairs x and y must be equal if x.equals(y) returns true;

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code for this object

toXML

public void toXML(java.io.Writer aWriter)
           throws org.xml.sax.SAXException,
                  java.io.IOException
Writes out this object's XML representation.

Specified by:
toXML in interface XMLizable
Parameters:
aWriter - a Writer to which the XML string will be written
Throws:
java.io.IOException - if an I/O failure occurs
org.xml.sax.SAXException

toXML

public void toXML(java.io.OutputStream aOutputStream)
           throws org.xml.sax.SAXException,
                  java.io.IOException
Writes out this object's XML representation.

Specified by:
toXML in interface XMLizable
Parameters:
aOutputStream - an OutputStream to which the XML string will be written
Throws:
java.io.IOException - if an I/O failure occurs
org.xml.sax.SAXException

toXML

public void toXML(org.xml.sax.ContentHandler aContentHandler)
           throws org.xml.sax.SAXException
Description copied from interface: XMLizable
Writes this object's XML representation by making calls on a SAX ContentHandler. This method just calls toXML(aContentHandler,false), so subclasses should override that version of this method, not this one.

Specified by:
toXML in interface XMLizable
Parameters:
aContentHandler - the content handler to which this object will write events that describe its XML representation.
Throws:
org.xml.sax.SAXException
See Also:
org.apache.uima.util.XMLizable#toXML(java.net.ContentHandler)

toXML

public void toXML(org.xml.sax.ContentHandler aContentHandler,
                  boolean aWriteDefaultNamespaceAttribute)
           throws org.xml.sax.SAXException
Description copied from interface: XMLizable
Writes this object's XML representation by making calls on a SAX ContentHandler.

Specified by:
toXML in interface XMLizable
Parameters:
aContentHandler - the content handler to which this object will write events that describe its XML representation.
aWriteDefaultNamespaceAttribute - whether the namespace of this element should be written as the default namespace. This should be done only for the root element, and it defaults to false.
Throws:
org.xml.sax.SAXException
See Also:
XMLizable.toXML(org.xml.sax.ContentHandler, boolean)

getXMLAttributes

protected org.xml.sax.helpers.AttributesImpl getXMLAttributes()
Called by the toXML(Writer,String) method to get the XML attributes that will be written as part of the element's tag. By default this method returns an empty Attributes object. Subclasses may override it in order to write attributes to the XML.

Returns:
an object defining the attributes to be written to the XML

getXmlizationInfo

protected abstract XmlizationInfo getXmlizationInfo()
To be implemented by subclasses to return information describing how to represent this object in XML.

Returns:
information defining this object's XML representation

getPropertyXmlInfo

protected PropertyXmlInfo getPropertyXmlInfo(java.lang.String aXmlElementName)
Looks in this class's XmlizationInfo for a property with the given XML element name.

Parameters:
aXmlElementName - the unqualified name of an XML element
Returns:
information on the property that corresponds to the given element name, null if none.

writePropertyAsElement

protected void writePropertyAsElement(PropertyXmlInfo aPropInfo,
                                      java.lang.String aNamespace,
                                      org.xml.sax.ContentHandler aContentHandler)
                               throws org.xml.sax.SAXException
Utility method used to write a property out as an XML element.

Parameters:
aPropInfo - information on how to represent the property in XML
aNamespace - XML namespace URI for this object
aContentHandler - content handler to which this object will send events that describe its XML representation
Throws:
org.xml.sax.SAXException

writeArrayPropertyAsElement

protected void writeArrayPropertyAsElement(java.lang.String aPropName,
                                           java.lang.Class aPropClass,
                                           java.lang.Object aValue,
                                           java.lang.String aArrayElementTagName,
                                           java.lang.String aNamespace,
                                           org.xml.sax.ContentHandler aContentHandler)
                                    throws org.xml.sax.SAXException
Utility method used to write an array property out as an XML element.

Parameters:
aPropName - name of the attribute
aPropClass - class of the attribute
aValue - value (guaranteed to be an array and non-null)
aArrayElementTagName - name of tag to be assigned to each element of the array. May be null, in which case each element will be assigned a value appropriate to its class.
aNamespace - the XML namespace URI for this object
aContentHandler - the ContentHandler to which this object will write events that describe its XML representation
Throws:
org.xml.sax.SAXException

writeMapPropertyToXml

protected void writeMapPropertyToXml(java.lang.String aPropName,
                                     java.lang.String aXmlElementName,
                                     java.lang.String aKeyXmlAttribute,
                                     java.lang.String aValueTagName,
                                     boolean aOmitIfNull,
                                     java.lang.String aNamespace,
                                     org.xml.sax.ContentHandler aContentHandler)
                              throws org.xml.sax.SAXException
Utility method for writing to XML an property whose value is a Map with String keys and XMLizable values.

Parameters:
aPropName - name of the property to write to XML
aXmlElementName - name of the XML element for the property, null if none
aKeyXmlAttributeName - name of the XML attribute for the key
aValueTagName - XML element tag name to use for each entry in the Map
aOmitIfNull - if true, null or empty map will not be written at all, if false, null or empty map will be written as an empty element
aNamespace - namespace for this object
aContentHandler - ContentHandler to which this object will send events describing its XML representation
Throws:
org.xml.sax.SAXException

buildFromXMLElement

public final void buildFromXMLElement(org.w3c.dom.Element aElement,
                                      XMLParser aParser)
                               throws InvalidXMLException
Initializes this object from its XML DOM representation. This method is typically called from the XMLParser.

Specified by:
buildFromXMLElement in interface XMLizable
Parameters:
aElement - the XML element that represents this object.
aParser - a reference to the UIMA XMLParser. The XMLParser.buildObject(Element) method can be used to construct sub-objects.
Throws:
InvalidXMLException - if the input XML element does not specify a valid object

buildFromXMLElement

public void buildFromXMLElement(org.w3c.dom.Element aElement,
                                XMLParser aParser,
                                XMLParser.ParsingOptions aOptions)
                         throws InvalidXMLException
Initializes this object from its XML DOM representation. This method is typically called from the XMLParser.

Specified by:
buildFromXMLElement in interface XMLizable
Parameters:
aElement - the XML element that represents this object.
aParser - a reference to the UIMA XMLParser. The XMLParser.buildObject(Element) method can be used to construct sub-objects.
aOptions - option settings
Throws:
InvalidXMLException - if the input XML element does not specify a valid object

readPropertyValueFromXMLElement

protected void readPropertyValueFromXMLElement(PropertyXmlInfo aPropXmlInfo,
                                               org.w3c.dom.Element aElement,
                                               XMLParser aParser,
                                               XMLParser.ParsingOptions aOptions)
                                        throws InvalidXMLException
Utility method to read an attribute's value from its DOM representation.

Parameters:
aPropXmlInfo - information about the property to read
aElement - DOM element to read from
aParser - parser to use to construct complex values
aOptions - option settings
Throws:
InvalidXMLException

readArrayPropertyValueFromXMLElement

protected void readArrayPropertyValueFromXMLElement(PropertyXmlInfo aPropXmlInfo,
                                                    java.lang.Class aPropClass,
                                                    org.w3c.dom.Element aElement,
                                                    XMLParser aParser,
                                                    XMLParser.ParsingOptions aOptions)
                                             throws InvalidXMLException
Utility method to read an array property's value from its DOM representation.

Parameters:
aPropXmlInfo - information about the property to read
aPropClass - class of the property's value
aElement - DOM element representing the entire array
aParser - parser to use to construct complex values
aOptions - option settings
Throws:
InvalidXMLException

readUnknownPropertyValueFromXMLElement

protected void readUnknownPropertyValueFromXMLElement(org.w3c.dom.Element aElement,
                                                      XMLParser aParser,
                                                      XMLParser.ParsingOptions aOptions,
                                                      java.util.List<java.lang.String> aKnownPropertyNames)
                                               throws InvalidXMLException
Utility method that attempts to read a property value from an XML element even though it is not known to which property the value should be assigned. If an object can be constructed from the XML element, it will be assigned to any unasigned property that can accept it.

Parameters:
aElement - DOM element to read from
aParser - parser to use to construct complex values
aKnownPropertyNames - List of propertiees that we've already values for (these values will not be overwritten)
Throws:
InvalidXMLException - if no acceptable object is described by aElement

readMapPropertyFromXml

protected void readMapPropertyFromXml(java.lang.String aPropName,
                                      org.w3c.dom.Element aElement,
                                      java.lang.String aKeyXmlAttribute,
                                      java.lang.String aValueTagName,
                                      XMLParser aParser,
                                      XMLParser.ParsingOptions aOptions,
                                      boolean aValueIsArray)
                               throws InvalidXMLException
Utility method for reading from XML an attribute whose value is a Map with String keys and XMLizable values.

Parameters:
aPropName - name of the property to read from XML
aElement - element to read from
aKeyXmlAttribute - XML attribute for the key
aValueTagName - XML element tag name for each entry in the map
aParser - parser to use to build sub-objects
aOptions - parsing option settings
aValueIsArray - true if the value of the map entires is an array. This method only supports homogeneous arrays.
Throws:
InvalidXMLException

getWrapperClass

protected java.lang.Class getWrapperClass(java.lang.Class aPrimitiveType)
Gets the wrapper class corresponding to the given primitive type. For example, java.lang.Integer is the wrapper class for the primitive type int.

Parameters:
aPrimitiveType - Class object representing a primitive type
Returns:
Class object representing the wrapper type for PrimitiveType. If aPrimitiveType is not a primitive type, it is itself returned.

getPropertyDescriptors

protected java.beans.PropertyDescriptor[] getPropertyDescriptors()
                                                          throws java.beans.IntrospectionException
Utility method that introspects this bean and returns a list of PropertyDescriptors for its properties.

The JavaBeans introspector is used, with the IGNORE_ALL_BEANINFO flag. This saves on initialization time by preventing the introspector from searching for nonexistent BeanInfo classes for all the MetaDataObjects.

Returns:
the PropertyDescriptors for all properties introduced by subclasses of MetaDataObject_impl.
Throws:
java.beans.IntrospectionException


Copyright © 2010 The Apache Software Foundation. All Rights Reserved.