db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r161168 [1/2] - in incubator/jdo/trunk/ri11/src/java/org/apache/jdo: impl/enhancer/meta/model/ impl/jdoql/jdoqlc/ impl/model/java/ impl/model/java/reflection/ impl/model/java/runtime/ impl/model/jdo/util/ impl/model/jdo/xml/ model/java/
Date Wed, 13 Apr 2005 09:11:16 GMT
Author: mbo
Date: Wed Apr 13 02:11:13 2005
New Revision: 161168

URL: http://svn.apache.org/viewcvs?view=rev&rev=161168
Log:
Changed java model implementation in ri11 to reduce dependencies between enhancer and runtime

Added:
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java
Removed:
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/ReflectionJavaField.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/ReflectionJavaType.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaField.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/util/Assertion.java
Modified:
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/jdoqlc/TypeSupport.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/JavaModel-Impl.jpg
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/PredefinedType.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/model/java/JavaModel.mdl

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java?view=diff&r1=161167&r2=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java Wed Apr 13 02:11:13 2005
@@ -19,7 +19,7 @@
 import java.io.InputStream;
 
 import org.apache.jdo.impl.enhancer.util.ResourceLocator;
-import org.apache.jdo.impl.model.java.runtime.RuntimeJavaModel;
+import org.apache.jdo.impl.model.java.reflection.ReflectionJavaModel;
 import org.apache.jdo.model.java.JavaType;
 import org.apache.jdo.model.jdo.JDOModel;
 
@@ -30,7 +30,7 @@
  * @author Martin Zaun
  */
 public class EnhancerJavaModel
