org.exolab.castor.xml.util
Class XMLClassDescriptorImpl

java.lang.Object
  extended by org.exolab.castor.xml.Validator
      extended by org.exolab.castor.xml.util.XMLClassDescriptorImpl
All Implemented Interfaces:
ClassDescriptor, ClassValidator, TypeValidator, XMLClassDescriptor
Direct Known Subclasses:
AccessTypeDescriptor, BindingDescriptor, BindingTypeDescriptor, BindXmlAutoNamingTypeDescriptor, BindXmlDescriptor, BindXmlNodeTypeDescriptor, CacheTypeMappingDescriptor, ClassMappingDescriptor, ClassTypeDescriptor, CollectionTypeDescriptor, ComponentBindingTypeChoiceDescriptor, ComponentBindingTypeDescriptor, ContainerDescriptor, DatabaseChoiceDescriptor, DatabaseDescriptor, DataSourceDescriptor, DirtyTypeDescriptor, EnumerationDescriptor, FieldMappingDescriptor, FieldTypeCollectionTypeDescriptor, FieldTypeDescriptor, IncludeDescriptor, IncludeTypeDescriptor, InterfaceDescriptor, IntrospectedXMLClassDescriptor, JdoConfDescriptor, KeyGeneratorDefDescriptor, LdapDescriptor, MappingRootDescriptor, MapToDescriptor, NamingTypeDescriptor, NamingXMLTypeDescriptor, PackageTypeChoiceDescriptor, PackageTypeDescriptor, ParamDescriptor, PathTypeDescriptor, PropertyTypeDescriptor, SqlDescriptor, TransactionDemarcationDescriptor, TransactionManagerDescriptor, TypeTypeDescriptor, XMLClassDescriptorAdapter

public class XMLClassDescriptorImpl
extends Validator
implements XMLClassDescriptor

The core implementation of XMLClassDescriptor. This class is used by both generated source code as well as the XMLMappingLoader.

Version:
$Revision: 1.9 $ $Date: 2005/03/01 06:20:16 $
Author:
Keith Visco

Constructor Summary
protected XMLClassDescriptorImpl()
          Protected constructor used by this class, and subclasses only
  XMLClassDescriptorImpl(java.lang.Class type)
          Creates an XMLClassDescriptor class used by the Marshalling Framework.
  XMLClassDescriptorImpl(java.lang.Class type, java.lang.String xmlName)
          Creates an XMLClassDescriptor class used by the Marshalling Framework.
 
Method Summary
 void addFieldDescriptor(XMLFieldDescriptor descriptor)
          Adds the given XMLFieldDescriptor to the list of descriptors.
 boolean canAccept(java.lang.String name, java.lang.String namespace, java.lang.Object object)
          Returns true if the given object, represented by this XMLClassDescriptor, can accept a value for the member associated with the given xml name and namespace.
 boolean contains(XMLFieldDescriptor descriptor)
          Returns true if the given XMLFieldDescriptor is contained within this XMLClassDescriptor.
 AccessMode getAccessMode()
          Returns the access mode specified for this class.
 XMLFieldDescriptor[] getAttributeDescriptors()
          Returns the set of XMLFieldDescriptors for all members that should be marshalled as XML attributes.
 XMLFieldDescriptor getContentDescriptor()
          Returns the XMLFieldDescriptor for the member that should be marshalled as text content.
 XMLFieldDescriptor[] getElementDescriptors()
          Returns the set of XMLFieldDescriptors for all members that should be marshalled as XML elements.
 ClassDescriptor getExtends()
          Returns the class descriptor of the class extended by this class.
 XMLFieldDescriptor getFieldDescriptor(java.lang.String name, java.lang.String namespace, NodeType nodeType)
          Returns the XML field descriptor matching the given xml name and nodeType.
 FieldDescriptor[] getFields()
          Returns a list of fields represented by this descriptor.
 FieldDescriptor getIdentity()
          Returns the identity field, null if this class has no identity.
 java.lang.Class getJavaClass()
          Returns the Java class represented by this descriptor.
 java.lang.String getNameSpacePrefix()
          Returns the namespace prefix to use when marshalling as XML.
 java.lang.String getNameSpaceURI()
          Returns the namespace URI used when marshalling and unmarshalling as XML.
 TypeValidator getValidator()
          Returns a specific validator for the class described by this ClassDescriptor.
 java.lang.String getXMLName()
          Returns the XML Name for the Class being described.
 boolean hasContainerFields()
          Returns true if this XMLClassDescriptorImpl has any fields which are container objects.
