org.jomc.modlet
Class ModelContext

Package class diagram package ModelContext
java.lang.Object
  extended by org.jomc.modlet.ModelContext
Direct Known Subclasses:
DefaultModelContext

public abstract class ModelContext
extends Object

Model context interface.

Use Cases:

Version:
$JOMC: ModelContext.java 4256 2012-02-13 06:32:10Z schulte2005 $
Author:
Christian Schulte
See Also:
ModelContextFactory

Nested Class Summary
static class ModelContext.Listener
          Listener interface.
 
Constructor Summary
ModelContext()
          Creates a new ModelContext instance.
ModelContext(ClassLoader classLoader)
          Creates a new ModelContext instance taking a class loader.
 
Method Summary
 void clearAttribute(String name)
          Removes an attribute from the context.
abstract  javax.xml.bind.JAXBContext createContext(String model)
          Creates a new JAXB context instance of a given model.
abstract  javax.xml.bind.JAXBContext createContext(URI publicId)
          Creates a new JAXB context instance for a given public identifier URI.
abstract  EntityResolver createEntityResolver(String model)
          Creates a new SAX entity resolver instance of a given model.
abstract  EntityResolver createEntityResolver(URI publicId)
          Creates a new SAX entity resolver instance for a given public identifier URI.
abstract  javax.xml.bind.Marshaller createMarshaller(String model)
          Creates a new JAXB marshaller instance of a given model.
abstract  javax.xml.bind.Marshaller createMarshaller(URI publicId)
          Creates a new JAXB marshaller instance for a given public identifier URI.
static ModelContext createModelContext(ClassLoader classLoader)
          Deprecated. As of JOMC 1.2, replaced by method ModelContextFactory.newModelContext(java.lang.ClassLoader). This method will be removed in version 2.0.
abstract  LSResourceResolver createResourceResolver(String model)
          Creates a new L/S resource resolver instance of a given model.
abstract  LSResourceResolver createResourceResolver(URI publicId)
          Creates a new L/S resource resolver instance for a given public identifier URI.
abstract  Schema createSchema(String model)
          Creates a new JAXP schema instance of a given model.
abstract  Schema createSchema(URI publicId)
          Creates a new JAXP schema instance for a given public identifier URI.
abstract
<T> T
createServiceObject(Service service, Class<T> type)
          Creates a new service object.
abstract  javax.xml.bind.Unmarshaller createUnmarshaller(String model)
          Creates a new JAXB unmarshaller instance of a given model.
abstract  javax.xml.bind.Unmarshaller createUnmarshaller(URI publicId)
          Creates a new JAXB unmarshaller instance for a given given public identifier URI.
 Class<?> findClass(String name)
          Searches the context for a class with a given name.
abstract  Model findModel(Model model)
          Populates a given Model instance.
abstract  Model findModel(String model)
          Creates a new Model instance.
abstract  Modlets findModlets()
          Searches the context for Modlets.
 URL findResource(String name)
          Searches the context for a resource with a given name.
 Enumeration<URL> findResources(String name)
          Searches the context for resources with a given name.
 Object getAttribute(String name)
          Gets an attribute of the context.
 Object getAttribute(String name, Object def)
          Gets an attribute of the context.
 Set<String> getAttributeNames()
          Gets a set holding the names of all attributes of the context.
 ClassLoader getClassLoader()
          Gets the class loader of the context.
static Level getDefaultLogLevel()
          Gets the default log level events are logged at.
static String getDefaultModletSchemaSystemId()
          Gets the default http://jomc.org/modlet namespace schema system id.
 List<ModelContext.Listener> getListeners()
          Gets the listeners of the context.
 Level getLogLevel()
          Gets the log level of the context.
