public abstract class MetaDataObject_impl extends Object implements MetaDataObject
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. BeanInfo augmentation is ignored; the implementation here uses the flag IGNORE_ALL_BEANINFO. See The Java Beans Tutorial for more information. To support XML Comments, which can occur between any sub-elements, including array values, the "data" for all objects is stored in a pair of ArrayLists; one holds the "name" of the slot, the other the value; comments are interspersed within this list where they occur. To the extent possible, this should be the *only* data storage used for the xml element. Subclasses should access these elements on demand. Data will be read into / written from this representation; Cloning will copy this information. For getters that need to do some special initial processing, a global flag will be set whenever this base code changes the underlying value.
Modifier and Type | Class and Description |
---|---|
static class |
MetaDataObject_impl.MetaDataAttr |
static class |
MetaDataObject_impl.SerialContext
Information, kept globally (by thread) for one serialization
Inherited by some custom impls, e.g.
|
static interface |
MetaDataObject_impl.Serializer
methods used for serializing
|
Modifier and Type | Field and Description |
---|---|
static ThreadLocal<MetaDataObject_impl.SerialContext> |
serialContext
Keeps the serialContext by thread
set when starting to serialize
cleared at the end (in finally clause) to prevent memory leaks
Inherited by some custom impls, e.g.
|
Constructor and Description |
---|
MetaDataObject_impl()
Creates a new
MetaDataObject_impl with null attribute values |
Modifier and Type | Method and Description |
---|---|
void |
buildFromXMLElement(Element aElement,
XMLParser aParser)
Initializes this object from its XML DOM representation.
|
void |
buildFromXMLElement(Element aElement,
XMLParser aParser,
XMLParser.ParsingOptions aOptions)
Initializes this object from its XML DOM representation.
|
Object |
clone()
Creates a clone of this
MetaDataObject . |
boolean |
equals(Object aObj)
Determines if this object is equal to another.
|
List<MetaDataObject_impl.MetaDataAttr> |
getAdditionalAttributes()
Override this method to include additional attributes
|
Class |
getAttributeClass(String aName)
Gets the Class of the given attribute's value.
|
Object |
getAttributeValue(String aName)
Retrieves the value of an attribute of this
MetaDataObject . |
Node |
getInfoset() |
protected Node |
getMatchingNode(MetaDataObject_impl.SerialContext serialContext,
String name) |
protected PropertyDescriptor[] |
getPropertyDescriptors()
Deprecated.
- use getAttributes instead
|
protected PropertyXmlInfo |
getPropertyXmlInfo(String aXmlElementName)
Looks in this class's XmlizationInfo for a property with the given XML element name.
|
URL |
getRelativePathBase()
Gets the relative path base used to resolve imports.
|
static MetaDataObject_impl.SerialContext |
getSerialContext(ContentHandler ch) |
URL |
getSourceUrl()
Gets the URL from which this object was parsed.
|
String |
getSourceUrlString()
If the sourceURL of this object is non-null, returns its string representation.
|
protected static Class |
getWrapperClass(Class aPrimitiveType)
Gets the wrapper class corresponding to the given primitive type.
|
protected AttributesImpl |
getXMLAttributes()
Called by the
toXML(ContentHandler, boolean) 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.
|
List<NameClassPair> |
listAttributes()
Deprecated.
- use getAttributes
|
protected void |
readArrayPropertyValueFromXMLElement(PropertyXmlInfo aPropXmlInfo,
Class aPropClass,
Element aElement,
XMLParser aParser,
XMLParser.ParsingOptions aOptions)
Utility method to read an array property's value from its DOM representation.
|
protected void |
readMapPropertyFromXml(String aPropName,
Element aElement,
String aKeyXmlAttribute,
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 (or an array of these) values. |
protected void |
readPropertyValueFromXMLElement(PropertyXmlInfo aPropXmlInfo,
Element aElement,
XMLParser aParser,
XMLParser.ParsingOptions aOptions)
Utility method to read an attribute's value from its DOM representation.
|
protected void |
readUnknownPropertyValueFromXMLElement(Element aElement,
XMLParser aParser,
XMLParser.ParsingOptions aOptions,
List<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.
|
protected String |
resolveSettings(String text) |
void |
setAttributeValue(String aName,
Object aValue)
Sets the value of an attribute of this
MetaDataObject . |
void |
setInfoset(Node infoset) |
void |
setSourceUrl(URL aUrl)
Sets the URL from which this object was parsed.
|
void |
setSourceUrlIfNull(URL aUrl)
Sets the source URL of this object, only if that URL is currently set to null.
|
String |
toString()
Dump this metadata object's attributes and values to a String.
|
void |
toXML(ContentHandler aContentHandler)
This is called internally, also for JSon serialization
|
void |
toXML(ContentHandler aContentHandler,
boolean aWriteDefaultNamespaceAttribute)
Writes this object's XML representation by making calls on a SAX
ContentHandler . |
void |
toXML(OutputStream aOutputStream)
Writes out this object's XML representation.
|
void |
toXML(Writer aWriter)
Writes out this object's XML representation.
|
boolean |
valueIsNullOrEmptyArray(Object val) |
protected void |
writeArrayPropertyAsElement(String aPropName,
Class aPropClass,
Object aValue,
String aArrayElementTagName,
String aNamespace)
Utility method used to write an array property out as an XML element.
|
protected void |
writeMapPropertyToXml(String aPropName,
String aXmlElementName,
String aKeyXmlAttribute,
String aValueTagName,
boolean aOmitIfNull,
String aNamespace)
Utility method for writing to XML an property whose value is a
Map with
String keys and XMLizable values. |
protected void |
writePropertyAsElement(PropertyXmlInfo aPropInfo,
String aNamespace)
Utility method used to write a property out as an XML element.
|
public static final ThreadLocal<MetaDataObject_impl.SerialContext> serialContext
public MetaDataObject_impl()
MetaDataObject_impl
with null attribute valuespublic static MetaDataObject_impl.SerialContext getSerialContext(ContentHandler ch)
public void setInfoset(Node infoset)
public Node getInfoset()
public List<MetaDataObject_impl.MetaDataAttr> getAdditionalAttributes()
@Deprecated public List<NameClassPair> listAttributes()
NameClassPair
objects indicating the attributes of this object
and the String names of the Classes of the attributes' values.
For primitive types, the wrapper classes will be
returned (e.g. java.lang.Integer
instead of int).
Several subclasses override this, to add additional items to the list.listAttributes
in interface MetaDataObject
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).MetaDataObject.listAttributes()
public Object getAttributeValue(String aName)
MetaDataObject
MetaDataObject
.getAttributeValue
in interface MetaDataObject
aName
- the name of the parameter to getaName
. Returns null
if
there is no attribute with that name.MetaDataObject.getAttributeValue(String)
public Class getAttributeClass(String aName)
java.lang.Integer
instead of int).aName
- name of an attributenull
if there is no attribute with the given name.public boolean isModifiable()
isModifiable
in interface MetaDataObject
MetaDataObject.isModifiable()
public void setAttributeValue(String aName, Object aValue)
MetaDataObject
MetaDataObject
. Applications should
first check the MetaDataObject.isModifiable()
method; calling
MetaDataObject.setAttributeValue(String, Object)
on an unmodifiable MetaDataObject
will result in an exception.setAttributeValue
in interface MetaDataObject
aName
- the name of the parameter to setaValue
- the value to assign to the parameterMetaDataObject.setAttributeValue(String, Object)
public URL getRelativePathBase()
public URL getSourceUrl()
This setting is used to resolve imports and is also included in exception messages to indicate the source of the problem.
getSourceUrl
in interface MetaDataObject
public String getSourceUrlString()
getSourceUrlString
in interface MetaDataObject
public void setSourceUrlIfNull(URL aUrl)
aUrl
- the location of the XML file from which this object was parsedpublic void setSourceUrl(URL aUrl)
setSourceUrl
in interface MetaDataObject
aUrl
- the location of the XML file from which this object was parsedpublic Object clone()
MetaDataObject
MetaDataObject
. This performs a "deep" copy by cloning
all attribute values that are also MetaDataObjects.clone
in interface MetaDataObject
clone
in class Object
MetaDataObject
multi-core: could be cloning while another thread is modifying?
public String toString()
public boolean equals(Object aObj)
equals
in interface MetaDataObject
equals
in class Object
aObj
- object with which to compare this objectaObj
public int hashCode()
x
and
y
must be equal if x.equals(y)
returns true;public void toXML(Writer aWriter) throws SAXException, IOException
toXML
in interface XMLizable
aWriter
- a Writer to which the XML string will be writtenSAXException
- passthruIOException
- if an I/O failure occurspublic void toXML(OutputStream aOutputStream) throws SAXException, IOException
toXML
in interface XMLizable
aOutputStream
- an OutputStream to which the XML string will be writtenSAXException
- pass thruIOException
- if an I/O failure occurspublic void toXML(ContentHandler aContentHandler) throws SAXException
toXML
in interface XMLizable
aContentHandler
- the content handler to which this object will write events that describe its XML
representation.SAXException
- pass thruXMLizable.toXML(ContentHandler)
public void toXML(ContentHandler aContentHandler, boolean aWriteDefaultNamespaceAttribute) throws SAXException
XMLizable
ContentHandler
.toXML
in interface XMLizable
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.SAXException
- pass thruThis is called internally, also for JSon serialization
If this is the first call to serialize, create a serialContext (and clean up afterwards)
Other callers (e.g. JSON) must set the serialContext first before calling
protected AttributesImpl getXMLAttributes()
toXML(ContentHandler, boolean)
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.protected abstract XmlizationInfo getXmlizationInfo()
protected PropertyXmlInfo getPropertyXmlInfo(String aXmlElementName)
aXmlElementName
- the unqualified name of an XML elementnull
if none.public boolean valueIsNullOrEmptyArray(Object val)
protected void writePropertyAsElement(PropertyXmlInfo aPropInfo, String aNamespace) throws SAXException
aPropInfo
- information on how to represent the property in XMLaNamespace
- XML namespace URI for this object
representationSAXException
- -protected void writeArrayPropertyAsElement(String aPropName, Class aPropClass, Object aValue, String aArrayElementTagName, String aNamespace) throws SAXException
aPropName
- name of the attributeaPropClass
- class of the attributeaValue
- 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 objectSAXException
- -protected void writeMapPropertyToXml(String aPropName, String aXmlElementName, String aKeyXmlAttribute, String aValueTagName, boolean aOmitIfNull, String aNamespace) throws SAXException
Map
with
String
keys and XMLizable
values.aPropName
- name of the property to write to XMLaXmlElementName
- name of the XML element for the property, null
if noneaKeyXmlAttribute
- name of the XML attribute for the keyaValueTagName
- XML element tag name to use for each entry in the MapaOmitIfNull
- if true, null or empty map will not be written at all, if false, null or empty map
will be written as an empty elementaNamespace
- namespace for this objectSAXException
- passthrupublic final void buildFromXMLElement(Element aElement, XMLParser aParser) throws InvalidXMLException
XMLParser
.buildFromXMLElement
in interface XMLizable
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.InvalidXMLException
- if the input XML element does not specify a valid objectpublic void buildFromXMLElement(Element aElement, XMLParser aParser, XMLParser.ParsingOptions aOptions) throws InvalidXMLException
XMLParser
.
It is overridden by specific Java impl classes to provide additional
defaulting (e.g. see AnalysisEngineDescription_impl)buildFromXMLElement
in interface XMLizable
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 settingsInvalidXMLException
- if the input XML element does not specify a valid objectprotected void readPropertyValueFromXMLElement(PropertyXmlInfo aPropXmlInfo, Element aElement, XMLParser aParser, XMLParser.ParsingOptions aOptions) throws InvalidXMLException
aPropXmlInfo
- information about the property to readaElement
- DOM element to read fromaParser
- parser to use to construct complex valuesaOptions
- option settingsInvalidXMLException
- -protected void readArrayPropertyValueFromXMLElement(PropertyXmlInfo aPropXmlInfo, Class aPropClass, Element aElement, XMLParser aParser, XMLParser.ParsingOptions aOptions) throws InvalidXMLException
aPropXmlInfo
- information about the property to readaPropClass
- class of the property's valueaElement
- DOM element representing the entire arrayaParser
- parser to use to construct complex valuesaOptions
- option settingsInvalidXMLException
- -protected void readUnknownPropertyValueFromXMLElement(Element aElement, XMLParser aParser, XMLParser.ParsingOptions aOptions, List<String> aKnownPropertyNames) throws InvalidXMLException
aElement
- DOM element to read fromaParser
- parser to use to construct complex valuesaOptions
- -aKnownPropertyNames
- List of propertiees that we've already values for (these values will not be
overwritten)InvalidXMLException
- if no acceptable object is described by aElementprotected void readMapPropertyFromXml(String aPropName, Element aElement, String aKeyXmlAttribute, String aValueTagName, XMLParser aParser, XMLParser.ParsingOptions aOptions, boolean aValueIsArray) throws InvalidXMLException
Map
with
String
keys and XMLizable
(or an array of these) values.aPropName
- name of the property to read from XMLaElement
- element to read fromaKeyXmlAttribute
- XML attribute for the keyaValueTagName
- XML element tag name for each entry in the mapaParser
- parser to use to build sub-objectsaOptions
- parsing option settingsaValueIsArray
- true if the value of the map entires is an array. This method only supports
homogeneous arrays.InvalidXMLException
- -protected static Class getWrapperClass(Class aPrimitiveType)
java.lang.Integer
is the wrapper class for the primitive type int
.aPrimitiveType
- Class
object representing a primitive typeClass
object representing the wrapper type for
PrimitiveType
. If aPrimitiveType
is not
a primitive type, it is itself returned.@Deprecated protected PropertyDescriptor[] getPropertyDescriptors() throws IntrospectionException
PropertyDescriptor
s
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. Caching needed, this method is called for every access to a field, and introspection doesn't cache (from observation... although the javadocs say otherwise (as of Java6 10/2011 - both IBM and Sun)
PropertyDescriptors
for all properties introduced by subclasses of
MetaDataObject_impl
.IntrospectionException
- if introspection failsprotected Node getMatchingNode(MetaDataObject_impl.SerialContext serialContext, String name)
Copyright © 2006–2021 The Apache Software Foundation. All rights reserved.