(package private) static boolean isDefaultPrimitiveValue(java.lang.Object value)
          Checks to see if the given Object is a java primitive (does not check for primitive wrappers) and has a value that is equal to the default value for that primitive.
(package private) static boolean isPrimitive(java.lang.Class type)
          Returns true if the given class should be treated as a primitive type.
 boolean removeFieldDescriptor(XMLFieldDescriptor descriptor)
          Removes the given XMLFieldDescriptor from the list of descriptors.
 void setCompositorAsAll()
          Sets the compositor for the fields of the described class to be ALL.
 void setCompositorAsChoice()
          Sets the compositor for the fields of the described class to be CHOICE.
 void setCompositorAsSequence()
          Sets the compositor for the fields of the described class to be a Sequence.
 void setExtends(XMLClassDescriptor classDesc)
          Sets the XMLClassDescriptor that this descriptor inherits from
protected  void setExtendsWithoutFlatten(XMLClassDescriptor classDesc)
           
 void setIdentity(XMLFieldDescriptor fieldDesc)
          Sets the Identity FieldDescriptor, if the FieldDescriptor is not already a contained in this ClassDescriptor, it will be added
protected  void setIntrospected(boolean introspected)
          Sets a flag to indicate whether or not this XMLClassDescriptorImpl was created via introspection
protected  void setJavaClass(java.lang.Class type)
          Sets the Class type being described by this descriptor.
 void setNameSpacePrefix(java.lang.String nsPrefix)
          Sets the namespace prefix used when marshalling as XML.
 void setNameSpaceURI(java.lang.String nsURI)
          Sets the namespace URI used when marshalling and unmarshalling as XML.
 void setXMLName(java.lang.String xmlName)
          Sets the XML name for the Class described by this XMLClassDescriptor
 void sortDescriptors()
          This method is used to keep the set of descriptors in the proper sorted lists.
 java.lang.String toString()
          Returns the String representation of this XMLClassDescriptor
protected  java.lang.String toXMLName(java.lang.String className)
           
 void validate(java.lang.Object object)
          Validates the given Object
 void validate(java.lang.Object object, ValidationContext context)
          Validates the given object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLClassDescriptorImpl

public XMLClassDescriptorImpl(java.lang.Class type)
Creates an XMLClassDescriptor class used by the Marshalling Framework.

Parameters:
type - the Class type with which this ClassDescriptor describes.

XMLClassDescriptorImpl

public XMLClassDescriptorImpl(java.lang.Class type,
                              java.lang.String xmlName)
Creates an XMLClassDescriptor class used by the Marshalling Framework.

Parameters:
type - the Class type with which this ClassDescriptor describes.

XMLClassDescriptorImpl

protected XMLClassDescriptorImpl()
Protected constructor used by this class, and subclasses only

Method Detail

addFieldDescriptor

public void addFieldDescriptor(XMLFieldDescriptor descriptor)
Adds the given XMLFieldDescriptor to the list of descriptors. The descriptor will be added to the appropriate list by calling XMLFieldDescriptor#getNodeType() to determine it's type.

Parameters:
descriptor - the XMLFieldDescriptor to add

contains

public boolean contains(XMLFieldDescriptor descriptor)
Returns true if the given XMLFieldDescriptor is contained within this XMLClassDescriptor.

Returns:
true if the XMLFieldDescriptor is part of this XMLClassDescriptor, otherwise false.

getAttributeDescriptors

public XMLFieldDescriptor[] getAttributeDescriptors()
Returns the set of XMLFieldDescriptors for all members that should be marshalled as XML attributes.

Specified by:
getAttributeDescriptors in interface XMLClassDescriptor
Returns:
an array of XMLFieldDescriptors for all members that should be marshalled as XML attributes.