static String getModelContextClassName()
          Deprecated. As of JOMC 1.2, replaced by class ModelContextFactory. This method will be removed in version 2.0.
 Modlets getModlets()
          Gets the Modlets of the context.
 String getModletSchemaSystemId()
          Gets the http://jomc.org/modlet namespace schema system id of the context.
 boolean isLoggable(Level level)
          Checks if a message at a given level is provided to the listeners of the context.
 void log(Level level, String message, Throwable throwable)
          Notifies all listeners of the context.
abstract  Model processModel(Model model)
          Processes a Model.
 Object setAttribute(String name, Object value)
          Sets an attribute in the context.
static void setDefaultLogLevel(Level value)
          Sets the default log level events are logged at.
static void setDefaultModletSchemaSystemId(String value)
          Sets the default http://jomc.org/modlet namespace schema system id.
 void setLogLevel(Level value)
          Sets the log level of the context.
static void setModelContextClassName(String value)
          Deprecated. As of JOMC 1.2, replaced by class ModelContextFactory. This method will be removed in version 2.0.
 void setModlets(Modlets value)
          Sets the Modlets of the context.
 void setModletSchemaSystemId(String value)
          Sets the http://jomc.org/modlet namespace schema system id of the context.
abstract  ModelValidationReport validateModel(Model model)
          Validates a given Model.
abstract  ModelValidationReport validateModel(String model, Source source)
          Validates a given model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelContext

public ModelContext()
Creates a new ModelContext instance.

Since:
1.2

ModelContext

public ModelContext(ClassLoader classLoader)
Creates a new ModelContext instance taking a class loader.

Parameters:
classLoader - The class loader of the context.
See Also:
getClassLoader()
Method Detail

getAttributeNames

public Set<String> getAttributeNames()
Gets a set holding the names of all attributes of the context.

Returns:
An unmodifiable set holding the names of all attributes of the context.
Since:
1.2
See Also:
clearAttribute(java.lang.String), getAttribute(java.lang.String), getAttribute(java.lang.String, java.lang.Object), setAttribute(java.lang.String, java.lang.Object)

getAttribute

public Object getAttribute(String name)
Gets an attribute of the context.

Parameters:
name - The name of the attribute to get.
Returns:
The value of the attribute with name name; null if no attribute matching name is found.
Throws:
NullPointerException - if name is null.
See Also:
getAttribute(java.lang.String, java.lang.Object), setAttribute(java.lang.String, java.lang.Object), clearAttribute(java.lang.String)

getAttribute

public Object getAttribute(String name,
                           Object def)
Gets an attribute of the context.

Parameters:
name - The name of the attribute to get.
def - The value to return if no attribute matching name is found.
Returns:
The value of the attribute with name name; def if no such attribute is found.
Throws:
NullPointerException - if name is null.
See Also:
getAttribute(java.lang.String), setAttribute(java.lang.String, java.lang.Object), clearAttribute(java.lang.String)

setAttribute

public Object setAttribute(String name,
                           Object value)
Sets an attribute in the context.

Parameters:
name - The name of the attribute to set.
value - The value of the attribute to set.
Returns:
The previous value of the attribute with name name; null if no such value is found.
Throws:
NullPointerException - if name or value is null.
See Also:
getAttribute(java.lang.String), getAttribute(java.lang.String, java.lang.Object), clearAttribute(java.lang.String)

clearAttribute

public void clearAttribute(String name)
Removes an attribute from the context.

Parameters:
name - The name of the attribute to remove.
Throws:
NullPointerException - if name is null.
See Also:
getAttribute(java.lang.String), getAttribute(java.lang.String, java.lang.Object), setAttribute(java.lang.String, java.lang.Object)

getClassLoader

public ClassLoader getClassLoader()
Gets the class loader of the context.

Returns:
The class loader of the context or null, indicating the bootstrap class loader.
See Also:
findClass(java.lang.String), findResource(java.lang.String), findResources(java.lang.String)

getListeners

public List<ModelContext.Listener> getListeners()
Gets the listeners of the context.

This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the object. This is why there is no set method for the listeners property.

