db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r171348 [5/7] - in /incubator/jdo/trunk/core20: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/model/ src/java/org/apache/jdo/impl/model/java/ src/java/org/apache/jdo/impl/model/java/reflection/ 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/model/ src/java/org/apache/jdo/model/java/ src/java/org/apache/jdo/model/jdo/ src/java/org/apache/jdo/util/
Date Sun, 22 May 2005 17:44:23 GMT
Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelFactoryImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelFactoryImplCaching.java?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelFactoryImplCaching.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelFactoryImplCaching.java Sun May 22 10:44:19 2005
@@ -0,0 +1,69 @@
+/*
+ * 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.jdo.caching;
+
+import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.model.jdo.JDOModel;
+import org.apache.jdo.model.jdo.JDOModelFactory;
+
+import org.apache.jdo.impl.model.jdo.JDOModelFactoryImplDynamic;
+
+/**
+ * Factory for caching JDOModel instances.
+ *
+ * @author Michael Bouschen
+ * @since 1.1
+ * @version 1.1
+ */
+public class JDOModelFactoryImplCaching extends JDOModelFactoryImplDynamic {
+
+    /** The singleton JDOModelFactory instance. */    
+    private static JDOModelFactory jdoModelFactory = 
+        new JDOModelFactoryImplCaching();
+
+    /**
+     * Creates new JDOModelFactoryImplCaching. This constructor
+     * should not be called directly; instead, the singleton access
+     * method  {@link #getInstance} should be used.
+     */
+    protected JDOModelFactoryImplCaching() {}
+
+    /** 
+     * Get an instance of JDOModelFactoryImpl.
+     * @return an instance of JDOModelFactoryImpl
+     */    
+    public static JDOModelFactory getInstance() {
+        return jdoModelFactory;
+    }
+    
+    /**
+     * Creates a new empty JDOModel instance. 
+     * The returned JDOModel instance uses the specified flag
+     * <code>loadXMLMetadataDefault</code> to set the default behavior 
+     * for the creation of new JDOClass instances  using methods 
+     * {@link JDOModel#createJDOClass(String)} and 
+     * {@link JDOModel#getJDOClass(String)} for which the caller doesn't 
+     * explicitly specify whether to read XML metatdata or not.
+     * @param loadXMLMetadataDefault the default setting for whether to 
+     * read XML metatdata in JDOModel's methods for JDOClass creation.
+     */
+    public JDOModel createJDOModel(JavaModel javaModel,
+                                   boolean loadXMLMetadataDefault) {
+        return new JDOModelImplCaching(javaModel, loadXMLMetadataDefault);
+    }
+
+}

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/caching/JDOModelImplCaching.java Sun May 22 10:44:19 2005
@@ -0,0 +1,126 @@
+/*
+ * 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.jdo.caching;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.model.jdo.JDOClass;
+import org.apache.jdo.impl.model.jdo.JDOModelImplDynamic;
+import org.apache.jdo.model.java.JavaType;
+
+/**
+ * A JDOModel instance bundles a number of JDOClass instances used by an 
+ * application. It provides factory methods to create and retrieve JDOClass 
+ * instances. A fully qualified class name must be unique within a JDOModel 
+ * instance. The model supports multiple classes having the same fully qualified 
+ * name by different JDOModel instances.
+ * <p>
+ * The caching JDOModel implementation caches any caclulated value to
+ * avoid re-calculating it if it is requested again. It is intended to
+ * be used in an environment where JDO metadata does NOT change
+ * (e.g. at runtime).
+ *
+ * @author Michael Bouschen
+ * @since 1.1
+ * @version 1.1
+ */
+public class JDOModelImplCaching extends JDOModelImplDynamic {
+
+    /** 
+     * This is a mapping from ObjectId classes to its JDOClass instances.
+     * Key is the type representation of the ObjectId class, value is the 
+     * corresponding JDOClass instance. Note, in the case of inheritance
+     * the top most persistence-capable class is stored.
+     */
+    private Map jdoClassesByObjectIdClasses = new HashMap();
+
+    /** 
+     * Set of fully qualified names of classes known to be 
+     * non persistence-capable. 
+     */
+    private Set nonPCClasses = new HashSet();
+
+    /** 
+     * Constructor. 
+     * JDOModel instances are created using the JDOModelFactory only.
+     */
+    protected JDOModelImplCaching(JavaModel javaModel, 
+                                  boolean loadXMLMetadataDefault) {
+        super(javaModel, loadXMLMetadataDefault);
+    }
+
+    /**
+     * This method returns the JDOClass instance that defines the specified type
+     * as its objectId class. In the case of an inheritance hierarchy it returns 
+     * the top most persistence-capable class of the hierarchy (see 
+     * {@link JDOClass#getPersistenceCapableSuperclass}).
+     * @param objectIdClass the type representation of the ObjectId class
+     * @return the JDOClass defining the specified class as ObjectId class
+     */
+    public JDOClass getJDOClassForObjectIdClass(JavaType objectIdClass)
+    {
+        // Note, method getJDOClassForObjectIdClass is not synchronized to
+        // avoid a deadlock with PC class registration.
+        if (objectIdClass == null)
+            return null;
+
+        synchronized (jdoClassesByObjectIdClasses) {
+            // First check the cache
+            JDOClass jdoClass = 
+                (JDOClass)jdoClassesByObjectIdClasses.get(objectIdClass);
+            if (jdoClass == null) {
+                // not found in the cache => call super
+                jdoClass = super.getJDOClassForObjectIdClass(objectIdClass);
+                if (jdoClass != null) {
+                    // found => update the cache
+                    jdoClassesByObjectIdClasses.put(objectIdClass, jdoClass);
+                }
+            }
+            
+            return jdoClass;
+        }
+    }
+
+    /** Returns a new instance of the JDOClass implementation class. */
+    protected JDOClass newJDOClassInstance() {
+        return new JDOClassImplCaching();
+    }
+
+    /**
+     * Checks whether the type with the specified name does NOT denote a
+     * persistence-capable class.
+     * @param typeName name of the type to be checked
+     * @return <code>true</code> if types is a name of a primitive type; 
+     * <code>false</code> otherwise
+     */
+    protected boolean isKnownNonPC(String typeName) {
+        return super.isKnownNonPC(typeName) || nonPCClasses.contains(typeName);
+    }
+
+    /** 
+     * Hook called when a class is known to be non persistence
+     * capable.
+     * @param className the name of the non-pc class
+     */
+    protected void knownNonPC(String className) {
+        nonPCClasses.add(className);
+    }
+}

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/package.html
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/package.html?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/package.html (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/package.html Sun May 22 10:44:19 2005
@@ -0,0 +1,27 @@
+<!--
+ 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.
+-->
+
+<html>
+<head>
+<title>JDOModel implementation package.</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<p>This package contains classes that implement the JDO model interfaces 
+and provide access to JDO metadata. 
+</body>
+</html>

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/util/PrintSupport.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/util/PrintSupport.java?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/util/PrintSupport.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/util/PrintSupport.java Sun May 22 10:44:19 2005
@@ -0,0 +1,294 @@
+/*
+ * 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.
+ */
+
+/**
+ * PrintSupport.java
+ *
+ */
+
+package org.apache.jdo.impl.model.jdo.util;
+
+import java.util.*;
+
+import org.apache.jdo.model.jdo.JDOArray;
+import org.apache.jdo.model.jdo.JDOClass;
+import org.apache.jdo.model.jdo.JDOCollection;
+import org.apache.jdo.model.jdo.JDOExtension;
+import org.apache.jdo.model.jdo.JDOField;
+import org.apache.jdo.model.jdo.JDOIdentityType;
+import org.apache.jdo.model.jdo.JDOMap;
+import org.apache.jdo.model.jdo.JDOModel;
+import org.apache.jdo.model.jdo.JDOReference;
+import org.apache.jdo.model.jdo.JDORelationship;
+import org.apache.jdo.model.jdo.NullValueTreatment;
+import org.apache.jdo.model.jdo.PersistenceModifier;
+
+public class PrintSupport 
+{
+    public static void printJDOModel(JDOModel jdoModel) 
+    {
+        JDOClass[] jdoClasses = jdoModel.getDeclaredClasses();
+        for (int i = 0; i < jdoClasses.length; i++) {
+            printJDOClass(0, jdoClasses[i]);
+        }
+    }
+    
+    public static void printJDOClass(JDOClass jdoClass)
+    {
+        printJDOClass(0, jdoClass);
+    }
+    
+    public static void printJDOFields(JDOField[] jdoFields)
+    {
+        printJDOFields(0, jdoFields);
+    }
+
+    public static void printJDOField(JDOField jdoField) 
+    {
+        printJDOField(0, jdoField);
+    }
+    
+    public static void printJDORelationship(JDORelationship jdoRelationship) 
+    {
+        printJDORelationship(0, jdoRelationship);
+    }
+
+    public static void printJDOExtensions(JDOExtension[] jdoExtensions)
+    {
+        printJDOExtensions(0, jdoExtensions);
+    }
+
+    public static void printJDOExtension(JDOExtension jdoExtension) 
+    {
+        printJDOExtension(0, jdoExtension);
+    }
+
+    // ----- methods taking indent level -----
+
+    private static void printJDOClass(int indent, JDOClass jdoClass) 
+    {
+        if (jdoClass == null)
+            return;
+
+        println(indent, "--> JDOClass "); //NOI18N
+        println(indent+1, "name                       = " + jdoClass.getName()); //NOI18N
+        println(indent+1, "packagePrefix              = " + jdoClass.getPackagePrefix()); //NOI18N
+        println(indent+1, "identityType               = " + JDOIdentityType.toString(jdoClass.getIdentityType())); //NOI18N
+        println(indent+1, "objectIdClass              = " + jdoClass.getObjectIdClass()); //NOI18N
+        println(indent+1, "declaredObjectIdClassName  = " + jdoClass.getDeclaredObjectIdClassName()); //NOI18N
+        println(indent+1, "requiresExtent             = " + jdoClass.requiresExtent()); //NOI18N
+        println(indent+1, "pcSuperclassName           = " + jdoClass.getPersistenceCapableSuperclassName()); //NOI18N
+        println(indent+1, "pcSuperclass               = " + jdoClass.getPersistenceCapableSuperclass()); //NOI18N
+        println(indent+1, "pcRootClass                = " + jdoClass.getPersistenceCapableRootClass()); //NOI18N
+        println(indent+1, "javaType                   = " + jdoClass.getJavaType()); //NOI18N
+        println(indent+1, "declaredManagedFieldCount  = " + jdoClass.getDeclaredManagedFieldCount()); //NOI18N
+        println(indent+1, "inheritedManagedFieldCount = " + jdoClass.getInheritedManagedFieldCount());  //NOI18N
+        println(indent+1, "managedFields              = " + Arrays.asList(jdoClass.getManagedFields())); //NOI18N
+        println(indent+1, "managedFieldNumbers        = " + asList(jdoClass.getManagedFieldNumbers()));  //NOI18N
+        println(indent+1, "persistentFieldNumbers     = " + asList(jdoClass.getPersistentFieldNumbers())); //NOI18N
+        println(indent+1, "primaryKeyFieldNumbers     = " + asList(jdoClass.getPrimaryKeyFieldNumbers())); //NOI18N
+        println(indent+1, "persistentNonPKFieldNs     = " + asList(jdoClass.getPersistentNonPrimaryKeyFieldNumbers())); //NOI18N
+        println(indent+1, "persistentRelshipFieldNs   = " + asList(jdoClass.getPersistentRelationshipFieldNumbers())); //NOI18N
+        println(indent+1, "persistentSerializableFNs  = " + asList(jdoClass.getPersistentSerializableFieldNumbers())); //NOI18N
+        println(indent+1, "declaredFields"); //NOI18N
+        printJDOFields(indent+1, jdoClass.getDeclaredFields());
+        printJDOExtensions(indent+1, jdoClass.getJDOExtensions());
+        println(0, "<-- JDOClass\n "); //NOI18N
+    }
+    
+    private static void printJDOFields(int indent, JDOField[] jdoFields) {
+        if ((jdoFields != null) && (jdoFields.length > 0)) {
+            TreeSet sorted = new TreeSet(new Comparator() {
+                    public int compare(Object o1, Object o2) {
+                        return (((JDOField)o1).getFieldNumber()
+                                - ((JDOField)o2).getFieldNumber());
+                    }
+                    public boolean equals(Object obj) {
+                        return obj.equals(this);
+                    }
+                });
+
+            for (int i = 0; i < jdoFields.length; i++) {
+                sorted.add(jdoFields[i]);
+            }
+
+            for (Iterator i = sorted.iterator(); i.hasNext();) {
+                printJDOField(indent, (JDOField)i.next());
+            }
+        }
+    }
+    
+    private static void printJDOField(int indent, JDOField jdoField) 
+    {
+        if (jdoField == null)
+            return;
+
+        println(indent, "--> JDOField "); //NOI18N
+        println(indent+1, "name                = " + jdoField.getName()); //NOI18N
+        println(indent+1, "declaringClass      = " + jdoField.getDeclaringClass().getName()); //NOI18N
+        println(indent+1, "persistenceModifier = " + PersistenceModifier.toString(jdoField.getPersistenceModifier())); //NOI18N
+        println(indent+1, "primaryKey          = " + jdoField.isPrimaryKey()); //NOI18N
+        println(indent+1, "nullValue           = " + NullValueTreatment.toString(jdoField.getNullValueTreatment())); //NOI18N
+        println(indent+1, "defaultFetchGroup   = " + jdoField.isDefaultFetchGroup()); //NOI18N
+        println(indent+1, "embedded            = " + jdoField.isEmbedded()); //NOI18N
+        println(indent+1, "type                = " + jdoField.getType()); //NOI18N
+        //println(indent+1, "typeName            = " + jdoField.getTypeName()); //NOI18N
+        println(indent+1, "javaField           = " + jdoField.getJavaField()); //NOI18N
+        println(indent+1, "serializable        = " + jdoField.isSerializable()); //NOI18N
+        println(indent+1, "fieldNumber         = " + jdoField.getFieldNumber()); //NOI18N
+        println(indent+1, "relativeFieldNumber = " + jdoField.getRelativeFieldNumber()); //NOI18N
+        printJDORelationship(indent+1, jdoField.getRelationship()); //NOI18N
+        printJDOExtensions(indent+1, jdoField.getJDOExtensions()); //NOI18N
+        println(indent, "<-- JDOField "); //NOI18N
+    }
+    
+    private static void printJDORelationship(int indent, 
+                                            JDORelationship jdoRelationship) 
+    {
+        if (jdoRelationship == null) 
+            return;
+
+        if (jdoRelationship instanceof JDOReference)
+            printJDOReference(indent, (JDOReference)jdoRelationship);
+        else if (jdoRelationship instanceof JDOCollection)
+            printJDOCollection(indent, (JDOCollection)jdoRelationship);
+        else if (jdoRelationship instanceof JDOArray)
+            printJDOArray(indent, (JDOArray)jdoRelationship);
+        else if (jdoRelationship instanceof JDOMap)
+            printJDOMap(indent, (JDOMap)jdoRelationship);
+    }
+    
+    private static void printJDORelationshipHelper(int indent, JDORelationship jdoRelationship) 
+    {
+        if (jdoRelationship == null)
+            return;
+
+        JDORelationship inverse = jdoRelationship.getInverseRelationship();
+        println(indent+1, "declaringField  = " + jdoRelationship.getDeclaringField().getName()); //NOI18N
+        println(indent+1, "bounds          = " + jdoRelationship.getLowerBound() + " / " +  jdoRelationship.getUpperBound()); //NOI18N
+        println(indent+1, "inverse         = " + ((inverse==null) ? "null" : //NOI18N
+            inverse.getDeclaringField().getDeclaringClass().getName() + "." + //NOI18N
+            inverse.getDeclaringField().getName()));
+    }
+    
+    private static void printJDOReference(int indent, JDOReference jdoReference) 
+    {
+        if (jdoReference == null)
+            return;
+
+        println(indent, "--> JDOReference"); //NOI18N
+        printJDORelationshipHelper(indent, jdoReference);
+        printJDOExtensions(indent+1, jdoReference.getJDOExtensions());
+        println(indent, "<-- JDOReference"); //NOI18N
+    }
+    
+    private static void printJDOCollection(int indent, JDOCollection jdoCollection) 
+    {
+        if (jdoCollection == null)
+            return;
+
+        println(indent, "--> JDOCollection"); //NOI18N
+        printJDORelationshipHelper(indent, jdoCollection);
+        println(indent+1, "embeddedElement = " + jdoCollection.isEmbeddedElement()); //NOI18N
+        println(indent+1, "elementType     = " + jdoCollection.getElementType()); //NOI18N
+        println(indent+1, "elementTypeName = " + jdoCollection.getElementTypeName()); //NOI18N
+        printJDOExtensions(indent+1, jdoCollection.getJDOExtensions()); //NOI18N
+        println(indent, "<-- JDOCollection"); //NOI18N
+    }
+    
+    private static void printJDOArray(int indent, JDOArray jdoArray) 
+    {
+        if (jdoArray == null)
+            return;
+
+        println(indent, "--> JDOArray"); //NOI18N
+        printJDORelationshipHelper(indent, jdoArray);
+        println(indent+1, "embeddedElement = " + jdoArray.isEmbeddedElement()); //NOI18N
+        printJDOExtensions(indent+1, jdoArray.getJDOExtensions());
+        println(indent, "<-- JDOArray"); //NOI18N
+    }
+    
+    private static void printJDOMap(int indent, JDOMap jdoMap) 
+    {
+        if (jdoMap == null)
+            return;
+
+        println(indent, "--> JDOMap"); //NOI18N
+        printJDORelationshipHelper(indent, jdoMap);
+        println(indent+1, "embeddedKey     = " + jdoMap.isEmbeddedKey()); //NOI18N
+        println(indent+1, "keyType         = " + jdoMap.getKeyType()); //NOI18N
+        println(indent+1, "keyTypeName     = " + jdoMap.getKeyTypeName()); //NOI18N
+        println(indent+1, "embeddedValue   = " + jdoMap.isEmbeddedValue()); //NOI18N
+        println(indent+1, "valueType       = " + jdoMap.getValueType()); //NOI18N
+        println(indent+1, "valueTypeName   = " + jdoMap.getValueTypeName()); //NOI18N
+        printJDOExtensions(indent+1, jdoMap.getJDOExtensions());
+        println(indent, "<-- JDOMap"); //NOI18N
+    }
+    
+    private static void printJDOExtensions(int indent, JDOExtension[] jdoExtensions) 
+    {
+        if ((jdoExtensions != null) && (jdoExtensions.length > 0)) {
+            TreeSet sorted = new TreeSet(new Comparator() {
+                    public int compare(Object o1, Object o2) {
+                        return ((JDOExtension)o1).getKey().compareTo(
+                          ((JDOExtension)o2).getKey());
+                    }
+                    public boolean equals(Object obj) {
+                        return obj.equals(this);
+                    }
+                });
+
+            for (int i = 0; i < jdoExtensions.length; i++) {
+                sorted.add(jdoExtensions[i]);
+            }
+
+            for (Iterator i = sorted.iterator(); i.hasNext();) {
+                printJDOExtension(indent, (JDOExtension)i.next());
+            }
+        }
+    }
+    
+    private static void printJDOExtension(int indent, JDOExtension jdoExtension) 
+    {
+        if (jdoExtension == null)
+            return;
+        
+        println(indent, "--> JDOExtension"); //NOI18N
+        println(indent+1, "vendorName = " + jdoExtension.getVendorName()); //NOI18N
+        println(indent+1, "key        = " + jdoExtension.getKey()); //NOI18N
+        println(indent+1, "value      = " + jdoExtension.getValue()); //NOI18N
+        println(indent, "<-- JDOExtension"); //NOI18N
+    }
+    
+    // ----- helper methods -----
+    
+    static void println(int indent, String text) {
+        for (int i = 0; i < indent; i++) {
+            System.out.print("    "); //NOI18N
+        }
+        System.out.println(text);
+    }
+
+    public static List asList(int[] array) 
+    {
+        int length = (array == null) ? 0 : array.length;
+        List list = new ArrayList(length);
+        for (int i = 0; i < length; i++) {
+            list.add(new Integer(array[i]));
+        }
+        return list;
+    }
+}

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/util/TypeSupport.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/util/TypeSupport.java?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/util/TypeSupport.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/util/TypeSupport.java Sun May 22 10:44:19 2005
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+
+/**
+ * TypeSupport.java
+ *
+ */
+
+package org.apache.jdo.impl.model.jdo.util;
+
+import java.util.Set;
+import java.util.HashSet;
+
+import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.model.jdo.JDOModel;
+
+
+/**
+ *
+ */
+public class TypeSupport
+{
+    /** */
+    private static Set primitiveTypeNames = new HashSet();
+
+    static 
+    {
+        // initialize set of names of primitive types
+        primitiveTypeNames.add("byte");
+        primitiveTypeNames.add("short");
+        primitiveTypeNames.add("int");
+        primitiveTypeNames.add("long");
+        primitiveTypeNames.add("char");
+        primitiveTypeNames.add("float");
+        primitiveTypeNames.add("double");
+        primitiveTypeNames.add("boolean");
+    }
+    
+
+    /** 
+     * Returns <code>true</code> if the persistence-modifier of a field
+     * having the specified type defaults to <code>true</code>. 
+     * @param type the type to be checked
+     * @return <code>true</code> if type is a value type; 
+     * <code>false</code> otherwise
+     */
+    public static boolean isPersistenceFieldType(JavaType type)
+    {
+        return type.isValue() ||
+               type.isJDOSupportedCollection() ||
+               type.isJDOSupportedMap() ||
+               type.isPersistenceCapable() ||
+               isPersistenceArrayType(type);
+    }
+     
+    /** 
+     * Returns <code>true</code> if the embedded-element property of a field 
+     * having the specified type defaults to <code>true</code>.
+     * @param type the type to be checked
+     * @return <code>true</code> if type is a embedded-element type; 
+     * <code>false</code> otherwise
+     */
+    public static boolean isEmbeddedElementType(JavaType type)
+    {
+        return !type.isPersistenceCapable() && !type.isInterface();
+    }
+
+    /** 
+     * Returns <code>true</code> if the embedded property of a field having 
+     * the specified type defaults to <code>true</code>.
+     * @param type the type to be checked
+     * @return <code>true</code> if type is a embedded type; 
+     * <code>false</code> otherwise
+     */
+    public static boolean isEmbeddedFieldType(JavaType type)
+    {
+        return type.isValue() ||
+               isPersistenceArrayType(type);
+    }
+
+    /**
+     * Returns a JavaType representation for the specified type name. 
+     * The method delegates the request to the JavaModel attached to the
+     * specified JDOModel. An unqualified name is qualified using first the 
+     * specified packagePrefix and then "java.lang.", but only if the type
+     * name is the the name of a primitive type. If the method still does
+     * not find a valid type, then it returns <code>null</code>.
+     * @param jdoModel the owning JDOModel
+     * @param typeName the name of the type to be checked
+     * @param packagePrefix the package prefix used to qualify the type name
+     * @return the JavaType representation of the specified type name or
+     * <code>null</code> if it cannot be resolved.
+     */
+    public static JavaType resolveType(JDOModel jdoModel, String typeName, 
+                                       String packagePrefix)
+    {
+        JavaType type = null;
+        JavaModel javaModel = jdoModel.getJavaModel();
+        if (primitiveTypeNames.contains(typeName) ||
+            (typeName.indexOf('.') != -1) || 
+            (packagePrefix == null) || (packagePrefix.length() == 0)) {
+            // Take the typeName as specified, 
+            // if typeName denotes a primitive type or is a qualified name
+            // or if there is no packagePrefix (default package)
+            type = javaModel.getJavaType(typeName);
+        }
+        else {
+            // Not a primitive type and not qualified and packagePrefix
+            // specified => qualify using packagePrefix
+            type = javaModel.getJavaType(packagePrefix + typeName);
+            if (type == null) {
+                // If type could not be resolved => 
+                // use java.lang. package prefix as qualifier 
+                type = javaModel.getJavaType("java.lang." + typeName); //NOI18N
+            }
+        }
+        return type;
+    }
+
+    /**
+     * Returns <code>true</code> if the specified type represents an array
+     * and its element type is a value type.
+     * @param type the JavaType to be checked
+     * @return <code>true</code> if type is a value array; 
+     * <code>false</code> otherwise.
+     */
+    public static boolean isValueArrayType(JavaType type)
+    {
+        if (type.isArray()) {
+            JavaType elementType = type.getArrayComponentType();
+            return elementType.isValue();
+        }
+        return false;
+    }
+    
+    
+    //========= Internal helper methods ==========
+    
+    /**
+     * Returns <code>true</code> if the specified type represents an array
+     * and its element type is a persistence capable class.
+     * @param type the JavaType to be checked
+     * @return <code>true</code> if type is a persistent array; 
+     * <code>false</code> otherwise.
+     */
+    private static boolean isPersistenceArrayType(JavaType type)
+    {
+         if (type.isArray()) {
+            JavaType elementType = type.getArrayComponentType();
+            return elementType.isValue() ||
+                   elementType.isPersistenceCapable();
+        }
+        return false;
+    }
+    
+}

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandler.java?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandler.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandler.java Sun May 22 10:44:19 2005
@@ -0,0 +1,140 @@
+/*
+ * 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.
+ */
+
+/*
+ * File:           JDOHandler.java
+ * Date:           July 3, 2001  2:16 PM
+ *
+ * @author  michael
+ * @version generated by FFJ XML module
+ */
+package org.apache.jdo.impl.model.jdo.xml;
+
+import java.util.Collection;
+import org.xml.sax.*;
+
+public interface JDOHandler 
+{
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_jdo(final Attributes meta)
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_jdo() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_package(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_package() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_class(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_class() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_field(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_field() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_collection(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_collection() 
+        throws SAXException;
+       
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_array(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_array() 
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_map(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_map()   
+        throws SAXException;
+    
+    /**
+     * A container element start event handling method.
+     * @param meta attributes
+     */
+    public void start_extension(final Attributes meta) 
+        throws SAXException;
+    
+    /**
+     * A container element end event handling method.
+     */
+    public void end_extension() 
+        throws SAXException;
+
+    /**
+     *
+     */
+    public Collection handledJDOClasses();
+}

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java Sun May 22 10:44:19 2005
@@ -0,0 +1,616 @@
+/*
+ * 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.
+ */
+
+/*
+ * File:           JDOHandlerImpl.java
+ * Date:           July 3, 2001  2:16 PM
+ *
+ * @author  michael
+ * @version generated by FFJ XML module
+ */
+package org.apache.jdo.impl.model.jdo.xml;
+
+import java.util.*;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.jdo.impl.model.jdo.JDOClassImplDynamic;
+import org.apache.jdo.model.ModelException;
+import org.apache.jdo.model.jdo.JDOArray;
+import org.apache.jdo.model.jdo.JDOClass;
+import org.apache.jdo.model.jdo.JDOCollection;
+import org.apache.jdo.model.jdo.JDOElement;
+import org.apache.jdo.model.jdo.JDOExtension;
+import org.apache.jdo.model.jdo.JDOField;
+import org.apache.jdo.model.jdo.JDOIdentityType;
+import org.apache.jdo.model.jdo.JDOMap;
+import org.apache.jdo.model.jdo.JDOModel;
+import org.apache.jdo.model.jdo.JDOPackage;
+import org.apache.jdo.model.jdo.NullValueTreatment;
+import org.apache.jdo.model.jdo.PersistenceModifier;
+import org.apache.jdo.util.I18NHelper;
+import org.xml.sax.*;
+
+/**
+ * 
+ * TBD:
+ * <ul>
+ * <li> Reading persistence capable superclass entry: check already existing 
+ * superclass entry for consistency
+ * <li> Only populate requested class info, not the entire .jdo file
+ */
+public class JDOHandlerImpl 
+    implements JDOHandler 
+{
+    /** */
+    private final JDOModel model;
+    
+    /** */
+    private final Stack context;
+    
+    /** 
+     * Flag indicating that the current entries should no be loaded,
+     * because JDO metadata has been loaded before for the current
+     * persistence capable class.
+     */
+    private boolean skipXMLElements;
+
+    /** */
+    private final Collection handledJDOClasses;
+
+    /** I18N support. */
+    private static final I18NHelper msg = I18NHelper.getInstance(
+        "org.apache.jdo.impl.model.jdo.Bundle", //NOI18N
+        JDOHandlerImpl.class.getClassLoader());
+
+    /** Logger */
+    private static Log logger = LogFactory.getFactory().getInstance(
+        "org.apache.jdo.impl.model.jdo.xml"); // NOI18N
+    
+    /**
+     * 
+     */
+    public JDOHandlerImpl (JDOModel model) 
+    {
+        this.model = model;
+        this.context = new Stack();
+        this.skipXMLElements = false;
+        this.handledJDOClasses = new HashSet();
+    }
+    
+    /**
+     * 
+     */
+    public void start_jdo(final Attributes meta) 
+    {
+        if (logger.isTraceEnabled()) 
+            logger.trace("  <jdo>"); //NOI18N
+        // push current JDOModel on context stack
+        context.push(model);
+    }
+    
+    /**
+     * 
+     */
+    public void end_jdo() 
+    {
+        if (logger.isTraceEnabled()) 
+            logger.trace("  </jdo>"); //NOI18N
+        // remove JDOModel fom context stack
+        context.pop();
+    }
+    
+    /**
+     * 
+     */
+    public void start_package(final Attributes meta) 
+        throws SAXException 
+    {
+        boolean trace = logger.isTraceEnabled();
+        if (trace) 
+            logger.trace("  <package>"); //NOI18N
+        JDOPackage jdoPackage = null;
+        try {
+            // get JDOModel from context stack
+            JDOModel model = (JDOModel)context.peek();
+            String packageName = meta.getValue("", "name"); //NOI18N
+            if ((packageName == null) || packageName.length() == 0)
+                packageName = ""; //NOI18N
+            if (trace)
+                logger.trace("    name = " + packageName); //NOI18N
+            jdoPackage = model.createJDOPackage(packageName);
+        }
+        catch (ModelException ex) {
+            SAXException e = 
+                new SAXException(msg.msg("EXC_ModelException"), ex); //NOI18N
+            if (trace)
+                logger.trace("Throwing exception in " + //NOI18N
+                             "JDOHandlerImpl.start_package:", e); //NOI18N
+            throw e;
+        }
+        
+        // push current JDOPackage on context stack
+        context.push(jdoPackage);
+    }
+    
+    /**
+     * 
+     */
+    public void end_package() 
+    {
+        if (logger.isTraceEnabled()) 
+            logger.trace("  </package>"); //NOI18N
+        // remove JDOPackage fom context stack
+        context.pop();
+    }
+    
+    /**
+     * 
+     */
+    public void start_class(final Attributes meta)  
+        throws SAXException 
+    {
+        boolean trace = logger.isTraceEnabled();
+        if (trace)
+            logger.trace("  <class>"); //NOI18N
+        JDOClass jdoClass = null;
+        try {
+            // get JDOPackage from context stack
+            //String packageName = (String)context.peek();
+            JDOPackage jdoPackage = (JDOPackage)context.peek();
+            String packageName = jdoPackage.getName();
+            String className = meta.getValue("", "name"); //NOI18N
+            if ((packageName != null) && (packageName.length() > 0))
+                className = packageName + "." + className; //NOI18N
+            jdoClass = model.createJDOClass(className, false);
+            skipXMLElements = jdoClass.isXMLMetadataLoaded();
+            if (skipXMLElements) {
+                if (trace)
+                    logger.trace(
+                        "  JDO metadata already loaded for class " + //NOI18N
+                        className + ", skipping class element"); //NOI18N
+                return;
+            }
+            for ( int i = 0; i < meta.getLength(); i++ ) {
+                String name = meta.getLocalName(i);
+                String value = meta.getValue(i);
+                if (trace)
+                    logger.trace("    " + name + " = " + value); //NOI18N
+                if ("name".equals(name)) { //NOI18N
+                    // name is already set during create => do nothing 
+                }
+                else if ("identity-type".equals(name)) { //NOI18N
+                    jdoClass.setIdentityType(
+                        JDOIdentityType.toJDOIdentityType(value));
+                }
+                else if ("objectid-class".equals(name)) { //NOI18N
+                    jdoClass.setDeclaredObjectIdClassName(value);
+                }
+                else if ("requires-extent".equals(name)) { //NOI18N
+                    jdoClass.setRequiresExtent(
+                        Boolean.valueOf(value).booleanValue());
+                }
+                else if ("persistence-capable-superclass".equals(name)) { //NOI18N
+                    // Do not overwrite existing entry
+                    // TBD check old and new entry for consistency
+                    if (jdoClass.getPersistenceCapableSuperclassName() == null) {
+                        jdoClass.setPersistenceCapableSuperclassName(value);
+                    }
+                }
+                else {
+                    SAXException e = new SAXException(
+                        msg.msg("EXC_UnknownAttribute", "<class>", //NOI18N
+                                name, value)); 
+                    if (trace)
+                        logger.trace("Throwing exception in " +  //NOI18N
+                                     "JDOHandlerImpl.start_class:", e); //NOI18N
+                    throw e;
+                }
+            }
+        }
+        catch (ModelException ex) {
+            SAXException e = 
+                new SAXException(msg.msg("EXC_ModelException"), ex); //NOI18N
+            if (trace)
+                logger.trace("Throwing exception in " +  //NOI18N
+                             "JDOHandlerImpl.start_class:", e); //NOI18N
+            throw e;
+        }
+        // store current jdoClass in handledJDOClasses
+        handledJDOClasses.add(jdoClass);
+
+        // push current JDOClass object on context stack
+        context.push(jdoClass);
+    }
+    
+    /**
+     * 
+     */
+    public void end_class()  
+    {
+        if (logger.isTraceEnabled()) 
+            logger.trace("  </class>"); //NOI18N
+        if (skipXMLElements) {
+            // set flag to false to allow next class entry to be populated
+            skipXMLElements = false;
+        }
+        else {
+            // remove JDOClass fom context stack
+            JDOClass jdoClass = (JDOClass)context.pop();
+            // set jdoClass' xmlMetadataLoaded flag
+            jdoClass.setXMLMetadataLoaded();
+        }
+    }
+    
+    /**
+     * 
+     */
+    public void start_field(final Attributes meta) 
+        throws SAXException 
+    {
+        if (skipXMLElements) 
+            return;
+        boolean trace = logger.isTraceEnabled();
+        if (trace)
+            logger.trace("  <field>"); //NOI18N
+        JDOField jdoField = null;
+        try {
+            // get the current JDOClass from context stack
+            JDOClass jdoClass = (JDOClass)context.peek();
+            String fieldName = meta.getValue("", "name"); //NOI18N
+            jdoField =  jdoClass.createJDOField(fieldName);
+            for (int i = 0; i < meta.getLength(); i++ ) {
+                String name = meta.getLocalName(i);
+                String value = meta.getValue(i);
+                if (trace)
+                    logger.trace("    " + name + " = " + value); //NOI18N
+                if ("name".equals(name)) { //NOI18N
+                    // name is already set during create => do nothing 
+                }
+                else if ("persistence-modifier".equals(name)) { //NOI18N
+                    int modifier = 
+                        PersistenceModifier.toPersistenceModifier(value);
+                    jdoField.setPersistenceModifier(modifier);
+                }
+                else if ("primary-key".equals(name)) { //NOI18N
+                    jdoField.setPrimaryKey(
+                        Boolean.valueOf(value).booleanValue());
+                }
+                else if ("null-value".equals(name)) { //NOI18N
+                    jdoField.setNullValueTreatment(
+                        NullValueTreatment.toNullValueTreatment(value));
+                }
+                else if ("default-fetch-group".equals(name)) { //NOI18N
+                    jdoField.setDefaultFetchGroup(
+                        Boolean.valueOf(value).booleanValue());
+                }
+                else if ("embedded".equals(name)) { //NOI18N
+                    jdoField.setEmbedded(
+                        Boolean.valueOf(value).booleanValue());
+                }
+                else {
+                    SAXException e = new SAXException(
+                        msg.msg("EXC_UnknownAttribute", "<field>", //NOI18N
+                                name, value)); 
+                    if (trace)
+                        logger.trace("Throwing exception in " + //NOI18N
+                                     "JDOHandlerImpl.start_field:", e); //NOI18N
+                    throw e;
+                }
+            }
+        }
+        catch (ModelException ex) {
+            SAXException e = 
+                new SAXException(msg.msg("EXC_ModelException"), ex); //NOI18N
+            if (trace)
+                logger.trace("Throwing exception in " + //NOI18N
+                             "JDOHandlerImpl.start_field:", e); //NOI18N
+            throw e;
+        }
+        
+        // push current JDOField on context stack
+        context.push(jdoField);
+    }
+    
+    /**
+     * 
+     */
+    public void end_field()  
+    {
+        if (skipXMLElements)
+            return;
+        if (logger.isTraceEnabled()) 
+            logger.trace("  </field>"); //NOI18N
+        // remove JDOField from context stack
+        context.pop();
+    }
+    
+    /**
+     * 
+     */
+    public void start_collection(final Attributes meta)  
+        throws SAXException 
+    {
+        if (skipXMLElements)
+            return;
+        
+        boolean trace = logger.isTraceEnabled();
+        if (trace)
+            logger.trace("  <collection>"); //NOI18N
+        JDOCollection jdoCollection = null;
+        try {
+            // get the current JDOField from context stack
+            JDOField jdoField = (JDOField)context.peek();
+            jdoCollection = jdoField.createJDOCollection();
+            for (int i = 0; i < meta.getLength(); i++ ) {
+                String name = meta.getLocalName(i);
+                String value = meta.getValue(i);
+                if (trace)
+                    logger.trace("    " + name + " = " + value); //NOI18N
+                if ("element-type".equals(name)) { //NOI18N
+                    jdoCollection.setElementTypeName(value);
+                }
+                else if ("embedded-element".equals(name)) { //NOI18N
+                    jdoCollection.setEmbeddedElement(
+                        Boolean.valueOf(value).booleanValue());
+                }
+                else {
+                    SAXException e = new SAXException(
+                        msg.msg("EXC_UnknownAttribute", "<collection>", //NOI18N
+                                name, value)); 
+                    if (trace)
+                        logger.trace("Throwing exception in " + //NOI18N
+                                     "JDOHandlerImpl.start_collection:", e); //NOI18N
+                    throw e;
+                }
+            }
+        }
+        catch (ModelException ex) {
+            SAXException e = 
+                new SAXException(msg.msg("EXC_ModelException"), ex); //NOI18N
+            if (trace)
+                logger.trace("Throwing exception in " + //NOI18N
+                             "JDOHandlerImpl.start_collection:", e); //NOI18N
+            throw e;
+        }
+        
+        // push current JDOCollection on context stack
+        context.push(jdoCollection);
+    }
+    
+    /**
+     * 
+     */
+    public void end_collection()  
+    {
+        if (skipXMLElements) 
+            return;
+        if (logger.isTraceEnabled()) 
+            logger.trace("  </collection>"); //NOI18N
+        // remove JDOCollection from context stack
+        context.pop();
+    }
+    
+    /**
+     * 
+     */
+    public void start_array(final Attributes meta) 
+        throws SAXException 
+    {
+        if (skipXMLElements)
+            return;
+
+        boolean trace = logger.isTraceEnabled();
+        if (trace)
+            logger.trace("  <array>"); //NOI18N
+        JDOArray jdoArray = null;
+        try {
+            // get the current JDOField from context stack
+            JDOField jdoField = (JDOField)context.peek();
+            jdoArray = jdoField.createJDOArray();
+            for (int i = 0; i < meta.getLength(); i++ ) {
+                String name = meta.getLocalName(i);
+                String value = meta.getValue(i);
+                if (trace)
+                    logger.trace("    " + name + " = " + value); //NOI18N
+                if ("embedded-element".equals(name)) { //NOI18N
+                    jdoArray.setEmbeddedElement(
+                        Boolean.valueOf(value).booleanValue());
+                }
+                else {
+                    SAXException e = new SAXException(
+                        msg.msg("EXC_UnknownAttribute", "<array>", //NOI18N
+                                name, value)); 
+                    if (trace)
+                        logger.trace("Throwing exception in " + //NOI18N
+                                     "JDOHandlerImpl.start_array:", e); //NOI18N
+                    throw e;
+                }
+            }
+        }
+        catch (ModelException ex) {
+            SAXException e = 
+                new SAXException(msg.msg("EXC_ModelException"), ex); //NOI18N
+            if (trace)
+                logger.trace("Throwing exception in " + //NOI18N
+                             "JDOHandlerImpl.start_array:", e); //NOI18N
+            throw e;
+        }
+        
+        // push current JDOArray on context stack
+        context.push(jdoArray);
+    }
+    
+    /**
+     * 
+     */
+    public void end_array() 
+    {
+        if (skipXMLElements)
+            return;
+        if (logger.isTraceEnabled()) 
+            logger.trace("  </array>"); //NOI18N
+        // remove JDOArray from context stack
+        context.pop();
+    }
+    
+    /**
+     * 
+     */
+    public void start_map(final Attributes meta) 
+        throws SAXException 
+    {
+        if (skipXMLElements)
+            return;
+        boolean trace = logger.isTraceEnabled();
+        if (trace)
+            logger.trace("  <map>"); //NOI18N
+        JDOMap jdoMap = null;
+        try {
+            // get the current JDOField from context stack
+            JDOField jdoField = (JDOField)context.peek();
+            jdoMap = jdoField.createJDOMap();
+            for (int i = 0; i < meta.getLength(); i++ ) {
+                String name = meta.getLocalName(i);
+                String value = meta.getValue(i);
+                if (trace)
+                    logger.trace("    " + name + " = " + value); //NOI18N
+                if ("key-type".equals(name)) { //NOI18N
+                    jdoMap.setKeyTypeName(value);
+                }
+                else if ("embedded-key".equals(name)) { //NOI18N
+                    jdoMap.setEmbeddedKey(
+                        Boolean.valueOf(value).booleanValue());
+                }
+                else if ("value-type".equals(name)) { //NOI18N
+                    jdoMap.setValueTypeName(value);
+                }
+                else if ("embedded-value".equals(name)) { //NOI18N
+                    jdoMap.setEmbeddedValue(
+                        Boolean.valueOf(value).booleanValue());
+                }
+                else {
+                    SAXException e = new SAXException(
+                        msg.msg("EXC_UnknownAttribute", "<map>", //NOI18N
+                                name, value)); 
+                    if (trace)
+                        logger.trace("Throwing exception in " + //NOI18N
+                                     "JDOHandlerImpl.start_map:", e); //NOI18N
+                    throw e;
+                }
+            }
+        }
+        catch (ModelException ex) {
+            SAXException e = 
+                new SAXException(msg.msg("EXC_ModelException"), ex); //NOI18N
+            if (trace)
+                logger.trace("Throwing exception in " + //NOI18N
+                             "JDOHandlerImpl.start_map:", e); //NOI18N
+            throw e;
+        }
+        
+        // push current JDOMap on context stack
+        context.push(jdoMap);
+    }
+    
+    /**
+     * 
+     */
+    public void end_map()  
+    {
+        if (skipXMLElements)
+            return;
+        if (logger.isTraceEnabled()) 
+            logger.trace("  </map>"); //NOI18N
+        // remove JDOMap from context stack
+        context.pop();
+    }
+    
+    /**
+     * 
+     */
+    public void start_extension(final Attributes meta) 
+        throws SAXException 
+    {
+        if (skipXMLElements)
+            return;
+        boolean trace = logger.isTraceEnabled();
+
+        if (trace)
+            logger.trace("  <extension>"); //NOI18N
+        JDOExtension jdoExtension = null;
+        try {
+            // get the current JDOElement from context stack
+            JDOElement jdoElement = (JDOElement)context.peek();
+            jdoExtension = jdoElement.createJDOExtension();
+            for ( int i = 0; i < meta.getLength(); i++ ) {
+                String name = meta.getLocalName(i);
+                String value = meta.getValue(i);
+                
+                if (trace)
+                    logger.trace("    " + name + " = " + value); //NOI18N
+                if ("vendor-name".equals(name)) { //NOI18N
+                    jdoExtension.setVendorName(value);
+                }
+                else if ("key".equals(name)) { //NOI18N
+                    jdoExtension.setKey(value);
+                }
+                else if ("value".equals(name)) { //NOI18N
+                    jdoExtension.setValue(value);
+                }
+                else {
+                    SAXException e = new SAXException(
+                        msg.msg("EXC_UnknownAttribute", "<extension>", //NOI18N
+                                name, value));
+                    if (trace)
+                        logger.trace("Throwing exception in " + //NOI18N
+                                     "JDOHandlerImpl.start_extension:", e); //NOI18N
+                    throw e;
+                }
+            }
+        }
+        catch (ModelException ex) {
+            SAXException e = 
+                new SAXException(msg.msg("EXC_ModelException"), ex); //NOI18N
+            if (trace)
+                logger.trace("Throwing exception in " + //NOI18N
+                             "JDOHandlerImpl.start_extension:", e); //NOI18N
+            throw e;
+        }
+    }
+    
+    /**
+     * 
+     */
+    public void end_extension()  
+    {
+        if (skipXMLElements)
+            return;
+        if (logger.isTraceEnabled()) 
+            logger.trace("  </extension>"); //NOI18N
+        // start did not push anything => do nothing
+    }
+    
+    /**
+     *
+     */
+    public Collection handledJDOClasses()
+    {
+        return handledJDOClasses;
+    }
+
+}

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java Sun May 22 10:44:19 2005
@@ -0,0 +1,312 @@
+/*
+ * 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.
+ */
+
+/*
+ * File:           JDOParser.java
+ * Date:           July 3, 2001  2:16 PM
+ *
+ * @author  michael
+ * @version generated by FFJ XML module
+ */
+package org.apache.jdo.impl.model.jdo.xml;
+
+import java.io.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.jdo.model.jdo.JDOModel;
+import org.apache.jdo.util.I18NHelper;
+import org.xml.sax.*;
+import org.xml.sax.helpers.*;
+
+/**
+ * The class reads XML documents according to specified DTD and
+ * translates all related events into JDOHandler events.
+ * <p>Usage sample:
+ * <pre>
+ *    JDOParser parser = new JDOParser(...);
+ *    parser.parse(new InputSource("..."));
+ * </pre>
+ * <p><b>Warning:</b> the class is machine generated. DO NOT MODIFY</p>
+ */
+public class JDOParser 
+    implements ContentHandler {
+    
+    /** I18N support. */
+    private static final I18NHelper msg = I18NHelper.getInstance(
+        "org.apache.jdo.impl.model.jdo.Bundle", JDOParser.class.getClassLoader()); //NOI18N
+
+    private StringBuffer buffer;
+    
+    private JDOHandler handler;
+    
+    private java.util.Stack context;
+    
+    public JDOParser(final JDOHandler handler) 
+    {
+        this.handler = handler;
+        buffer = new StringBuffer(111);
+        context = new java.util.Stack();
+    }
+    
+    public void setDocumentLocator(Locator locator) 
+    {
+    }
+    
+    public void startDocument() throws SAXException 
+    {
+    }
+    
+    public void endDocument() throws SAXException 
+    {
+    }
+    
+    public void startElement(String ns, String name, String qname, Attributes attrs) 
+        throws SAXException 
+    {
+        dispatch(true);
+        context.push(new Object[] {qname, new org.xml.sax.helpers.AttributesImpl(attrs)});
+        
+        if ("package".equals(name)) { //NOI18N
+            handler.start_package(attrs);
+        } else if ("jdo".equals(name)) { //NOI18N
+            handler.start_jdo(attrs);
+        } else if ("class".equals(name)) { //NOI18N
+            handler.start_class(attrs);
+        } else if ("map".equals(name)) { //NOI18N
+            handler.start_map(attrs);
+        } else if ("field".equals(name)) { //NOI18N
+            handler.start_field(attrs);
+        } else if ("collection".equals(name)) { //NOI18N
+            handler.start_collection(attrs);
+        } else if ("extension".equals(name)) { //NOI18N
+            handler.start_extension(attrs);
+        } else if ("array".equals(name)) { //NOI18N
+            handler.start_array(attrs);
+        }
+    }
+    
+    public void endElement(String ns, String name, String qname) 
+        throws SAXException 
+    {
+        dispatch(false);
+        context.pop();
+        if ("package".equals(name)) { //NOI18N
+            handler.end_package();
+        } else if ("jdo".equals(name)) { //NOI18N
+            handler.end_jdo();
+        } else if ("class".equals(name)) { //NOI18N
+            handler.end_class();
+        } else if ("map".equals(name)) { //NOI18N
+            handler.end_map();
+        } else if ("field".equals(name)) { //NOI18N
+            handler.end_field();
+        } else if ("collection".equals(name)) { //NOI18N
+            handler.end_collection();
+        } else if ("extension".equals(name)) { //NOI18N
+            handler.end_extension();
+        } else if ("array".equals(name)) { //NOI18N
+            handler.end_array();
+        }
+    }
+    
+    public void characters(char[] chars, int start, int len) 
+        throws SAXException 
+    {
+        buffer.append(chars, start, len);
+    }
+    
+    public void ignorableWhitespace(char[] chars, int start, int len) 
+        throws SAXException 
+    {
+    }
+    
+    public void processingInstruction(String target, String data) 
+        throws SAXException 
+    {
+    }
+    
+    public void startPrefixMapping(final String prefix, final String uri) 
+        throws SAXException 
+    {
+    }
+    
+    public void endPrefixMapping(final String prefix) 
+        throws SAXException 
+    {
+    }
+    
+    public void skippedEntity(String name) 
+        throws SAXException 
+    {
+    }
+    
+    private void dispatch(final boolean fireOnlyIfMixed) 
+        throws SAXException 
+    {
+        if (fireOnlyIfMixed && buffer.length() == 0)
+            return; //skip it
+        
+        Object[] ctx = (Object[]) context.peek();
+        String here = (String) ctx[0];
+        Attributes attrs = (Attributes) ctx[1];
+        buffer.delete(0, buffer.length());
+    }
+    
+    /**
+     * The recognizer entry method taking an InputSource.
+     * @param input InputSource to be parsed.
+     * @throws java.io.IOException on I/O error.
+     * @throws SAXException propagated exception thrown by a DocumentHandler.
+     * @throws javax.xml.parsers.ParserConfigurationException a parser 
+     * satisfining requested configuration can not be created.
+     * @throws javax.xml.parsers.FactoryConfigurationError if the implementation 
+     * can not be instantiated.
+     */
+    public void parse(final InputSource input) 
+        throws SAXException, ParserConfigurationException, IOException 
+    {
+        parse(input, this);
+    }
+    
+    /**
+     * The recognizer entry method taking a URL.
+     * @param url URL source to be parsed.
+     * @throws java.io.IOException on I/O error.
+     * @throws SAXException propagated exception thrown by a DocumentHandler.
+     * @throws javax.xml.parsers.ParserConfigurationException a parser 
+     * satisfining requested configuration can not be created.
+     * @throws javax.xml.parsers.FactoryConfigurationError if the implementation 
+     * can not be instantiated.
+     */
+    public void parse(final java.net.URL url) 
+        throws SAXException, ParserConfigurationException, IOException 
+    {
+        parse(new InputSource(url.toExternalForm()), this);
+    }
+    
+    /**
+     * The recognizer entry method taking an Inputsource.
+     * @param input InputSource to be parsed.
+     * @throws java.io.IOException on I/O error.
+     * @throws SAXException propagated exception thrown by a DocumentHandler.
+     * @throws javax.xml.parsers.ParserConfigurationException a parser 
+     * satisfining requested configuration can not be created.
+     * @throws javax.xml.parsers.FactoryConfigurationError if the implementation 
+     * can not be instantiated.
+     */
+    public static void parse(final InputSource input, final JDOHandler handler) 
+        throws SAXException, ParserConfigurationException, IOException 
+    {
+        parse(input, new JDOParser(handler));
+    }
+    
+    /**
+     * The recognizer entry method taking a URL.
+     * @param url URL source to be parsed.
+     * @throws java.io.IOException on I/O error.
+     * @throws SAXException propagated exception thrown by a DocumentHandler.
+     * @throws javax.xml.parsers.ParserConfigurationException a parser 
+     * satisfining requested configuration can not be created.
+     * @throws javax.xml.parsers.FactoryConfigurationError if the implementation 
+     * can not be instantiated.
+     */
+    public static void parse(final java.net.URL url, final JDOHandler handler) 
+        throws SAXException, ParserConfigurationException, IOException 
+    {
+        parse(new InputSource(url.toExternalForm()), handler);
+    }
+    
+    private static void parse(final InputSource input, final JDOParser recognizer) 
+        throws SAXException, ParserConfigurationException, IOException 
+    {
+        SAXParserFactory factory = SAXParserFactory.newInstance();
+        factory.setValidating(true);
+        factory.setNamespaceAware(true);
+        XMLReader parser = factory.newSAXParser().getXMLReader();
+        parser.setEntityResolver(new JDOEntityResolver());
+        parser.setContentHandler(recognizer);
+        parser.setErrorHandler(recognizer.getDefaultErrorHandler());
+        parser.parse(input);
+    }
+    
+    private ErrorHandler getDefaultErrorHandler() 
+    {
+        return new ErrorHandler() {
+            public void error(SAXParseException ex) 
+                throws SAXException  {
+                if (context.isEmpty()) 
+                    System.err.println("Missing DOCTYPE."); //NOI18N
+                throw ex;
+            }
+            
+            public void fatalError(SAXParseException ex) 
+                throws SAXException {
+                throw ex;
+            }
+            
+            public void warning(SAXParseException ex) 
+                throws SAXException {
+                // ignore
+            }
+        };
+    }
+    
+    /**
+     * Implementation of EntityResolver interface to check the jdo.dtd location
+     **/
+    private static class JDOEntityResolver 
+        implements EntityResolver 
+    {
+        private static final String RECOGNIZED_PUBLIC_ID = 
+            "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 1.0//EN";
+        private static final String RECOGNIZED_SYSTEM_ID = 
+            "file:/javax/jdo/jdo.dtd";
+
+        public InputSource resolveEntity(String publicId, String systemId)
+            throws SAXException, IOException 
+        {
+            // check for recognized ids
+            if (((publicId != null) && RECOGNIZED_PUBLIC_ID.equals(publicId)) ||
+                ((publicId == null) && (systemId != null) && 
+                 RECOGNIZED_SYSTEM_ID.equals(systemId))) {
+                // Substitute the dtd with the one from javax.jdo.jdo.dtd,
+                // but only if the publicId is equal to RECOGNIZED_PUBLIC_ID
+                // or there is no publicID and the systemID is equal to
+                // RECOGNIZED_SYSTEM_ID. 
+                    InputStream stream = (InputStream) AccessController.doPrivileged (
+                        new PrivilegedAction () {
+                            public Object run () {
+                            return getClass().getClassLoader().
+                                getResourceAsStream("javax/jdo/jdo.dtd"); //NOI18N
+                            }
+                         }
+                     );
+                    if (stream == null) {
+                        throw new RuntimeException(
+                            msg.msg("EXC_MissingJDODTD", //NOI18N
+                                publicId, systemId)); 
+                    }
+                return new InputSource(new InputStreamReader(stream));
+            }
+            return null;
+        }
+    }
+}
+
+

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/Bundle.properties?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/Bundle.properties (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/Bundle.properties Sun May 22 10:44:19 2005
@@ -0,0 +1,33 @@
+#
+# 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.
+
+# This file should conform to netbeans standards
+# (http://www.netbeans.org/i18n)
+
+# resource bundle for the messages
+# key consists of: <PREFIX_><description>
+# <PREFIX_> - any valid prefix like MSG_, EXC_, etc.
+# <description> - short description started with the upper case letter and used
+# upper case to represent each next word.
+
+# ResourceBundle properties file for model
+
+MSG_OffendingObject=OffendingObject:
+MSG_CauseThrowable=CauseThrowable:
+MSG_CauseThrowableStackTrace=CauseThrowableStackTrace:
+
+# General validation messages
+# Validation warning prefix (prepended to some of the messages below)
+MSG_ValidationWarning=Warning: 

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/ModelException.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/ModelException.java?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/ModelException.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/ModelException.java Sun May 22 10:44:19 2005
@@ -0,0 +1,190 @@
+/*
+ * 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;
+
+import org.apache.jdo.util.I18NHelper;
+
+/**
+ * This exception indicates a Model problem. It is the root for all
+ * checked model exceptions.
+ *
+ * @author Michael Bouschen
+ * @since JDO 1.0.1
+ */
+public class ModelException 
+    extends Exception
+{
+    /** The throwable that caused this model exception to be thrown. */
+    private Throwable cause;
+    
+    /** Flag indicating whether printStackTrace is being executed. */
+    private boolean inPrintStackTrace = false;
+
+    /** I18N support */
+    private static I18NHelper msg = 
+        I18NHelper.getInstance(ModelException.class);
+
+    /**
+     * Creates new <code>ModelException</code> without detail message.
+     */
+    public ModelException() 
+    {
+    }
+    
+    /**
+     * Constructs a <code>ModelException</code> with the specified detail
+     * message.
+     * @param message the detail message.
+     */
+    public ModelException(String message)
+    {
+        super(message);
+    }
+
+    /** 
+     * Constructs a new <code>ModelException</code> with the specified 
+     * detail message and cause.
+     * @param message the detail message.
+     * @param cause the cause (which is saved for later retrieval by the
+     * {@link #getCause()} method). (A null value is permitted, and
+     * indicates that the cause is nonexistent or unknown.) 
+     */
+    public ModelException(String message, Throwable cause) 
+    {
+        super(message);
+        this.cause = cause;
+    }
+
+    /** 
+     * Returns the cause of this throwable or null if the cause is
+     * nonexistent or unknown. (The cause is the throwable that caused this 
+     * throwable to get thrown.) 
+     * @return the cause of this throwable or null if the cause is
+     * nonexistent or unknown. 
+     */
+    public synchronized Throwable getCause() 
+    {
+        // super.printStackTrace calls getCause to handle the cause. 
+        // Returning null prevents the superclass from handling the cause;
+        // instead the local implementation of printStackTrace should
+        // handle the cause. Otherwise, the cause is printed twice.
+        return inPrintStackTrace ? null : cause;
+    }
+
+    /**
+     * Initializes the cause of this throwable to the specified value. (The
+     * cause is the throwable that caused this throwable to get thrown.) 
+     * @param cause the cause (which is saved for later retrieval by the
+     * {@link #getCause()} method). (A null value is permitted, and
+     * indicates that the cause is nonexistent or unknown.)
+     * @return a reference to this <code>ModelException</code> instance.
+     */
+    public Throwable initCause(Throwable cause)
+    {
+        this.cause = cause;
+        return this;
+    }
+    
+	/**
+     * Returns the error message string of this throwable object.
+     * @return the error message string of this <code>ModelException</code>
+     * object if it was created with an error message string, the error 
+     * message of the cause if it was not created a message but the cause
+     * has a message, or <code>null</code> if neither has an error message. 
+     */
+	public String getMessage()
+	{
+		String message = super.getMessage();
+		if ((message == null) || (message.length() == 0)) {
+            // Get the message of the cause Throwable, if this
+            // ModelException does not have a message
+            if (cause != null)
+                message	= cause.getMessage();
+		}
+		return message;
+	}
+
+    /** 
+     * The <code>String</code> representation includes the name of the class,
+     * the descriptive comment (if any),
+     * and the <code>String</code> representation of the cause (if any).
+     * @return the <code>String</code>.
+     */
+    public synchronized String toString() 
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append(super.toString());
+        // Do not include cause information, if called by printStackTrace: 
+        // the stacktrace will include the cause anyway.
+        if ((cause != null) && !inPrintStackTrace) {
+            sb.append("\n");  //NOI18N
+            sb.append(msg.msg("MSG_CauseThrowable")); //NOI18N
+            sb.append("\n");  //NOI18N
+            sb.append(cause.toString()); //NOI18N
+        }
+        return sb.toString();
+    }
+  
+    /**
+     * Prints this <code>ModelException</code> and its backtrace to the 
+     * standard error output.
+     * Print cause Throwable's stack trace as well.
+     */
+    public void printStackTrace()
+    {
+        printStackTrace(System.err);
+    }
+
+    /**
+     * Prints this <code>ModelException</code> and its backtrace to the 
+     * specified print stream.
+     * Print cause Throwable's stack trace as well.
+     * @param s <code>PrintStream</code> to use for output
+     */
+    public synchronized void printStackTrace(java.io.PrintStream s) 
+    { 
+        synchronized (s) {
+            inPrintStackTrace = true;
+            super.printStackTrace(s);
+            if (cause != null) {
+                s.println(msg.msg("MSG_CauseThrowableStackTrace")); //NOI18N
+                cause.printStackTrace(s);
+            }
+            inPrintStackTrace = false;
+        }
+    }
+    
+    /**
+     * Prints this <code>ModelException</code> and its backtrace to the specified
+     * print writer.
+     * Print cause Throwable' stack trace as well.
+     * @param s <code>PrintWriter</code> to use for output
+     */
+    public synchronized void printStackTrace(java.io.PrintWriter s) 
+    { 
+        synchronized (s) {
+            inPrintStackTrace = true;
+            super.printStackTrace(s);
+            if (cause != null) {
+                s.println(msg.msg("MSG_CauseThrowableStackTrace")); //NOI18N
+                cause.printStackTrace(s);
+            }
+            inPrintStackTrace = false;
+        }
+    }
+    
+}

Added: incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/ModelFatalException.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/ModelFatalException.java?rev=171348&view=auto
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/ModelFatalException.java (added)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/model/ModelFatalException.java Sun May 22 10:44:19 2005
@@ -0,0 +1,191 @@
+/*
+ * 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;
+
+import org.apache.jdo.util.I18NHelper;
+
+/**
+ * This exception indicates a fatal Model problem. Note this is an
+ * unchecked exception.
+ *
+ * @author Michael Bouschen
+ * @since JDO 1.0.1
+ */
+public class ModelFatalException 
+    extends RuntimeException
+{
+    /** The throwable that caused this model exception to be thrown. */
+    private Throwable cause;
+    
+    /** Flag indicating whether printStackTrace is being executed. */
+    private boolean inPrintStackTrace = false;
+
+    /** I18N support */
+    private static I18NHelper msg = 
+        I18NHelper.getInstance(ModelFatalException.class);
+
+    /**
+     * Creates new <code>ModelFatalException</code> without detail
+     * message. 
+     */
+    public ModelFatalException() 
+    {
+    }
+    
+    /**
+     * Constructs a <code>ModelFatalException</code> with the specified
+     * detail message.
+     * @param message the detail message.
+     */
+    public ModelFatalException(String message)
+    {
+        super(message);
+    }
+
+    /** 
+     * Constructs a new <code>ModelFatalException</code> with the specified 
+     * detail message and cause Exception.
+     * @param message the detail message.
+     * @param cause the cause (which is saved for later retrieval by the
+     * {@link #getCause()} method). (A null value is permitted, and
+     * indicates that the cause is nonexistent or unknown.) 
+     */
+    public ModelFatalException(String message, Throwable cause) 
+    {
+        super(message);
+        this.cause = cause;
+    }
+
+    /** 
+     * Returns the cause of this throwable or null if the cause is
+     * nonexistent or unknown. (The cause is the throwable that caused this 
+     * throwable to get thrown.) 
+     * @return the cause of this throwable or null if the cause is
+     * nonexistent or unknown. 
+     */
+    public Throwable getCause() 
+    {
+        // super.printStackTrace calls getCause to handle the cause. 
+        // Returning null prevents the superclass from handling the cause;
+        // instead the local implementation of printStackTrace should
+        // handle the cause. Otherwise, the cause is printed twice.
+        return inPrintStackTrace ? null : cause;
+    }
+
+    /**
+     * Initializes the cause of this throwable to the specified value. (The
+     * cause is the throwable that caused this throwable to get thrown.) 
+     * @param cause the cause (which is saved for later retrieval by the
+     * {@link #getCause()} method). (A null value is permitted, and
+     * indicates that the cause is nonexistent or unknown.)
+     * @return a reference to this <code>ModelFatalException</code> instance.
+     */
+    public Throwable initCause(Throwable cause)
+    {
+        this.cause = cause;
+        return this;
+    }
+    
+	/**
+     * Returns the error message string of this throwable object.
+     * @return the error message string of this <code>ModelException</code>
+     * object if it was created with an error message string, the error 
+     * message of the cause if it was not created a message but the cause
+     * has a message, or <code>null</code> if neither has an error message. 
+     */
+	public String getMessage()
+	{
+		String message = super.getMessage();
+		if ((message == null) || (message.length() == 0)) {
+            // Get the message of the cause Throwable, if this
+            // ModelException does not have a message
+            if (cause != null)
+                message	= cause.getMessage();
+		}
+		return message;
+	}
+
+    /** 
+     * The <code>String</code> representation includes the name of the class,
+     * the descriptive comment (if any),
+     * and the <code>String</code> representation of the cause (if any).
+     * @return the <code>String</code>.
+     */
+    public synchronized String toString() 
+    {
+        StringBuffer sb = new StringBuffer();
+        sb.append(super.toString());
+        // Do not include cause information, if called by printStackTrace: 
+        // the stacktrace will include the cause anyway.
+        if ((cause != null) && !inPrintStackTrace) {
+            sb.append("\n");  //NOI18N
+            sb.append(msg.msg("MSG_CauseThrowable")); //NOI18N
+            sb.append("\n");  //NOI18N
+            sb.append(cause.toString()); //NOI18N
+        }
+        return sb.toString();
+    }
+  
+    /**
+     * Prints this <code>ModelFatalException</code> and its backtrace to the 
+     * standard error output.
+     * Print cause Throwable's stack trace as well.
+     */
+    public void printStackTrace()
+    {
+        printStackTrace(System.err);
+    }
+
+    /**
+     * Prints this <code>ModelFatalException</code> and its backtrace to the 
+     * specified print stream.
+     * Print cause Throwable's stack trace as well.
+     * @param s <code>PrintStream</code> to use for output
+     */
+    public synchronized void printStackTrace(java.io.PrintStream s) 
+    { 
+        synchronized (s) {
+            inPrintStackTrace = true;
+            super.printStackTrace(s);
+            if (cause != null) {
+                s.println(msg.msg("MSG_CauseThrowableStackTrace")); //NOI18N
+                cause.printStackTrace(s);
+            }
+            inPrintStackTrace = false;
+        }
+    }
+    
+    /**
+     * Prints this <code>ModelFatalException</code> and its backtrace to the specified
+     * print writer.
+     * Print cause Throwable' stack trace as well.
+     * @param s <code>PrintWriter</code> to use for output
+     */
+    public void printStackTrace(java.io.PrintWriter s) 
+    { 
+        synchronized (s) {
+            inPrintStackTrace = true;
+            super.printStackTrace(s);
+            if (cause != null) {
+                s.println(msg.msg("MSG_CauseThrowableStackTrace")); //NOI18N
+                cause.printStackTrace(s);
+            }
+            inPrintStackTrace = false;
+        }
+    }
+    
+}



Mime
View raw message