getContentDescriptor

public XMLFieldDescriptor getContentDescriptor()
Returns the XMLFieldDescriptor for the member that should be marshalled as text content.

Specified by:
getContentDescriptor in interface XMLClassDescriptor
Returns:
the XMLFieldDescriptor for the member that should be marshalled as text content.

getElementDescriptors

public XMLFieldDescriptor[] getElementDescriptors()
Returns the set of XMLFieldDescriptors for all members that should be marshalled as XML elements.

Specified by:
getElementDescriptors in interface XMLClassDescriptor
Returns:
an array of XMLFieldDescriptors for all members that should be marshalled as XML elements.

getFieldDescriptor

public XMLFieldDescriptor getFieldDescriptor(java.lang.String name,
                                             java.lang.String namespace,
                                             NodeType nodeType)
Returns the XML field descriptor matching the given xml name and nodeType. If NodeType is null, then either an AttributeDescriptor, or ElementDescriptor may be returned. Null is returned if no matching descriptor is available. If an field is matched in one of the container field, it will return the container field that contain the field named 'name'

Specified by:
getFieldDescriptor in interface XMLClassDescriptor
Parameters:
name - the xml name to match against
nodeType, - the NodeType to match against, or null if the node type is not known.
Returns:
the matching descriptor, or null if no matching descriptor is available.

getNameSpacePrefix

public java.lang.String getNameSpacePrefix()
Description copied from interface: XMLClassDescriptor
Returns the namespace prefix to use when marshalling as XML.

Specified by:
getNameSpacePrefix in interface XMLClassDescriptor
Returns:
the namespace prefix to use when marshalling as XML.

getNameSpaceURI

public java.lang.String getNameSpaceURI()
Description copied from interface: XMLClassDescriptor
Returns the namespace URI used when marshalling and unmarshalling as XML.

Specified by:
getNameSpaceURI in interface XMLClassDescriptor
Returns:
the namespace URI used when marshalling and unmarshalling as XML.

getValidator

public TypeValidator getValidator()
Returns a specific validator for the class described by this ClassDescriptor. A null value may be returned if no specific validator exists.

Specified by:
getValidator in interface XMLClassDescriptor
Returns:
the type validator for the class described by this ClassDescriptor.

getXMLName

public java.lang.String getXMLName()
Returns the XML Name for the Class being described.

Specified by:
getXMLName in interface XMLClassDescriptor
Returns:
the XML name.

hasContainerFields

public boolean hasContainerFields()
Returns true if this XMLClassDescriptorImpl has any fields which are container objects. A container object is a Java object which holds data the should be marshalled, but the object itself should not be. So the container object will be "unwrapped" and the fields associated with the container will appear as if they were part of this class.

Returns:
true if any of the fields are container fields, otherwise false.

removeFieldDescriptor

public boolean removeFieldDescriptor(XMLFieldDescriptor descriptor)
Removes the given XMLFieldDescriptor from the list of descriptors.

Parameters:
descriptor - the XMLFieldDescriptor to remove

setCompositorAsAll

public void setCompositorAsAll()
Sets the compositor for the fields of the described class to be ALL.


setCompositorAsChoice

public void setCompositorAsChoice()
Sets the compositor for the fields of the described class to be CHOICE.


setCompositorAsSequence

public void setCompositorAsSequence()
Sets the compositor for the fields of the described class to be a Sequence.


setExtends

public void setExtends(XMLClassDescriptor classDesc)
Sets the XMLClassDescriptor that this descriptor inherits from

Parameters:
classDesc - the XMLClassDescriptor that this descriptor extends

setIdentity

public void setIdentity(XMLFieldDescriptor fieldDesc)
Sets the Identity FieldDescriptor, if the FieldDescriptor is not already a contained in this ClassDescriptor, it will be added


setNameSpacePrefix

public void setNameSpacePrefix(java.lang.String nsPrefix)
Sets the namespace prefix used when marshalling as XML.

Parameters:
nsPrefix - the namespace prefix used when marshalling the "described" object

setNameSpaceURI

public void setNameSpaceURI(java.lang.String nsURI)
Sets the namespace URI used when marshalling and unmarshalling as XML.