Returns:
The list of listeners of the context.
See Also:
log(java.util.logging.Level, java.lang.String, java.lang.Throwable)

getDefaultModletSchemaSystemId

public static String getDefaultModletSchemaSystemId()
Gets the default http://jomc.org/modlet namespace schema system id.

The default http://jomc.org/modlet namespace schema system id is controlled by system property org.jomc.modlet.ModelContext.defaultModletSchemaSystemId holding a system id URI. If that property is not set, the http://jomc.sourceforge.net/modlet/jomc-modlet-1.2.xsd default is returned.

Returns:
The default system id of the http://jomc.org/modlet namespace schema.
See Also:
setDefaultModletSchemaSystemId(java.lang.String)

setDefaultModletSchemaSystemId

public static void setDefaultModletSchemaSystemId(String value)
Sets the default http://jomc.org/modlet namespace schema system id.

Parameters:
value - The new default http://jomc.org/modlet namespace schema system id or null.
See Also:
getDefaultModletSchemaSystemId()

getModletSchemaSystemId

public final String getModletSchemaSystemId()
Gets the http://jomc.org/modlet namespace schema system id of the context.

Returns:
The http://jomc.org/modlet namespace schema system id of the context.
See Also:
getDefaultModletSchemaSystemId(), setModletSchemaSystemId(java.lang.String)

setModletSchemaSystemId

public final void setModletSchemaSystemId(String value)
Sets the http://jomc.org/modlet namespace schema system id of the context.

Parameters:
value - The new http://jomc.org/modlet namespace schema system id or null.
See Also:
getModletSchemaSystemId()

getDefaultLogLevel

public static Level getDefaultLogLevel()
Gets the default log level events are logged at.

The default log level is controlled by system property org.jomc.modlet.ModelContext.defaultLogLevel holding the log level to log events at by default. If that property is not set, the WARNING default is returned.

Returns:
The log level events are logged at by default.
See Also:
getLogLevel(), Level.parse(java.lang.String)

setDefaultLogLevel

public static void setDefaultLogLevel(Level value)
Sets the default log level events are logged at.

Parameters:
value - The new default level events are logged at or null.
See Also:
getDefaultLogLevel()

getLogLevel

public final Level getLogLevel()
Gets the log level of the context.

Returns:
The log level of the context.
See Also:
getDefaultLogLevel(), setLogLevel(java.util.logging.Level), isLoggable(java.util.logging.Level)

setLogLevel

public final void setLogLevel(Level value)
Sets the log level of the context.

Parameters:
value - The new log level of the context or null.
See Also:
getLogLevel(), isLoggable(java.util.logging.Level)

isLoggable

public boolean isLoggable(Level level)
Checks if a message at a given level is provided to the listeners of the context.

Parameters:
level - The level to test.
Returns:
true, if messages at level are provided to the listeners of the context; false, if messages at level are not provided to the listeners of the context.
Throws:
NullPointerException - if level is null.
See Also:
getLogLevel(), setLogLevel(java.util.logging.Level)

log

public void log(Level level,
                String message,
                Throwable throwable)
Notifies all listeners of the context.

Parameters:
level - The level of the event.
message - The message of the event or null.
throwable - The throwable of the event null.
Throws:
NullPointerException - if level is null.
See Also:
getListeners(), isLoggable(java.util.logging.Level)

getModlets

public final Modlets getModlets()
                         throws ModelException
Gets the Modlets of the context.

If no Modlets have been set using the setModlets method, this method calls the findModlets method to initialize the Modlets of the context.

This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the object.

Returns:
The Modlets of the context.
Throws:
ModelException - if getting the Modlets of the context fails.
See Also:
setModlets(org.jomc.modlet.Modlets), findModlets()

setModlets

public final void setModlets(Modlets value)
Sets the Modlets of the context.

Parameters:
value - The new Modlets of the context or null.
See Also:
getModlets()

