db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r178436 [1/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/
Date Wed, 25 May 2005 13:22:13 GMT
Author: mbo
Date: Wed May 25 06:22:12 2005
New Revision: 178436

URL: http://svn.apache.org/viewcvs?rev=178436&view=rev
Log:
Add support for JavaProperties to the JavaModel

Added:
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaMember.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-MemberImpl.jpg   (with props)
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-ModelImpl.jpg   (with props)
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-TypeImpl.jpg   (with props)
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaPropertyImpl.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaMethod.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaTypeIntrospector.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaElement.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMember.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMethod.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaProperty.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/ComponentTypeHelper.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaField.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaMethod.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModel.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaModelFactory.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaProperty.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/jdk5/JDK5RuntimeJavaType.java
Removed:
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaField.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-Impl.jpg
Modified:
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaModelFactory.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaType.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/Bundle.properties
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaField.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaModel-API.jpg
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaModel.mdl
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaType.java
    incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java
    incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java
    incubator/jdo/trunk/runtime20/maven.xml
    incubator/jdo/trunk/runtime20/project.xml
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModel.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaType.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/jdo/xml/XMLExists.java

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaMember.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaMember.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaMember.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaMember.java Wed May 25 06:22:12 2005
@@ -0,0 +1,154 @@
+/*
+ * 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 org.apache.jdo.model.java.JavaMember;
+import org.apache.jdo.model.java.JavaType;
+
+/**
+ * Abstract super class for JavaMember implementations. 
+ * It provides getters for the name and declaringClass properties which are
+ * initialized in the constructor. 
+ * <p>
+ * A non-abstract subclass must implement methods 
+ * {@link #getModifiers()} and {@link #getType()}.
+ *
+ * @author Michael Bouschen
+ * @since JDO 2.0
+ */
+abstract public class AbstractJavaMember
+    implements JavaMember
+{
+    /** The Field name. */
+    private String name;
+
+    /** The declaring class. */
+    private JavaType declaringClass;
+
+    /** 
+     * Constructor setting the name and declaringClass property.
+     * @param name field name
+     * @param declaringClass the JavaType of the class or interface that
+     * declares this JavaMember.
+     */
+    public AbstractJavaMember(String name, JavaType declaringClass)
+    {
+        this.name = name;
+        this.declaringClass = declaringClass;
+    }
+
+    // ===== Methods specified in JavaMember =====
+
+    /**
+     * Returns the name of the field. 
+     * @return field name
+     */
+    public String getName()
+    {
+        return name;
+    }
+    
+    /**
+     * Returns the JavaType instance representing the class or interface
+     * that declares the field represented by this JavaMember instance.
+     * @return the JavaType instance of the declaring class.
+     */
+    public JavaType getDeclaringClass()
+    {
+        return declaringClass;
+    }
+    
+    /**
+     * Returns the Java language modifiers for the member represented by
+     * this JavaMember, as an integer. The java.lang.reflect.Modifier class
+     * should be used to decode the modifiers. 
+     * @return the Java language modifiers for this JavaMember
+     * @see java.lang.reflect.Modifier
+     */
+    abstract public int getModifiers();
+
+    /**
+     * Returns the JavaType representation of the type of the memeber.
+     * @return type of the member
+     */
+    abstract public JavaType getType();
+    
+    /**
+     * 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()
+    {
+        JavaType componentType = null;
+        JavaType type = getType();
+        if (type.isArray())
+            componentType = type.getArrayComponentType();
+        else if (type.isJDOSupportedCollection())
+            componentType = PredefinedType.objectType;
+        return componentType;
+    }
+
+    // ===== Methods not specified in JavaMember =====
+
+    /**
+     * Indicates whether some other object is "equal to" this one.
+     * @param obj the reference object with which to compare. 
+     * <p>
+     * This implementation matches the declaring class and the name of the
+     * specified object to the declaring class and the name of this
+     * JavaMember. 
+     * @return <code>true</code> if this object is the same as the obj
+     * argument; <code>false</code> otherwise. 
+     */
+    public boolean equals(Object obj)
+    {
+        // return true if obj is this
+        if (obj == this) return  true;
+        // return false if obj does not have the correct type
+        if ((obj == null) || !(obj instanceof JavaMember)) return false;
+
+        JavaMember other = (JavaMember)obj;
+        // compare declaringClass and field names
+        return (getDeclaringClass() == other.getDeclaringClass())
+            && (getName().equals(other.getName()));
+    }
+    
+    /**
+     * Returns a hash code value for the object. 
+     * <p>
+     * This is computed as the exclusive-or of the hashcodes for the
+     * underlying field's declaring class name and its name.
+     * @return a hash code value for this object.
+     */
+    public int hashCode()
+    {
+        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
+    }
+    
+    /**
+     * Returns a string representation of the object. 
+     * @return a string representation of the object.
+     */
+    public String toString()
+    {
+        return getDeclaringClass().getName() + "." + getName(); //NOI18N
+    }
+}

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaModelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaModelFactory.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaModelFactory.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaModelFactory.java Wed May 25 06:22:12 2005
@@ -19,22 +19,17 @@
 import java.util.Map;
 import java.util.HashMap;
 
-import org.apache.jdo.impl.model.jdo.JDOModelFactoryImplDynamic;
 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.JDOModel;
-import org.apache.jdo.model.jdo.JDOModelFactory;
 import org.apache.jdo.util.I18NHelper;
 
 /**
  * Abstract super class for JavaModelFactory implementations. It provides a
  * JavaModel cache and implements the JavaModel lookup method 
- * {@link #getJavaModel(Object key)}. Any JavaModel instance returned by
- * this method is automatically connected to its corresponding JDOModel
- * instance.
+ * {@link #getJavaModel(Object key)}.
  * <p>
  * A non-abstract subclass must implement method 
  * {@link #createJavaModel(Object key)}. The lookup method calls this
@@ -107,7 +102,7 @@
                 }
                 catch (ModelException ex) {
                     throw new ModelFatalException(
-                        "EXC_CannotCreateJavaModel", ex); //NOI18N
+                        msg.msg("EXC_CannotCreateJavaModel"), ex); //NOI18N
                 }
             } 
             return javaModel;

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaType.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaType.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/AbstractJavaType.java Wed May 25 06:22:12 2005
@@ -17,10 +17,10 @@
 package org.apache.jdo.impl.model.java;
 
 import org.apache.jdo.model.java.JavaField;
+import org.apache.jdo.model.java.JavaProperty;
 import org.apache.jdo.model.java.JavaType;
 import org.apache.jdo.model.jdo.JDOClass;
 
-
 /**
  * Abstract super class for JavaType implementations. It provides a
  * default implementation for all methods except getName. The methods return
@@ -35,10 +35,12 @@
  *
  * @author Michael Bouschen
  * @since JDO 1.0.1
+ * @version JDO 2.0
  */
 abstract public class AbstractJavaType
     implements JavaType 
 {
+    public Object getUnderlyingObject() { return null; }
     public boolean isPrimitive() { return false; }
     public boolean isIntegral()  { return false; }
     public boolean isFloatingPoint() { return false; }
@@ -58,6 +60,9 @@
     public JDOClass getJDOClass() { return null; }
     public JavaType getArrayComponentType() { return null; }
     public JavaField getJavaField(String name) { return null; }
+    public JavaField[] getDeclaredJavaFields() { return null; }
+    public JavaProperty getJavaProperty(String name) { return null; }
+    public JavaProperty[] getDeclaredJavaProperties() { return null; }
     
     // ===== Methods not defined in JavaType =====
 
@@ -106,5 +111,4 @@
     {
         return getName();
     }
-    
 }

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaField.java Wed May 25 06:22:12 2005
@@ -20,7 +20,6 @@
 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;
@@ -38,9 +37,11 @@
  * @see PredefinedType
  * @author Michael Bouschen
  * @since JDO 1.1
+ * @version JDO 2.0
  */
 public class BaseReflectionJavaField
-    extends AbstractJavaField
+    extends AbstractJavaMember
+    implements JavaField
 {
     /** The wrapped java.lang.reflect.Field instance. */
     private Field field;
@@ -78,6 +79,22 @@
         super(fieldName, declaringClass);
     }
 
+    // ===== Methods specified in JavaElement =====
+
+    /**
+     * Returns the environment specific instance wrapped by this JavaModel
+     * element. This implementation returns the
+     * <code>java.lang.reflect.Field</code> instance for this JavaField.
+     * @return the environment specific instance wrapped by this JavaModel
+     * element.
+     */
+    public Object getUnderlyingObject() 
+    {
+        return getField();
+    }
+
+    // ===== Methods specified in JavaMember =====
+
     /**
      * Returns the Java language modifiers for the field represented by
      * this JavaField, as an integer. The java.lang.reflect.Modifier class
@@ -91,6 +108,8 @@
         return field.getModifiers();
     }
 
+    // ===== Methods specified in JavaField =====
+
     /**
      * Returns the JavaType representation of the field type.
      * @return field type
@@ -106,7 +125,22 @@
         return type;
     }
     
-    // ===== Methods not defined in JavaField =====
+    /**
+     * Returns the corresponding JDOField instance, if the JDOModel
+     * provides any JDO metadata for the field represented by this
+     * JavaField. If there is no corresponding JDOField representation, the
+     * method returns <code>null</code>.
+     * <p>
+     * This implementation always returns <code>null</code>.
+     * @return the corresponding JDOField instance (if available);
+     * <code>null</code> otherwise.
+     */
+    public JDOField getJDOField()
+    {
+        return null;
+    }
+
+    // ===== Methods not specified in JavaField =====
 
     /** 
      * Returns the java.lang.reflect.Field that is wrapped by this
@@ -120,10 +154,11 @@
     }
 
     /**
-     * Helper method to retrieve the java.lang.reflect.Field for this
-     * JavaField.
+     * Helper method to retrieve the java.lang.reflect.Field for the specified
+     * field name.
      * @param clazz the Class instance of the declaring class or interface
      * @param fieldName the field name
+     * @return the java.lang.reflect.Field for the specified field name.
      */
     public static Field getDeclaredFieldPrivileged(final Class clazz, 
                                                    final String fieldName)
@@ -144,6 +179,39 @@
                     }
                     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()));