Parameters:
nsURI - the namespace URI used when marshalling and unmarshalling the "described" Object.

setXMLName

public void setXMLName(java.lang.String xmlName)
Sets the XML name for the Class described by this XMLClassDescriptor

Parameters:
xmlName - the XML name for the Class described by this XMLClassDescriptor

sortDescriptors

public void sortDescriptors()
This method is used to keep the set of descriptors in the proper sorted lists. If you dynamically change the NodeType of an XMLFieldDescriptor after adding it the this ClassDescriptor, then call this method.


toString

public java.lang.String toString()
Returns the String representation of this XMLClassDescriptor

Overrides:
toString in class java.lang.Object
Returns:
the String representation of this XMLClassDescriptor

validate

public void validate(java.lang.Object object)
              throws ValidationException
Validates the given Object

Overrides:
validate in class Validator
Parameters:
object - the Object to validate
Throws:
ValidationException

validate

public void validate(java.lang.Object object,
                     ValidationContext context)
              throws ValidationException
Validates the given object

Specified by:
validate in interface ClassValidator
Specified by:
validate in interface TypeValidator
Overrides:
validate in class Validator
Parameters:
object - the Object to validate
context - the ValidationContext
Throws:
ValidationException - when the class is not valid.

getJavaClass

public java.lang.Class getJavaClass()
Returns the Java class represented by this descriptor.

Specified by:
getJavaClass in interface ClassDescriptor
Returns:
The Java class

getFields

public FieldDescriptor[] getFields()
Returns a list of fields represented by this descriptor.

Specified by:
getFields in interface ClassDescriptor
Returns:
A list of fields

getExtends

public ClassDescriptor getExtends()
Returns the class descriptor of the class extended by this class.

Specified by:
getExtends in interface ClassDescriptor
Returns:
The extended class descriptor

getIdentity

public FieldDescriptor getIdentity()
Returns the identity field, null if this class has no identity.

Specified by:
getIdentity in interface ClassDescriptor
Returns:
The identity field

getAccessMode

public AccessMode getAccessMode()
Returns the access mode specified for this class.

Specified by:
getAccessMode in interface ClassDescriptor
Returns:
The access mode

canAccept

public boolean canAccept(java.lang.String name,
                         java.lang.String namespace,
                         java.lang.Object object)
Description copied from interface: XMLClassDescriptor

Returns true if the given object, represented by this XMLClassDescriptor, can accept a value for the member associated with the given xml name and namespace.

An XMLClassDescriptor can accept a value for a field if it contains a descriptor that matches the given xml name and namespace and if the given object can hold this field (i.e a value is not already set for this field).

Specified by:
canAccept in interface XMLClassDescriptor
Parameters:
name - the xml name of the field to check
namespace - the namespace uri
object - the object instance represented by this XMLCLassDescriptor
Returns:
true if the given object represented by this XMLClassDescriptor can accept a member whose name is given.

isPrimitive

static boolean isPrimitive(java.lang.Class type)
Returns true if the given class should be treated as a primitive type. This method will return true for all Java primitive types, the set of primitive object wrappers, as well as Strings.

Returns:
true if the given class should be treated as a primitive type

isDefaultPrimitiveValue

static boolean isDefaultPrimitiveValue(java.lang.Object value)
Checks to see if the given Object is a java primitive (does not check for primitive wrappers) and has a value that is equal to the default value for that primitive. This method will return true if the value is a java primitive with a default value.

Returns:
true if the value is a java primitive with a default value

setJavaClass

protected void setJavaClass(java.lang.Class type)
Sets the Class type being described by this descriptor.


setExtendsWithoutFlatten

protected void setExtendsWithoutFlatten(XMLClassDescriptor classDesc)

setIntrospected

protected void setIntrospected(boolean introspected)
Sets a flag to indicate whether or not this XMLClassDescriptorImpl was created via introspection

Parameters:
introspected - a boolean, when true indicated that this XMLClassDescriptor was created via introspection

toXMLName

protected java.lang.String toXMLName(java.lang.String className)


Intalio Inc. (C) 1999-2004. All rights reserved http://www.intalio.com