findClass

public Class<?> findClass(String name)
                   throws ModelException
Searches the context for a class with a given name.

Parameters:
name - The name of the class to search.
Returns:
A class object of the class with name name or null, if no such class is found.
Throws:
NullPointerException - if name is null.
ModelException - if searching fails.
See Also:
getClassLoader()

findResource

public URL findResource(String name)
                 throws ModelException
Searches the context for a resource with a given name.

Parameters:
name - The name of the resource to search.
Returns:
An URL object for reading the resource or null, if no such resource is found.
Throws:
NullPointerException - if name is null.
ModelException - if searching fails.
See Also:
getClassLoader()

findResources

public Enumeration<URL> findResources(String name)
                               throws ModelException
Searches the context for resources with a given name.

Parameters:
name - The name of the resources to search.
Returns:
An enumeration of URL objects for reading the resources. If no resources are found, the enumeration will be empty.
Throws:
NullPointerException - if name is null.
ModelException - if searching fails.
See Also:
getClassLoader()

findModlets

public abstract Modlets findModlets()
                             throws ModelException
Searches the context for Modlets.

Returns:
The Modlets found in the context.
Throws:
ModelException - if searching Modlets fails.
See Also:
META-INF/services/org.jomc.modlet.ModletProvider, getModlets()

findModel

public abstract Model findModel(String model)
                         throws ModelException
Creates a new Model instance.

Parameters:
model - The identifier of the Model to create.
Returns:
A new instance of the Model identified by model.
Throws:
NullPointerException - if model is null.
ModelException - if creating a new Model instance fails.
See Also:
createServiceObject( service, ModelProvider.class ), ModletObject.MODEL_PUBLIC_ID

findModel

public abstract Model findModel(Model model)
                         throws ModelException
Populates a given Model instance.

Parameters:
model - The Model to populate.
Returns:
The populated model.
Throws:
NullPointerException - if model is null.
ModelException - if populating model fails.
Since:
1.2
See Also:
createServiceObject( service, ModelProvider.class )

getModelContextClassName

@Deprecated
public static String getModelContextClassName()
Deprecated. As of JOMC 1.2, replaced by class ModelContextFactory. This method will be removed in version 2.0.

Gets the name of the class providing the default ModelContext implementation.

The name of the class providing the default ModelContext implementation returned by method createModelContext(java.lang.ClassLoader) is controlled by system property org.jomc.modlet.ModelContext.className. If that property is not set, the name of the DefaultModelContext class is returned.

Returns:
The name of the class providing the default ModelContext implementation.
See Also:
setModelContextClassName(java.lang.String)

setModelContextClassName

@Deprecated
public static void setModelContextClassName(String value)
Deprecated. As of JOMC 1.2, replaced by class ModelContextFactory. This method will be removed in version 2.0.

Sets the name of the class providing the default ModelContext implementation.

Parameters:
value - The new name of the class providing the default ModelContext implementation or null.
See Also:
getModelContextClassName()

createModelContext

public static ModelContext createModelContext(ClassLoader classLoader)
                                       throws ModelException
Deprecated. As of JOMC 1.2, replaced by method ModelContextFactory.newModelContext(java.lang.ClassLoader). This method will be removed in version 2.0.

Creates a new default ModelContext instance.

Parameters:
classLoader - The class loader to create a new default ModelContext instance with or null, to create a new context using the platform's bootstrap class loader.
Returns:
A new ModelContext instance.
Throws:
ModelException - if creating a new ModelContext instance fails.
See Also:
getModelContextClassName()

createServiceObject

public abstract <T> T createServiceObject(Service service,
                                          Class<T> type)
                               throws ModelException
Creates a new service object.

Type Parameters:
T - The type of the service.
Parameters:
service - The service to create a new object of.
type - The class of the type of the service.
Returns:
An new service object for service.
Throws:
NullPointerException - if service or type is null.
ModelException - if creating the service object fails.
Since:
1.2
See Also:
ModelProvider, ModelProcessor, ModelValidator

