Package org.exolab.castor.xml
Class Introspector
java.lang.Object
org.exolab.castor.xml.Introspector
- All Implemented Interfaces:
PropertyChangeListener
,EventListener
A Helper class for the Marshaller and Unmarshaller, basically the common code base between the
two. This class handles the introspection to dynamically create descriptors.
- Version:
- $Revision$ $Date: 2006-04-14 04:14:43 -0600 (Fri, 14 Apr 2006) $
- Author:
- Keith Visco
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of the Introspector.Introspector
(ClassLoader classLoader) Creates a new instance of the Introspector. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Registers the given "generalized" FieldHandlerFactory with this Introspector.Creates an XMLClassDescriptor for the given class by using Reflection.generateClassDescriptor
(Class c, PrintWriter errorWriter) Creates an XMLClassDescriptor for the given class by using Reflection.Returns the NodeType for java primitivesstatic boolean
introspected
(XMLClassDescriptor descriptor) Returns true if the given XMLClassDescriptor was created via introspectionstatic boolean
isCollection
(Class clazz) Returns true if the given Class is an instance of a collection class.static boolean
isMapCollection
(Class clazz) Returns true if the given Class is an instance of a collection class.static boolean
marshallable
(Class type) Returns true if the given Class can be marshalled.void
boolean
Removes the given FieldHandlerFactory from this Introspectorvoid
setInternalContext
(InternalContext internalContext) void
Sets the Naming conventions to be used by the Introspectorvoid
setPrimitiveNodeType
(NodeType nodeType) Sets the NodeType for primitives.void
setSaveMapKeys
(boolean saveMapKeys) Sets whether or not keys from Hastable / Map instances should be saved in the XML.void
setWrapCollections
(boolean wrapCollections) Sets whether or not collections (arrays, vectors, etc) should be wrapped in a container element.static String
toJavaName
(String name, boolean upperFirst) Converts the given xml name to a Java name.
-
Constructor Details
-
Introspector
public Introspector()Creates a new instance of the Introspector. -
Introspector
Creates a new instance of the Introspector.- Parameters:
classLoader
-
-
-
Method Details
-
setInternalContext
-
addFieldHandlerFactory
Registers the given "generalized" FieldHandlerFactory with this Introspector.- Parameters:
factory
- the FieldHandlerFactory to add to this introspector- Throws:
IllegalArgumentException
- if the given factory is null
-
getPrimitiveNodeType
Returns the NodeType for java primitives- Returns:
- the NodeType for java primitives
-
generateClassDescriptor
Creates an XMLClassDescriptor for the given class by using Reflection.- Parameters:
c
- the Class to create the XMLClassDescriptor for- Returns:
- the new XMLClassDescriptor created for the given class
- Throws:
MarshalException
- when an error occurs during the creation of the ClassDescriptor.
-
generateClassDescriptor
public XMLClassDescriptor generateClassDescriptor(Class c, PrintWriter errorWriter) throws MarshalException Creates an XMLClassDescriptor for the given class by using Reflection.- Parameters:
c
- the Class to create the XMLClassDescriptor forerrorWriter
- a PrintWriter to print error information to- Returns:
- the new XMLClassDescriptor created for the given class
- Throws:
MarshalException
- when an error occurs during the creation of the ClassDescriptor.
-
removeFieldHandlerFactory
Removes the given FieldHandlerFactory from this Introspector- Parameters:
factory
- the FieldHandlerFactory to remove- Returns:
- true if the given FieldHandlerFactory was removed, or false otherwise.
- Throws:
IllegalArgumentException
- if the given factory is null
-
setWrapCollections
public void setWrapCollections(boolean wrapCollections) Sets whether or not collections (arrays, vectors, etc) should be wrapped in a container element. For example:<foos> <foo>foo1</foo> <foo>foo2</foo> </foos> instead of the default: <foos>foo1<foos> <foos>foo2</foos>
- Parameters:
wrapCollections
- a boolean that when true indicates collections should be wrapped in a container element.
-
introspected
Returns true if the given XMLClassDescriptor was created via introspection -
marshallable
Returns true if the given Class can be marshalled.- Parameters:
type
- the Class to check marshallability for.- Returns:
- true if the given Class can be marshalled.
-
setNaming
Sets the Naming conventions to be used by the Introspector- Parameters:
naming
- the implementation of Naming to use. A value of null, will reset the XMLNaming to the default specified in the castor.properties file.
-
setPrimitiveNodeType
Sets the NodeType for primitives. If the NodeType is NodeType.Element, all primitives will be treated as Elements, otherwise all primitives will be treated as Attributes.- Parameters:
nodeType
- the NodeType to use for primitive values.
-
setSaveMapKeys
public void setSaveMapKeys(boolean saveMapKeys) Sets whether or not keys from Hastable / Map instances should be saved in the XML.Note: This is true by default since Castor 0.9.5.3
- Parameters:
saveMapKeys
- a boolean that when true indicates keys from Hashtable or Map instances should be saved. Otherwise only the value object is saved.
-
toJavaName
-
isCollection
Returns true if the given Class is an instance of a collection class. -
isMapCollection
Returns true if the given Class is an instance of a collection class. -
propertyChange
- Specified by:
propertyChange
in interfacePropertyChangeListener
-