Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 84930 invoked from network); 19 Mar 2005 05:03:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Mar 2005 05:03:26 -0000 Received: (qmail 86338 invoked by uid 500); 19 Mar 2005 05:03:26 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Delivered-To: moderator for jdo-commits@db.apache.org Received: (qmail 34767 invoked by uid 99); 19 Mar 2005 02:06:06 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Message-ID: <20050319010600.28047.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Sat, 19 Mar 2005 01:06:00 -0000 Subject: svn commit: r158176 [14/79] - in incubator/jdo/trunk/ri11: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/ejb/ src/java/org/apache/jdo/enhancer/ src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/enhancer/ src/java/org/apache/jdo/impl/enhancer/classfile/ src/java/org/apache/jdo/impl/enhancer/core/ src/java/org/apache/jdo/impl/enhancer/generator/ src/java/org/apache/jdo/impl/enhancer/meta/ src/java/org/apache/jdo/impl/enhancer/meta/model/ src/java/org/apache/jdo/impl/enhancer/meta/prop/ src/java/org/apache/jdo/impl/enhancer/meta/util/ src/java/org/apache/jdo/impl/enhancer/util/ src/java/org/apache/jdo/impl/fostore/ src/java/org/apache/jdo/impl/jdoql/ src/java/org/apache/jdo/impl/jdoql/jdoqlc/ src/java/org/apache/jdo/impl/jdoql/scope/ src/java/org/apache/jdo/impl/jdoql/tree/ src/java/org/apache/jdo/impl/model/ src/java/org/apache/jdo/impl/model/java/ src/java/org/apache/jdo/impl/model/java/runtime/ src/java/org/apache/jdo/impl/model/jdo/ src/java/org/apache/jdo/impl/model/jdo/caching/ src/java/org/apache/jdo/impl/model/jdo/util/ src/java/org/apache/jdo/impl/model/jdo/xml/ src/java/org/apache/jdo/impl/pm/ src/java/org/apache/jdo/impl/sco/ src/java/org/apache/jdo/impl/state/ src/java/org/apache/jdo/jdoql/ src/java/org/apache/jdo/jdoql/tree/ src/java/org/apache/jdo/model/ src/java/org/apache/jdo/model/java/ src/java/org/apache/jdo/model/jdo/ src/java/org/apache/jdo/pm/ src/java/org/apache/jdo/sco/ src/java/org/apache/jdo/state/ src/java/org/apache/jdo/store/ src/java/org/apache/jdo/util/ test/ test/conf/ test/enhancer/ test/enhancer/sempdept/ test/enhancer/sempdept/src/ test/enhancer/sempdept/src/empdept/ test/fsuid2/ test/fsuid2/org/ test/fsuid2/org/apache/ test/fsuid2/org/apache/jdo/ test/fsuid2/org/apache/jdo/pc/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/impl/ test/java/org/apache/jdo/impl/fostore/ test/java/org/apache/jdo/pc/ test/java/org/apache/jdo/pc/appid/ test/java/org/apache/jdo/pc/empdept/ test/java/org/apache/jdo/pc/serializable/ test/java/org/apache/jdo/pc/xempdept/ test/java/org/apache/jdo/test/ test/java/org/apache/jdo/test/query/ test/java/org/apache/jdo/test/util/ test/jdo/ test/jdo/org/ test/jdo/org/apache/ test/jdo/org/apache/jdo/ test/jdo/org/apache/jdo/pc/ test/jdo/org/apache/jdo/pc/appid/ test/jdo/org/apache/jdo/pc/empdept/ test/jdo/org/apache/jdo/pc/serializable/ test/jdo/org/apache/jdo/pc/xempdept/ xdocs/ To: jdo-commits@db.apache.org From: mbo@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/= EnhancerMetaData.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/enhancer/meta/EnhancerMetaData.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/Enh= ancerMetaData.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/Enh= ancerMetaData.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,434 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.enhancer.meta; + + +/** + * Provides the JDO meta information neccessary for byte-code enhancement. + *

+ * Please note: This interface deals with fully qualified names in the + * JVM notation, that is, with '/' as package separator character  + * (instead of '.'). + */ +public interface EnhancerMetaData +{ + /** + * The JDO field flags. + */ + int CHECK_READ =3D 0x01; + int MEDIATE_READ =3D 0x02; + int CHECK_WRITE =3D 0x04; + int MEDIATE_WRITE =3D 0x08; + int SERIALIZABLE =3D 0x10; + + // -------------------------------------------------------------------= --- + // Class Metadata + // -------------------------------------------------------------------= --- + + /** + * Returns whether a class is not to be modified by the enhancer. + *

+ * It is an error if an unenhanceable class is persistence-capable + * (or persistence-aware). The following holds: + * isKnownUnenhancableClass(classPath) + * =3D=3D> !isPersistenceCapableClass(classPath) + * @param classPath the non-null JVM-qualified name of the class + * @return true if this class is known to be unmodifiable; otherwise f= alse + * @see #isPersistenceCapableClass(String) + */ + boolean isKnownUnenhancableClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns whether a class is persistence-capable. + *

+ * If a persistence-capable class is also known to be unenhancable, + * an exception is thrown. + * The following holds: + * isPersistenceCapableClass(classPath) + * =3D=3D> !isKnownUnenhancableClass(classPath) + * @param classPath the non-null JVM-qualified name of the class + * @return true if this class is persistence-capable; otherwise false + * @see #isKnownUnenhancableClass(String) + */ + boolean isPersistenceCapableClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns whether a class implements java.io.Serializable. + * @param classPath the non-null JVM-qualified name of the class + * @return true if this class is serializable; otherwise false + */ + boolean isSerializableClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns the name of the persistence-capable superclass of a class. + *

+ * The following holds: + * (String s =3D getPersistenceCapableSuperClass(classPath)) !=3D nu= ll + * =3D=3D> isPersistenceCapableClass(classPath) + * && !isPersistenceCapableRootClass(classPath) + * @param classPath the non-null JVM-qualified name of the class + * @return the name of the PC superclass or null if there is none + * @see #isPersistenceCapableClass(String) + * @see #getPersistenceCapableRootClass(String) + */ + String getPersistenceCapableSuperClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns the name of the key class of a class. + *

+ * The following holds: + * (String s =3D getKeyClass(classPath)) !=3D null + * =3D=3D> !isPersistenceCapableClass(s) + * && isPersistenceCapableClass(classPath) + * @param classPath the non-null JVM-qualified name of the class + * @return the name of the key class or null if there is none + * @see #isPersistenceCapableClass(String) + */ + String getKeyClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns an array of field names of all declared persistent and + * transactional fields of a class. + *

+ * The position of the field names in the result array corresponds + * to their unique field index as returned by getFieldNumber such that + * these equations hold: + *

getFieldNumber(getManagedFields(classPath)[i]) =3D=3D i + *

getManagedFields(classPath)[getFieldNumber(fieldName)] =3D=3D f= ieldName + *

+ * This method requires all fields having been declared by + * declareField(). + * @param classPath the non-null JVM-qualified name of the class + * @return an array of all declared persistent and transactional + * fields of a class + * @see #getFieldNumber(String, String) + * @see #declareField(String, String, String) + */ + String[] getManagedFields(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + // -------------------------------------------------------------------= --- + // Field Metadata + // -------------------------------------------------------------------= --- + + /**=20 + * Returns the JVM-qualified name of the specified field's declaring + * class. The method first checks whether the class of the specified + * classPath (the JVM-qualified name) declares such a field. If yes, + * classPath is returned. Otherwise, it checks its superclasses. The + * method returns null for an unkown field. + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return the JVM-qualified name of the declararing class of the + * field, or null if there is no such field. + */ + String getDeclaringClass(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError;=20 + + /** + * Declares a field to the JDO model passing its type information. + *

+ * By the new JDO model, it's a requirement to declare fields to + * the model for their type information before any field information + * based on persistence-modifiers can be retrieved. This method + * passes a field's type information to the underlying JDO model. + *

+ * There's one important exception: The method isKnownNonManagedField() + * may be called at any time. + *

+ * The class must be persistence-capable, otherwise an exception + * is thrown. + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @param fieldSig the non-null JVM signature of the field + * @see #isPersistenceCapableClass(String) + */ + void declareField(String classPath, String fieldName, String fieldSig) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns whether a field of a class is known to be non-managed. + *

+ * This method differs from isManagedField() in that a field may or + * may not be managed if its not known as non-managed. + * The following holds (not vice versa!): + * isKnownNonManagedField(classPath, fieldName, fieldSig) + * =3D=3D> !isManagedField(classPath, fieldName) + *

+ * This method doesn't require the field having been declared by + * declareField(). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @param fieldSig the non-null type signature of the field + * @return true if this field is known to be non-managed; otherwise fa= lse + * @see #isManagedField(String, String) + * @see #declareField(String, String, String) + */ + boolean isKnownNonManagedField(String classPath, + String fieldName, + String fieldSig) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns whether a field of a class is transient transactional + * or persistent. + *

+ * A managed field must not be known as non-managed and must be either + * transient transactional or persistent. The following holds: + * isManagedField(classPath, fieldName) + * =3D=3D> !isKnownNonManagedField(classPath, fieldName, fieldSi= g) + * && (isPersistentField(classPath, fieldName) + * ^ isTransactionalField(classPath, fieldName)) + *

+ * This method requires the field having been declared by declareField= (). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return true if this field is managed; otherwise false + * @see #isKnownNonManagedField(String, String, String) + * @see #isPersistentField(String, String) + * @see #isTransactionalField(String, String) + * @see #isPersistenceCapableClass(String) + */ + boolean isManagedField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns whether a field of a class is transient + * transactional. + *

+ * A transient transactional field cannot be persistent. + * The following holds: + * isTransactionalField(classPath, fieldName) + * =3D=3D> isManagedField(classPath, fieldName) + * && !isPersistentField(classPath, fieldName) + *

+ * This method requires the field having been declared by declareField= (). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return true if this field is transactional; otherwise false + * @see #isManagedField(String, String) + * @see #declareField(String, String, String) + */ + boolean isTransactionalField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns whether a field of a class is persistent. + *

+ * A persistent field cannot be transient transactional. + * The following holds: + * isPersistentField(classPath, fieldName) + * =3D=3D> isManagedField(classPath, fieldName) + * && !isTransactionalField(classPath, fieldName) + *

+ * This method requires the field having been declared by declareField= (). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return true if this field is persistent; otherwise false + * @see #isManagedField(String, String) + * @see #declareField(String, String, String) + */ + boolean isPersistentField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns whether a field of a class is key. + *

+ * A key field must be persistent. + * The following holds: + * isKeyField(classPath, fieldName) + * =3D=3D> isPersistentField(classPath, fieldName) + * && !isDefaultFetchGroupField(classPath, fieldName) + *

+ * This method requires the field having been declared by declareField= (). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return true if this field is key; otherwise false + * @see #isPersistentField(String, String) + * @see #declareField(String, String, String) + */ + boolean isKeyField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns whether a field of a class is part of the + * default fetch group. + *

+ * A field in the default fetch group must be persistent. + * The following holds: + * isDefaultFetchGroupField(classPath, fieldName) + * =3D=3D> isPersistentField(classPath, fieldName) + * && !isKeyField(classPath, fieldName) + *

+ * This method requires the field having been declared by declareField= (). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return true if this field is part of the + * default fetch group; otherwise false + * @see #isPersistentField(String, String) + * @see #declareField(String, String, String) + */ + boolean isDefaultFetchGroupField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns the unique field index of a declared, managed field of a + * class. + *

+ * The following holds: + * int i =3D getFieldFlags(classPath, fieldName); + * i > 0 =3D=3D> getManagedFields(classPath)[i] =3D=3D fieldName + *

+ * This method requires the field having been declared by declareField= (). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return the non-negative, unique field index or -1 if the field + * is non-managed + * @see #getManagedFields(String) + * @see #declareField(String, String, String) + */ + int getFieldNumber(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns the field flags for a declared field of a class. + *

+ * The following holds for the field flags: + * int f =3D getFieldFlags(classPath, fieldName); + * + * !isManagedField(classPath, fieldName) + * =3D=3D> (f & CHECK_READ =3D=3D 0) && (f & MEDIATE_READ =3D=3D= 0) && + * (f & CHECK_WRITE =3D=3D 0) && (f & MEDIATE_WRITE =3D=3D 0) + * + * isTransactionalField(classPath, fieldName) + * =3D=3D> (f & CHECK_READ =3D=3D 0) && (f & MEDIATE_READ =3D=3D= 0) && + * (f & CHECK_WRITE !=3D 0) && (f & MEDIATE_WRITE =3D=3D 0) + * + * isKeyField(classPath, fieldName) + * =3D=3D> (f & CHECK_READ =3D=3D 0) && (f & MEDIATE_READ =3D=3D= 0) && + * (f & CHECK_WRITE =3D=3D 0) && (f & MEDIATE_WRITE !=3D 0) + * + * isDefaultFetchGroupField(classPath, fieldName) + * =3D=3D> (f & CHECK_READ !=3D 0) && (f & MEDIATE_READ !=3D 0) = && + * (f & CHECK_WRITE =3D=3D 0) && (f & MEDIATE_WRITE =3D=3D 0) + * + * isPersistentField(classPath, fieldName) + * && isKeyField(classPath, fieldName) + * && isDefaultFetchGroupField(classPath, fieldName) + * =3D=3D> (f & CHECK_READ =3D=3D 0) && (f & MEDIATE_READ =3D=3D= 0) && + * (f & CHECK_WRITE !=3D 0) && (f & MEDIATE_WRITE !=3D 0) + *

+ * This method requires the field having been declared by declareField= (). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return the field flags for this field + * @see #declareField(String, String, String) + */ + int getFieldFlags(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + // -------------------------------------------------------------------= --- + // Convenience Methods + // -------------------------------------------------------------------= --- + + /** + * Returns whether a class is persistence-capable root class. + *

+ * The following holds: + * isPersistenceCapableRootClass(classPath) + * <=3D=3D> isPersistenceCapableClass(classPath) + * && getPersistenceCapableSuperClass(classPath) =3D=3D null + * @param classPath the non-null JVM-qualified name of the class + * @return true if this class is persistence-capable and does not + * derive from another persistence-capable class; otherwise fa= lse + */ + boolean isPersistenceCapableRootClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns the name of the persistence-capable root class of a class. + *

+ * The following holds: + * (String s =3D getPersistenceCapableRootClass(classPath)) !=3D null + * =3D=3D> isPersistenceCapableClass(classPath) + * && getPersistenceCapableSuperClass(classPath) =3D=3D null + * @param classPath the non-null JVM-qualified name of the class + * @return the name of the least-derived persistence-capable class that + * is equal to or a super class of the argument class; if the + * argument class is not persistence-capable, null is returned. + */ + String getPersistenceCapableRootClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns the name of the key class of the next persistence-capable + * superclass that defines one. + *

+ * The following holds: + * (String s =3D getSuperKeyClass(classPath)) !=3D null + * =3D=3D> !isPersistenceCapableClass(s) + * && isPersistenceCapableClass(classPath) + * && !isPersistenceCapableRootClass(classPath) + * @param classPath the non-null JVM-qualified name of the class + * @return the name of the key class or null if there is none + * @see #getKeyClass(String) + * @see #getPersistenceCapableSuperClass(String) + */ + String getSuperKeyClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns an array of field names of all key fields of a class. + *

+ * This method requires all fields having been declared by declareFiel= d(). + * @param classPath the non-null JVM-qualified name of the class + * @return an array of all declared key fields of a class + * @see #declareField(String, String, String) + */ + String[] getKeyFields(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns the unique field index of some declared, managed fields of a + * class. + *

+ * This method requires all fields having been declared by declareFiel= d(). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldNames the non-null array of names of the declared fields + * @return the non-negative, unique field indices + * @see #declareField(String, String, String) + */ + int[] getFieldNumber(String classPath, String[] fieldNames) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns the field flags for some declared, managed fields of a clas= s=2E + *

+ * This method requires all fields having been declared by declareFiel= d(). + * @param classPath the non-null JVM-qualified name of the class + * @param fieldNames the non-null array of names of the declared fields + * @return the field flags for the fields + * @see #declareField(String, String, String) + */ + int[] getFieldFlags(String classPath, String[] fieldNames) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/= EnhancerMetaDataFatalError.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/enhancer/meta/EnhancerMetaDataFatalError.java?view=3Dauto&rev= =3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/Enh= ancerMetaDataFatalError.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/Enh= ancerMetaDataFatalError.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,72 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + + +package org.apache.jdo.impl.enhancer.meta; + + +/** + * Thrown to indicate that an access to JDO meta-data failed due to a + * serious error, which might have left the meta-data component in an + * inconsistent state. + */ +public class EnhancerMetaDataFatalError + //^olsen: provisional, convert to a checked exception + extends RuntimeException +{ + /** + * An optional nested exception. + */ + public final Throwable nested; + + /** + * Constructs an EnhancerMetaDataFatalError with no detai= l message. + */ + public EnhancerMetaDataFatalError() + { + this.nested =3D null; + } + + /** + * Constructs an EnhancerMetaDataFatalError with the spec= ified + * detail message. + */ + public EnhancerMetaDataFatalError(String msg) + { + super(msg); + this.nested =3D null; + } + + /** + * Constructs an EnhancerMetaDataFatalError with an optio= nal + * nested exception. + */ + public EnhancerMetaDataFatalError(Throwable nested) + { + super(nested.toString()); + this.nested =3D nested; + } + + /** + * Constructs an EnhancerMetaDataFatalError with the spec= ified + * detail message and an optional nested exception. + */ + public EnhancerMetaDataFatalError(String msg, Throwable nested) + { + super(msg); + this.nested =3D nested; + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/= EnhancerMetaDataUserException.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/enhancer/meta/EnhancerMetaDataUserException.java?view=3Dauto&= rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/Enh= ancerMetaDataUserException.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/Enh= ancerMetaDataUserException.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,72 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + + +package org.apache.jdo.impl.enhancer.meta; + + +/** + * Thrown to indicate that an access to JDO meta-data failed; the + * meta-data component is assured to remain in consistent state. + */ +public class EnhancerMetaDataUserException + //^olsen: provisional, convert to a checked exception + extends RuntimeException +{ + /** + * An optional nested exception. + */ + public final Throwable nested; + + /** + * Constructs an EnhancerMetaDataUserException with no de= tail + * message. + */ + public EnhancerMetaDataUserException() + { + this.nested =3D null; + } + + /** + * Constructs an EnhancerMetaDataUserException with the s= pecified + * detail message. + */ + public EnhancerMetaDataUserException(String msg) + { + super(msg); + this.nested =3D null; + } + + /** + * Constructs an EnhancerMetaDataUserException with an op= tional + * nested exception. + */ + public EnhancerMetaDataUserException(Throwable nested) + { + super("nested exception: " + nested); + this.nested =3D nested; + } + + /** + * Constructs an EnhancerMetaDataUserException with the s= pecified + * detail message and an optional nested exception. + */ + public EnhancerMetaDataUserException(String msg, Throwable nested) + { + super(msg); + this.nested =3D nested; + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/= ExtendedMetaData.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/enhancer/meta/ExtendedMetaData.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/Ext= endedMetaData.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/Ext= endedMetaData.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,111 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.enhancer.meta; + + +/** + * Provides extended JDO meta information for byte-code enhancement. + */ +public interface ExtendedMetaData + extends EnhancerMetaData +{ + /** + * Gets all known classnames. + * + * @return All known classnames. + */ + String[] getKnownClasses() + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; = =20 + + /** + * Gets the modifiers of a class. The return value is a constant of t= he + * java.lang.reflect.Modifier class. + * + * @param classname The classname. + * @return The modifiers. + * @see java.lang.reflect.Modifier + */ + int getClassModifiers(String classname) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Returns the name of the superclass of a class. + *

+ * @param classPath the JVM-qualified name of the class=20 + * @return the name of the superclass or null if there is none + */ + String getSuperClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Gets all known fieldnames of a class. + * + * @param classname The classname. + * @return All known fieldnames. + */ + String[] getKnownFields(String classname) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Gets the type of a field. + * + * @param classname The classname. + * @param fieldname The fieldname. + * @return The type of the field. + */ + String getFieldType(String classname, + String fieldname) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Gets the modifiers of a field. The return value is a constant of t= he + * java.lang.reflect.Modifier class. + * + * @param classname The classname. + * @param fieldname The fieldname. + * @return The modifiers. + * @see java.lang.reflect.Modifier + */ + int getFieldModifiers(String classname, + String fieldname) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + // convenience methods + + /** + * Gets the type of some fields. + * + * @param classname The classname. + * @param fieldnames The fieldnames. + * @return The type of the fields. + */ + String[] getFieldType(String classname, + String[] fieldnames) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; + + /** + * Gets the modifiers of some fields. + * + * @param classname The classname. + * @param fieldnames The fieldnames. + * @return The modifiers. + * @see java.lang.reflect.Modifier + */ + int[] getFieldModifiers(String classname, + String[] fieldnames) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError; +} Added: 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/ap= ache/jdo/impl/enhancer/meta/model/EnhancerJavaModel.java?view=3Dauto&rev=3D= 158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/mod= el/EnhancerJavaModel.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/mod= el/EnhancerJavaModel.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,158 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.enhancer.meta.model; + +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.model.java.JavaType; +import org.apache.jdo.model.jdo.JDOModel; + +/** + * Provides some basic Java type information based on JVM descriptors. + *=20 + * @author Michael Bouschen + * @author Martin Zaun + */ +public class EnhancerJavaModel + extends RuntimeJavaModel +{ + /** + * The "package" jdo file. + */ + final private ResourceLocator locator; + + /** + * Creates an instance. + */ + public EnhancerJavaModel(ClassLoader classLoader, + ResourceLocator locator) + { + super(classLoader, false); + this.locator =3D locator; + } + =20 + /** + * Finds a resource with a given name. This method returns + * null if no resource with this name is found. + * The name of a resource is a "/"-separated path name. + */ + public InputStream getInputStreamForResource(String resourceName) + { + // first try the locator + InputStream stream =3D locator.getInputStreamForResource(resourceN= ame); + if (stream =3D=3D null) + // if the locator cannot find the resource try the class loader + stream =3D super.getInputStreamForResource(resourceName); + return stream; + } + + // =3D=3D=3D=3D=3D Methods not defined in JavaModel =3D=3D=3D=3D=3D + + /**=20 + * Creates a new JavaType instance for the specified Class object. + *

+ * This implementation returns a EnhancerJavaType instance. + * @param clazz the Class instance representing the type + * @return a new JavaType instance + */ + protected JavaType createJavaType(Class clazz, JDOModel jdoModel) + { + return new EnhancerJavaType(clazz, getJDOModel(), this); + } + + /**=20 + * Returns the fully qualified name of the specified type representati= on. + */ + public String getTypeName(String sig) + { + // translates a VM type field signature into Java-format signature + final int n =3D sig.length(); + affirm(n > 0, "invalid field signature: \"\""); + + // handle arrays + if (sig.startsWith("[")) + return sig.replace('/','.'); + + // parse rest of signature + final String name; + final char c =3D sig.charAt(0); + switch (c) { + case 'Z': + name =3D "boolean"; + break; + case 'C': + name =3D "char"; + break; + case 'B': + name =3D "byte"; + break; + case 'S': + name =3D "short"; + break; + case 'I': + name =3D "int"; + break; + case 'F': + name =3D "float"; + break; + case 'J': + name =3D "long"; + break; + case 'D': + name =3D "double"; + break; + case 'L': + // return reference type with array dimensions + affirm(sig.indexOf(';') =3D=3D n - 1, + "invalid field signature: " + sig); + name =3D sig.substring(1, n - 1); + affirm(isValidName(name, '/'), + "invalid field signature: " + sig); + return name.replace('/','.'); + default: + name =3D ""; + affirm(false, "invalid field signature: " + sig); + } + return name; + } + + static private boolean isValidName(String name, char separator)=20 + { + final int n =3D name.length(); + if (n =3D=3D 0) { + return false; + } + if (!Character.isJavaIdentifierStart(name.charAt(0))) { + return false; + } + for (int i =3D 1; i < n; i++) { + final char c =3D name.charAt(i); + if (!Character.isJavaIdentifierPart(c) && c !=3D separator) { + return false; + } + } + return true; + } + + static protected final void affirm(boolean condition, String msg) { + if (!condition) + throw new InternalError("assertion failed: " + msg); + } + +} Added: 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/ap= ache/jdo/impl/enhancer/meta/model/EnhancerJavaType.java?view=3Dauto&rev=3D1= 58176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/mod= el/EnhancerJavaType.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/mod= el/EnhancerJavaType.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,64 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +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.model.java.JavaModel; +import org.apache.jdo.model.java.JavaType; +import org.apache.jdo.model.jdo.JDOModel; + + + +/** + * Provides some basic Java type information based on JVM descriptors. + *=20 + * @author Michael Bouschen + * @since JDO 1.0.1 + */ +public class EnhancerJavaType + extends RuntimeJavaType +{ + /** The declaring EnhancerJavaModel instance. */ + private JavaModel javaModel =3D null; + + /** + * Creates an instance. + */ + public EnhancerJavaType(Class clazz, JDOModel jdoModel, JavaModel java= Model) + { + super(clazz, jdoModel); + this.javaModel =3D javaModel; + } + =20 + // =3D=3D=3D=3D=3D Methods not defined in JavaType =3D=3D=3D=3D=3D + + /**=20 + * Returns a JavaType instance for the specified Class object.=20 + *

+ * This implementation delegates the call to the javaModel. + * @param clazz the Class instance representing the type + * @return a JavaType instance for the name of the specified class + * object or null if not present in this model instance. + */ + protected JavaType getJavaTypeInternal(Class clazz) + { + return javaModel.getJavaType(clazz); + } + =20 + =20 +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/= model/EnhancerMetaDataJDOModelImpl.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/enhancer/meta/model/EnhancerMetaDataJDOModelImpl.java?view=3D= auto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/mod= el/EnhancerMetaDataJDOModelImpl.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/mod= el/EnhancerMetaDataJDOModelImpl.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,555 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.enhancer.meta.model; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.File; + +import java.util.List; +import java.util.ArrayList; +import java.util.Iterator; + +import org.apache.jdo.impl.enhancer.meta.EnhancerMetaData; +import org.apache.jdo.impl.enhancer.meta.EnhancerMetaDataFatalError; +import org.apache.jdo.impl.enhancer.meta.EnhancerMetaDataUserException; +import org.apache.jdo.impl.enhancer.meta.util.EnhancerMetaDataBaseModel; +import org.apache.jdo.impl.enhancer.util.CombinedResourceLocator; +import org.apache.jdo.impl.enhancer.util.ListResourceLocator; +import org.apache.jdo.impl.enhancer.util.PathResourceLocator; +import org.apache.jdo.impl.enhancer.util.ResourceLocator; +import org.apache.jdo.impl.model.jdo.caching.JDOModelFactoryImplCaching; +import org.apache.jdo.impl.model.jdo.util.TypeSupport; +import org.apache.jdo.model.ModelException; +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.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.model.jdo.JDOModelFactory; +import org.apache.jdo.model.jdo.PersistenceModifier; + +/** + * Provides the JDO meta information based on a JDO meta model. + */ +public class EnhancerMetaDataJDOModelImpl + extends EnhancerMetaDataBaseModel + implements EnhancerMetaData +{ + /** + * The jdoModel instance. + */ + private final JDOModel jdoModel; + + /** + * The model instance. + */ + private final EnhancerJavaModel javaModel; + + /** + * The JavaType representation for java.io.Serializable. + */ + private final JavaType serializableJavaType; + =20 + /** + * Creates an instance. + */ + public EnhancerMetaDataJDOModelImpl(PrintWriter out, + boolean verbose, + List jdoFileNames, + List jarFileNames, + String sourcePath) + throws EnhancerMetaDataFatalError + { + super(out, verbose); + + try { + final List locators =3D new ArrayList(); + ClassLoader classLoader =3D null; + + // create resource locator for specified jdo files + if (jdoFileNames !=3D null && !jdoFileNames.isEmpty()) { + final StringBuffer s =3D new StringBuffer(); + for (Iterator i =3D jdoFileNames.iterator(); i.hasNext();)= { + s.append(" " + i.next()); + } + final ResourceLocator jdos + =3D new ListResourceLocator(out, verbose, jdoFileNames= ); + //printMessage(getI18N("enhancer.metadata.using_jdo_files", + // s.toString())); + locators.add(jdos); + } + + // create resource locator for specified jar files + if (jarFileNames !=3D null && !jarFileNames.isEmpty()) { + final StringBuffer s =3D new StringBuffer(); + final Iterator i =3D jarFileNames.iterator(); + s.append(i.next()); + while (i.hasNext()) { + s.append(File.pathSeparator + i.next()); + } + final PathResourceLocator jars + =3D new PathResourceLocator(out, verbose, s.toString()= ); + //printMessage(getI18N("enhancer.metadata.using_jar_files", + // s.toString())); + locators.add(jars); + classLoader =3D jars.getClassLoader(); + } + + // create resource locator for specified source path + if (sourcePath !=3D null && sourcePath.length() > 0) { + final PathResourceLocator path + =3D new PathResourceLocator(out, verbose, sourcePath); + //printMessage(getI18N("enhancer.metadata.using_source_pat= h", + // sourcePath)); + locators.add(path); + classLoader =3D path.getClassLoader(); + } + + if (classLoader =3D=3D null) { + // use the current class loader as the default, if there is + // no -s option and no archives specified. + classLoader =3D EnhancerMetaDataJDOModelImpl.class.getClas= sLoader(); + } + + // print warning if no meta-data source specified + if (locators.isEmpty()) { + printWarning(getI18N("enhancer.metadata.using_no_metadata"= )); + } + + // create JavaModel with combined resource locators + final ResourceLocator locator + =3D new CombinedResourceLocator(out, verbose, locators); + //^olsen: wrap with timing jdo file locator + //if (options.doTiming.value) { + // classLocator =3D new ResourceLocatorTimer(classLocator); + //} + javaModel =3D new EnhancerJavaModel(classLoader, locator); + final JDOModelFactory factory =3D JDOModelFactoryImplCaching.g= etInstance(); + affirm(factory !=3D null); + jdoModel =3D factory.createJDOModel(javaModel); + affirm(jdoModel !=3D null); + javaModel.setJDOModel(jdoModel); + serializableJavaType =3D javaModel.getJavaType("java.io.Serial= izable"); + } catch (IOException ex) { + final String msg + =3D getI18N("enhancer.metadata.io_error", ex.getMessage()); + throw new EnhancerMetaDataFatalError(msg, ex); + } catch (ModelFatalException ex) { + final String msg + =3D getI18N("enhancer.metadata.jdomodel_error", ex.getMess= age()); + throw new EnhancerMetaDataFatalError(msg, ex); + } catch (ModelException ex) { + final String msg + =3D getI18N("enhancer.metadata.jdomodel_error", ex.getMess= age()); + throw new EnhancerMetaDataFatalError(msg, ex); + } =20 + } + + // -------------------------------------------------------------------= --- + =20 + private JDOClass getJDOClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final String className =3D classPath.replace('/', '.'); + final JDOClass clazz =3D jdoModel.getJDOClass(className); + return clazz; + } + =20 + private JDOField getJDOField(String classPath, + String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + if (clazz =3D=3D null) { + return null; + } + final JDOField field =3D clazz.getDeclaredField(fieldName); + affirm(field =3D=3D null || field.getDeclaringClass() =3D=3D clazz, + "field not declared in class: " + classPath + "." + fieldNa= me); + return field; + } + =20 + private boolean hasFieldModifier(String classPath, + String fieldName, + int fieldModifier) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOField field =3D getJDOField(classPath, fieldName); + if (field =3D=3D null) { + return false; + } + final int pm =3D field.getPersistenceModifier(); + affirm(pm !=3D PersistenceModifier.UNSPECIFIED, + "field modifier 'UNSPECIFIED': " + classPath + "." + fieldN= ame); + return (pm & fieldModifier) !=3D 0; + } + + // -------------------------------------------------------------------= --- + =20 + + /**=20 + * Returns the JVM-qualified name of the specified field's declaring + * class. The method first checks whether the class of the specified + * classPath (the JVM-qualified name) declares such a field. If yes, + * classPath is returned. Otherwise, it checks its superclasses. The + * method returns null for an unkown field. + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return the JVM-qualified name of the declararing class of the + * field, or null if there is no such field. + */ + public String getDeclaringClass(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + affirm(classPath); + affirm(fieldName); + final String className =3D classPath.replace('/', '.'); + try { + final JavaType javaType =3D javaModel.getJavaType(className); + final JavaField javaField =3D javaType.getJavaField(fieldName); + final JavaType declaringClass =3D javaField.getDeclaringClass(= ); + return declaringClass.getName().replace('.', '/'); + } catch (ModelFatalException ex) { + throw new EnhancerMetaDataUserException(ex); + } + } + + /** + * Declares a field to the JDO model passing its type information. + * @see declareField(String, String, String) + */ +/* + public void declareField(String classPath, + String fieldName, + String fieldSig) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { =20 + affirm(classPath); + affirm(fieldName); + affirm(fieldSig); + final JDOClass clazz =3D getJDOClass(classPath); + affirm(clazz !=3D null, + "class is not persistence-capable: " + classPath); + try { + final JDOField field =3D clazz.createJDOField(fieldName); + affirm(field !=3D null, + "cannot create JDO field: " + classPath + "." + fieldNa= me); + field.setType(fieldSig); + affirm(fieldSig =3D=3D field.getType()); =20 + + //^olsen: cleanup debugging code + String s0 =3D model.getJavaModel().getTypeName(fieldSig); + String s1 =3D (String)model.getJavaModel().getTypeForName(s0); + //out.println("s0 =3D " + s0); + //out.println("s1 =3D " + s1); + affirm(fieldSig.equals(s1)); + } catch (JDOModelException ex) { + throw new EnhancerMetaDataUserException(ex); + } + } +*/ + =20 + /** + * Declares a field to the JDO model passing its type information. + */ + public void declareField(String classPath, + String fieldName, + String fieldSig) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { =20 + affirm(classPath); + affirm(fieldName); + try { + final JDOClass clazz =3D getJDOClass(classPath); + JavaType javaClass =3D clazz.getJavaType(); + affirm(javaClass !=3D null, + "cannot find class file for class: " + classPath); + JavaField javaField =3D javaClass.getJavaField(fieldName); + affirm(javaField !=3D null, + "cannot find java field " + classPath + "." + fieldName= ); + JavaType fieldType =3D javaField.getType(); + JDOField field =3D clazz.getField(fieldName); + // if field not known by JDOClass (not specified in JDO XML), + // create the field only if the model's method of default + // calculation would yield a persistent field. We must not + // change the models state by newly created fields with + // a persistence-modifier "none", because this would lead to + // in a different annotation by isKnownNonManagedField(). + if (field =3D=3D null + && TypeSupport.isPersistenceFieldType(fieldType)) { + field =3D clazz.createJDOField(fieldName); + affirm(field !=3D null, + "cannot create JDO field: " + + classPath + "." + fieldName); + affirm(field.getPersistenceModifier() + =3D=3D PersistenceModifier.UNSPECIFIED, + "unknown, specified JDO field: " + + classPath + "." + fieldName); + } + field.setJavaField(javaField); + affirm(fieldType =3D=3D field.getType()); + affirm(field.getPersistenceModifier() + !=3D PersistenceModifier.UNSPECIFIED, + "known, unspecified JDO field: " + classPath + "." + fi= eldName); + } catch (ModelFatalException ex) { + throw new EnhancerMetaDataUserException(ex); + } catch (ModelException ex) { + throw new EnhancerMetaDataUserException(ex); + } + } + =20 + /** + * Tests whether a class is known to be persistence-capable. + */ + public boolean isPersistenceCapableClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + return (clazz !=3D null); + } + + /** + * Returns whether a class implements java.io.Serializable + * @param classPath the non-null JVM-qualified name of the class + * @return true if this class is serializable; otherwise false + */ + public boolean isSerializableClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final String className =3D classPath.replace('/', '.'); + final JavaType javaType =3D javaModel.getJavaType(className); + return javaType.isCompatibleWith(serializableJavaType); + } + + /** + * Returns the name of the persistence-capable root class of a class. + */ +/* + public String getPersistenceCapableRootClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + if (clazz =3D=3D null) { + return null; + } + final JDOClass root =3D clazz.getPersistenceCapableRootClass(); + if (root =3D=3D null) { + return null; + } + final String name =3D root.getName(); + affirm(name !=3D null); + return name.replace('.', '/'); + } +*/ + + /** + * Returns the name of the persistence-capable superclass of a class. + */ + public String getPersistenceCapableSuperClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + if (clazz =3D=3D null) { + return null; + } + final String name =3D clazz.getPersistenceCapableSuperclassName(); + return (name !=3D null ? name.replace('.', '/') : null); + } + + /** + * Returns the name of the key class of a persistence-capable class. + */ + public String getKeyClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + if (clazz =3D=3D null) { + return null; + } + final String name =3D clazz.getDeclaredObjectIdClassName(); + return (name !=3D null ? name.replace('.', '/') : null); + } + + /** + * Returns an array of field names of all declared persistent and + * transactional fields of a class. + */ + public String[] getManagedFields(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + if (clazz =3D=3D null) { + return new String[]{}; + } + + final JDOField[] fields =3D clazz.getDeclaredManagedFields(); + if (fields =3D=3D null) { + return new String[]{}; + } + affirm(fields.length =3D=3D clazz.getDeclaredManagedFieldCount()); + =20 + final int n =3D fields.length; + final String[] names =3D new String[n]; + for (int i =3D 0; i < n; i++) { + affirm(fields[i] !=3D null); + affirm(fields[i].getRelativeFieldNumber() =3D=3D i); + affirm(fields[i].isManaged()); + names[i] =3D fields[i].getName(); + affirm(names[i] !=3D null); + } + return names; + } + + /** + * Returns whether a field of a class is known to be non-managed. + */ + //^olsen: cleanup old code +/* + public boolean isKnownNonManagedField(String classPath, String fieldNa= me) + { + final JDOClass clazz =3D getJDOClass(classPath); + if (clazz =3D=3D null) { + // class not known to be persistence-capable + return true; + } + final JDOField field =3D clazz.getField(fieldName); + if (field =3D=3D null) { + // field not known by JDOClass (thus, not specified in JDO XML) + return false; + } + return field.isKnownNonManaged(); + } +*/ + + /** + * Returns whether a field of a class is known to be non-managed. + */ + public boolean isKnownNonManagedField(String classPath, + String fieldName, + String fieldSig) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + affirm(classPath); + affirm(fieldName); + affirm(fieldSig); + try { + final JDOClass clazz =3D getJDOClass(classPath); + if (clazz =3D=3D null) { + // class not known to be persistence-capable + return true; + } + =20 + // check whether field is managed only if field's + // persistence-modifier is known by the JDO model + final JDOField field =3D clazz.getField(fieldName); + if (field !=3D null && (field.getPersistenceModifier() + !=3D PersistenceModifier.UNSPECIFIED)) { + // only field's persistence-modifier known by model + return !field.isManaged(); + } + + // field not known by JDOClass (not specified in JDO XML) + // apply model's method of default calculation without + // changing the model's state + JavaType fieldType =3D javaModel.getJavaType(javaModel.getType= Name(fieldSig)); + affirm(fieldType !=3D null,=20 + "cannot get java type for: " + fieldSig); + return !TypeSupport.isPersistenceFieldType(fieldType); + } catch (ModelFatalException ex) { + throw new EnhancerMetaDataUserException(ex); + } + } + + /** + * Tests whether a field of a class is transient transactional or + * persistent. + */ + public boolean isManagedField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + return hasFieldModifier(classPath, fieldName, + (PersistenceModifier.PERSISTENT + | PersistenceModifier.POSSIBLY_PERSISTENT + | PersistenceModifier.TRANSACTIONAL)); + } + + /** + * Tests whether a field of a class is persistent. + */ + public boolean isPersistentField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + return hasFieldModifier(classPath, fieldName, + (PersistenceModifier.PERSISTENT + | PersistenceModifier.POSSIBLY_PERSISTENT= )); + } + + /** + * Tests whether a field of a class is transient transactional. + */ + public boolean isTransactionalField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + return hasFieldModifier(classPath, fieldName, + PersistenceModifier.TRANSACTIONAL); + } + + /** + * Tests whether a field of a class is known to be Key. + */ + public boolean isKeyField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOField field =3D getJDOField(classPath, fieldName); + if (field =3D=3D null) { + return false; + } + return field.isPrimaryKey(); + } + + /** + * Tests whether a field of a class is known to be part of the + * Default Fetch Group. + */ + public boolean isDefaultFetchGroupField(String classPath, String field= Name) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOField field =3D getJDOField(classPath, fieldName); + if (field =3D=3D null) { + return false; + } + return field.isDefaultFetchGroup(); + } + + /** + * Returns the unique field index of a declared, persistent field of a + * class. + */ + public int getFieldNumber(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOField field =3D getJDOField(classPath, fieldName); + if (field =3D=3D null) { + return -1; + } + return field.getRelativeFieldNumber(); + } + +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/= prop/EnhancerMetaDataPropertyImpl.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/enhancer/meta/prop/EnhancerMetaDataPropertyImpl.java?view=3Da= uto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/pro= p/EnhancerMetaDataPropertyImpl.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/pro= p/EnhancerMetaDataPropertyImpl.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,482 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + + +package org.apache.jdo.impl.enhancer.meta.prop; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.FileInputStream; + +import java.util.Iterator; +import java.util.Properties; + +import org.apache.jdo.impl.enhancer.meta.EnhancerMetaDataFatalError; +import org.apache.jdo.impl.enhancer.meta.EnhancerMetaDataUserException; +import org.apache.jdo.impl.enhancer.meta.ExtendedMetaData; +import org.apache.jdo.impl.enhancer.meta.util.EnhancerMetaDataBaseModel; + + + + +/** + * Provides the JDO meta information based on properties. + */ +public class EnhancerMetaDataPropertyImpl + extends EnhancerMetaDataBaseModel + implements ExtendedMetaData +{ + /** + * The model instance. + */ + final private MetaDataProperties model; + =20 + /** + * Creates an instance. + */ + public EnhancerMetaDataPropertyImpl(PrintWriter out, + boolean verbose, + Properties properties) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + super(out, verbose); + affirm(properties !=3D null); + model =3D new MetaDataProperties(properties); + initModel(); + affirm(model !=3D null); + printMessage(getI18N("enhancer.metadata.using_properties", + "")); + } + + /** + * Creates an instance. + */ + public EnhancerMetaDataPropertyImpl(PrintWriter out, + boolean verbose, + String fileName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + super(out, verbose); + affirm(fileName !=3D null); + + InputStream stream =3D null; + try { + stream =3D new FileInputStream(fileName); + final Properties properties =3D new Properties(); + properties.load(stream); + model =3D new MetaDataProperties(properties); + initModel(); + } catch (IOException ex) { + final String msg + =3D getI18N("enhancer.metadata.io_error", ex.getMessage()); + throw new EnhancerMetaDataFatalError(msg, ex); + } finally { + if (stream !=3D null) { + try { + stream.close(); + } catch (IOException ex) { + final String msg + =3D getI18N("enhancer.metadata.io_error", + ex.getMessage()); + throw new EnhancerMetaDataFatalError(msg, ex); + } + } + } + affirm(model !=3D null); + printMessage(getI18N("enhancer.metadata.using_properties", fileNam= e)); + } + + // -------------------------------------------------------------------= --- + =20 + /** + * Initializes the model. + */ + private void initModel() + { + // we'd like to have all classes (and fields) parsed and + // cached in order to early report errors with the properties + final String[] classNames =3D model.getKnownClassNames(); + affirm(classNames !=3D null); + for (int i =3D classNames.length - 1; i >=3D 0; i--) { + final JDOClass clazz =3D getJDOClass(classNames[i]); + affirm(clazz !=3D null); + } + } + + /**=20 + * Returns the JVM-qualified name of the specified field's declaring + * class. The method first checks whether the class of the specified + * classPath (the JVM-qualified name) declares such a field. If yes, + * classPath is returned. Otherwise, it checks its superclasses. The + * method returns null for an unkown field. + * @param classPath the non-null JVM-qualified name of the class + * @param fieldName the non-null name of the field + * @return the JVM-qualified name of the declararing class of the + * field, or null if there is no such field. + */ + public String getDeclaringClass(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + String declaringClass =3D null; + JDOField field =3D getJDOField(classPath, fieldName); + if (field !=3D null) { + // this class declares the filed =3D> return classPath + declaringClass =3D classPath; + } else { + String superclass =3D getSuperClass(classPath); + if (superclass !=3D null) { + declaringClass =3D getDeclaringClass(superclass, fieldName= ); + } + } + return declaringClass; + } + + /** + * Declares a field to the JDO model passing its type information. + */ + public void declareField(String classPath, + String fieldName, + String signature) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + affirm(isPersistenceCapableClass(classPath)); + // nothing to be done: the properties-based model doesn't + // support default calculation of persistence modifiers + } + =20 + /** + * Returns whether a class is known to be persistence-capable. + */ + public boolean isPersistenceCapableClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + return (clazz !=3D null ? clazz.isPersistent() : false); + } + + /** + * Returns whether a class implements java.io.Serializable. + * @param classPath the non-null JVM-qualified name of the class + * @return true if this class is serializable; otherwise false + */ + public boolean isSerializableClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + return (clazz !=3D null ? clazz.isSerializable() : false); + } + =20 + /** + * Returns the name of the persistence-capable root class of a class. + */ +//@olsen: use the inherited method +/* + public String getPersistenceCapableRootClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + String pcRootClass =3D null; + for (String clazz =3D classPath; + clazz !=3D null; + clazz =3D getSuperClass(clazz)) { + if (isPersistenceCapableClass(clazz)) { + pcRootClass =3D clazz; + } + } + return pcRootClass; + } +*/ + + /** + * Returns the name of the persistence-capable superclass of a class. + */ + public String getPersistenceCapableSuperClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + for (String clazz =3D getSuperClass(classPath); + clazz !=3D null; + clazz =3D getSuperClass(clazz)) { + if (isPersistenceCapableClass(clazz)) { + return clazz; + } + } + return null; + } + + /** + * Returns the superclass of a class. + */ + public final String getSuperClass(String classname) + { + final JDOClass clazz =3D getJDOClass(classname); + return (clazz !=3D null ? clazz.getSuperClassName() : null); + } + + /** + * Returns the name of the key class of a persistence-capable class. + */ + public String getKeyClass(String classPath) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + return (clazz !=3D null ? clazz.getOidClassName() : null); + } + + /** + * Returns whether a field of a class is known to be non-managed. + */ + public boolean isKnownNonManagedField(String classPath, + String fieldName, + String fieldSig) + { + final JDOClass clazz =3D getJDOClass(classPath); + if (clazz =3D=3D null) { + return true; + } + final JDOField field =3D getJDOField(clazz, fieldName); + return (field !=3D null ? field.isKnownTransient() : false); + } =20 + + /** + * Returns whether a field of a class is transient transactional + * or persistent. + */ + public boolean isManagedField(String classPath, String fieldName) + { + final JDOField field =3D getJDOField(classPath, fieldName); + return (field !=3D null + ? (field.isPersistent() | field.isTransactional()) : false= ); + } + + /** + * Returns whether a field of a class is known to be persistent. + */ + public boolean isPersistentField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOField field =3D getJDOField(classPath, fieldName); + return (field !=3D null ? field.isPersistent() : false); + } + + /** + * Returns whether a field of a class is known to be transactional. + */ + public boolean isTransactionalField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOField field =3D getJDOField(classPath, fieldName); + return (field !=3D null ? field.isTransactional() : false); + } + + /** + * Returns whether a field of a class is known to be Primary Key. + */ + public boolean isKeyField(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOField field =3D getJDOField(classPath, fieldName); + return (field !=3D null ? field.isKey() : false); + } + + /** + * Returns whether a field of a class is known to be part of the + * Default Fetch Group. + */ + public boolean isDefaultFetchGroupField(String classPath, String field= Name) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOField field =3D getJDOField(classPath, fieldName); + return (field !=3D null ? field.isInDefaultFetchGroup() : false); + } + + /** + * Returns the unique field index of a declared, persistent field of a + * class. + */ + public int getFieldNumber(String classPath, String fieldName) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final JDOClass clazz =3D getJDOClass(classPath); + return (clazz !=3D null ? clazz.getIndexOfField(fieldName) : -1); + } + + /** + * Returns an array of field names of all declared, persistent fields + * of a class. + */ + public String[] getManagedFields(String classname) + { + final JDOClass clazz =3D getJDOClass(classname); + return (clazz !=3D null ? clazz.getManagedFieldNames() : new Strin= g[]{}); + } + + /** + * Not member of EnhancerMetaData Interface. + */ + public final String[] getKnownClasses() + { + return model.getKnownClassNames(); + } + + /** + * Gets all known fields of a class. + */ + public final String[] getKnownFields(String classname) + { + final JDOClass clazz =3D getJDOClass(classname); + return (clazz !=3D null ? clazz.getFieldNames() : new String[]{}); + } + + + /** + * Gets the access modifier of a class. + */ + public final int getClassModifiers(String classname) + { + final JDOClass clazz =3D getJDOClass(classname); + return (clazz !=3D null ? clazz.getModifiers() : 0); + } + + /** + * Gets the access modifier of a field. + */ + public final int getFieldModifiers(String classname, + String fieldname) + { + final JDOField field =3D getJDOField(classname, fieldname); + return (field !=3D null ? field.getModifiers() : 0); + } + + public final String getFieldType(String classname, + String fieldname) + { + final JDOField field =3D getJDOField(classname, fieldname); + return (field !=3D null ? field.getType() : null); + } + + public final String[] getFieldType(String classname, + String[] fieldnames) + { + final int n =3D (fieldnames !=3D null ? fieldnames.length : 0); + final String[] types =3D new String[n]; + for (int i =3D 0; i < n; i++) { + types[i] =3D getFieldType(classname, fieldnames[i]); + } + return types; + } + + public final int[] getFieldModifiers(String classname, + String[] fieldnames) + throws EnhancerMetaDataUserException, EnhancerMetaDataFatalError + { + final int n =3D (fieldnames !=3D null ? fieldnames.length : 0); + final int[] mods =3D new int[n]; + for (int i =3D 0; i < n; i++) { + mods[i] =3D getFieldModifiers(classname, fieldnames[i]); + } + return mods; + } + + private final JDOClass getJDOClass(String classname) + throws EnhancerMetaDataUserException + { + return model.getJDOClass(classname); + } + + private final JDOField getJDOField(JDOClass clazz, + String fieldname) + { + return (clazz !=3D null ? clazz.getField(fieldname) : null); + } + + private final JDOField getJDOField(String classname, + String fieldname) + { + final JDOClass clazz =3D getJDOClass(classname); + return getJDOField(clazz, fieldname); + } + + // -------------------------------------------------------------------= --- + =20 + public static void main(String[] argv) + { + final PrintWriter out =3D new PrintWriter(System.out, true); + =20 + if (argv.length !=3D 1) { + System.err.println("No property file specified."); + return; + } + + final Properties p =3D new Properties(); + try { + java.io.InputStream in =3D + new java.io.FileInputStream(new java.io.File(argv[0])); + p.load(in); + in.close(); + out.println("PROPERTIES: " + p); + out.println("############"); + MetaDataProperties props =3D new MetaDataProperties(p); + } catch (Throwable ex) { + ex.printStackTrace(System.err); + } + + final EnhancerMetaDataPropertyImpl jdo + =3D new EnhancerMetaDataPropertyImpl(out, true, p); + final String[] classes =3D jdo.getKnownClasses(); + for (int k =3D 0; k < classes.length; k++) { + final String clazz =3D classes[k]; + out.println("CLAZZ: " + clazz); + out.println("\tpersistent: " + + jdo.isPersistenceCapableClass(clazz)); + out.println("\tpersistent root: " + + jdo.isPersistenceCapableRootClass(clazz)); + out.println("\tpersistent root class: " + + jdo.getPersistenceCapableRootClass(clazz)); + out.println("\tpersistent super class: " + + jdo.getPersistenceCapableSuperClass(clazz)); + out.println("\tkey class: " + + jdo.getKeyClass(clazz)); + + final String[] fields =3D jdo.getKnownFields(clazz); + for (int j =3D 0; j < fields.length; j++) { + final String field =3D fields[j]; + out.println("FIELD: " + field); + out.println("\tpersistent field: " + + jdo.isPersistentField(clazz, field)); + out.println("\tpk field: " + + jdo.isKeyField(clazz, field)); + out.println("\tdfg field: " + + jdo.isDefaultFetchGroupField(clazz, field)); + out.println("\tnumber: " + + jdo.getFieldNumber(clazz, field)); + + final String[] names =3D jdo.getManagedFields(clazz); + final int n =3D (fields !=3D null ? names.length : 0); + out.println("managed fields: number: " + n); + for (int i =3D 0; i < n; i++) { + final String name =3D names[i]; + out.println(i + ": " + name + + " number: " + + jdo.getFieldNumber(clazz, name) + + " pk: " + + jdo.isKeyField(clazz, name) + + " dfg: " + + jdo.isDefaultFetchGroupField(clazz, name= )); + } + } + } + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/= prop/JDOClass.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/enhancer/meta/prop/JDOClass.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/pro= p/JDOClass.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/enhancer/meta/pro= p/JDOClass.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,349 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.enhancer.meta.prop; + +import java.lang.reflect.Modifier; + +import java.util.Comparator; +import java.util.List; +import java.util.Collections; +import java.util.ArrayList; + + +/** + * A class to hold all parsed attributes of a class. + */ +final class JDOClass +{ + /** + * The name of the class. + */ + private final String name; + =20 + /** + * The name of the superclass. + */ + private String superClassName =3D null; + =20 + /** + * The name of the oid class. + */ + private String oidClassName =3D null; + =20 + /** + * The access modifier of the class. + */ + private int modifiers =3D Modifier.PUBLIC; + =20 + /** + * The persistence modifier of the class. + */ + private boolean isPersistent =3D true; + =20 + /** + * Flag indicating whether this class is serializable. + */ + private boolean isSerializable =3D true; + =20 + /** + * A list of all parsed fields. + */ + private final List fields =3D new ArrayList(); + =20 + /** + * The names of all managed fields this class. + */ + private String[] managedFieldNames =3D null; + =20 + /** + * The names of all fields this class. + */ + private String[] fieldNames =3D null; + =20 + /** + * Constructs a new object with the given name. + * + * @param name The name of the class. + */ + JDOClass(String name) + { + this.name =3D name; + } + =20 + /** + * Returns the name of the class. + * + * @return The name of the class. + */ + public String getName() + { + return name; + } + =20 + /** + * Returns the modifiers of the class. + * + * @param modifiers The modifiers of the class. + */ + public void setModifiers(int modifiers) + { + this.modifiers =3D modifiers; + } + =20 + /** + * Returns the modifiers of the class. + * + * @return The modifiers of the class. + */ + public int getModifiers() + { + return modifiers; + } + =20 + /** + * Sets the superclassname. The given classname should have a canonical + * form (with dots). It is converted to the CM-similar notation + * (with slashes). + * + * @param classname The superclassname. + */ + public void setSuperClassName(String classname) + { + superClassName =3D NameHelper.fromCanonicalClassName(classname); + } + =20 + /** + * Returns the superclassname. + * + * @return The superclassname. + */ + public String getSuperClassName() + { + return superClassName; + } + =20 + /** + * Sets the oid classname. The given classname should have a canonical + * form (with dots). It is converted to the CM-similar notation + * (with slashes). + * + * @param classname The oid classname + */ + public void setOidClassName(String classname) + { + oidClassName =3D NameHelper.fromCanonicalClassName(classname); + } + =20 + /** + * Returns the oid classname. + * + * @return The oid classname + */ + public String getOidClassName() + { + return oidClassName; + } + =20 + /** + * Sets the persistence modifier of the class. + * + * @param persistent the persistence modifer + * @see #isPersistent + */ + public void setPersistent(boolean persistent) + { + this.isPersistent =3D persistent; + } + =20 + /** + * Returns whether the class is persistent. + * + * @return true if persistent class. + * @see #isPersistent + */ + public boolean isPersistent() + { + return isPersistent; + } + =20 + /** + * Returns whether the class is transient. + * + * @return true if transient class. + * @see #isPersistent + */ + public boolean isTransient() + { + return !isPersistent(); + } + =20 + /** + * Returns whether the class is serializable. + * + * @return true if serializable class. + * @see #isSerializable + */ + public boolean isSerializable() + { + return isSerializable; + } + =20 + /** + * Sets the serializable flag of the class. + * + * @param serializable the serializable flag + * @see #isSerializable + */ + public void setSerializable(boolean serializable) + { + this.isSerializable =3D serializable; + } + /** + * Adds a new field. + * + * @param field The new field. + */ + public void addField(JDOField field) + { + fields.add(field); + } + =20 + /** + * Returns the field with the given name. + * + * @param name The name of the requested field. + * @return The field or null if not found. + */ + public JDOField getField(String name) + { + int idx =3D getIndexOfField(name); + return (idx > -1 ? (JDOField) fields.get(idx) : null); + } + =20 + /** + * Returns the index of the field with the given name. + * + * @param name The name of the field. + * @return The index or -1 if the field was not found. + */ + public int getIndexOfField(String name) + { + for (int i =3D 0; i < fields.size(); i++) { + JDOField field =3D (JDOField)fields.get(i); + if (field.getName().equals(name)) { + return i; + } + } + =20 + return -1; + } + =20 + /** + * Returns all fields of the class. + * + * @return The fields + */ + public List getFields() + { + return fields; + } + =20 + /** + * Returns the names of all fields of the class. + * + * @return The field names + */ + public String[] getFieldNames() + { + if (fieldNames =3D=3D null) { + final int n =3D fields.size(); + String[] fields =3D new String[n]; + for (int i =3D 0; i < n; i++) { + fields[i] =3D ((JDOField)this.fields.get(i)).getName(); + } + fieldNames =3D fields; + } + =20 + return fieldNames; + } + =20 + /** + * Sorts the fields of this class according to the names. This method + * should be called if all fields are added. It is necessary to + * establish an order on the fields. + * + */ + final void sortFields() + { + Collections.sort( + fields, + new Comparator() { + public int compare(Object f1, Object f2) + { + JDOField field1 =3D (JDOField)f1; + JDOField field2 =3D (JDOField)f2; + //if we dont have managed fields we dont care + if (!(field1.isManaged() && field2.isManaged())) + { + return (field1.isManaged() ? -1 : 1); + } + return field1.getName().compareTo(field2.getName()= ); + } + }); + } + =20 + /** + * Returns the names of all managed fields this class. + * + * @return The persistent fieldnames. + */ + public String[] getManagedFieldNames() + { + if (managedFieldNames =3D=3D null) { + final int n =3D fields.size(); + List tmp =3D new ArrayList(n); + for (int i =3D 0; i < n; i++) { + JDOField field =3D (JDOField)fields.get(i); + if (field.isManaged()) { + tmp.add(field.getName()); + } + } + managedFieldNames + =3D (String[])tmp.toArray(new String[tmp.size()]); + } + =20 + return managedFieldNames; + } + =20 + /** + * Creates a string-representation for this object. + * + * @return The string-representation of this object. + */ + public String toString() + { + return ('<' + MetaDataProperties.PROPERTY_SUPER_CLASSNAME + + ':' + superClassName + + MetaDataProperties.PROPERTY_OID_CLASSNAME + + ':' + oidClassName + + ',' + MetaDataProperties.PROPERTY_ACCESS_MODIFIER + + ':' + Modifier.toString(modifiers) + + ',' + MetaDataProperties.PROPERTY_JDO_MODIFIER + + ':' + isPersistent + + ',' + "fields:" + fields + '>'); + } +}