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

java.lang.Object
  extended by org.apache.jdo.impl.model.java.AbstractJavaModelFactory
All Implemented Interfaces:
JavaModelFactory
Direct Known Subclasses:
ReflectionJavaModelFactory

public abstract class AbstractJavaModelFactory
extends java.lang.Object
implements JavaModelFactory

Abstract super class for JavaModelFactory implementations. It provides a JavaModel cache and implements the JavaModel lookup method getJavaModel(Object key).

A non-abstract subclass must implement method createJavaModel(Object key). The lookup method calls this method if it cannot find a JavaModel instance in the cache. The method should also check whether the specified key is of an appropriate type for the JavaModelFactory implementation. A subclass should check whether it can implement method getJavaType(Object typeDesc). The implementation in AbstractJavaModelFactory always throws a ModelFatalException.

Since:
1.0.1
Version:
2.0
Author:
Michael Bouschen

Constructor Summary
AbstractJavaModelFactory()
           
 
Method Summary
abstract  JavaModel createJavaModel(java.lang.Object key)
          Creates a new empty JavaModel instance.
 JavaModel getJavaModel(java.lang.Object key)
          Returns the JavaModel instance for the specified key.
 JavaType getJavaType(java.lang.Object typeDesc)
          Returns a JavaType instance for the specified type description (optional operation).
 void removeJavaModel(JavaModel javaModel)
          Removes the specified javaModel from the JavaModel cache.
 void removeJavaModel(java.lang.Object key)
          Removes the JavaModel for the specified key from the JavaModel cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractJavaModelFactory

public AbstractJavaModelFactory()
Method Detail

createJavaModel

public abstract JavaModel createJavaModel(java.lang.Object key)
                                   throws ModelException
Creates a new empty JavaModel instance. A factory implementation may use the specified key when caching the new JavaModel instance.

Each JavaModelFactory imposes its own restrictions for the keys to cache JavaModel instances. Some implementation will allow only keys of a certain type. Some implementations will prohibit null keys. Attempting to use an ineligible key will result in a ModelException. This means the specified key is of an inappropriate type for this JavaModelFactory or if the key is null and this JavaModelFactory does not support null keys.

Specified by:
createJavaModel in interface JavaModelFactory
Parameters:
key - the key that may be used to cache the returned JavaModel instance.
Returns:
a new JavaModel instance.
Throws:
ModelException - if impossible; the key is of an inappropriate type or the key is null and this JavaModelFactory does not support null keys.

getJavaModel

public JavaModel getJavaModel(java.lang.Object key)
Returns the JavaModel instance for the specified key.

The method throws a ModelFatalException, if the specified key is of an inappropriate type for this JavaModelFactory or if the key is null and this JavaModelFactory does not support null keys.

Specified by:
getJavaModel in interface JavaModelFactory
Parameters:
key - the key used to cache the returned JavaModel instance.
Returns:
a JavaModel instance for the specified key.
Throws:
ModelFatalException - the key is of an inappropriate type or the key is null and this JavaModelFactory does not support null keys.

removeJavaModel

public void removeJavaModel(JavaModel javaModel)
Removes the specified javaModel from the JavaModel cache. Note, if there are multiple entries in the cache with the specified javaModel as value, then all of them get removed. The method does not have an effect, if this factory does not have the specified javaModel.

Specified by:
removeJavaModel in interface JavaModelFactory
Parameters:
javaModel - the JavaModel to be removed.
Since:
2.0

removeJavaModel

public void removeJavaModel(java.lang.Object key)
Removes the JavaModel for the specified key from the JavaModel cache. The method does not have an effect, if this factory does not have a JavaModel for the the specified key.

Specified by:
removeJavaModel in interface JavaModelFactory
Parameters:
key - the key used to find the JavaModel instance to be removed.
Since:
2.0

getJavaType

public JavaType getJavaType(java.lang.Object typeDesc)
Returns a JavaType instance for the specified type description (optional operation). This method is a convenience method and a short cut for getJavaModel(key).getJavaType(typeName). If the factory supports this method, it needs to be able to get the key for the JavaModel lookup and the type name for the JavaType lookup from the specified typeDesc. An example for such a type description is the java.lang.Class instance in the runtime environment.

The method throws a ModelFatalException, if this factory does not support this short cut or if it does not support the specified type description.

This implementation always throws a ModelFatalException.

Specified by:
getJavaType in interface JavaModelFactory
Parameters:
typeDesc - the type description.
Returns:
a JavaType instance for the specified type.
Throws:
ModelFatalException - this factory does not support this short cut or does not support the specified type description.


Copyright © 2005-2008 Apache Software Foundation. All Rights Reserved.