org.apache.jdo.impl.model.java
Class AbstractJavaModel

java.lang.Object
  extended byorg.apache.jdo.impl.model.java.AbstractJavaModel
All Implemented Interfaces:
JavaModel
Direct Known Subclasses:
ReflectionJavaModel

public abstract class AbstractJavaModel
extends java.lang.Object
implements JavaModel

Abstract super class for JavaModel implementations. It implements the jdoModel property and the parent/child relationship between javaModels. It also provides a map of types managed by this JavaModel (see types). The AbstractJavaModel constructor automatically adds all the predefined types to this map.

A non-abstract subclass must implement methods getJavaType(String name) and getInputStreamForResource(String resourceName).

Since:
JDO 1.0.1
Author:
Michael Bouschen

Field Summary
protected  java.util.Set children
          The child JavaModels.
protected  JDOModel jdoModel
          The corresponding JDOModel instance.
protected  JavaModel parent
          The parent JavaModel.
protected  java.util.Map types
          Map of known JavaTypes.
 
Constructor Summary
protected AbstractJavaModel()
          Constructor.
 
Method Summary
 JavaModel[] getChildren()
          Returns a collection of child JavaModel instances in the form of an array.
abstract  java.io.InputStream getInputStreamForResource(java.lang.String resourceName)
          Finds a resource with a given name.
 JavaType getJavaType(java.lang.Class clazz)
          The method returns the JavaType instance for the type name of the specified class object.
abstract  JavaType getJavaType(java.lang.String name)
          The method returns the JavaType instance for the specified type name.
 JDOModel getJDOModel()
          Returns the corresponding JDOModel instance.
 JavaModel getParent()
          Returns the parent JavaModel instance of this JavaModel.
 void setJDOModel(JDOModel jdoModel)
          Sets the corresponding JDOModel instance.
 void setParent(JavaModel parent)
          Set the parent JavaModel for this JavaModel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

types

protected java.util.Map types
Map of known JavaTypes. Key is the type name as a string.


parent

protected JavaModel parent
The parent JavaModel.


children

protected java.util.Set children
The child JavaModels.


jdoModel

protected JDOModel jdoModel
The corresponding JDOModel instance.

Constructor Detail

AbstractJavaModel

protected AbstractJavaModel()
Constructor. It adds all predefined types to the cache of types known by this model instance.

See Also:
PredefinedType
Method Detail

getJavaType

public abstract JavaType getJavaType(java.lang.String name)
The method returns the JavaType instance for the specified type name. A type name is unique within one JavaModel instance. The method returns null if this model instance does not know a type with the specified name.

Specified by:
getJavaType in interface JavaModel
Parameters:
name - the name of the type
Returns:
a JavaType instance for the specified name or null if not present in this model instance.

getJavaType

public JavaType getJavaType(java.lang.Class clazz)
The method returns the JavaType instance for the type name of the specified class object. This is a convenience method for getJavaType(clazz.getName()). The major difference between this method and getJavaType taking a type name is that this method is supposed to return a non-null value. The specified class object describes an existing type.

Specified by:
getJavaType in interface JavaModel
Parameters:
clazz - the Class instance representing the type
Returns:
a JavaType instance for the name of the specified class object.

getInputStreamForResource

public abstract java.io.InputStream getInputStreamForResource(java.lang.String resourceName)
Finds a resource with a given name. A resource is some data that can be accessed by class code in a way that is independent of the location of the code. The name of a resource is a "/"-separated path name that identifies the resource. The method method opens the resource for reading and returns an InputStream. It returns null if no resource with this name is found or if the caller doesn't have adequate privileges to get the resource.

Specified by:
getInputStreamForResource in interface JavaModel
Parameters:
resourceName - the resource name
Returns:
an input stream for reading the resource, or null if the resource could not be found or if the caller doesn't have adequate privileges to get the resource.

getParent

public JavaModel getParent()
Returns the parent JavaModel instance of this JavaModel.

Specified by:
getParent in interface JavaModel
Returns:
the parent JavaModel

setParent

public void setParent(JavaModel parent)
               throws ModelException
Set the parent JavaModel for this JavaModel. The method automatically adds this JavaModel to the collection of children of the specified parent JavaModel.

Specified by:
setParent in interface JavaModel
Parameters:
parent - the parent JavaModel
Throws:
ModelException - if impossible

getChildren

public JavaModel[] getChildren()
Returns a collection of child JavaModel instances in the form of an array. All instances from the returned array have this JavaModel instance as parent.

Specified by:
getChildren in interface JavaModel
Returns:
the child JavaModel instances

getJDOModel

public JDOModel getJDOModel()
Returns the corresponding JDOModel instance.

Specified by:
getJDOModel in interface JavaModel
Returns:
the corresponding JDOModel.

setJDOModel

public void setJDOModel(JDOModel jdoModel)
                 throws ModelException
Sets the corresponding JDOModel instance.

Specified by:
setJDOModel in interface JavaModel
Parameters:
jdoModel - the JDOModel instance
Throws:
ModelException - if impossible


Copyright © 2005 Apache Software Foundation. All Rights Reserved.