createEntityResolver

public abstract EntityResolver createEntityResolver(String model)
                                             throws ModelException
Creates a new SAX entity resolver instance of a given model.

Parameters:
model - The identifier of the model to create a new SAX entity resolver of.
Returns:
A new SAX entity resolver instance of the model identified by model.
Throws:
NullPointerException - if model is null.
ModelException - if creating a new SAX entity resolver instance fails.
See Also:
ModletObject.MODEL_PUBLIC_ID

createEntityResolver

public abstract EntityResolver createEntityResolver(URI publicId)
                                             throws ModelException
Creates a new SAX entity resolver instance for a given public identifier URI.

Parameters:
publicId - The public identifier URI to create a new SAX entity resolver for.
Returns:
A new SAX entity resolver instance for the public identifier URI publicId.
Throws:
NullPointerException - if publicId is null.
ModelException - if creating a new SAX entity resolver instance fails.
Since:
1.2
See Also:
ModletObject.PUBLIC_ID

createResourceResolver

public abstract LSResourceResolver createResourceResolver(String model)
                                                   throws ModelException
Creates a new L/S resource resolver instance of a given model.

Parameters:
model - The identifier of the model to create a new L/S resource resolver of.
Returns:
A new L/S resource resolver instance of the model identified by model.
Throws:
NullPointerException - if model is null.
ModelException - if creating a new L/S resource resolver instance fails.
See Also:
ModletObject.MODEL_PUBLIC_ID

createResourceResolver

public abstract LSResourceResolver createResourceResolver(URI publicId)
                                                   throws ModelException
Creates a new L/S resource resolver instance for a given public identifier URI.

Parameters:
publicId - The public identifier URI to create a new L/S resource resolver for.
Returns:
A new L/S resource resolver instance for the public identifier URI publicId.
Throws:
NullPointerException - if publicId is null.
ModelException - if creating a new L/S resource resolver instance fails.
Since:
1.2
See Also:
ModletObject.PUBLIC_ID

createSchema

public abstract Schema createSchema(String model)
                             throws ModelException
Creates a new JAXP schema instance of a given model.

Parameters:
model - The identifier of the model to create a new JAXP schema instance of.
Returns:
A new JAXP schema instance of the model identified by model.
Throws:
NullPointerException - if model is null.
ModelException - if creating a new JAXP schema instance fails.
See Also:
ModletObject.MODEL_PUBLIC_ID

createSchema

public abstract Schema createSchema(URI publicId)
                             throws ModelException
Creates a new JAXP schema instance for a given public identifier URI.

Parameters:
publicId - The public identifier URI to create a new JAXP schema instance for.
Returns:
A new JAXP schema instance for the public identifier URI publicId.
Throws:
NullPointerException - if publicId is null.
ModelException - if creating a new JAXP schema instance fails.
Since:
1.2
See Also:
ModletObject.PUBLIC_ID

createContext

public abstract javax.xml.bind.JAXBContext createContext(String model)
                                                  throws ModelException
Creates a new JAXB context instance of a given model.

Parameters:
model - The identifier of the model to create a new JAXB context instance of.
Returns:
A new JAXB context instance of the model identified by model.
Throws:
NullPointerException - if model is null.
ModelException - if creating a new JAXB context instance fails.
See Also:
ModletObject.MODEL_PUBLIC_ID

createContext

public abstract javax.xml.bind.JAXBContext createContext(URI publicId)
                                                  throws ModelException
Creates a new JAXB context instance for a given public identifier URI.

Parameters:
publicId - The public identifier URI to create a new JAXB context instance for.
Returns:
A new JAXB context instance for the public identifier URI publicId.
Throws:
NullPointerException - if publicId is null.
ModelException - if creating a new JAXB context instance fails.
Since:
1.2
See Also:
ModletObject.PUBLIC_ID

