Package org.exolab.castor.xml
Class XMLContext
- java.lang.Object
-
- org.exolab.castor.xml.XMLContext
-
public class XMLContext extends java.lang.ObjectBootstrap class for Castor XML that allows you to load information about the domain objects used with Castor XML (marshallers and unmarshallers) by various means.- Since:
- 1.1.2
- Author:
- Werner Guttmann
-
-
Constructor Summary
Constructors Constructor Description XMLContext()Creates an instance ofXMLContextwith an internal XML context.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddClass(java.lang.Class clazz)Loads the class descriptor for the class instance specified.voidaddClasses(java.lang.Class[] clazzes)Loads the class descriptor for the class instance specified.voidaddMapping(Mapping mapping)Instructs Castor to load class descriptors from the mapping given.voidaddPackage(java.lang.String packageName)Loads class descriptors from the package specified.voidaddPackages(java.lang.String[] packageNames)Loads class descriptors from the packages specified.ChangeLog2XMLcreateChangeLog2XML()To create a newChangeLog2XMLinstance.MappingcreateMapping()Creates an instance of a Castor XML specificMappinginstance.MappingToolcreateMappingTool()To create a MappingTool instance.MarshallercreateMarshaller()Creates a newMarshallerinstance to be used for marshalling.UnmarshallercreateUnmarshaller()Creates a newUnmarshallerinstance to be used for unmarshalling.InternalContextgetInternalContext()Deprecated.java.lang.ObjectgetProperty(java.lang.String propertyName)To get the value of a specific property.voidsetClassLoader(java.lang.ClassLoader classLoader)Sets a customClassLoaderto be used for loading classes.voidsetProperty(java.lang.String propertyName, boolean value)To set properties for marshalling and unmarshalling behavior.voidsetProperty(java.lang.String propertyName, java.lang.Object value)To set properties for marshalling and unmarshalling behavior.
-
-
-
Constructor Detail
-
XMLContext
public XMLContext()
Creates an instance ofXMLContextwith an internal XML context.
-
-
Method Detail
-
addMapping
public void addMapping(Mapping mapping) throws MappingException
Instructs Castor to load class descriptors from the mapping given.- Parameters:
mapping- Castor XML mapping (file), from which the required class descriptors will be derived.- Throws:
MappingException- If theMappingcannot be loaded and analyzed successfully.
-
addClass
public void addClass(java.lang.Class clazz) throws ResolverExceptionLoads the class descriptor for the class instance specified. The use of this method is useful when no mapping is used, as happens when the domain classes has been generated using the XML code generator (in which case instead of a mapping file class descriptor files will be generated).- Parameters:
clazz- the class for which the associated descriptor should be loaded.- Throws:
ResolverException- in case that resolving the Class fails fatally
-
addClasses
public void addClasses(java.lang.Class[] clazzes) throws ResolverExceptionLoads the class descriptor for the class instance specified. The use of this method is useful when no mapping is used, as happens when the domain classes hase been generated using the XML code generator (in which case instead of a mapping file class descriptor files will be generated).- Parameters:
clazzes- the classes for which the associated descriptor should be loaded.- Throws:
ResolverException- in case that resolving the Class fails fatally
-
addPackage
public void addPackage(java.lang.String packageName) throws ResolverExceptionLoads class descriptors from the package specified. The use of this method is useful when no mapping is used, as happens when the domain classes hase been generated using the XML code generator (in which case instead of a mapping file class descriptor files will be generated).Please note that this functionality will work only if you provide the .castor.cdr file with your generated classes (as generated by the XML code generator).
- Parameters:
packageName- The package name for the (descriptor) classes- Throws:
ResolverException- If there's a problem loading class descriptors for the given package.
-
addPackages
public void addPackages(java.lang.String[] packageNames) throws ResolverExceptionLoads class descriptors from the packages specified. The use of this method is useful when no mapping is used, as happens when the domain classes hase been generated using the XML code generator (in which case instead of a mapping file class descriptor files will be generated).Please note that this functionality will work only if you provide the .castor.cdr files with your generated classes (as generated by the XML code generator).
- Parameters:
packageNames- The package names for the (descriptor) classes- Throws:
ResolverException- If there's a problem loading class descriptors for the given package.
-
createMapping
public Mapping createMapping()
Creates an instance of a Castor XML specificMappinginstance.- Returns:
- a Castor XML specific
Mappinginstance.
-
createMarshaller
public Marshaller createMarshaller()
Creates a newMarshallerinstance to be used for marshalling.- Returns:
- A new
Marshallerinstance.
-
createUnmarshaller
public Unmarshaller createUnmarshaller()
Creates a newUnmarshallerinstance to be used for unmarshalling.- Returns:
- A new
Unmarshallerinstance, preconfigured with aXMLClassDescriptorResolverinstance with the class descriptors cached as loaded above.
-
createMappingTool
public MappingTool createMappingTool()
To create a MappingTool instance.- Returns:
- the MappingTool instance ready to use
-
createChangeLog2XML
public ChangeLog2XML createChangeLog2XML()
To create a newChangeLog2XMLinstance.- Returns:
- the
ChangeLog2XMLinstance ready to use
-
setProperty
public void setProperty(java.lang.String propertyName, java.lang.Object value)To set properties for marshalling and unmarshalling behavior.- Parameters:
propertyName- name of the property to setvalue- the value to set to
-
setProperty
public void setProperty(java.lang.String propertyName, boolean value)To set properties for marshalling and unmarshalling behavior.- Parameters:
propertyName- name of the property to setvalue- the value to set to
-
getProperty
public java.lang.Object getProperty(java.lang.String propertyName)
To get the value of a specific property.- Parameters:
propertyName- name of the Property- Returns:
- the value (Object) of the property
-
getInternalContext
public InternalContext getInternalContext()
Deprecated.To get theInternalContextas used when instantiating other classes. Mind that this method is only used in tests and should NOT be used in production code!- Returns:
- the
InternalContextused
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
Sets a customClassLoaderto be used for loading classes.- Parameters:
classLoader- A customClassLoader.
-
-