-    extends RuntimeJavaModel
+    extends ReflectionJavaModel
 {
     /**
      * The "package" jdo file.
@@ -71,7 +71,7 @@
      * @param clazz the Class instance representing the type
      * @return a new JavaType instance
      */
-    protected JavaType createJavaType(Class clazz, JDOModel jdoModel)
+    protected JavaType createJavaType(Class clazz)
     {
         return new EnhancerJavaType(clazz, getJDOModel(), this);
     }

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java?view=diff&r1=161167&r2=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java Wed Apr 13 02:11:13 2005
@@ -17,7 +17,7 @@
 package org.apache.jdo.impl.enhancer.meta.model;
 
 import org.apache.jdo.impl.enhancer.meta.EnhancerMetaDataFatalError;
-import org.apache.jdo.impl.model.java.runtime.RuntimeJavaType;
+import org.apache.jdo.impl.model.java.reflection.ReflectionJavaType;
 import org.apache.jdo.model.java.JavaModel;
 import org.apache.jdo.model.java.JavaType;
 import org.apache.jdo.model.jdo.JDOModel;
@@ -31,7 +31,7 @@
  * @since JDO 1.0.1
  */
 public class EnhancerJavaType
-    extends RuntimeJavaType
+    extends ReflectionJavaType
 {
     /** The declaring EnhancerJavaModel instance. */
     private JavaModel javaModel = null;

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/jdoqlc/TypeSupport.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/jdoqlc/TypeSupport.java?view=diff&r1=161167&r2=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/jdoqlc/TypeSupport.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/jdoqlc/TypeSupport.java Wed Apr 13 02:11:13 2005
@@ -38,7 +38,7 @@
 import org.apache.jdo.impl.model.java.ErrorType;
 import org.apache.jdo.impl.model.java.PredefinedType;
 import org.apache.jdo.impl.model.java.WrapperClassType;
-import org.apache.jdo.impl.model.java.runtime.RuntimeJavaField;
+import org.apache.jdo.impl.model.java.reflection.ReflectionJavaField;
 import org.apache.jdo.impl.model.java.runtime.RuntimeJavaModelFactory;
 import org.apache.jdo.jdoql.JDOQueryException;
 import org.apache.jdo.model.ModelFatalException;
@@ -404,7 +404,7 @@
         Class clazz = javaModelFactory.getJavaClass(javaField.getDeclaringClass());
         String fieldName = javaField.getName();
         final Field field = 
-            RuntimeJavaField.getDeclaredFieldPrivileged(clazz, fieldName);
+            ReflectionJavaField.getDeclaredFieldPrivileged(clazz, fieldName);
         if (field == null) {
             throw new JDOQueryException( 
                 msg.msg("EXC_CannotFindField", //NOI18N

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java?view=auto&rev=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java Wed Apr 13 02:11:13 2005
@@ -0,0 +1,177 @@
+/*
+ * 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;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.lang.reflect.Field;
+
+import org.apache.jdo.impl.model.java.AbstractJavaField;
+import org.apache.jdo.model.ModelFatalException;
+import org.apache.jdo.model.java.JavaField;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.model.jdo.JDOField;
+import org.apache.jdo.util.I18NHelper;
+
+/**
+ * This class provides a basic JavaField implementation using a reflection
+ * Field instance. The implementation supports lazy initialization of the
+ * wrapped reflection field instance (see 
+ * {@link #BaseReflectionJavaField(String fieldName, JavaType declaringClass)}.
+ * <p>
+ * Note, this implementation is not connected to a JavaModelFactory, thus
+ * it can only support predefined types as field types.
+ * @see PredefinedType
+ * @author Michael Bouschen
+ * @since JDO 1.1
+ */
+public class BaseReflectionJavaField
+    extends AbstractJavaField
+{
+    /** The wrapped java.lang.reflect.Field instance. */
+    private Field field;
+
+    /** The type of the field. */
+    protected JavaType type;
+
+    /** I18N support */
+    private final static I18NHelper msg = 
+        I18NHelper.getInstance(BaseReflectionJavaField.class);
+
+    /** 
+     * Constructor taking a reflection field representation. The specifie
+     * field must not be <code>null</code>. 
+     * @param field the java.lang.reflect.Field instance
+     * @param declaringClass the JavaType of the declaring class or interface.
+     */
+    protected BaseReflectionJavaField(Field field, JavaType declaringClass)
+    {
+        super((field == null) ? null : field.getName(), declaringClass);
+        if (field == null)
+            throw new ModelFatalException(msg.msg(
+                "ERR_InvalidNullFieldInstance", "BaseReflectionJavaField.<init>")); //NOI18N
+        this.field = field;
+    }
+    
+    /** 
+     * Constructor taking the field name. This constructor allows lazy
+     * initialization of the field reference. 
+     * @param fieldName the name of the field.
+     * @param declaringClass the JavaType of the declaring class or interface.
+     */
+    protected BaseReflectionJavaField(String fieldName, JavaType declaringClass)
+    {
+        super(fieldName, declaringClass);
+    }
+
+    /**
+     * Returns the Java language modifiers for the field represented by
+     * this JavaField, as an integer. The java.lang.reflect.Modifier class
+     * should be used to decode the modifiers. 
+     * @return the Java language modifiers for this JavaField
+     * @see java.lang.reflect.Modifier
+     */
+    public int getModifiers()
+    {
+        ensureInitializedField();
+        return field.getModifiers();
+    }
+
+    /**
+     * Returns the JavaType representation of the field type.
+     * @return field type
+     */
+    public JavaType getType()
+    {
+        if (type == null) {
+            ensureInitializedField();
+            String typeName = field.getType().getName();
+            // Note, this only checks for predefined types!
+            type = PredefinedType.getPredefinedType(typeName);
+        }
+        return type;
+    }
+    
+    // ===== Methods not defined in JavaField =====
+
+    /** 
+     * Returns the java.lang.reflect.Field that is wrapped by this
+     * JavaField.
+     * @return the java.lang.reflect.Field instance.
+     */
+    protected Field getField()
+    {
+        ensureInitializedField();
+        return this.field;
+    }
+
+    /**
+     * Helper method to retrieve the java.lang.reflect.Field for this
+     * JavaField.
+     * @param clazz the Class instance of the declaring class or interface
+     * @param fieldName the field name
+     */
+    public static Field getDeclaredFieldPrivileged(final Class clazz, 
+                                                   final String fieldName)
+    {
+        if ((clazz == null) || (fieldName == null))
+            return null;
+
+        return (Field) AccessController.doPrivileged(
+            new PrivilegedAction() {
+                public Object run () {
+                    try {
+                        return clazz.getDeclaredField(fieldName);
+                    }
+                    catch (SecurityException ex) {
+                        throw new ModelFatalException(
+                            msg.msg("EXC_CannotGetDeclaredField", //NOI18N
+                                    clazz.getName()), ex); 
+                    }
+                    catch (NoSuchFieldException ex) {
+                        return null; // do nothing, just return null
+                    }
+                    catch (LinkageError ex) {
+                        throw new ModelFatalException(msg.msg(
+                           "EXC_ClassLoadingError", clazz.getName(), //NOI18N
+                           ex.toString()));
+                    }
+                }
+            }
+            );
+    }
+
+    // ===== Internal helper methods =====
+    
+    /**
+     * This method makes sure the reflection field is set.
+     */
+    protected void ensureInitializedField()
+    {
+        if (this.field == null) {
+            this.field = getDeclaredFieldPrivileged(
+                ((BaseReflectionJavaType)getDeclaringClass()).getJavaClass(),
+                getName());
+            if (field == null) {
+                throw new ModelFatalException(msg.msg(
+                    "ERR_MissingFieldInstance", //NOI18N
+                    "BaseReflectionJavaField.ensureInitializedField", getName())); //NOI18N
+            }
+        }
+    }
+
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java?view=auto&rev=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java Wed Apr 13 02:11:13 2005
@@ -0,0 +1,170 @@
+/*
+ * 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;
+
+import java.lang.reflect.Field;
+
+import org.apache.jdo.model.ModelFatalException;
+import org.apache.jdo.model.java.JavaField;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.util.I18NHelper;
+
+
+
+/**
+ * This class provides a basic JavaType implementation using a reflection
+ * Class instance.
+ * <p> 
+ * Note, BaseReflectionJavaType must not be used for array types, since it inherits
+ * the default implemention of methods isArray and getArrayComponentType
+ * from its superclass AbstractJavaType.
+ * 
+ * @author Michael Bouschen
+ * @since JDO 1.1
+ */
+public class BaseReflectionJavaType
+    extends AbstractJavaType
+{
+    /** The java.lang.Class instance for this BaseReflectionJavaType. */
+    protected Class clazz;
+
+    /** The superclass JavaType. */
+    protected JavaType superclass;
+
+    /** I18N support */
+    private static I18NHelper msg = 
+        I18NHelper.getInstance(BaseReflectionJavaType.class);
+
+    /**
+     * Constructor. The specified java.lang.Class instance must not be
+     * <code>null</code>. The 
+     * @param clazz the Class instance representing the type
+     * @param superclass JavaType instance representing the superclass.
+     */
+    public BaseReflectionJavaType(Class clazz, JavaType superclass)
+    {
+        if (clazz == null)
+            throw new ModelFatalException(msg.msg(
+                "ERR_InvalidNullClassInstance", "BaseReflectionJavaType.<init>")); //NOI18N
+        this.clazz = clazz;
+        this.superclass = superclass;
+    }
+    
+    /** 
+     * Determines if this JavaType object represents an interface type.
+     * @return <code>true</code> if this object represents an interface type; 
+     * <code>false</code> otherwise.
+     */
+    public boolean isInterface()
+    {
+        return clazz.isInterface();
+    }
+    
+    /** 
+     * Returns true if this JavaType is compatible with the specified
+     * JavaType. 
+     * @param javaType the type this JavaType is checked with.
+     * @return <code>true</code> if this is compatible with the specified
+     * type; <code>false</code> otherwise.
+     */
+    public boolean isCompatibleWith(JavaType javaType)
+    {
+        if (javaType == null)
+            return false;
+        
+        if (javaType instanceof BaseReflectionJavaType) {
+            BaseReflectionJavaType otherType = (BaseReflectionJavaType)javaType;
+            return otherType.getJavaClass().isAssignableFrom(clazz);
+        }
+        
+        return false;
+    }
+
+    /**
+     * Returns the name of the type. If this type represents a class or
+     * interface, the name is fully qualified.
+     * @return type name
+     */
+    public String getName()
+    {
+        return clazz.getName();
+    }
+
+    /**
+     * Returns the Java language modifiers for the field represented by
+     * this JavaType, as an integer. The java.lang.reflect.Modifier class
+     * should be used to decode the modifiers. 
+     * @return the Java language modifiers for this JavaType
+     */
+    public int getModifiers() 
+    { 
+        return clazz.getModifiers(); 
+    }
+
+    /** 
+     * Returns the JavaType representing the superclass of the entity
+     * represented by this JavaType. If this JavaType represents either the 
+     * Object class, an interface, a primitive type, or <code>void</code>, 
+     * then <code>null</code> is returned. If this object represents an
+     * array class then the JavaType instance representing the Object class
+     * is returned.  
+     * @return the superclass of the class represented by this JavaType.
+     */
+    public JavaType getSuperclass()
+    {
+        return superclass;
+    }
+
+    /**
+     * Returns a JavaField instance that reflects the field with the
+     * specified name of the class or interface represented by this
+     * JavaType instance. The method returns <code>null</code>, if the
+     * class or interface (or one of its superclasses) does not have a
+     * field with that name.
+     * @param fieldName the name of the field 
+     * @return the JavaField instance for the specified field in this class
+     * or <code>null</code> if there is no such field.
+     */
+    public JavaField getJavaField(String fieldName) 
+    { 
+        Field field = 
+            BaseReflectionJavaField.getDeclaredFieldPrivileged(clazz, fieldName);
+        if (field != null) {
+            return new BaseReflectionJavaField(field, this);
+        }
+        
+        // check superclass, if available and other than Object
+        JavaType superclass = getSuperclass();
+        if ((superclass != null) && (superclass != PredefinedType.objectType)) {
+            return superclass.getJavaField(fieldName);
+        }
+        
+        return null;
+    }
+
+    // ===== Methods not defined in JavaType =====
+
+    /**
+     * Returns the java.lang.Class instance wrapped by this JavaType.
+     * @return the Class instance for this JavaType.
+     */
+    public Class getJavaClass()
+    {
+        return clazz;
+    }
+
+}

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/JavaModel-Impl.jpg
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/JavaModel-Impl.jpg?view=diff&r1=161167&r2=161168
==============================================================================
Binary files - no diff available.

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/PredefinedType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/PredefinedType.java?view=diff&r1=161167&r2=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/PredefinedType.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/PredefinedType.java Wed Apr 13 02:11:13 2005
@@ -50,7 +50,7 @@
  * @since JDO 1.0.1
  */
 public class PredefinedType
-    extends ReflectionJavaType
+    extends BaseReflectionJavaType
 {
     /** Map of all predefined types. */
     private static final Map predefinedTypes = new HashMap();

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java?view=auto&rev=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java Wed Apr 13 02:11:13 2005
@@ -0,0 +1,130 @@
+/*
+ * 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.reflection;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.lang.reflect.Field;
+
+import org.apache.jdo.impl.model.java.BaseReflectionJavaField;
+import org.apache.jdo.model.ModelFatalException;
+import org.apache.jdo.model.java.JavaField;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.model.jdo.JDOField;
+import org.apache.jdo.util.I18NHelper;
+
+/**
+ * A reflection based JavaField implementation used at runtime.  
+ * The implementation takes <code>java.lang.reflect.Field</code> instances
+ * to get Java related metadata about fields. 
+ * 
+ * @author Michael Bouschen
+ * @since JDO 1.1
+ */
+public class ReflectionJavaField
+    extends BaseReflectionJavaField
+{
+    /** The corresponding JDO metadata. */
+    protected JDOField jdoField;
+
+    /** I18N support */
+    private final static I18NHelper msg =  
+        I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle"); //NOI18N
+
+    /** 
+     * 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 ReflectionJavaField(Field field, JavaType declaringClass)
+    {
+        super(field, declaringClass);
+        this.type = getJavaTypeInternal(field.getType());
+    }
+    
+    /** 
+     * Constructor for fields having JDO metadata. The constructor takes
+     * the field type from the JDO metadata.
+     * @param jdoField the JDO field metadata.
+     * @param declaringClass the JavaType of the class that declares the field.
+     */
+    public ReflectionJavaField(JDOField jdoField, JavaType declaringClass)
+    {
+        this(jdoField, null, 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 ReflectionJavaField(JDOField jdoField, JavaType type, JavaType declaringClass)
+    {
+        super((jdoField == null) ? null : jdoField.getName(), declaringClass);
+        if (jdoField == null)
+            throw new ModelFatalException(msg.msg(
+                "ERR_InvalidNullFieldInstance", //NOI18N
+                "ReflectionJavaField.<init>")); //NOI18N
+        this.jdoField = jdoField;
+        this.type = type;
+    }
+    
+    /**
+     * Returns the JavaType representation of the field type.
+     * @return field type
+     */
+    public JavaType getType()
+    {
+        if (type == null) {
+            type = getJavaTypeInternal(getField().getType());
+        }
+        return type;
+    }
+
+    /**
+     * Returns the JDOField instance if this JavaField represents a
+     * managed field of a persistence capable class. The method returns
+     * <code>null</code>, if this JavaField does not represent a managed
+     * field. 
+     * <p>
+     * The method throws a {@link org.apache.jdo.model.ModelFatalException},
+     * if there is a problem accessing the JDO meta data for this JavaField. 
+     * @return the JDOField instance if this JavaField represents a managed
+     * field; <code>null</code> otherwise.
+     */
+    public JDOField getJDOField()
+    {
+        return jdoField;
+    }
+
+    // ===== Methods not defined in JavaField =====
+
+    /** 
+     * 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. 
+     */
+    protected JavaType getJavaTypeInternal(Class clazz)
+    {
+        return ((ReflectionJavaType)getDeclaringClass()).getJavaTypeInternal(clazz);
+    }
+    
+
+    
+}
+

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java?view=auto&rev=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java Wed Apr 13 02:11:13 2005
@@ -0,0 +1,182 @@
+/*
+ * 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.reflection;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.io.InputStream;
+
+import org.apache.jdo.impl.model.java.AbstractJavaModel;
+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.  
+ * 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 ReflectionJavaModel 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 1.1
+ */
+public abstract class ReflectionJavaModel
+    extends AbstractJavaModel
+{
+    /** The ClassLoader instance used as key to cache this JavaModel. */
+    private final ClassLoader classLoader;
+
+    /** Flag passed to the Class.forName call. */
+    private final boolean initialize;
+
+    /** I18N support */
+    private final static I18NHelper msg =  
+        I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle"); //NOI18N
+
+    /** Constructor taking the ClassLoader. */
+    public ReflectionJavaModel(ClassLoader classLoader) 
+    {
+        this(classLoader, true);
+    }
+    
+    /** */
+    protected ReflectionJavaModel(ClassLoader classLoader, boolean initialize)
+    {
+        super();
+        this.classLoader = classLoader;
+        this.initialize = initialize;
+    }
+
+    /** 
+     * The method returns the JavaType instance for the specified type
+     * name. A type name is unique within one JavaModel instance. The
+     * method returns <code>null</code> if this model instance does not
+     * know a type with the specified name.
+     * <p>
+     * Note, this method calls Class.forName with the wrapped ClassLoader,
+     * if it cannot find a JavaType with the specified name in the cache.
+     * @param name the name of the type
+     * @return a JavaType instance for the specified name or
+     * <code>null</code> if not present in this model instance.
+     */
+    public JavaType getJavaType(String name) 
+    {
+        synchronized (types) {
+            JavaType javaType = (JavaType)types.get(name);
+            if (javaType == null) {
+                try {
+                    // Note, if name denotes a pc class that has not been
+                    // loaded, Class.forName will load the class which
+                    // calls RegisterClassListener.registerClass.
+                    // This will create a new JavaType entry in the cache.
+                    javaType = getJavaType(Class.forName(name, initialize, 
+                                                         classLoader));
+                }
+                catch (ClassNotFoundException ex) {
+                    // cannot find class => return null
+                }
+                catch (LinkageError ex) {
+                    throw new ModelFatalException(msg.msg(
+                        "EXC_ClassLoadingError", name, ex.toString())); //NOI18N
+                }
+            }
+            return javaType;
+        }
+    }
+
+    /** 
+     * The method returns the JavaType instance for the type name of the
+     * specified class object. This is a convenience method for 
+     * <code>getJavaType(clazz.getName())</code>. The major difference
+     * between this method and getJavaType taking a type name is that this 
+     * method is supposed to return a non-<code>null<code> value. The
+     * specified class object describes an existing type.
+     * <p>
+     * Note, this implementation does not call the overloaded getJavaType
+     * method taking a String, because this would retrieve the Class
+     * instance for the specified type again. Instead, it checks the cache 
+     * directly. If not available it creates a new ReflectionJavaType using
+     * the specified class instance.
+     * @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.
+     */
+    public JavaType getJavaType(Class clazz)
+    {
+        String name = clazz.getName();
+        synchronized (types) {
+            JavaType javaType = (JavaType)types.get(name);
+            if (javaType == null) {
+                javaType = createJavaType(clazz);
+                types.put(name, javaType);
+            }
+            return javaType;
+        }
+    }
+
+    /**
+     * 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 
+     * <code>null</code> if no resource with this name is found or if the
+     * caller doesn't have adequate privileges to get the resource.  
+     * <p>
+     * This implementation delegates the request to the wrapped
+     * ClassLoader. 
+     * @param resourceName the resource name
+     * @return an input stream for reading the resource, or <code>null</code> 
+     * if the resource could not be found or if the caller doesn't have
+     * adequate privileges to get the resource. 
+     */
+    public InputStream getInputStreamForResource(final String resourceName)
+    {
+        return (InputStream) AccessController.doPrivileged(
+            new PrivilegedAction () {
+                public Object run () {
+                    return classLoader.getResourceAsStream(resourceName);
+                }
+            }
+            );
+    }
+
+    // ===== Methods not defined in JavaModel =====
+
+    /** 
+     * Returns the ClassLoader wrapped by this ReflectionJavaModel instance.
+     * @return the ClassLoader
+     */
+    public ClassLoader getClassLoader()
+    {
+        return classLoader;
+    }
+
+    /** 
+     * Creates a new JavaType instance for the specified Class object.
+     * This method provides a hook such that ReflectionJavaModel subclasses
+     * can create instances of a different JavaType implementation. 
+     * @param clazz the Class instance representing the type
+     * @return a new JavaType instance
+     */
+    protected abstract JavaType createJavaType(Class clazz);
+    
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java?view=auto&rev=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java Wed Apr 13 02:11:13 2005
@@ -0,0 +1,259 @@
+/*
+ * 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.reflection;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import java.lang.reflect.Field;
+
+import org.apache.jdo.impl.model.java.PredefinedType;
+import org.apache.jdo.impl.model.java.BaseReflectionJavaField;
+import org.apache.jdo.impl.model.java.BaseReflectionJavaType;
+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
+ * <code>java.lang.reflect.Field</code> instances to get Java related
+ * metadata about types and fields. 
+ *
+ * @author Michael Bouschen
+ * @since JDO 1.1
+ */
+public abstract class ReflectionJavaType
+    extends BaseReflectionJavaType
+{
+    /** The JDOModel instance to lookup JDO metadata. */
+    private JDOModel jdoModel;
+
+    /** Flag indicating whether the superclass is checked already. */
+    private boolean superclassUnchecked = true;
+
+    /** Flag indicating whether the JDOClass info is retrieved already. */
+    private boolean jdoClassUnchecked = true;
+
+    /** The JDO metadata, if this type represents a pc class. */
+    private JDOClass jdoClass;
+
+    /** Map of JavaField instances, key is the field name. */
+    private Map javaFields = new HashMap();
+
+    /** I18N support */
+    private final static I18NHelper msg =  
+        I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle"); //NOI18N
+
+    /** Constructor. */
+    public ReflectionJavaType(Class clazz, JDOModel jdoModel)
+    {
+        // Pass null as the superclass to the super call. This allows lazy
+        // evaluation of the superclass (see getSuperclass implementation).
+        super(clazz, null); 
+        this.jdoModel = jdoModel;
+    }
+
+    /**
+     * Determines if this JavaType object represents an array type.
+     * @return <code>true</code> if this object represents an array type; 
+     * <code>false</code> otherwise.
+     */
+    public boolean isArray()
+    {
+        return clazz.isArray();
+    }
+
+    /** 
+     * Returns <code>true</code> if this JavaType represents a persistence
+     * capable class.
+     * <p>
+     * A {@link org.apache.jdo.model.ModelFatalException} indicates a
+     * problem accessing the JDO meta data for this JavaType.
+     * @return <code>true</code> if this JavaType represents a persistence
+     * capable class; <code>false</code> otherwise.
+     * @exception ModelFatalException if there is a problem accessing the
+     * JDO metadata
+     */
+    public boolean isPersistenceCapable()
+        throws ModelFatalException
+    {
+        return (getJDOClass() != null);
+    }
+
+    /** 
+     * Returns the JavaType representing the superclass of the entity
+     * represented by this JavaType. If this JavaType represents either the 
+     * Object class, an interface, a primitive type, or <code>void</code>, 
+     * then <code>null</code> is returned. If this object represents an
+     * array class then the JavaType instance representing the Object class
+     * is returned.  
+     * @return the superclass of the class represented by this JavaType.
+     */
+    public synchronized JavaType getSuperclass()
+    {
+        if (superclassUnchecked) {
+            superclassUnchecked = false;
+            superclass = getJavaTypeInternal(clazz.getSuperclass());
+        }
+        return superclass;
+    }
+
+    /**
+     * Returns the JDOClass instance if this JavaType represents a
+     * persistence capable class. The method returns <code>null</code>, 
+     * if this JavaType does not represent a persistence capable class.
+     * <p>
+     * A {@link org.apache.jdo.model.ModelFatalException} indicates a
+     * problem accessing the JDO meta data for this JavaType.
+     * @return the JDOClass instance if this JavaType represents a
+     * persistence capable class; <code>null</code> otherwise.
+     * @exception ModelFatalException if there is a problem accessing the
+     * JDO metadata
+     */
+    public synchronized JDOClass getJDOClass()
+        throws ModelFatalException
+    {
+        if (jdoClassUnchecked) {
+            jdoClassUnchecked = false;
+            jdoClass = jdoModel.getJDOClass(getName());
+        }
+        return jdoClass;
+    }
+ 
+    /** 
+     * Returns the JavaType representing the component type of an array. 
+     * If this JavaType does not represent an array type this method
+     * returns <code>null</code>.
+     * @return the JavaType representing the component type of this
+     * JavaType if this class is an array; <code>null</code> otherwise. 
+     */ 
+    public JavaType getArrayComponentType()
+    {
+        JavaType componentType = null;
+        if (isArray()) {
+            Class componentClass = clazz.getComponentType();
+            if (componentClass != null)
+                componentType = getJavaTypeInternal(componentClass);
+        }
+        return componentType;
+    }
+
+    /**
+     * Returns a JavaField instance that reflects the field with the
+     * specified name of the class or interface represented by this
+     * JavaType instance. The method returns <code>null</code>, if the
+     * class or interface (or one of its superclasses) does not have a
+     * field with that name.
+     * @param fieldName the name of the field 
+     * @return the JavaField instance for the specified field in this class
+     * or <code>null</code> if there is no such field.
+     */
+    public JavaField getJavaField(String fieldName) 
+    { 
+        JavaField javaField = getDeclaredJavaField(fieldName);
+        if (javaField == null) {
+            // check superclass
+            JavaType superclass = getSuperclass();
+            if ((superclass != null) &&
+                (superclass != PredefinedType.objectType)) {
+                javaField = superclass.getJavaField(fieldName);
+            }
+        }
+        return javaField;
+    }
+
+    // ===== Methods not defined 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
+     */
+    public JavaField createJavaField(JDOField jdoField, JavaType type)
+    {
+        String name = jdoField.getName();
+        synchronized(javaFields) {
+            JavaField javaField = (JavaField)javaFields.get(name);
+            if (javaField != null) {
+                throw new ModelFatalException(msg.msg(
+                    "ERR_MultipleJavaField", //NOI18N
+                    "ReflectionJavaType.createJavaField", name, getName())); //NOI18N
+            }
+            javaField = new ReflectionJavaField(jdoField, type, this);
+            javaFields.put(name, javaField);
+            return javaField;
+        }
+    }
+
+    /**
+     * Returns a JavaField instance that reflects the declared field with
+     * the specified name of the class or interface represented by this
+     * JavaType instance. The method returns <code>null</code>, if the 
+     * class or interface does not declared a field with that name. It does
+     * not check whether one of its superclasses declared such a field.
+     * @param fieldName the name of the field 
+     * @return the JavaField instance for the specified field in this class
+     */
+    public JavaField getDeclaredJavaField(String fieldName)
+    {
+        synchronized (javaFields) {
+            JavaField javaField = (JavaField)javaFields.get(fieldName);
+            if (javaField == null) {
+                JDOClass jdoClass = getJDOClass();
+                if (jdoClass != null) {
+                    // pc class => look for JDOField first
+                    JDOField jdoField = jdoClass.getDeclaredField(fieldName);
+                    if (jdoField != null) {
+                        javaField = new ReflectionJavaField(jdoField, this);
+                        javaFields.put(fieldName, javaField);
+                    }
+                }
+                
+                // if no field info check reflection
+                if (javaField == null) {
+                    Field field = ReflectionJavaField.getDeclaredFieldPrivileged(
+                        clazz, fieldName);
+                    if (field != null) {
+                        javaField = new ReflectionJavaField(field, this);
+                        javaFields.put(fieldName, javaField);
+                    }
+                }
+            }
+            return javaField;   
+        }
+    }
+
+    /** 
+     * Returns a JavaType instance for the specified Class object. 
+     * This method provides a hook such that ReflectionJavaType subclasses can
+     * implement their own mapping of Class objects to JavaType instances. 
+     */
+    protected abstract JavaType getJavaTypeInternal(Class clazz);
+    
+}

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java?view=diff&r1=161167&r2=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java Wed Apr 13 02:11:13 2005
@@ -20,7 +20,7 @@
 import java.security.PrivilegedAction;
 import java.io.InputStream;
 
-import org.apache.jdo.impl.model.java.AbstractJavaModel;
+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;
@@ -40,135 +40,18 @@
  * @since JDO 1.0.1
  */
 public class RuntimeJavaModel
-    extends AbstractJavaModel
+    extends ReflectionJavaModel
 {
-    /** The ClassLoader instance used as key to cache this JavaModel. */
-    private final ClassLoader classLoader;
-
-    /** Flag passed to the Class.forName call. */
-    private final boolean initialize;
-
-    /** I18N support */
-    private final static I18NHelper msg =  
-        I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle"); //NOI18N
-
     /** Constructor taking the ClassLoader. */
     public RuntimeJavaModel(ClassLoader classLoader) 
     {
-        this(classLoader, true);
+        super(classLoader, true);
     }
     
     /** */
     protected RuntimeJavaModel(ClassLoader classLoader, boolean initialize)
     {
-        super();
-        this.classLoader = classLoader;
-        this.initialize = initialize;
-    }
-
-    /** 
-     * The method returns the JavaType instance for the specified type
-     * name. A type name is unique within one JavaModel instance. The
-     * method returns <code>null</code> if this model instance does not
-     * know a type with the specified name.
-     * <p>
-     * Note, this method calls Class.forName with the wrapped ClassLoader,
-     * if it cannot find a JavaType with the specified name in the cache.
-     * @param name the name of the type
-     * @return a JavaType instance for the specified name or
-     * <code>null</code> if not present in this model instance.
-     */
-    public JavaType getJavaType(String name) 
-    {
-        synchronized (types) {
-            JavaType javaType = (JavaType)types.get(name);
-            if (javaType == null) {
-                try {
-                    // Note, if name denotes a pc class that has not been
-                    // loaded, Class.forName will load the class which
-                    // calls RegisterClassListener.registerClass.
-                    // This will create a new JavaType entry in the cache.
-                    javaType = getJavaType(Class.forName(name, initialize, 
-                                                         classLoader));
-                }
-                catch (ClassNotFoundException ex) {
-                    // cannot find class => return null
-                }
-                catch (LinkageError ex) {
-                    throw new ModelFatalException(msg.msg(
-                        "EXC_ClassLoadingError", name, ex.toString())); //NOI18N
-                }
-            }
-            return javaType;
-        }
-    }
-
-    /** 
-     * The method returns the JavaType instance for the type name of the
-     * specified class object. This is a convenience method for 
-     * <code>getJavaType(clazz.getName())</code>. The major difference
-     * between this method and getJavaType taking a type name is that this 
-     * method is supposed to return a non-<code>null<code> value. The
-     * specified class object describes an existing type.
-     * <p>
-     * Note, this implementation does not call the overloaded getJavaType
-     * method taking a String, because this would retrieve the Class
-     * instance for the specified type again. Instead, it checks the cache 
-     * directly. If not available it creates a new RuntimeJavaType using
-     * the specified class instance.
-     * @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.
-     */
-    public JavaType getJavaType(Class clazz)
-    {
-        String name = clazz.getName();
-        synchronized (types) {
-            JavaType javaType = (JavaType)types.get(name);
-            if (javaType == null) {
-                javaType = createJavaType(clazz);
-                types.put(name, javaType);
-            }
-            return javaType;
-        }
-    }
-
-    /**
-     * 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 
-     * <code>null</code> if no resource with this name is found or if the
-     * caller doesn't have adequate privileges to get the resource.  
-     * <p>
-     * This implementation delegates the request to the wrapped
-     * ClassLoader. 
-     * @param resourceName the resource name
-     * @return an input stream for reading the resource, or <code>null</code> 
-     * if the resource could not be found or if the caller doesn't have
-     * adequate privileges to get the resource. 
-     */
-    public InputStream getInputStreamForResource(final String resourceName)
-    {
-        return (InputStream) AccessController.doPrivileged(
-            new PrivilegedAction () {
-                public Object run () {
-                    return classLoader.getResourceAsStream(resourceName);
-                }
-            }
-            );
-    }
-
-    // ===== Methods not defined in JavaModel =====
-
-    /** 
-     * Returns the ClassLoader wrapped by this RuntimeJavaModel instance.
-     * @return the ClassLoader
-     */
-    public ClassLoader getClassLoader()
-    {
-        return classLoader;
+        super(classLoader, initialize);
     }
 
     /** 

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java?view=diff&r1=161167&r2=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java Wed Apr 13 02:11:13 2005
@@ -30,7 +30,7 @@
 import org.apache.jdo.model.java.JavaType;
 import org.apache.jdo.model.jdo.JDOModelFactory;
 import org.apache.jdo.impl.model.java.AbstractJavaModelFactory;
-import org.apache.jdo.impl.model.java.ReflectionJavaType;
+import org.apache.jdo.impl.model.java.BaseReflectionJavaType;
 import org.apache.jdo.impl.model.jdo.caching.JDOModelFactoryImplCaching;
 import org.apache.jdo.util.I18NHelper;
 
@@ -255,7 +255,7 @@
             return null;
         
         try {
-            return ((ReflectionJavaType)javaType).getJavaClass();
+            return ((BaseReflectionJavaType)javaType).getJavaClass();
         }
         catch (ClassCastException ex) {
             throw new ModelFatalException(msg.msg(

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java?view=diff&r1=161167&r2=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java Wed Apr 13 02:11:13 2005
@@ -16,17 +16,10 @@
 
 package org.apache.jdo.impl.model.java.runtime;
 
-import java.util.Map;
-import java.util.HashMap;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
-import java.lang.reflect.Field;
-
-import org.apache.jdo.impl.model.java.PredefinedType;
-import org.apache.jdo.impl.model.java.ReflectionJavaField;
-import org.apache.jdo.impl.model.java.ReflectionJavaType;
-import org.apache.jdo.model.ModelFatalException;
+import org.apache.jdo.impl.model.java.reflection.ReflectionJavaType;
 import org.apache.jdo.model.java.JavaField;
 import org.apache.jdo.model.java.JavaModel;
 import org.apache.jdo.model.java.JavaModelFactory;
@@ -51,21 +44,6 @@
 public class RuntimeJavaType
     extends ReflectionJavaType
 {
-    /** The JDOModel instance to lookup JDO metadata. */
-    private JDOModel jdoModel;
-
-    /** Flag indicating whether the superclass is checked already. */
-    private boolean superclassUnchecked = true;
-
-    /** Flag indicating whether the JDOClass info is retrieved already. */
-    private boolean jdoClassUnchecked = true;
-
-    /** The JDO metadata, if this type represents a pc class. */
-    private JDOClass jdoClass;
-
-    /** Map of JavaField instances, key is the field name. */
-    private Map javaFields = new HashMap();
-
     /** JavaModelFactory */
     private static final RuntimeJavaModelFactory javaModelFactory =
         (RuntimeJavaModelFactory) AccessController.doPrivileged(
@@ -76,189 +54,10 @@
             }
         );
 
-    /** I18N support */
-    private final static I18NHelper msg =  
-        I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle"); //NOI18N
-
     /** Constructor. */
     public RuntimeJavaType(Class clazz, JDOModel jdoModel)
     {
-        // Pass null as the superclass to the super call. This allows lazy
-        // evaluation of the superclass (see getSuperclass implementation).
-        super(clazz, null); 
-        this.jdoModel = jdoModel;
-    }
-
-    /**
-     * Determines if this JavaType object represents an array type.
-     * @return <code>true</code> if this object represents an array type; 
-     * <code>false</code> otherwise.
-     */
-    public boolean isArray()
-    {
-        return clazz.isArray();
-    }
-
-    /** 
-     * Returns <code>true</code> if this JavaType represents a persistence
-     * capable class.
-     * <p>
-     * A {@link org.apache.jdo.model.ModelFatalException} indicates a
-     * problem accessing the JDO meta data for this JavaType.
-     * @return <code>true</code> if this JavaType represents a persistence
-     * capable class; <code>false</code> otherwise.
-     * @exception ModelFatalException if there is a problem accessing the
-     * JDO metadata
-     */
-    public boolean isPersistenceCapable()
-        throws ModelFatalException
-    {
-        return (getJDOClass() != null);
-    }
-
-    /** 
-     * Returns the JavaType representing the superclass of the entity
-     * represented by this JavaType. If this JavaType represents either the 
-     * Object class, an interface, a primitive type, or <code>void</code>, 
-     * then <code>null</code> is returned. If this object represents an
-     * array class then the JavaType instance representing the Object class
-     * is returned.  
-     * @return the superclass of the class represented by this JavaType.
-     */
-    public synchronized JavaType getSuperclass()
-    {
-        if (superclassUnchecked) {
-            superclassUnchecked = false;
-            superclass = getJavaTypeInternal(clazz.getSuperclass());
-        }
-        return superclass;
-    }
-
-    /**
-     * Returns the JDOClass instance if this JavaType represents a
-     * persistence capable class. The method returns <code>null</code>, 
-     * if this JavaType does not represent a persistence capable class.
-     * <p>
-     * A {@link org.apache.jdo.model.ModelFatalException} indicates a
-     * problem accessing the JDO meta data for this JavaType.
-     * @return the JDOClass instance if this JavaType represents a
-     * persistence capable class; <code>null</code> otherwise.
-     * @exception ModelFatalException if there is a problem accessing the
-     * JDO metadata
-     */
-    public synchronized JDOClass getJDOClass()
-        throws ModelFatalException
-    {
-        if (jdoClassUnchecked) {
-            jdoClassUnchecked = false;
-            jdoClass = jdoModel.getJDOClass(getName());
-        }
-        return jdoClass;
-    }
- 
-    /** 
-     * Returns the JavaType representing the component type of an array. 
-     * If this JavaType does not represent an array type this method
-     * returns <code>null</code>.
-     * @return the JavaType representing the component type of this
-     * JavaType if this class is an array; <code>null</code> otherwise. 
-     */ 
-    public JavaType getArrayComponentType()
-    {
-        JavaType componentType = null;
-        if (isArray()) {
-            Class componentClass = clazz.getComponentType();
-            if (componentClass != null)
-                componentType = getJavaTypeInternal(componentClass);
-        }
-        return componentType;
-    }
-
-    /**
-     * Returns a JavaField instance that reflects the field with the
-     * specified name of the class or interface represented by this
-     * JavaType instance. The method returns <code>null</code>, if the
-     * class or interface (or one of its superclasses) does not have a
-     * field with that name.
-     * @param fieldName the name of the field 
-     * @return the JavaField instance for the specified field in this class
-     * or <code>null</code> if there is no such field.
-     */
-    public JavaField getJavaField(String fieldName) 
-    { 
-        JavaField javaField = getDeclaredJavaField(fieldName);
-        if (javaField == null) {
-            // check superclass
-            JavaType superclass = getSuperclass();
-            if ((superclass != null) &&
-                (superclass != PredefinedType.objectType)) {
-                javaField = superclass.getJavaField(fieldName);
-            }
-        }
-        return javaField;
-    }
-
-    // ===== Methods not defined in JavaType =====
-
-    /**
-     * RegisterClassListener calls this method to create a RuntimeJavaField
-     * instance when processing the enhancer generated metadata.
-     * @param jdoField the JDO field metadata
-     * @param type the type of the field
-     * @return the RuntimeJavaField representation
-     */
-    public JavaField createJavaField(JDOField jdoField, JavaType type)
-    {
-        String name = jdoField.getName();
-        synchronized(javaFields) {
-            JavaField javaField = (JavaField)javaFields.get(name);
-            if (javaField != null) {
-                throw new ModelFatalException(msg.msg(
-                    "ERR_MultipleJavaField", //NOI18N
-                    "RuntimeJavaType.createJavaField", name, getName())); //NOI18N
-            }
-            javaField = new RuntimeJavaField(jdoField, type, this);
-            javaFields.put(name, javaField);
-            return javaField;
-        }
-    }
-
-    /**
-     * Returns a JavaField instance that reflects the declared field with
-     * the specified name of the class or interface represented by this
-     * JavaType instance. The method returns <code>null</code>, if the 
-     * class or interface does not declared a field with that name. It does
-     * not check whether one of its superclasses declared such a field.
-     * @param fieldName the name of the field 
-     * @return the JavaField instance for the specified field in this class
-     */
-    public JavaField getDeclaredJavaField(String fieldName)
-    {
-        synchronized (javaFields) {
-            JavaField javaField = (JavaField)javaFields.get(fieldName);
-            if (javaField == null) {
-                JDOClass jdoClass = getJDOClass();
-                if (jdoClass != null) {
-                    // pc class => look for JDOField first
-                    JDOField jdoField = jdoClass.getDeclaredField(fieldName);
-                    if (jdoField != null) {
-                        javaField = new RuntimeJavaField(jdoField, this);
-                        javaFields.put(fieldName, javaField);
-                    }
-                }
-                
-                // if no field info check reflection
-                if (javaField == null) {
-                    Field field = ReflectionJavaField.getDeclaredFieldPrivileged(
-                        clazz, fieldName);
-                    if (field != null) {
-                        javaField = new RuntimeJavaField(field, this);
-                        javaFields.put(fieldName, javaField);
-                    }
-                }
-            }
-            return javaField;   
-        }
+        super(clazz, jdoModel);
     }
 
     /** 

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java?view=diff&r1=161167&r2=161168
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java Wed Apr 13 02:11:13 2005
@@ -34,9 +34,6 @@
 import org.xml.sax.*;
 import org.xml.sax.helpers.*;
 
-import javax.jdo.JDOFatalInternalException;
-
-
 /**
  * The class reads XML documents according to specified DTD and
  * translates all related events into JDOHandler events.
@@ -301,7 +298,7 @@
                          }
                      );
                     if (stream == null) {
-                        throw new JDOFatalInternalException(
+                        throw new RuntimeException(
                             msg.msg("EXC_MissingJDODTD", //NOI18N
                                 publicId, systemId)); 
                     }



Mime
View raw message