createMarshaller

public abstract javax.xml.bind.Marshaller createMarshaller(String model)
                                                    throws ModelException
Creates a new JAXB marshaller instance of a given model.

Parameters:
model - The identifier of the model to create a new JAXB marshaller instance of.
Returns:
A new JAXB marshaller instance of the model identified by model.
Throws:
NullPointerException - if model is null.
ModelException - if creating a new JAXB marshaller instance fails.
See Also:
ModletObject.MODEL_PUBLIC_ID

createMarshaller

public abstract javax.xml.bind.Marshaller createMarshaller(URI publicId)
                                                    throws ModelException
Creates a new JAXB marshaller instance for a given public identifier URI.

Parameters:
publicId - The public identifier URI to create a new JAXB marshaller instance for.
Returns:
A new JAXB marshaller instance for the public identifier URI publicId.
Throws:
NullPointerException - if publicId is null.
ModelException - if creating a new JAXB marshaller instance fails.
Since:
1.2
See Also:
ModletObject.PUBLIC_ID

createUnmarshaller

public abstract javax.xml.bind.Unmarshaller createUnmarshaller(String model)
                                                        throws ModelException
Creates a new JAXB unmarshaller instance of a given model.

Parameters:
model - The identifier of the model to create a new JAXB unmarshaller instance of.
Returns:
A new JAXB unmarshaller instance of the model identified by model.
Throws:
NullPointerException - if model is null.
ModelException - if creating a new JAXB unmarshaller instance fails.
See Also:
ModletObject.MODEL_PUBLIC_ID

createUnmarshaller

public abstract javax.xml.bind.Unmarshaller createUnmarshaller(URI publicId)
                                                        throws ModelException
Creates a new JAXB unmarshaller instance for a given given public identifier URI.

Parameters:
publicId - The public identifier URI to create a new JAXB unmarshaller instance for.
Returns:
A new JAXB unmarshaller instance for the public identifier URI publicId.
Throws:
NullPointerException - if publicId is null.
ModelException - if creating a new JAXB unmarshaller instance fails.
Since:
1.2
See Also:
ModletObject.PUBLIC_ID

processModel

public abstract Model processModel(Model model)
                            throws ModelException
Processes a Model.

Parameters:
model - The Model to process.
Returns:
The processed Model.
Throws:
NullPointerException - if model is null.
ModelException - if processing model fails.
See Also:
createServiceObject( service, ModelProcessor.class )

validateModel

public abstract ModelValidationReport validateModel(Model model)
                                             throws ModelException
Validates a given Model.

Parameters:
model - The Model to validate.
Returns:
Validation report.
Throws:
NullPointerException - if model is null.
ModelException - if validating the modules fails.
See Also:
createServiceObject( service, ModelValidator.class ), ModelValidationReport.isModelValid()

validateModel

public abstract ModelValidationReport validateModel(String model,
                                                    Source source)
                                             throws ModelException
Validates a given model.

Parameters:
model - The identifier of the Model to use for validating source.
source - A source providing the model to validate.
Returns:
Validation report.
Throws:
NullPointerException - if model or source is null.
ModelException - if validating the model fails.
See Also:
createSchema(java.lang.String), ModelValidationReport.isModelValid(), ModletObject.MODEL_PUBLIC_ID


Copyright © 2005-2012 The JOMC Project. All Rights Reserved.Get JOMC at SourceForge.net. Fast, secure and Free Open Source software downloads
Please note that this documentation is maintained by non-native english speaking authors. As such, you may encounter phrases or wordings which seem imprecise or may even have a totally different meaning to native english speaking readers than what the individual author was trying to express. If you are a native english speaking reader and find any such phrases or wordings we kindly ask you to send an email to the corresponding author and help us improve this documentation in order to avoid misunderstandings. You will find the authors' email addresses at the top of each class. Please accept our apologies for any inconvenience caused.