You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2005/05/25 15:22:13 UTC
svn commit: r178436 [2/2] - in /incubator/jdo/trunk:
core20/src/java/org/apache/jdo/impl/model/java/
core20/src/java/org/apache/jdo/impl/model/java/reflection/
core20/src/java/org/apache/jdo/model/java/
enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/ runtime20/
runtime20/src/java/org/apache/jdo/impl/model/java/runtime/
runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/
runtime20/src/java/org/apache/jdo/impl/model/jdo/xml/
Modified: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties (original)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties Wed May 25 06:22:12 2005
@@ -14,53 +14,18 @@
# limitations under the License.
#
-# Generic messages
-#
-
-# {0} - location (class.method)
-#NOI18N
-ERR_InvalidNullFieldInstance={0}: specified Field instance is null.
-
-
-# {0} - class name
-# {1} - detailed message of the cause
-EXC_ClassLoadingError=Error during loading of class ''{0}'': {1}.
-
-#
# RuntimeJavaModelFactory
#
EXC_CannotGetJDOImplHelper=A SecurityException was thrown when trying to get \
the singleton JDOImplHelper instance. In order to get runtime metadata, you \
must grant javax.jdo.spi.JDOPermission("getMetadata") to the codeBases \
-containing the JDO Reference Implementation (jdo.jar and jdori.jar).
+containing the JDO API and the JavaModel and JDOModel implementation.
EXC_CannotGetRuntimeJavaModelFactory=A SecurityException was thrown when trying \
to get the singleton RuntimeJavaModelFactory instance. In order to get runtime \
metadata, you must grant javax.jdo.spi.JDOPermission("getMetadata") to the \
-codeBases containing the JDO Reference Implementation (jdo.jar and jdori.jar).
-
-# {0} - class instance
-EXC_CannotGetClassLoader=A SecurityException was thrown when trying to get the \
-class loader of class instance ''{0}''. In order to get runtime metadata, you \
-must grant ReflectPermission("getClassLoader") to the codeBase containing the \
-JDO Reference Implementation (jdori.jar).
-
-# {0} - key instance
-EXC_InvalidJavaModelKey=Invalid key for runtime JavaModel lookup: \
-expected ''java.lang.ClassLoader'' instance, found ''{0}'' instance.
-
-# {0} - type description instance
-EXC_InvalidTypeDesc=Invalid type description for runtime JavaType lookup: \
-expected ''java.lang.Class'' instance, found ''{0}'' instance.
-
-# {0} - JavaType instance
-EXC_InvalidJavaType=Invalid JavaType instance for getJavaClass method: \
-expected ''org.apache.jdo.impl.model.java.ReflectionJavaType'' instance, \
-found ''{0}'' instance.
-
-#NOI18N
-ERR_CannotSetJDOModel=Cannot set JDOModel for JavaModel instance.
+codeBases containing the JDO API and the JavaModel and JDOModel implementation.
#
# RuntimeJavaType
Modified: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java (original)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java Wed May 25 06:22:12 2005
@@ -16,15 +16,8 @@
package org.apache.jdo.impl.model.java.runtime;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.io.InputStream;
-
import org.apache.jdo.impl.model.java.reflection.ReflectionJavaModel;
-import org.apache.jdo.model.ModelFatalException;
import org.apache.jdo.model.java.JavaType;
-import org.apache.jdo.model.jdo.JDOModel;
-import org.apache.jdo.util.I18NHelper;
/**
* A reflection based JavaModel implementation used at runtime.
@@ -38,34 +31,28 @@
*
* @author Michael Bouschen
* @since JDO 1.0.1
+ * @version JDO 2.0
*/
public class RuntimeJavaModel
extends ReflectionJavaModel
{
- /** Constructor taking the ClassLoader. */
- public RuntimeJavaModel(ClassLoader classLoader)
+ /** Constructor. */
+ public RuntimeJavaModel(ClassLoader classLoader,
+ RuntimeJavaModelFactory declaringJavaModelFactory)
{
- super(classLoader, true);
+ super(classLoader, declaringJavaModelFactory);
}
- /** */
- protected RuntimeJavaModel(ClassLoader classLoader, boolean initialize)
- {
- super(classLoader, initialize);
- }
-
/**
- * Creates a new JavaType instance for the specified Class object.
- * This method provides a hook such that RuntimeJavaModel subclasses
- * can create instances of a different JavaType implementation.
+ * Creates a new instance of the JavaType implementation class.
* <p>
* This implementation returns a RuntimeJavaType instance.
* @param clazz the Class instance representing the type
* @return a new JavaType instance
*/
- protected JavaType createJavaType(Class clazz)
+ protected JavaType newJavaTypeInstance(Class clazz)
{
- return new RuntimeJavaType(clazz, getJDOModel());
+ return new RuntimeJavaType(clazz, this);
}
}
Modified: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java (original)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java Wed May 25 06:22:12 2005
@@ -18,21 +18,14 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.lang.reflect.Field;
import javax.jdo.spi.JDOImplHelper;
import javax.jdo.spi.JDOPermission;
-import org.apache.jdo.model.ModelException;
import org.apache.jdo.model.ModelFatalException;
import org.apache.jdo.model.java.JavaModel;
import org.apache.jdo.model.java.JavaModelFactory;
-import org.apache.jdo.model.java.JavaType;
-import org.apache.jdo.model.jdo.JDOModelFactory;
-import org.apache.jdo.model.jdo.JDOModel;
-import org.apache.jdo.impl.model.java.AbstractJavaModelFactory;
-import org.apache.jdo.impl.model.java.BaseReflectionJavaType;
-import org.apache.jdo.impl.model.jdo.caching.JDOModelFactoryImplCaching;
+import org.apache.jdo.impl.model.java.reflection.ReflectionJavaModelFactory;
import org.apache.jdo.util.I18NHelper;
/**
@@ -50,9 +43,10 @@
*
* @author Michael Bouschen
* @since JDO 1.0.1
+ * @version JDO 2.0
*/
public class RuntimeJavaModelFactory
- extends AbstractJavaModelFactory
+ extends ReflectionJavaModelFactory
{
/** The singleton RuntimeJavaModelFactory instance. */
private static final RuntimeJavaModelFactory runtimeJavaModelFactory =
@@ -60,39 +54,18 @@
/** I18N support */
private final static I18NHelper msg =
- I18NHelper.getInstance("org.apache.jdo.impl.model.java.runtime.Bundle"); //NOI18N
-
- /** */
- static
- {
- // initialize RuntimeJavaModelFactory singleton instance
- try {
- JDOImplHelper helper =
- (JDOImplHelper) AccessController.doPrivileged(
- new PrivilegedAction () {
- public Object run () {
- return JDOImplHelper.getInstance();
- }
- }
- );
- // register listener to JDOImplHelpers class registration
- RegisterClassListener crl = new RegisterClassListener(
- helper, runtimeJavaModelFactory);
- helper.addRegisterClassListener(crl);
- }
- catch (SecurityException ex) {
- throw new ModelFatalException(
- msg.msg("EXC_CannotGetJDOImplHelper"), ex); // NOI18N
- }
- }
+ I18NHelper.getInstance(RuntimeJavaModelFactory.class);
/**
* Creates a new RuntimeJavaModelFactory. This constructor should not
* be called directly; instead, the singleton access method
* {@link #getInstance()} should be used.
*/
- protected RuntimeJavaModelFactory() {}
-
+ protected RuntimeJavaModelFactory()
+ {
+ registerFactory();
+ }
+
/**
* Returns the singleton instance of RuntimeJavaModelFactory. On first
* call it registers a model listener at the JDOImplHelper.
@@ -106,7 +79,23 @@
public static RuntimeJavaModelFactory getInstance()
throws ModelFatalException
{
- // first check whether caller has the getMetadata permission
+ checkPermission();
+ return runtimeJavaModelFactory;
+ }
+
+ //========= Internal helper methods ==========
+
+ /**
+ * This method checks that the caller is authorized for
+ * <code>JDOPermission("getMetadata")</code>, and if not, throws
+ * <code>ModelFatalException</code> wrapping the SecurityException.
+ * @throws ModelFatalException if the caller does not have the
+ * getMetadata permission.
+ */
+ protected static void checkPermission()
+ throws ModelFatalException
+ {
+ // check whether caller has the getMetadata permission
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
try {
@@ -118,173 +107,42 @@
msg.msg("EXC_CannotGetRuntimeJavaModelFactory"), ex); // NOI18N
}
}
-
- return runtimeJavaModelFactory;
}
- /**
- * Creates a new empty JavaModel instance. A factory implementation may
- * use the specified key when caching the new JavaModel instance.
- * <p>
- * This implementation only accepts <code>java.lang.ClassLoader</code>
- * instances as key and does not support <code>null</code> keys. A
- * ModelException indicates an invalid key.
- * <p>
- * The method automatically sets the parent/child relationship for the
- * created JavaModel according to the parent/child relationship of the
- * ClassLoader passed as key.
- * @param key the key that may be used to cache the returned JavaModel
- * instance.
- * @return a new JavaModel instance.
- * @exception ModelException if impossible; the key is of an
- * inappropriate type or the key is <code>null</code> and this
- * JavaModelFactory does not support <code>null</code> keys.
- */
- public JavaModel createJavaModel(Object key)
- throws ModelException
- {
- if ((key == null) || (!(key instanceof ClassLoader)))
- throw new ModelException(msg.msg("EXC_InvalidJavaModelKey", //NOI18N
- (key==null?"null":key.getClass().getName())));
-
- ClassLoader classLoader = (ClassLoader)key;
- JavaModel javaModel = new RuntimeJavaModel(classLoader);
-
- // check parent <-> child relationship
- if (classLoader != ClassLoader.getSystemClassLoader()) {
- // if the specified classLoader is not the system class loader
- // try to get the parent class loader and update the parent property
- try {
- ClassLoader parentClassLoader = classLoader.getParent();
- if (parentClassLoader != null) {
- javaModel.setParent(getJavaModel(parentClassLoader));
- }
- }
- catch (SecurityException ex) {
- // ignore => parentClassLoader and parent JavaModel are null
- }
- }
-
- // set the JDOModel property in JavaModel
- setJDOModelInternal(javaModel);
-
- return javaModel;
- }
-
- /**
- * Returns the JavaModel instance for the specified key.
- * @param key the key used to cache the returned JavaModel instance
- */
- public JavaModel getJavaModel(Object key)
- {
- if (key == null) {
- // null classLoader might happen for classes loaded by the
- // bootstrap class loder
- key = ClassLoader.getSystemClassLoader();
- }
- return super.getJavaModel(key);
- }
-
- /**
- * Returns a JavaType instance for the specified type description
- * (optional operation). This method is a convenience method and a
- * short cut for <code>getJavaModel(key).getJavaType(typeName)</code>.
- * <p>
- * The RuntimeJavaModelFactory supports this short cut and accepts
- * <code>java.lang.Class</code> instances as valid arguments for this
- * method. The method throws a
- * {@link org.apache.jdo.model.ModelFatalException}, if the specified
- * type descriptor is not a <code>java.lang.Class</code> instance.
- * @param typeDesc the type description
- * @return a JavaType instance for the specified type.
- * @exception ModelFatalException the specified type description is not
- * a <code>java.lang.Class</code> instance.
+ /**
+ * Registers this JavaModelFactory instance at the JDOImplHelper.
*/
- public JavaType getJavaType(Object typeDesc)
+ protected void registerFactory()
{
- if (typeDesc == null)
- return null;
-
+ // initialize RuntimeJavaModelFactory singleton instance
try {
- Class clazz = (Class)typeDesc;
- ClassLoader classLoader = getClassLoaderPrivileged(clazz);
- return getJavaModel(classLoader).getJavaType(clazz);
- }
- catch (ClassCastException ex) {
- throw new ModelFatalException(msg.msg("EXC_InvalidTypeDesc", //NOI18N
- typeDesc.getClass().getName()));
- }
- }
-
- // ===== Methods not defined in JavaModelFactory =====
-
- /**
- * Calls getClassLoader on the specified class instance in a
- * doPrivileged block. Any SecurityException is wrapped into a
- * ModelFatalException.
- * @return the class loader that loaded the specified class instance.
- * @exception ModelFatalException wraps the SecurityException thrown by
- * getClassLoader.
- */
- public ClassLoader getClassLoaderPrivileged(final Class clazz)
- {
- if (clazz == null)
- return null;
-
- try {
- return (ClassLoader) AccessController.doPrivileged(
- new PrivilegedAction () {
- public Object run () {
- return clazz.getClassLoader();
+ JDOImplHelper helper =
+ (JDOImplHelper) AccessController.doPrivileged(
+ new PrivilegedAction () {
+ public Object run () {
+ return JDOImplHelper.getInstance();
+ }
}
- }
- );
+ );
+ // register listener to JDOImplHelpers class registration
+ RegisterClassListener crl = new RegisterClassListener(
+ helper, this);
+ helper.addRegisterClassListener(crl);
}
catch (SecurityException ex) {
throw new ModelFatalException(
- msg.msg("EXC_CannotGetClassLoader", clazz), ex); //NOI18N
+ msg.msg("EXC_CannotGetJDOImplHelper"), ex); // NOI18N
}
}
- /**
- * Returns the <code>java.lang.Class</code> wrapped in the specified
- * JavaType.
- * @return the <code>java.lang.Class</code> for the specified
- * JavaType.
- * @exception ModelFatalException the specified JavaType does
- * not wrap a <code>java.lang.Class</code> instance.
+ /**
+ * Creates a new instance of the JavaModel implementation class.
+ * <p>
+ * This implementation returns a <code>RuntimeJavaModel</code> instance.
+ * @return a new JavaModel instance.
*/
- public Class getJavaClass(JavaType javaType)
- {
- if (javaType == null)
- return null;
-
- try {
- return ((BaseReflectionJavaType)javaType).getJavaClass();
- }
- catch (ClassCastException ex) {
- throw new ModelFatalException(msg.msg(
- "EXC_InvalidJavaType", javaType.getClass())); //NOI18N
- }
+ protected JavaModel newJavaModelInstance(ClassLoader classLoader) {
+ return new RuntimeJavaModel(classLoader, this);
}
- //========= Internal helper methods ==========
-
- /**
- * Sets the JDOModel instance for the specified JavaModel.
- * @param javaModel the JavaModel
- */
- protected void setJDOModelInternal(JavaModel javaModel)
- {
- JDOModelFactory factory = JDOModelFactoryImplCaching.getInstance();
- JDOModel jdoModel = factory.getJDOModel(javaModel);
- // update the JDOModel property of the JavaModel
- try {
- javaModel.setJDOModel(jdoModel);
- }
- catch (ModelException ex) {
- throw new ModelFatalException("ERR_CannotSetJDOModel", ex); //NOI18N
- }
- }
}
-
Modified: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java (original)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java Wed May 25 06:22:12 2005
@@ -16,22 +16,14 @@
package org.apache.jdo.impl.model.java.runtime;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
import org.apache.jdo.impl.model.java.reflection.ReflectionJavaType;
+import org.apache.jdo.model.ModelFatalException;
import org.apache.jdo.model.java.JavaField;
import org.apache.jdo.model.java.JavaModel;
-import org.apache.jdo.model.java.JavaModelFactory;
import org.apache.jdo.model.java.JavaType;
-import org.apache.jdo.model.jdo.JDOClass;
import org.apache.jdo.model.jdo.JDOField;
-import org.apache.jdo.model.jdo.JDOModel;
import org.apache.jdo.util.I18NHelper;
-
-
-/**
/**
* A reflection based JavaType implementation used at runtime.
* The implementation takes <code>java.lang.Class</code> and
@@ -40,39 +32,41 @@
*
* @author Michael Bouschen
* @since JDO 1.0.1
+ * @version JDO 2.0
*/
public class RuntimeJavaType
extends ReflectionJavaType
{
- /** JavaModelFactory */
- private static final RuntimeJavaModelFactory javaModelFactory =
- (RuntimeJavaModelFactory) AccessController.doPrivileged(
- new PrivilegedAction () {
- public Object run () {
- return RuntimeJavaModelFactory.getInstance();
- }
- }
- );
+ /** I18N support */
+ private final static I18NHelper msg =
+ I18NHelper.getInstance(RuntimeJavaType.class);
/** Constructor. */
- public RuntimeJavaType(Class clazz, JDOModel jdoModel)
+ public RuntimeJavaType(Class clazz, RuntimeJavaModel javaModel)
{
- super(clazz, jdoModel);
+ super(clazz, javaModel);
}
- /**
- * Returns a JavaType instance for the specified Class object.
- * This method provides a hook such that RuntimeJavaType subclasses can
- * implement their own mapping of Class objects to JavaType instances.
- * <p>
- * This implementation delegates the call to the javaModelFactory.
- * @param clazz the Class instance representing the type
- * @return a JavaType instance for the name of the specified class
- * object or <code>null</code> if not present in this model instance.
+ // ===== Methods not specified in JavaType =====
+
+ /**
+ * RegisterClassListener calls this method to create a ReflectionJavaField
+ * instance when processing the enhancer generated metadata.
+ * @param jdoField the JDO field metadata
+ * @param type the type of the field
+ * @return the ReflectionJavaField representation
*/
- protected JavaType getJavaTypeInternal(Class clazz)
+ public synchronized JavaField createJavaField(JDOField jdoField, JavaType type)
{
- return javaModelFactory.getJavaType(clazz);
+ String name = jdoField.getName();
+ JavaField javaField = (JavaField)declaredJavaFields.get(name);
+ if (javaField != null) {
+ throw new ModelFatalException(msg.msg(
+ "ERR_MultipleJavaField", //NOI18N
+ "RuntimeJavaType.createJavaField", name, getName())); //NOI18N
+ }
+ javaField = newJavaFieldInstance(jdoField, type);
+ declaredJavaFields.put(name, javaField);
+ return javaField;
}
-
}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/ComponentTypeHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/ComponentTypeHelper.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/ComponentTypeHelper.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/ComponentTypeHelper.java Wed May 25 06:22:12 2005
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.impl.model.java.runtime.jdk5;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.lang.reflect.ParameterizedType;
+
+import org.apache.jdo.impl.model.java.PredefinedType;
+import org.apache.jdo.model.java.JavaField;
+import org.apache.jdo.model.java.JavaMethod;
+import org.apache.jdo.model.java.JavaProperty;
+import org.apache.jdo.model.java.JavaType;
+
+/**
+ * Helper class to calculate the component type of he type of a field, method
+ * or property in a J2SE5.0 environment.
+*/
+public class ComponentTypeHelper
+{
+ /**
+ * Returns the Class instance representing the component type of the
+ * type of the specified field.
+ */
+ public static Class getComponentClass(JavaField javaField)
+ {
+ JavaType type = javaField.getType();
+ Field field = (Field) javaField.getUnderlyingObject();
+ return getComponentClass(type, field.getGenericType());
+ }
+
+ /**
+ * Returns the Class instance representing the component type of the
+ * return type of the specified method.
+ */
+ public static Class getComponentClass(JavaMethod javaMethod)
+ {
+ JavaType type = javaMethod.getReturnType();
+ if (type == PredefinedType.voidType)
+ // return null for void method
+ return null;
+ Method method = (Method) javaMethod.getUnderlyingObject();
+ return getComponentClass(type, method.getGenericReturnType());
+ }
+
+ /**
+ * Returns the Class instance representing the component type of the
+ * type of the specified property.
+ */
+ public static Class getComponentClass(JavaProperty javaProperty)
+ {
+ Class componentClass = null;
+ JavaMethod getter = javaProperty.getGetterMethod();
+ JavaMethod setter = javaProperty.getSetterMethod();
+ if (getter != null)
+ componentClass = getComponentClass(getter);
+ else if (setter != null) {
+ JavaType[] paramJavaTypes = setter.getParameterTypes();
+ assert(paramJavaTypes.length == 1);
+ Method method = (Method) setter.getUnderlyingObject();
+ Type[] genericParamTypes = method.getGenericParameterTypes();
+ assert(genericParamTypes.length == 1);
+ componentClass =
+ getComponentClass(paramJavaTypes[0], genericParamTypes[0]);
+ }
+ return componentClass;
+ }
+
+ // ===== Internal helper methods =====
+
+ /** Helper method. */
+ private static Class getComponentClass(JavaType type, Type genericType)
+ {
+ Class componentClass = null;
+ if (type.isArray()) {
+ Class clazz = (Class) type.getUnderlyingObject();
+ componentClass = clazz.getComponentType();
+ }
+ else if (type.isJDOSupportedCollection()) {
+ if (genericType instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) genericType;
+ Type[] actualTypeArgs = pt.getActualTypeArguments();
+ assert(actualTypeArgs.length == 1);
+ assert(actualTypeArgs[0] instanceof Class);
+ componentClass = (Class) actualTypeArgs[0];
+ }
+ }
+ return componentClass;
+ }
+
+
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaField.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaField.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaField.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaField.java Wed May 25 06:22:12 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.impl.model.java.runtime.jdk5;
+
+import java.lang.reflect.Field;
+
+import org.apache.jdo.impl.model.java.reflection.ReflectionJavaField;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.model.jdo.JDOField;
+
+/**
+ * A reflection based JavaField implementation used at runtime in a
+ * J2SE5.0 environment.
+ *
+ * @author Michael Bouschen
+ */
+public class JDK5RuntimeJavaField
+ extends ReflectionJavaField
+{
+ /**
+ * Constructor for fields w/o JDO metadata.
+ * @param field the reflection field representation.
+ * @param declaringClass the JavaType of the class that declares the field.
+ */
+ public JDK5RuntimeJavaField(Field field, JavaType declaringClass)
+ {
+ super(field, declaringClass);
+ }
+
+ /**
+ * Constructor for fields having JDO metadata.
+ * @param jdoField the JDO field metadata.
+ * @param type the field type.
+ * @param declaringClass the JavaType of the class that declares the field.
+ */
+ public JDK5RuntimeJavaField(JDOField jdoField, JavaType type,
+ JavaType declaringClass)
+ {
+ super(jdoField, type, declaringClass);
+ }
+
+ // ===== methods specified in JavaMember =====
+
+ /**
+ * Returns the JavaType representation of the component type of the type
+ * of the property, if the property type is an array or collection. The
+ * method returns <code>null</code>, if the property type is not an array
+ * or collection.
+ * @return the component type of the property type in case of an array or
+ * collection.
+ */
+ public JavaType getComponentType()
+ {
+ Class componentClass = ComponentTypeHelper.getComponentClass(this);
+ return (componentClass == null) ? null :
+ getJavaTypeForClass(componentClass);
+ }
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaMethod.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaMethod.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaMethod.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaMethod.java Wed May 25 06:22:12 2005
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.impl.model.java.runtime.jdk5;
+
+import org.apache.jdo.impl.model.java.reflection.ReflectionJavaMethod;
+import java.lang.reflect.Method;
+import org.apache.jdo.model.java.JavaType;
+
+/**
+ * A reflection based JavaMethod implementation used at runtime in a
+ * J2SE5.0 environment.
+ *
+ * @author Michael Bouschen
+ */
+public class JDK5RuntimeJavaMethod
+ extends ReflectionJavaMethod
+{
+ /**
+ * Constructor.
+ * @param method the reflection method representation.
+ * @param declaringClass the JavaType of the class that declares the
+ * method.
+ */
+ public JDK5RuntimeJavaMethod(Method method, JavaType declaringClass)
+ {
+ super(method, declaringClass);
+ }
+
+ // ===== methods specified in JavaMember =====
+
+ /**
+ * Returns the JavaType representation of the component type of the return
+ * type of the method, if the method return type is an array or
+ * collection. The method returns <code>null</code>, if the property type
+ * is not an array or collection.
+ * @return the component type of the method return type in case of an
+ * array or collection.
+ */
+ public JavaType getComponentType()
+ {
+ Class componentClass = ComponentTypeHelper.getComponentClass(this);
+ return (componentClass == null) ? null :
+ getJavaTypeForClass(componentClass);
+ }
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModel.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModel.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModel.java Wed May 25 06:22:12 2005
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.impl.model.java.runtime.jdk5;
+
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.impl.model.java.runtime.*;
+
+/**
+ * A reflection based JavaModel implementation used at runtime in a J2SE5.0
+ * environment.
+ * The implementation takes <code>java.lang.Class</code> and
+ * <code>java.lang.reflect.Field</code> instances to get Java related
+ * metadata about types and fields.
+ * <p>
+ * The RuntimeJavaModelFactory caches JavaModel instances per ClassLoader.
+ * The RuntimeJavaModel implementation will use this ClassLoader to lookup
+ * any type by name. This makes sure that the type name is unique.
+ *
+ * @author Michael Bouschen
+ * @since JDO 2.0
+ */
+public class JDK5RuntimeJavaModel
+ extends RuntimeJavaModel
+{
+ /** Constructor. */
+ public JDK5RuntimeJavaModel(ClassLoader classLoader,
+ JDK5RuntimeJavaModelFactory declaringJavaModelFactory)
+ {
+ super(classLoader, declaringJavaModelFactory);
+ }
+
+ /**
+ * Creates a new instance of the JavaType implementation class.
+ * <p>
+ * This implementation returns a RuntimeJavaType instance.
+ * @param clazz the Class instance representing the type
+ * @return a new JavaType instance
+ */
+ protected JavaType newJavaTypeInstance(Class clazz)
+ {
+ return new JDK5RuntimeJavaType(clazz, this);
+ }
+
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModelFactory.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModelFactory.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModelFactory.java Wed May 25 06:22:12 2005
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.impl.model.java.runtime.jdk5;
+import org.apache.jdo.model.ModelFatalException;
+import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.util.I18NHelper;
+import javax.jdo.spi.JDOPermission;
+import org.apache.jdo.impl.model.java.runtime.*;
+
+/**
+ * A reflection based JavaModelFactory implementation used at runtime in a
+ * J2SE5.0 environment.
+ * The implementation takes <code>java.lang.Class</code> and
+ * <code>java.lang.reflect.Field</code> instances to get Java related
+ * metadata about types and fields. This implementation caches JavaModel
+ * instances per ClassLoader.
+ * <p>
+ * JDK5RuntimeJavaModelFactory implements the singleton pattern; method
+ * {@link #getInstance()} provides access to the singleton factory
+ * instance. This method also registers a model listener at the
+ * JDOImplHelper to handle the runtime metadata as generated by the
+ * enhancer.
+ *
+ * @author Michael Bouschen
+ * @since JDO 2.0
+ */
+public class JDK5RuntimeJavaModelFactory
+ extends RuntimeJavaModelFactory
+{
+ /** The singleton JDK5RuntimeJavaModelFactory instance. */
+ private static final JDK5RuntimeJavaModelFactory runtimeJavaModelFactory =
+ new JDK5RuntimeJavaModelFactory();
+
+ /** I18N support */
+ private final static I18NHelper msg =
+ I18NHelper.getInstance(JDK5RuntimeJavaModelFactory.class);
+
+ /**
+ * Creates a new RuntimeJavaModelFactory. This constructor should not
+ * be called directly; instead, the singleton access method
+ * {@link #getInstance()} should be used.
+ */
+ protected JDK5RuntimeJavaModelFactory() {}
+
+ /**
+ * Returns the singleton instance of JDK5RuntimeJavaModelFactory. On first
+ * call it registers a model listener at the JDOImplHelper.
+ * This method checks that the caller is authorized for
+ * <code>JDOPermission("getMetadata")</code>, and if not, throws
+ * <code>ModelFatalException</code> wrapping the SecurityException.
+ * @return RuntimeJavaModelFactory instance
+ * @exception ModelFatalException if the caller does not have the
+ * getMetadata permission.
+ */
+ public static JDK5RuntimeJavaModelFactory getInstance()
+ throws ModelFatalException
+ {
+ checkPermission();
+ return runtimeJavaModelFactory;
+ }
+
+ //========= Internal helper methods ==========
+
+ /**
+ * Creates a new instance of the JavaModel implementation class.
+ * <p>
+ * This implementation returns a <code>JDK5RuntimeJavaModel</code> instance.
+ * @return a new JavaModel instance.
+ */
+ protected JavaModel newJavaModelInstance(ClassLoader classLoader) {
+ return new JDK5RuntimeJavaModel(classLoader, this);
+ }
+
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaProperty.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaProperty.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaProperty.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaProperty.java Wed May 25 06:22:12 2005
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.impl.model.java.runtime.jdk5;
+
+import org.apache.jdo.impl.model.java.JavaPropertyImpl;
+import org.apache.jdo.model.java.JavaMethod;
+import org.apache.jdo.model.java.JavaType;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import org.apache.jdo.impl.model.java.runtime.*;
+
+/**
+ * Default implementation for the JavaProperty interfaces. A JavaProperty
+ * represents a JavaBeans property.
+ *
+ * @author Michael Bouschen
+ */
+public class JDK5RuntimeJavaProperty
+ extends JavaPropertyImpl
+{
+ /** */
+ public JDK5RuntimeJavaProperty(String name,
+ JavaMethod getter, JavaMethod setter,
+ JavaType type, JavaType declaringClass)
+ {
+ super(name, getter, setter, type, declaringClass);
+ }
+
+ // ===== methods specified in JavaMember =====
+
+ /**
+ * Returns the JavaType representation of the component type of the type
+ * of the property, if the property type is an array or collection. The
+ * method returns <code>null</code>, if the property type is not an array
+ * or collection.
+ * @return the component type of the property type in case of an array or
+ * collection.
+ */
+ public JavaType getComponentType()
+ {
+ Class componentClass = ComponentTypeHelper.getComponentClass(this);
+ return (componentClass == null) ? null :
+ getJavaTypeForClass(componentClass);
+ }
+
+ // ===== Methods not specified in JavaProperty =====
+
+ /**
+ * Returns a JavaType instance for the specified Class object.
+ * This method provides a hook such that ReflectionJavaField subclasses can
+ * implement their own mapping of Class objects to JavaType instances.
+ */
+ public JavaType getJavaTypeForClass(Class clazz)
+ {
+ return ((JDK5RuntimeJavaType) getDeclaringClass()).
+ getJavaTypeForClass(clazz);
+ }
+}
Added: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaType.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaType.java (added)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaType.java Wed May 25 06:22:12 2005
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.impl.model.java.runtime.jdk5;
+
+import org.apache.jdo.model.java.JavaField;
+import org.apache.jdo.model.java.JavaMethod;
+import org.apache.jdo.model.java.JavaProperty;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.model.jdo.JDOField;
+
+import java.lang.reflect.Field;
+import org.apache.jdo.impl.model.java.runtime.*;
+
+/**
+/**
+ * A reflection based JavaType implementation used at runtime in a
+ * J2SE5.0 environment.
+ * The implementation takes <code>java.lang.Class</code> and
+ * <code>java.lang.reflect.Field</code> instances to get Java related
+ * metadata about types and fields.
+ *
+ * @author Michael Bouschen
+ */
+public class JDK5RuntimeJavaType
+ extends RuntimeJavaType
+{
+ /** Constructor. */
+ public JDK5RuntimeJavaType(Class clazz, JDK5RuntimeJavaModel javaModel)
+ {
+ super(clazz, javaModel);
+ }
+
+ /**
+ * Creates a new instance of the JavaField implementation class.
+ * <p>
+ * This implementation returns a <code>ReflectionJavaField</code>
+ * instance.
+ * @return a new JavaField instance.
+ */
+ protected JavaField newJavaFieldInstance(JDOField jdoField, JavaType type)
+ {
+ return new JDK5RuntimeJavaField(jdoField, type, this);
+ }
+
+ /**
+ * Creates a new instance of the JavaField implementation class.
+ * <p>
+ * This implementation returns a <code>ReflectionJavaField</code>
+ * instance.
+ * @return a new JavaField instance.
+ */
+
+ protected JavaField newJavaFieldInstance(Field field)
+ {
+ return new JDK5RuntimeJavaField(field, this);
+ }
+
+ /**
+ * Creates a new instance of the JavaProperty implementation class.
+ * <p>
+ * This implementation returns a <code>JavaPropertyImpl</code>
+ * instance.
+ * @return a new JavaProperty instance.
+ */
+ protected JavaProperty newJavaPropertyInstance(String name,
+ JavaMethod getter, JavaMethod setter, JavaType type)
+ {
+ return new JDK5RuntimeJavaProperty(name, getter, setter, type, this);
+ }
+
+}
Modified: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/jdo/xml/XMLExists.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/jdo/xml/XMLExists.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/jdo/xml/XMLExists.java (original)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/jdo/xml/XMLExists.java Wed May 25 06:22:12 2005
@@ -18,16 +18,12 @@
import java.util.*;
-import org.apache.jdo.impl.model.java.AbstractJavaModelFactory;
-import org.apache.jdo.impl.model.java.runtime.RuntimeJavaModel;
-import org.apache.jdo.impl.model.jdo.caching.JDOModelFactoryImplCaching;
+import org.apache.jdo.impl.model.java.reflection.ReflectionJavaModelFactory;
import org.apache.jdo.impl.model.jdo.util.PrintSupport;
-import org.apache.jdo.model.ModelException;
-import org.apache.jdo.model.ModelFatalException;
import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.model.java.JavaModelFactory;
import org.apache.jdo.model.jdo.JDOClass;
import org.apache.jdo.model.jdo.JDOModel;
-import org.apache.jdo.model.jdo.JDOModelFactory;
/**
* This class allows to check whether there is JDO metadata for a class with
@@ -136,7 +132,7 @@
public boolean run(List classNames)
{
ClassLoader classLoader = getClass().getClassLoader();
- XMLExistsJDOModelFactory factory = new XMLExistsJDOModelFactory();
+ JavaModelFactory factory = new JavaModelFactoryImpl();
JavaModel javaModel = factory.getJavaModel(classLoader);
JDOModel jdoModel = javaModel.getJDOModel();
boolean ok = true;
@@ -267,41 +263,6 @@
* metadata is present from a .jdo we do not want to the enhancer
* generated metadata.
*/
- private static class XMLExistsJDOModelFactory
- extends AbstractJavaModelFactory {
-
- /** */
- protected XMLExistsJDOModelFactory() {}
-
- /** */
- public JavaModel createJavaModel(Object key) throws ModelException {
- if ((key == null) || (!(key instanceof ClassLoader)))
- throw new ModelException("Invalid key " + key +
- " expected ClassLoader");
- ClassLoader classLoader = (ClassLoader)key;
- JavaModel javaModel = new RuntimeJavaModel(classLoader);
-
- // set the JDOModel property in JavaModel
- setJDOModelInternal(javaModel);
-
- return javaModel;
- }
-
- /**
- * Sets the JDOModel instance for the specified JavaModel.
- * @param javaModel the JavaModel
- */
- protected void setJDOModelInternal(JavaModel javaModel) {
- JDOModelFactory factory = JDOModelFactoryImplCaching.getInstance();
- JDOModel jdoModel = factory.getJDOModel(javaModel);
- // update the JDOModel property of the JavaModel
- try {
- javaModel.setJDOModel(jdoModel);
- }
- catch (ModelException ex) {
- throw new ModelFatalException("Cannot set JDOModel", ex); //NOI18N
- }
- }
- }
-
+ private static class JavaModelFactoryImpl
+ extends ReflectionJavaModelFactory { }
}