+                    }
+                }
+            }
+            );
+    }
+
+    /**
+     * Helper method to retrieve the declared java.lang.reflect.Field
+     * instances for the specified class.
+     * @param clazz the Class instance of the declaring class or interface
+     * @return the java.lang.reflect.Field instances for the declared fields
+     * of the specified class.
+     */
+    public static Field[] getDeclaredFieldsPrivileged(final Class clazz)
+    {
+        if (clazz == null)
+            return null;
+
+        return (Field[]) AccessController.doPrivileged(
+            new PrivilegedAction() {
+                public Object run () {
+                    try {
+                        return clazz.getDeclaredFields();
+                    }
+                    catch (SecurityException ex) {
+                        throw new ModelFatalException(
+                            msg.msg("EXC_CannotGetDeclaredFields", //NOI18N
+                                    clazz.getName()), ex); 
                     }
                     catch (LinkageError ex) {
                         throw new ModelFatalException(msg.msg(

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/BaseReflectionJavaType.java Wed May 25 06:22:12 2005
@@ -20,6 +20,7 @@
 
 import org.apache.jdo.model.ModelFatalException;
 import org.apache.jdo.model.java.JavaField;
+import org.apache.jdo.model.java.JavaProperty;
 import org.apache.jdo.model.java.JavaType;
 import org.apache.jdo.util.I18NHelper;
 
@@ -64,6 +65,22 @@
         this.superclass = superclass;
     }
     
+    // ===== Methods specified in JavaElement =====
+
+    /**
+     * Returns the environment specific instance wrapped by this JavaModel
+     * element. This implementation returns the
+     * <code>java.lang.Class</code> instance for this JavaType.
+     * @return the environment specific instance wrapped by this JavaModel
+     * element.
+     */
+    public Object getUnderlyingObject() 
+    {
+        return getJavaClass();
+    }
+
+    // ===== Methods specified in JavaType =====
+
     /** 
      * Determines if this JavaType object represents an interface type.
      * @return <code>true</code> if this object represents an interface type; 
@@ -154,6 +171,24 @@
         }
         
         return null;
+    }
+
+    /** */
+    public JavaField[] getDeclaredJavaFields()
+    {
+        throw new UnsupportedOperationException();
+    }
+    
+    /** */
+    public JavaProperty getJavaProperty(String name)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /** */
+    public JavaProperty[] getDeclaredJavaProperties()
+    {
+        throw new UnsupportedOperationException();
     }
 
     // ===== Methods not defined in JavaType =====

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/Bundle.properties?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/Bundle.properties (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/Bundle.properties Wed May 25 06:22:12 2005
@@ -27,7 +27,7 @@
 EXC_ClassLoadingError=Error during loading of class ''{0}'': {1}.
 
 #
-# ReflectionJavaType
+# BaseReflectionJavaType
 #
 
 # {0} - error location (class.method)
@@ -41,16 +41,60 @@
 EXC_CannotGetDeclaredField=A SecurityException was thrown when trying to \
 get a declared field of class ''{0}''.  You must grant \
 java.lang.RuntimePermission("accessDeclaredMembers") to the codeBase \
-containing the JDO Reference Implementation (jdori.jar).
+containing the JavaModel and JDOModel implementation.
+# {0} - class name
+EXC_CannotGetDeclaredFields=A SecurityException was thrown when trying to \
+get the declared fields of class ''{0}''.  You must grant \
+java.lang.RuntimePermission("accessDeclaredMembers") to the codeBase \
+containing the JavaModel and JDOModel implementation.
 
 #NOI18N
 ERR_MissingFieldInstance={0}: cannot find reflection field instance for field {1}.
 
 #
+# JavaPropertyImpl
+#
+EXC_MissingGetterAndSetter=Cannot define property ''{0}'' of class ''{1}'' with setter and getter method being null.
+
+#
 # AbstractJavaModelFactory
 #
 
 # {0} - class name
 # {1} - method name
 EXC_MethodNotSupported=Class {0} does not support method {1}.
+EXC_CannotCreateJavaModel=Problems during JavaModel creation.
+
+#
+# ReflectionJavaModelFactory
+#
 
+# {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 \
+JavaModel and JDOModel implementation.
+
+# {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.
+
+#
+# ReflectionJavaTypeIntrospector
+#
+
+#NOI18N
+# {0} - Class
+ERR_CannotIntrospectClass=Cannot introspect class ''{0}''.

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-MemberImpl.jpg
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-MemberImpl.jpg?rev=178436&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-MemberImpl.jpg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-ModelImpl.jpg
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-ModelImpl.jpg?rev=178436&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-ModelImpl.jpg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-TypeImpl.jpg
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-TypeImpl.jpg?rev=178436&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaModel-TypeImpl.jpg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaPropertyImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaPropertyImpl.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaPropertyImpl.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/JavaPropertyImpl.java Wed May 25 06:22:12 2005
@@ -0,0 +1,147 @@
+/*
+ * 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 org.apache.jdo.model.ModelFatalException;
+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.util.I18NHelper;
+
+/**
+ * Default Implementation of the JavaProperty interface. A JavaProperty
+ * instance represents a JavaBeans property.
+ *
+ * @author Michael Bouschen
+ * @since JDO 2.0
+ */
+public class JavaPropertyImpl
+    extends AbstractJavaMember
+    implements JavaProperty
+{
+    /** The method object of the getter method. */
+    private final JavaMethod getter;
+
+    /** The method object of the setter method. */
+    private final JavaMethod setter;
+
+    /** The type of the property. */
+    private final JavaType type;
+
+    /** I18N support */
+    private static I18NHelper msg = 
+        I18NHelper.getInstance(JavaPropertyImpl.class);
+
+    /** Constructor setting name, getter, setter, type and declaringClass. */
+    public JavaPropertyImpl(String name, JavaMethod getter, JavaMethod setter,
+                            JavaType type, JavaType declaringClass)
+        throws ModelFatalException
+    {
+        super(name, declaringClass);
+        this.getter = getter;
+        this.setter = setter;
+        this.type = type;
+        if ((getter == null) && (setter == null))
+            throw new ModelFatalException(
+                msg.msg("EXC_MissingGetterAndSetter", //NOI18N
+                         name, declaringClass.getName()));
+    }
+    
+    // ===== Methods specified in JavaElement =====
+    
+    /** 
+     * Returns the environment specific instance wrapped by this JavaModel
+     * element.
+     * <p> 
+     * This implementation returns the underlying object of the
+     * getter method if available; otherwise the one from the setter method. 
+     * @return the environment specific instance wrapped by this JavaModel
+     * element.
+     */
+    public Object getUnderlyingObject() 
+    {
+        Object underlyingObject = null;
+        
+        if (getter != null)
+            underlyingObject = getter.getUnderlyingObject();
+        else if (setter != null)
+            underlyingObject = setter.getUnderlyingObject();
+
+        return underlyingObject;
+    }   
+
+    // ===== Methods specified in JavaMember =====
+
+    /**
+     * Returns the Java language modifiers for the field represented by
+     * this JavaMember, as an integer. The java.lang.reflect.Modifier class
+     * should be used to decode the modifiers. 
+     * <p> 
+     * This implementation returns the underlying object of the getter method
+     * if available; otherwise the one from the setter method.  
+     * @return the Java language modifiers for this JavaMember
+     * @see java.lang.reflect.Modifier
+     */
+    public int getModifiers()
+    {
+        int modifiers = 0;
+        
+        if (getter != null)
+            modifiers = getter.getModifiers();
+        else if (setter != null)
+            modifiers = setter.getModifiers();
+
+        return modifiers;
+    }
+    
+    // ===== Methods specified in JavaProperty =====
+
+    /**
+     * Returns the JavaMethod representation of the getter method for this
+     * JavaProperty. If there is no getter method for this JavaProperty
+     * (i.e. the property is write-only), then the method returns
+     * <code>null</code>.
+     * @return the getter method if available; or <code>null</code>
+     * otherwise.
+     */
+    public JavaMethod getGetterMethod()
+    {
+        return getter;
+    }
+
+    /**
+     * Returns the JavaMethod representation of the setter method for this
+     * JavaProperty. If there is no setter method for this JavaProperty
+     * (i.e. the property is read-only), then the method returns
+     * <code>null</code>.
+     * @return the setter method if available; or <code>null</code>
+     * otherwise.
+     */
+    public JavaMethod getSetterMethod()
+    {
+        return setter;
+    }
+
+    /**
+     * Returns the JavaType representation of the property type.
+     * @return property type
+     */
+    public JavaType getType()
+    {
+        return type;
+    }
+}

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaField.java Wed May 25 06:22:12 2005
@@ -16,8 +16,6 @@
 
 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;
@@ -34,6 +32,7 @@
  * 
  * @author Michael Bouschen
  * @since JDO 1.1
+ * @version JDO 2.0
  */
 public class ReflectionJavaField
     extends BaseReflectionJavaField
@@ -53,18 +52,7 @@
     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);
+        this.type = getJavaTypeForClass(field.getType());
     }
     
     /** 
@@ -91,7 +79,7 @@
     public JavaType getType()
     {
         if (type == null) {
-            type = getJavaTypeInternal(getField().getType());
+            type = getJavaTypeForClass(getField().getType());
         }
         return type;
     }
@@ -119,12 +107,8 @@
      * 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)
+    public JavaType getJavaTypeForClass(Class clazz)
     {
-        return ((ReflectionJavaType)getDeclaringClass()).getJavaTypeInternal(clazz);
+        return ((ReflectionJavaType)getDeclaringClass()).getJavaTypeForClass(clazz);
     }
-    
-
-    
 }
-

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaMethod.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaMethod.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaMethod.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaMethod.java Wed May 25 06:22:12 2005
@@ -0,0 +1,124 @@
+/*
+ * 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.lang.reflect.Method;
+
+import org.apache.jdo.model.java.JavaMethod;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.impl.model.java.AbstractJavaMember;
+
+/**
+ * A reflection based JavaMethod implementation.
+ * The implementation takes <code>java.lang.reflect.Method</code> instances
+ * to get Java related metadata about methods. 
+ * 
+ * @author Michael Bouschen
+ * @since JDO 2.0
+ */
+public class ReflectionJavaMethod
+    extends AbstractJavaMember
+    implements JavaMethod
+{
+    /** The wrapped java.lang.reflect.Method instance. */
+    private final Method method;
+    
+    /** 
+     * Constructor.
+     * @param method the reflection method representation.
+     * @param declaringClass the JavaType of the class that declares the field.
+     */
+    public ReflectionJavaMethod(Method method, JavaType declaringClass)
+    {
+        super(method.getName(), declaringClass);
+        this.method = method;
+    }
+
+    // ===== Methods specified in JavaElement =====
+
+    /**
+     * Returns the environment specific instance wrapped by this JavaModel
+     * element. This implementation returns the
+     * <code>java.lang.reflect.Method</code> instance for this JavaMethod.
+     * @return the environment specific instance wrapped by this JavaModel
+     * element.
+     */
+    public Object getUnderlyingObject() 
+    {
+        return method;
+    }
+
+    // ===== Methods specified in JavaMember =====
+    
+    /**
+     * Returns the Java language modifiers for the field represented by
+     * this JavaMember, as an integer. The java.lang.reflect.Modifier class
+     * should be used to decode the modifiers. 
+     * @return the Java language modifiers for this JavaMember
+     * @see java.lang.reflect.Modifier
+     */
+    public int getModifiers()
+    {
+        return method.getModifiers();
+    }
+
+    /** */
+    public JavaType getType() 
+    {
+        return getReturnType();
+    }
+
+    // ===== Methods specified in JavaMethod =====
+
+    /**
+     * Returns the JavaType representation of the method return type.
+     * @return method return type.
+     */
+    public JavaType getReturnType()
+    {
+        return getJavaTypeForClass(method.getReturnType());
+    }
+
+    /**
+     * Returns an array of JavaType instances that represent the formal
+     * parameter types, in declaration order, of the method represented by
+     * this JavaMethod instance.
+     * @return the types of teh formal parameters.
+     */
+    public JavaType[] getParameterTypes()
+    {
+        Class[] params = method.getParameterTypes();
+        JavaType[] paramTypes = new JavaType[params.length];
+        for (int i = 0; i < params.length; i++) {
+            paramTypes[i] = getJavaTypeForClass(params[i]);
+        }
+        return paramTypes;
+    }
+    
+    // ===== Methods not defined in JavaMethod =====
+
+    /** 
+     * 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 ((ReflectionJavaType) getDeclaringClass()).
+            getJavaTypeForClass(clazz);
+    }
+}

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java Wed May 25 06:22:12 2005
@@ -23,7 +23,6 @@
 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;
 
 /**
@@ -37,8 +36,9 @@
  *
  * @author Michael Bouschen
  * @since JDO 1.1
+ * @version JDO 2.0
  */
-public abstract class ReflectionJavaModel
+public class ReflectionJavaModel
     extends AbstractJavaModel
 {
     /** The ClassLoader instance used as key to cache this JavaModel. */
@@ -47,22 +47,28 @@
     /** Flag passed to the Class.forName call. */
     private final boolean initialize;
 
+    /** The declaring JavaModelFactory. */
+    protected final ReflectionJavaModelFactory declaringJavaModelFactory;
+
     /** 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) 
+    /** Constructor. */
+    public ReflectionJavaModel(ClassLoader classLoader,
+        ReflectionJavaModelFactory declaringJavaModelFactory)
     {
-        this(classLoader, true);
+        this(classLoader, true, declaringJavaModelFactory);
     }
     
-    /** */
-    protected ReflectionJavaModel(ClassLoader classLoader, boolean initialize)
+    /** Constructor. */
+    protected ReflectionJavaModel(ClassLoader classLoader, boolean initialize, 
+        ReflectionJavaModelFactory declaringJavaModelFactory)
     {
         super();
         this.classLoader = classLoader;
         this.initialize = initialize;
+        this.declaringJavaModelFactory = declaringJavaModelFactory;
     }
 
     /** 
@@ -125,7 +131,7 @@
         synchronized (types) {
             JavaType javaType = (JavaType)types.get(name);
             if (javaType == null) {
-                javaType = createJavaType(clazz);
+                javaType = newJavaTypeInstance(clazz);
                 types.put(name, javaType);
             }
             return javaType;
@@ -169,14 +175,23 @@
     {
         return classLoader;
     }
+    
+    /** */
+    public ReflectionJavaModelFactory getDeclaringJavaModelFactory()
+    {
+        return declaringJavaModelFactory;
+    }
 
     /** 
-     * 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. 
+     * Creates a new instance of the JavaType implementation class.
+     * <p>
+     * This implementation returns a ReflectionJavaType instance.
      * @param clazz the Class instance representing the type
      * @return a new JavaType instance
      */
-    protected abstract JavaType createJavaType(Class clazz);
+    protected JavaType newJavaTypeInstance(Class clazz)
+    {
+        return new ReflectionJavaType(clazz, this);
+    }
     
 }

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java Wed May 25 06:22:12 2005
@@ -0,0 +1,226 @@
+/*
+ * 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 org.apache.jdo.model.ModelException;
+import org.apache.jdo.model.ModelFatalException;
+import org.apache.jdo.model.java.JavaModel;
+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.util.I18NHelper;
+
+/**
+ * A reflection based JavaModelFactory implementation. 
+ * 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.
+ * 
+ * @author Michael Bouschen
+ * @since JDO 2.0
+ */
+public abstract class ReflectionJavaModelFactory
+    extends AbstractJavaModelFactory
+{    
+    /** I18N support */
+    private final static I18NHelper msg =  
+        I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle"); //NOI18N
+
+    /**
+     * 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()))); //NOI18N
+        
+        ClassLoader classLoader = (ClassLoader)key;
+        JavaModel javaModel = newJavaModelInstance(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 ReflectionJavaModelFactory 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.
+     */
+    public JavaType getJavaType(Object typeDesc)
+    {
+        if (typeDesc == null)
+            return null;
+
+        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();
+                    }
+                }
+                );
+        }
+        catch (SecurityException ex) {
+            throw new ModelFatalException(
+                msg.msg("EXC_CannotGetClassLoader", clazz), 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.
+     */
+    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
+        }
+    }
+
+    //========= Internal helper methods ==========
+    
+    /** 
+     * Creates a new instance of the JavaModel implementation class.
+     * <p>
+     * This implementation returns a <code>ReflectionJavaModel</code>
+     * instance.
+     * @return a new JavaModel instance.
+     */
+    protected JavaModel newJavaModelInstance(ClassLoader classLoader) {
+        return new ReflectionJavaModel(classLoader, this);
+    }
+    
+    /**
+     * 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(
+                msg.msg("ERR_CannotSetJDOModel"), ex); //NOI18N
+        }
+    }
+}

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaType.java Wed May 25 06:22:12 2005
@@ -18,26 +18,23 @@
 
 import java.util.Map;
 import java.util.HashMap;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 
 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.impl.model.java.JavaPropertyImpl;
 import org.apache.jdo.model.ModelFatalException;
 import org.apache.jdo.model.java.JavaField;
+import org.apache.jdo.model.java.JavaMethod;
 import org.apache.jdo.model.java.JavaModel;
-import org.apache.jdo.model.java.JavaModelFactory;
+import org.apache.jdo.model.java.JavaProperty;
 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
@@ -45,12 +42,13 @@
  *
  * @author Michael Bouschen
  * @since JDO 1.1
+ * @version JDO 2.0
  */
-public abstract class ReflectionJavaType
+public class ReflectionJavaType
     extends BaseReflectionJavaType
 {
-    /** The JDOModel instance to lookup JDO metadata. */
-    private JDOModel jdoModel;
+    /** The declaring JavaModel instance. */
+    protected final ReflectionJavaModel declaringJavaModel;
 
     /** Flag indicating whether the superclass is checked already. */
     private boolean superclassUnchecked = true;
@@ -62,19 +60,22 @@
     private JDOClass jdoClass;
 
     /** Map of JavaField instances, key is the field name. */
-    private Map javaFields = new HashMap();
+    protected Map declaredJavaFields = new HashMap();
+
+    /** Map of JavaProperty instances, key is the property name. */
+    protected Map declaredJavaProperties = new HashMap();
 
-    /** I18N support */
-    private final static I18NHelper msg =  
-        I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle"); //NOI18N
+    /** Flag indicating whether thsi JavaTYpe has been introspected. */
+    private boolean introspected = false;
 
     /** Constructor. */
-    public ReflectionJavaType(Class clazz, JDOModel jdoModel)
+    public ReflectionJavaType(Class clazz, 
+        ReflectionJavaModel declaringJavaModel)
     {
         // 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;
+        this.declaringJavaModel = declaringJavaModel;
     }
 
     /**
@@ -117,7 +118,7 @@
     {
         if (superclassUnchecked) {
             superclassUnchecked = false;
-            superclass = getJavaTypeInternal(clazz.getSuperclass());
+            superclass = getJavaTypeForClass(clazz.getSuperclass());
         }
         return superclass;
     }
@@ -139,7 +140,7 @@
     {
         if (jdoClassUnchecked) {
             jdoClassUnchecked = false;
-            jdoClass = jdoModel.getJDOClass(getName());
+            jdoClass = declaringJavaModel.getJDOModel().getJDOClass(getName());
         }
         return jdoClass;
     }
@@ -157,7 +158,7 @@
         if (isArray()) {
             Class componentClass = clazz.getComponentType();
             if (componentClass != null)
-                componentType = getJavaTypeInternal(componentClass);
+                componentType = getJavaTypeForClass(componentClass);
         }
         return componentType;
     }
@@ -186,67 +187,109 @@
         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
+     * Returns an array of JavaField instances representing the declared
+     * fields of the class represented by this JavaType instance. Note, this
+     * method does not return JavaField instances representing inherited
+     * fields. 
+     * @return an array of declared JavaField instances. 
+     */
+    public JavaField[] getDeclaredJavaFields()
+    {
+        introspectClass();
+        return (JavaField[]) declaredJavaFields.values().toArray(
+            new JavaField[0]);
+    }
+    
+     /**
+     * Returns a JavaProperty instance that reflects the property 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 name the name of the property 
+     * @return the JavaProperty instance for the specified property in this
+     * class or <code>null</code> if there is no such property.
+     */
+    public JavaProperty getJavaProperty(String name)
+    {
+        JavaProperty javaProperty = getDeclaredJavaProperty(name);
+        if (javaProperty == null) {
+            // check superclass
+            JavaType superclass = getSuperclass();
+            if ((superclass != null) &&
+                (superclass != PredefinedType.objectType)) {
+                javaProperty = superclass.getJavaProperty(name);
             }
-            javaField = new ReflectionJavaField(jdoField, type, this);
-            javaFields.put(name, javaField);
-            return javaField;
         }
+        return javaProperty;
     }
 
     /**
+     * Returns an array of JavaProperty instances representing the declared
+     * properties of the class represented by this JavaType instance. Note,
+     * this method does not return JavaField instances representing inherited
+     * properties. 
+     * @return an array of declared JavaField instances. 
+     */
+    public JavaProperty[] getDeclaredJavaProperties()
+    {
+        introspectClass();
+        return (JavaProperty[]) declaredJavaProperties.values().toArray(
+            new JavaProperty[0]);
+    }
+
+    // ===== Methods not specified in JavaType =====
+
+    /**
      * 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.
+     * not check whether one of its superclasses declares 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)
+    public synchronized 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);
-                    }
+        JavaField javaField = (JavaField)declaredJavaFields.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 = newJavaFieldInstance(jdoField, null);
+                    declaredJavaFields.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);
-                    }
+            }
+            
+            // if no field info check reflection
+            if (javaField == null) {
+                Field field = ReflectionJavaField.getDeclaredFieldPrivileged(
+                    clazz, fieldName);
+                if (field != null) {
+                    javaField = newJavaFieldInstance(field);
+                    declaredJavaFields.put(fieldName, javaField);
                 }
             }
-            return javaField;   
         }
+        return javaField;   
+    }
+
+    /**
+     * Returns a JavaProperty instance that reflects the declared property
+     * 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 property with that name. It does
+     * not check whether one of its superclasses declares such a property.
+     * @param name the name of the property 
+     * @return the JavaField instance for the specified property in this class
+     */
+    public JavaProperty getDeclaredJavaProperty(String name) 
+    {
+        introspectClass();
+        return (JavaProperty)declaredJavaProperties.get(name);
     }
 
     /** 
@@ -254,6 +297,113 @@
      * 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);
+    public JavaType getJavaTypeForClass(Class clazz)
+    {
+        return declaringJavaModel.getDeclaringJavaModelFactory().getJavaType(clazz);
+    }
+
+    /** 
+     * Creates a new JavaProperty instance and adds it to the list of
+     * declared properties of this class.
+     * @param name the name of the property
+     * @param getter the getter method
+     * @param setter the setter method
+     * @param type the ytpe of the property
+     * @return a new JavaProperty declared by this class
+     */
+    public synchronized JavaProperty createJavaProperty(
+        String name, JavaMethod getter, JavaMethod setter, JavaType type)
+        throws ModelFatalException
+    {
+        JavaProperty javaProperty = 
+            newJavaPropertyInstance(name, getter, setter, type);
+        declaredJavaProperties.put(name, javaProperty);
+        return javaProperty;
+    }
+
+    /**
+     * Creates a new JavaMethod instance.
+     * @param method the java.lang.reflect.Method instance
+     * @return a new JavaMethod declared by this class
+     */
+    public JavaMethod createJavaMethod(Method method)
+    {
+        return newJavaMethodInstance(method);
+    }
+
+    /**
+     * 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 ReflectionJavaField(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 ReflectionJavaField(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) 
+        throws ModelFatalException
+    {
+        return new JavaPropertyImpl(name, getter, setter, type, this);
+    }
+
+    /**
+     * Creates a new instance of the JavaMethod implementation class.
+     * <p>
+     * This implementation returns a <code>ReflectionJavaMethod</code>
+     * instance.
+     * @return a new JavaMethod instance.
+     */
+    protected JavaMethod newJavaMethodInstance(Method method) 
+    {
+        return new ReflectionJavaMethod(method, this);
+    }
+
+    /** 
+     * Helper method to introspect the class and set the declared fields and
+     * properties. 
+     */
+    protected synchronized void introspectClass() 
+    {
+        if (introspected)
+            // has been introspected before => return;
+            return;
+        
+        introspected = true;
+        
+        new ReflectionJavaTypeIntrospector().addDeclaredJavaProperties(this);
+
+        // now get all the declared fields
+        Field[] fields = ReflectionJavaField.getDeclaredFieldsPrivileged(clazz);
+        for (int i = 0; i < fields.length; i++) {
+            Field field = fields[i];
+            String fieldName = field.getName();
+            if (declaredJavaFields.get(fieldName) == null) {
+                JavaField javaField = newJavaFieldInstance(field);
+                declaredJavaFields.put(fieldName, javaField);
+            }
+        }
+    }
+} 

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaTypeIntrospector.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaTypeIntrospector.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaTypeIntrospector.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaTypeIntrospector.java Wed May 25 06:22:12 2005
@@ -0,0 +1,82 @@
+/*
+ * 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.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+
+import java.lang.reflect.Method;
+
+import org.apache.jdo.model.ModelFatalException;
+import org.apache.jdo.model.java.JavaMethod;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.util.I18NHelper;
+
+/** 
+ * Helper clas to intropsect a ReflectionJavaType representing a class for
+ * properties. 
+ *
+ * @author Michael Bouschen
+ * @since JDO 2.0
+ */
+public class ReflectionJavaTypeIntrospector
+{
+    /** I18N support */
+    private final static I18NHelper msg =  
+        I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle"); //NOI18N
+    
+    /** 
+     * Returns a map of properties for the specified class. The key is the
+     * property name, value is the JavaProperty instance.
+     * @param beanClass the class to be introspected
+     * @return a map of JavaProperty instances
+     */
+    public void addDeclaredJavaProperties(ReflectionJavaType beanClass) 
+    {
+        Class clazz = beanClass.getJavaClass();
+        try {
+            BeanInfo beanInfo = Introspector.getBeanInfo(
+                clazz, clazz.getSuperclass());
+            PropertyDescriptor[] descrs = 
+                beanInfo.getPropertyDescriptors();
+            if (descrs != null) {
+                for (int i = 0; i < descrs.length; i++) {
+                    PropertyDescriptor descr = descrs[i];
+                    if (descr == null) continue;
+                    String name = descr.getName();
+                    JavaType type = 
+                        beanClass.getJavaTypeForClass(descr.getPropertyType());
+                    Method getter = descr.getReadMethod();
+                    JavaMethod javaGetter = (getter == null) ? null : 
+                        beanClass.createJavaMethod(getter);
+                    Method setter = descr.getWriteMethod();
+                    JavaMethod javaSetter = (setter == null) ? null : 
+                        beanClass.createJavaMethod(setter);
+                    beanClass.createJavaProperty(name, javaGetter, 
+                                                 javaSetter, type);
+                }
+            }
+        }
+        catch (IntrospectionException ex) {
+            throw new ModelFatalException(msg.msg(
+                "ERR_CannotIntrospectClass", beanClass.getName()), ex); //NOI18N
+        }
+    }
+}
+

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaElement.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaElement.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaElement.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaElement.java Wed May 25 06:22:12 2005
@@ -0,0 +1,38 @@
+/*
+ * 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.model.java;
+
+/**
+ * This is the super interface for all the JavaModel elements, such as 
+ * JavaField, JavaType, etc.
+ * 
+ * @author Michael Bouschen
+ * @since JDO 2.0
+ */
+public interface JavaElement 
+{
+
+    /**
+     * Returns the environment specific instance wrapped by this JavaModel
+     * element. E.g. a runtime implementation of JavaField might use a
+     * java.lang.reflect.Field instance as the underlying object.
+     * @return the environment specific instance wrapped by this JavaModel
+     * element.
+     */
+    public Object getUnderlyingObject();
+    
+}

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaField.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaField.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaField.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaField.java Wed May 25 06:22:12 2005
@@ -25,43 +25,16 @@
  * available). 
  * <p>
  * Different environments (runtime, enhancer, development) will have
- * different JavaType implementations to provide answers to the various
+ * different JavaField implementations to provide answers to the various
  * methods. 
  * 
  * @author Michael Bouschen
  * @since JDO 1.0.1
+ * @version JDO 2.0
  */
-public interface JavaField 
+public interface JavaField extends JavaMember 
 {
     /**
-     * Returns the name of the field. 
-     * @return field name
-     */
-    public String getName();
-
-    /**
-     * 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();
-
-    /**
-     * Returns the JavaType representation of the field type.
-     * @return field type
-     */
-    public JavaType getType();
-
-    /**
-     * Returns the JavaType instance representing the class or interface
-     * that declares the field represented by this JavaField instance.
-     * @return the JavaType instance of the declaring class.
-     */
-    public JavaType getDeclaringClass();    
-
-    /**
      * Returns the corresponding JDOField instance, if the JDOModel
      * provides any JDO metadata for the field represented by this
      * JavaField. If there is no corresponding JDOField representation, the
@@ -81,5 +54,4 @@
      * <code>null</code> otherwise.
      */
     public JDOField getJDOField();
-
 }

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMember.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMember.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMember.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMember.java Wed May 25 06:22:12 2005
@@ -0,0 +1,65 @@
+/*
+ * 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.model.java;
+
+/**
+ * This is the super interface for named JavaModel elements having a declaring
+ * class such as JavaField, JavaMethod, etc.
+ * 
+ * @author Michael Bouschen
+ * @since JDO 2.0
+ */
+public interface JavaMember extends JavaElement 
+{
+    /**
+     * Returns the name of the member. 
+     * @return member name
+     */
+    public String getName();
+
+    /**
+     * Returns the JavaType instance representing the class or interface
+     * that declares the member represented by this JavaMember instance.
+     * @return the JavaType instance of the declaring class.
+     */
+    public JavaType getDeclaringClass();
+
+    /**
+     * Returns the Java language modifiers for the field represented by
+     * this JavaMember, as an integer. The java.lang.reflect.Modifier class
+     * should be used to decode the modifiers. 
+     * @return the Java language modifiers for this JavaMember
+     * @see java.lang.reflect.Modifier
+     */
+    public int getModifiers();
+
+    /**
+     * Returns the JavaType representation of the type of the member.
+     * @return type of the member
+     */
+    public JavaType getType();
+
+    /**
+     * Returns the JavaType representation of the component type of the type
+     * of the member, if the field type is an array or collection. The
+     * method returns <code>null</code>, if the member type is not an array
+     * or collection.
+     * @return the component type of the member type in case of an array or
+     * collection.
+     */
+    public JavaType getComponentType();
+}

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMethod.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMethod.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMethod.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaMethod.java Wed May 25 06:22:12 2005
@@ -0,0 +1,46 @@
+/*
+ * 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.model.java;
+
+/**
+ * A JavaMethod instance represents a method declared by a class. It allows
+ * to get detailed information about the method such as name, modifiers,
+ * return type, parameters, and the declaring class.
+ * <p>
+ * Different environments (runtime, enhancer, development) will have
+ * different JavaMethod implementations to provide answers to the various
+ * methods. 
+ * 
+ * @author Michael Bouschen
+ * @version JDO 2.0
+ */
+public interface JavaMethod extends JavaMember 
+{
+    /**
+     * Returns the JavaType representation of the method return type.
+     * @return method return type.
+     */
+    public JavaType getReturnType();
+
+    /**
+     * Returns an array of JavaType instances that represent the formal
+     * parameter types, in declaration order, of the method represented by
+     * this JavaMethod instance.
+     * @return the types of teh formal parameters.
+     */
+    public JavaType[] getParameterTypes();
+}

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaModel-API.jpg
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaModel-API.jpg?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaModel.mdl
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaModel.mdl?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
Binary files - no diff available.

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaProperty.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaProperty.java?rev=178436&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaProperty.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaProperty.java Wed May 25 06:22:12 2005
@@ -0,0 +1,46 @@
+/*
+ * 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.model.java;
+
+/**
+ * A JavaProperty instance represents a JavaBeans property.
+ * 
+ * @author Michael Bouschen
+ * @version JDO 2.0
+ */
+public interface JavaProperty extends JavaMember 
+{
+    /**
+     * Returns the JavaMethod representation of the getter method for this
+     * JavaProperty. If there is no getter method for this JavaProperty
+     * (i.e. the property is write-only), then the method returns
+     * <code>null</code>.
+     * @return the getter method if available; or <code>null</code>
+     * otherwise.
+     */
+    public JavaMethod getGetterMethod();
+
+    /**
+     * Returns the JavaMethod representation of the setter method for this
+     * JavaProperty. If there is no setter method for this JavaProperty
+     * (i.e. the property is read-only), then the method returns
+     * <code>null</code>.
+     * @return the setter method if available; or <code>null</code>
+     * otherwise.
+     */
+    public JavaMethod getSetterMethod();
+}

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaType.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaType.java (original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/java/JavaType.java Wed May 25 06:22:12 2005
@@ -36,7 +36,7 @@
  * @author Michael Bouschen
  * @since JDO 1.0.1
  */
-public interface JavaType 
+public interface JavaType extends JavaElement
 {
     /** 
      * Returns <code>true</code> if this JavaType represents a primitive
@@ -282,5 +282,36 @@
      * or <code>null</code> if there is no such field.
      */
     public JavaField getJavaField(String name);
+
+    /**
+     * Returns an array of JavaField instances representing the declared
+     * fields of the class represented by this JavaType instance. Note, this
+     * method does not return JavaField instances representing inherited
+     * fields. 
+     * @return an array of declared JavaField instances. 
+     */
+    public JavaField[] getDeclaredJavaFields();
+
+    /**
+     * Returns a JavaProperty instance that reflects the property 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
+     * property with that name.
+     * @param name the name of the property 
+     * @return the JavaProperty instance for the specified property in this
+     * class or <code>null</code> if there is no such property.
+     */
+    public JavaProperty getJavaProperty(String name);
+
+    /**
+     * Returns an array of JavaProperty instances representing the declared
+     * properties of the class represented by this JavaType instance. Note,
+     * this method does not return JavaProperty instances representing inherited
+     * properties. 
+     * @return an array of declared JavaProperty instances. 
+     */
+    public JavaProperty[] getDeclaredJavaProperties();
+    
 
 }

Modified: incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java (original)
+++ incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java Wed May 25 06:22:12 2005
@@ -43,7 +43,7 @@
     public EnhancerJavaModel(ClassLoader classLoader,
                              ResourceLocator locator)
     {
-        super(classLoader, false);
+        super(classLoader, false, null);
         this.locator = locator;
     }
     
@@ -71,9 +71,9 @@
      * @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 EnhancerJavaType(clazz, getJDOModel(), this);
+        return new EnhancerJavaType(clazz, this);
     }
 
     /** 

Modified: incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java (original)
+++ incubator/jdo/trunk/enhancer20/src/java/org/apache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java Wed May 25 06:22:12 2005
@@ -22,8 +22,6 @@
 import org.apache.jdo.model.java.JavaType;
 import org.apache.jdo.model.jdo.JDOModel;
 
-
-
 /**
  * Provides some basic Java type information based on JVM descriptors.
  * 
@@ -33,16 +31,12 @@
 public class EnhancerJavaType
     extends ReflectionJavaType
 {
-    /** The declaring EnhancerJavaModel instance. */
-    private JavaModel javaModel = null;
-
     /**
      * Creates an instance.
      */
-    public EnhancerJavaType(Class clazz, JDOModel jdoModel, JavaModel javaModel)
+    public EnhancerJavaType(Class clazz, EnhancerJavaModel declaringJavaModel)
     {
-        super(clazz, jdoModel);
-        this.javaModel = javaModel;
+        super(clazz, declaringJavaModel);
     }
     
     // ===== Methods not defined in JavaType =====
@@ -50,15 +44,14 @@
     /** 
      * Returns a JavaType instance for the specified Class object. 
      * <p>
-     * This implementation delegates the call to the javaModel.
+     * This implementation delegates the call to the declaringJavaModel.
      * @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.
      */
-    protected JavaType getJavaTypeInternal(Class clazz)
+    public JavaType getJavaTypeForClass(Class clazz)
     {
-        return javaModel.getJavaType(clazz);
+        return declaringJavaModel.getJavaType(clazz.getName());
     }
-    
     
 }

Modified: incubator/jdo/trunk/runtime20/maven.xml
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/maven.xml?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/runtime20/maven.xml (original)
+++ incubator/jdo/trunk/runtime20/maven.xml Wed May 25 06:22:12 2005
@@ -38,6 +38,15 @@
         <attainGoal name="build"/>
     </goal>
 
+    <preGoal name="java:compile">
+        <available property="jdk5" classname="java.lang.reflect.ParameterizedType"/>
+        <!-- Compile with -source 1.5 and -target 1.5 in a JDK5 environment. -->
+        <j:if test="${jdk5}">
+            <j:set var="maven.compile.source" value="1.5"/>
+            <j:set var="maven.compile.target" value="1.5"/>
+        </j:if>
+    </preGoal>
+
     <goal name="clobber" prereqs="clean">
         <delete>
             <fileset dir="." defaultexcludes="no" includes="**/*~"/>

Modified: incubator/jdo/trunk/runtime20/project.xml
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/project.xml?rev=178436&r1=178435&r2=178436&view=diff
==============================================================================
--- incubator/jdo/trunk/runtime20/project.xml (original)
+++ incubator/jdo/trunk/runtime20/project.xml Wed May 25 06:22:12 2005
@@ -60,6 +60,15 @@
     <!-- =================== -->
     <build>
         <sourceDirectory>src/java</sourceDirectory>
+        <!-- Exclude JDK5 specific classes in a non JDK5 environment. -->
+        <sourceModifications>
+            <sourceModification>
+                <className>java.lang.reflect.ParameterizedType</className>
+                <excludes>
+                    <exclude>**/jdk5/*.java</exclude>
+                </excludes>
+            </sourceModification>
+        </sourceModifications>
         <!-- J A R  R E S O U R C E S -->
         <!-- Resources that are packaged up inside the JAR file -->
         <resources>



Mime
View raw message