|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.andromda.core.common.XmlObjectFactory
public class XmlObjectFactory
Creates and returns Objects based on a set of Apache Digester rules in a consistent manner, providing validation in the process.
This XML object factory allows us to define a consistent/clean of configuring java objects from XML configuration files (i.e. it uses the class name of the java object to find what rule file and what XSD file to use). It also allows us to define a consistent way in which schema validation is performed.
It seperates each concern into one file, for example: to configure and perform validation on the MetafacadeMappings class, we need 3 files 1.) the java object (MetafacadeMappings.java), 2.) the rules file which tells the apache digester how to populate the java object from the XML configuration file (MetafacadeMappings-Rules.xml), and 3.) the XSD schema validation file (MetafacadeMappings.xsd). Note that each file is based on the name of the java object: 'java object name'.xsd and 'java object name'-Rules.xml'. After you have these three files then you just need to call the method #getInstance(java.net.URL objectClass) in this class from the java object you want to configure. This keeps the dependency to digester (or whatever XML configuration tool we are using at the time) to this single file.
In order to add/modify an existing element/attribute in your configuration file, first make the modification in your java object, then modify it's rules file to instruct the digester on how to configure your new attribute/method in the java object, and then modify your XSD file to provide correct validation for this new method/attribute. Please see the org.andromda.core.metafacade.MetafacadeMappings* files for an example on how to do this.
| Field Summary | |
|---|---|
protected java.lang.String |
JAXP_SCHEMA_LANGUAGE
The JAXP 1.2 property to set up the schemaLanguage used. |
protected static java.lang.String |
JAXP_SCHEMA_SOURCE
The JAXP 1.2 property required to set up the schema location. |
protected static org.apache.log4j.Logger |
logger
The class logger. |
| Method Summary | |
|---|---|
static XmlObjectFactory |
getInstance(java.lang.Class objectClass)
Gets an instance of this XmlObjectFactory using the digester rules belonging to the objectClass. |
java.lang.Object |
getObject(java.io.Reader objectXml)
Returns a configured Object based on the objectXml configuration reader. |
java.lang.Object |
getObject(java.lang.String objectXml)
Returns a configured Object based on the objectXml configuration file passed in as a String. |
java.lang.Object |
getObject(java.lang.String objectXml,
java.net.URL resource)
Returns a configured Object based on the objectXml configuration file passed in as a String. |
java.lang.Object |
getObject(java.net.URL objectXml)
Returns a configured Object based on the objectXml configuration file |
static void |
setDefaultValidating(boolean validating)
Allows us to set default validation to true/false for all instances of objects instantiated by this factory. |
void |
setValidating(boolean validating)
Sets whether or not the XmlObjectFactory should be validating, default is true. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final org.apache.log4j.Logger logger
XmlObjectValidator
protected static final java.lang.String JAXP_SCHEMA_SOURCE
protected java.lang.String JAXP_SCHEMA_LANGUAGE
| Method Detail |
|---|
public static XmlObjectFactory getInstance(java.lang.Class objectClass)
objectClass.
objectClass - the Class of the object from which to configure this factory.
public static void setDefaultValidating(boolean validating)
validating - true/falsepublic void setValidating(boolean validating)
true. If it IS set to be
validating, then there needs to be a schema named objectClass.xsd in the same package as the objectClass that
this factory was created from.
validating - true/falsepublic java.lang.Object getObject(java.net.URL objectXml)
objectXml - the path to the Object XML config file.
public java.lang.Object getObject(java.io.Reader objectXml)
objectXml - the path to the Object XML config file.
public java.lang.Object getObject(java.lang.String objectXml)
objectXml - the path to the Object XML config file.
public java.lang.Object getObject(java.lang.String objectXml,
java.net.URL resource)
objectXml - the path to the Object XML config file.resource - the resource from which the objectXml was retrieved (this is needed to resolve
any relative references; like XML entities).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||