db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r158176 [40/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/
Date Sat, 19 Mar 2005 01:06:07 GMT
Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,629 @@
+/*
+ * 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", 
+        JDOHandlerImpl.class.getClassLoader()); //NOI18N
+
+    /** 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 = isXMLProcessed(jdoClass);
+            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' xmlProcessed flag
+            setXMLProcessed(jdoClass);
+        }
+    }
+    
+    /**
+     * 
+     */
+    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;
+    }
+
+    /** */
+    private boolean isXMLProcessed(JDOClass jdoClass) {
+        if (jdoClass instanceof JDOClassImplDynamic)
+            return ((JDOClassImplDynamic)jdoClass).isXMLProcessed();
+        return false;
+    }
+
+    /** */
+    private void setXMLProcessed(JDOClass jdoClass) {
+        if (jdoClass instanceof JDOClassImplDynamic)
+            ((JDOClassImplDynamic)jdoClass).setXMLProcessed();
+    }
+    
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/JDOParser.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,315 @@
+/*
+ * 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.*;
+
+import javax.jdo.JDOFatalInternalException;
+
+
+/**
+ * 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 JDOFatalInternalException(
+                            msg.msg("EXC_MissingJDODTD", //NOI18N
+                                publicId, systemId)); 
+                    }
+                return new InputSource(new InputStreamReader(stream));
+            }
+            return null;
+        }
+    }
+}
+
+

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/XMLExists.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/XMLExists.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/XMLExists.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/jdo/xml/XMLExists.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,290 @@
+/*
+ * 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.xml;
+
+import java.util.*;
+
+import org.apache.jdo.impl.model.java.AbstractJavaModelFactory;
+import org.apache.jdo.impl.model.java.runtime.RuntimeJavaModel;
+import org.apache.jdo.impl.model.jdo.caching.JDOModelFactoryImplCaching;
+import org.apache.jdo.impl.model.jdo.util.PrintSupport;
+import org.apache.jdo.model.ModelException;
+import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.model.jdo.JDOClass;
+import org.apache.jdo.model.jdo.JDOModel;
+import org.apache.jdo.model.jdo.JDOModelFactory;
+
+/**
+ * This class allows to check whether there is JDO metadata for a class with 
+ * a given class name. There must be a class file (enhanced or not enhanced)
+ * available in the classpath of the caller.
+ * <p>
+ * Usage: XMLExists &lt;options&gt; &lt;arguments&gt;...
+ * <br>
+ * Options:
+ * <br>
+ * <code>&nbsp;&nbsp;-h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>
+ * print usage message
+ * <br>
+ * <code>&nbsp;&nbsp;-v&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>
+ * print verbose messages and JDO metadata
+ * <br>
+ * <code>&nbsp;&nbsp;-q&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>
+ * do not print any output; just set the exit code
+ * <br>
+ * <code>&nbsp;&nbsp;-xml&nbsp;&nbsp;&nbsp;&nbsp;</code>
+ * expected to find JDO XML metadata for the specified class(es)
+ * <br>
+ * <code>&nbsp;&nbsp;-noxml&nbsp;&nbsp;</code>
+ * expected to find no JDO XML metadata for the specified class(es)
+ * <br>
+ * Arguments:
+ * <br>
+ * <code>&nbsp;&nbsp;&lt;classname&gt;&nbsp;</code>
+ * the fully qualified name of a class to be checked
+ * <p>
+ * The following sample call checks whether there is JDO XML metadata for the 
+ * classes Emplyoe and Department from the com.xyz.hr package and dumps the 
+ * JDOClass instances:
+ * <br>
+ * <code>&nbsp;&nbsp;java org.apache.jdo.impl.model.jdo.util.XMLExists -v 
+ * com.xyz.hr.Employee com.xyz.hr.Department</code>
+ * <p>
+ * Method main will exit the JVM with an exit code 1 if the test fails for 
+ * at least one class. Please note, the class dumps the JDOClass if the 
+ * outputLevel is set to VERBOSE (e.g. by setting the -v option). This JDOClass 
+ * info does NOT include runtime metadata, even if the class file is enhanced.
+ * 
+ * @author Michael Bouschen
+ */
+public class XMLExists
+{
+    /** 
+     * Flag indicating whether the classes to be checked is expected to have 
+     * JDO XML metadata or not.
+     */
+    private boolean xmlExpected;
+    
+    /** Print verbose messages. */
+    public static final int VERBOSE = 1;
+
+    /** Normal output. */
+    public static final int NORMAL = 0;
+
+    /** No messages, just set the exit code. */
+    public static final int QUIET = -1;
+       
+    /** Output level.*/
+    private int outputLevel = NORMAL;
+
+    /** 
+     * The main method checks all classes specified as argument.
+     * It will exit the JVM with an exit code 1 if the test fails for 
+     * at least one class. 
+     * @param args arguments which are options followed by class names.
+     */
+    public static void main(String[] args)
+    {
+        final XMLExists test = new XMLExists();
+        final List classNames = test.processArgs(args);
+        if (!test.run(classNames))
+            System.exit(1);
+    }
+
+    /** 
+     * No arg constructor. The flags default to
+     * <ul>
+     * <li> <code>xmlExpected == true</code>
+     * <li> <code>outputLevel == NORMAL</code>
+     * </ul>
+     */
+    public XMLExists()
+    {
+        this(true, NORMAL);
+    }
+
+    /** Constructor taking checkXMLExists and outputLevel. */
+    public XMLExists(boolean xmlExpected, int outputLevel)
+    {
+        this.xmlExpected = xmlExpected;
+        this.outputLevel = outputLevel;
+    }
+
+    /**
+     * This method checks all classes from the specified list of class names.
+     * It uses the current classLoader to load the classes. The method returns 
+     * <code>false</code> if there is at least one class that fails on checking.
+     * @param classNames list of classes to be checked
+     * @return <code>true</code> if all classes are ok;
+     * <code>false</code> otherwise.
+     */
+    public boolean run(List classNames)
+    {
+        ClassLoader classLoader = getClass().getClassLoader();
+        XMLExistsJDOModelFactory factory = new XMLExistsJDOModelFactory();
+        JavaModel javaModel = factory.getJavaModel(classLoader);
+        JDOModel jdoModel = javaModel.getJDOModel();
+        boolean ok = true;
+        for (Iterator i = classNames.iterator(); i.hasNext(); ) {
+            final String className = (String)i.next();
+            try {
+                checkClass(className, classLoader, jdoModel, xmlExpected);
+                if ((outputLevel == NORMAL) && xmlExpected)
+                    System.out.println(
+                        "Found XML metadata for class " + className); //NOI18N
+                                       
+                else if ((outputLevel == NORMAL) && !xmlExpected)
+                    System.out.println(
+                        "No MXL metadata for class " + className); //NOI18N
+            }
+            catch (Exception ex) {
+                if (outputLevel > QUIET) {
+                    System.err.println(ex);
+                    ex.printStackTrace();
+                }
+                ok = false;
+            }
+        }
+        return ok;
+    }
+    
+    /** 
+     * The method checks the class with the specified class name.
+     * It first loads the class using the specified class loader.
+     * If the flag xmlExpected is <code>true</code> it expects to get a non-null
+     * JDOClass instance. If the flag xmlExpected is <code>false</code> it 
+     * expects to get a null JDOClass instance. 
+     * <p>
+     * The method indicates any failure by throwing an exception. 
+     * It dumps the JDOClass if the output level is VERBOSE.
+     * @param className the name of the class to be checked
+     * @param classLoader the class loader to be used to load the class
+     * @param jdoModel JDOModel for type info
+     * @param xmlExpected flag whether the class to be checked is expected to 
+     * have JDO XML metadata or not.
+     */
+    public void checkClass(String className, 
+                           ClassLoader classLoader,
+                           JDOModel jdoModel, 
+                           boolean xmlExpected)
+        throws Exception
+    {
+        Class clazz = Class.forName(className, true, classLoader);
+        if (outputLevel == VERBOSE)
+            System.out.println("Found " + clazz); //NOI18N
+        JDOClass jdoClass = jdoModel.getJDOClass(className);
+        if (xmlExpected && (jdoClass == null)) {
+            throw new Exception(
+                "Missing JDO XML metadata for class " + //NOI18N
+                className);
+        }
+        if (!xmlExpected && (jdoClass != null)) {
+            throw new Exception(
+                "Found JDO XML metadata for class " + className); //NOI18N
+        }
+        if ((outputLevel == VERBOSE) && (jdoClass != null)) {
+            PrintSupport.printJDOClass(jdoClass);
+        }
+    }
+    
+    // ==== Comand line processing helper method =====
+    
+    /**
+     * Helper method to do command line argument processing.
+     * @param args the arguments passed to main.
+     * @return the list of classes to be checked.
+     */
+    protected List processArgs(String[] args)
+    { 
+        List classNames = new ArrayList();
+        for (int i = 0; i < args.length; i++) {
+            final String arg = args[i];
+            if (arg.equals("-h")) { //NOI18N
+                usage();
+            }
+            else if (arg.equals("-v")) { //NOI18N
+                outputLevel = VERBOSE;
+            }
+            else if (arg.equals("-q")) { //NOI18N
+                outputLevel = QUIET;
+            }
+            else if (arg.equals("-xml")) { //NOI18N
+                xmlExpected = true;
+            }
+            else if (arg.equals("-noxml")) { //NOI18N
+                xmlExpected = false;
+            }
+            else if (arg.length() > 0 && arg.charAt(0) == '-') {
+                System.err.println("Unrecognized option:" + arg); //NOI18N
+                usage();
+            }
+            else if (arg.length() == 0) {
+                System.err.println("Ignoring empty command line argument."); //NOI18N
+            }
+            else {
+                classNames.add(arg);
+            }
+        }
+        return classNames;
+    }
+    
+    /**
+     * Print a usage message to System.err.
+     */
+    public void usage() 
+    {
+        System.err.println("Usage: main <options> <arguments>..."); //NOI18N
+        System.err.println("Options:"); //NOI18N
+        System.err.println("  -h      print usage message"); //NOI18N
+        System.err.println("  -v      print verbose messages and JDO metadata"); //NOI18N
+        System.err.println("  -q      do not print any messages; just set the exit code"); //NOI18N
+        System.err.println("  -xml    expected to find JDO XML metadata for the specified class(es)"); //NOI18N
+        System.err.println("  -noxml  expected to find no JDO XML metadata for the specified class(es)"); //NOI18N
+        System.err.println("Arguments:"); //NOI18N
+        System.err.println("  <classname>   the fully qualified name of a class to be checked"); //NOI18N
+    }
+    
+    /**
+     * JavaModelFactory implementation. 
+     * We cannot use the RuntimeJavaModelFactory, because it registers
+     * a JDOImplHelper event listener to populate enhancer generated
+     * metadata into the model. Since XMLExists checks whether JDO
+     * metadata is present from a .jdo we do not want to the enhancer
+     * generated metadata.
+     */
+    private static class XMLExistsJDOModelFactory 
+        extends AbstractJavaModelFactory {
+
+        /** */
+        protected XMLExistsJDOModelFactory() {}
+
+        /** */
+        public JavaModel createJavaModel(Object key) throws ModelException {
+            if ((key == null) || (!(key instanceof ClassLoader)))
+                throw new ModelException("Invalid key " + key + 
+                                         " expected ClassLoader");
+            ClassLoader classLoader = (ClassLoader)key;
+            return new RuntimeJavaModel(classLoader); 
+        }
+        
+        /** */
+        protected JDOModelFactory getJDOModelFactory() {
+            return JDOModelFactoryImplCaching.getInstance();
+        }
+    }
+    
+}

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/Bundle.properties?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/Bundle.properties (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/Bundle.properties Fri Mar 18 17:02:29 2005
@@ -0,0 +1,102 @@
+#
+# 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.
+
+# XXX TBD: this message is not used:
+notsupported=Operation is not supported in this release.
+
+
+#
+# CacheManagerImpl
+#
+EXC_MetaDataNotAvailable=Metadata for the owning Class is not available.
+EXC_NonTransactional=Instance is not transactional.
+EXC_ObjectExistsInCache=Object exists. Instance with the same primary key is already in the PersistenceManager cache.
+EXC_NotOID=Given object is not a valid OID.
+# NOI18N
+EXC_ObjectIdExistsInCache=ObjectId {0} already exists in this PersistenceManager cache.
+# NOI18N
+EXC_ObjectIdNotExistsInCache=ObjectId {0} does not exist in this PersistenceManager cache.
+
+#
+# PersistenceManagerFactoryImpl
+#
+EXC_NotConfigurable=This instance of PersistenceManagerFactory is not configurable.
+EXC_IntegerInInvalidFormat=Integer found in invalid format: should not happen!
+EXC_IncompleteConfiguration=One of ConnectionURL, ConnectionFactory, or ConnectionFactoryName must be set before using this PersistenceManagerFactory.
+EXC_WrongUsernamePassword=Cannot use multiple combinations of username/password in the same transaction.
+# NOI18N
+EXC_WrongJTATransaction=This instance of javax.transaction.Transaction is registered with another PersistenceManager.
+EXC_PersistenceManagerFactoryClosed=This operation cannot be performed because this PersistenceManagerFactory is closed.
+EXC_ActivePersistenceManager=This PersistenceManagerFactory cannot be closed while a PersistenceManager has an active transaction.
+EXC_CannotAddShutdownHook=A SecurityException was thrown when trying \
+to add a JVM shudown hook. In order to register a shutdown hook, \
+you must grant java.lang.RuntimePermission("shutdownHooks") to the \
+codeBases containing the JDO Reference Implementation (jdo-ri.jar).
+
+#
+# PersistenceManagerImpl
+#
+EXC_CannotGetRuntimeJavaModelFactory=A SecurityException was thrown when trying \
+to get the singleton RuntimeJavaModelFactory instance. In order to get runtime \
+metadata, you must grant javax.jdo.spi.JDOPermission("getMetadata") to the \
+codeBases containing the JDO Reference Implementation (jdo.jar and jdo-ri.jar).
+EXC_ActiveTransaction=Cannot close PersistenceManager while transaction is still active.
+EXC_WrongSCOType=Tracked SCO instances of type {0} are not supported.
+EXC_CannotConstructSCO=Exception during construction of type {0}.
+EXC_IllegalArguments=Wrong arguments for construction of type {0}.
+EXC_PersistenceManagerClosed=PersistenceManager was closed.
+EXC_TransactionNotActive=Transaction is not active.
+EXC_NotPersistenceCapable=Class {0} not PersistenceCapable. The class of the instance does not implement PersistenceCapable. Check to see that the class has been enhanced and that the class path is correct (the unenhanced version of the class should not be in the class path).
+EXC_CollectionType=Parameter is of a Collection type; use method {0}All(Collection).
+EXC_ArrayType=Parameter is of an array type; use method {0}All(Object[]).
+EXC_TransientInstance=Instance of class {0} is not persistent.
+EXC_AnotherPersistenceManager=Object owned by another PersistenceManager.
+EXC_ClassNotPersistenceCapable=Class given to getExtent, {0},  does not implement javax.jdo.spi.PersistenceCapable
+EXC_FailedToProcessAll=Failed to process all objects.
+EXC_CannotFindSM=Could not find a StateManager for the given PersistenceCapable of class {0}.
+# NOI18N
+EXC_NotNullJTATransaction=Attempt to replace not null javax.transaction.Transaction.
+EXC_UnsupportedQueryLanguage=Unsupported query language ''{0}''
+EXC_CannotFindPCClassForObjectIdClass=Cannot find persistence-capable class for ObjectId class ''{0}''
+
+#
+# TransactionImpl
+#
+EXC_CannotChangeType=Cannot change transaction type during an active transaction.
+EXC_CannotSetFlag=Cannot change flag value during commit or rollback processing.
+EXC_CannotSetFlagIfActive=Cannot change flag value if transaction is active.
+EXC_SynchronizationNotNull=A Synchronization object has already been set for this transaction.
+EXC_ErrorBegin=Transaction has already begun.
+EXC_TransactionRolledback=Transaction already rolled back or rollback in progress.
+EXC_TransactionCommitting=Transaction has already started to commit.
+EXC_MarkedRolledback=This transaction was marked rollback-only.
+EXC_WrongStateCommit=Transaction in wrong state to commit.
+EXC_WrongStateRollback=Transaction in wrong state to rollback.
+EXC_InvalidStatus=Invalid Transaction.{0}(). This transaction status is not {1} (status = {2}).
+EXC_WrongMgdOperation=Operation {0} is not allowed in managed environment.
+EXC_WrongNonMgdOperation=Operation {0} is not allowed in non-managed environment.
+EXC_NontransactionalRead=This operation requires that a transaction be active or the NontransactionalRead flag be true.
+# NOI18N
+EXC_ErrorRegister=Cannot register this instance with JTA Synchronization.
+

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/CacheManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/CacheManagerImpl.java?view=auto&rev=158176
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/CacheManagerImpl.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/CacheManagerImpl.java Fri Mar 18 17:02:29 2005
@@ -0,0 +1,630 @@
+/*
+ * 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.
+ */
+
+/*
+ * CacheManagerImpl.java
+ *
+ * Created on December 1, 2000
+ */
+
+package org.apache.jdo.impl.pm;
+
+import java.util.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Constructor;
+import java.lang.ref.WeakReference;
+
+import javax.jdo.*;
+import javax.jdo.spi.*;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.jdo.impl.state.StateManagerFactory;
+import org.apache.jdo.pm.PersistenceManagerInternal;
+import org.apache.jdo.state.StateManagerInternal;
+import org.apache.jdo.store.StoreManager;
+import org.apache.jdo.util.I18NHelper;
+import org.apache.jdo.util.WeakValueHashMap;
+
+/*
+ * This is the cache manager that is responsible for operation of
+ * all types of caches (weak, transactional, flushed, transient)
+ * associated with the referenced instance of a PersistenceManager.
+ *
+ * @author Marina Vatkina
+ */
+class CacheManagerImpl {
+
+    // Reference to the corresponding PersistenceManagerImpl.
+    PersistenceManagerImpl pm = null;
+
+    /**
+     * Collection of Persistent instances created and/or updated
+     * in this Transaction
+     */
+    private Collection _txCache = Collections.synchronizedSet(new HashSet());
+
+    /**
+     * Collection of Transient-transactional instances registered
+     * with this Transaction
+     */
+    private Collection _transientCache = new Vector();
+
+    /**
+     * Collection of Persistent instances that will require state
+     * change at the transaction completion
+     */
+    private ArrayList _flushedCache = new ArrayList();
+
+    /**
+     * Collection of StateManager instances that represent Persistent
+     * instances that had been made newly persistent in the current
+     * transaction.
+     */
+    private ArrayList _newInstances = new ArrayList();
+
+    /** 
+     * Weak Hashtable of Persistent instances accessed by this PersistenceManager
+     */
+    private WeakValueHashMap _weakCache = new WeakValueHashMap();
+
+    /**
+     * Logger instance
+     */
+    private static final Log logger = LogFactory.getFactory().getInstance(
+        "org.apache.jdo.impl.pm"); // NOI18N
+
+    /**
+     * I18N message handler
+     */
+    private final static I18NHelper msg = 
+        I18NHelper.getInstance(CacheManagerImpl.class);
+
+    /**
+     * Constructs new instnstance of CacheManagerImpl
+     * 
+     * @param pm calling instance of PersistenceManagerImpl
+     */
+    CacheManagerImpl(PersistenceManagerImpl pm) {
+        this.pm = pm;
+    }
+
+    /**
+     * close the CacheManagerImpl
+     */
+    protected void close() {
+        // RELEASE THE CACHE...
+        // Nothing should be in _txCache and/or _flushedCache because
+        // PersistenceManager verified that transaction is not
+        // active. _transientCache can have transient transactional
+        // instances, but it is OK to clear them. 
+       _weakCache.clear();
+       _txCache.clear();
+       _flushedCache.clear();
+       _transientCache.clear();
+    }
+
+    
+
+    /** This method locates a persistent instance in the cache of instances
+     * managed by this PersistenceManager.
+     *   
+     * <P>If the validate flag is true: This method verifies that there
+     * is an instance in the data store with the same oid, constructs an
+     * instance, and returns it.  If there is no transaction active, then
+     * a hollow instance or persistent non-transactional instance is returned.
+     * If there is a transaction active, then
+     * a persistent clean instance is returned.
+     * <P>If the validate flag is false: If there is not already an instance
+     * in the cache with the same oid, then an instance is constructed and
+     * returned.  If the instance does not exist
+     * in the data store, then this method will
+     * not fail.  However, a request to access fields of the instance will
+     * throw an exception.
+     * @return the PersistenceCapable instance with the specified
+     * ObjectId
+     * @param oid an ObjectId
+     * @param validate if the existence of the instance is to be validated
+     */
+    protected Object getObjectById (Object oid, boolean validate) {
+        if (debugging())
+            debug ("getObjectById"); // NOI18N
+
+        StateManagerInternal sm = this.getStateManager(oid, validate);
+        return ((StateManagerInternal)sm).getObject();
+    }
+
+    /**
+     * Returns StateManager instance associated with this instance of ObjectId
+     * Creates a Hollow instance of a PersistenceCapable object, if it cannot be 
+     * found in the cache
+     * @param oid an ObjectId
+     * @param pcClass Class of a Hollow instance to be created.
+     * @return the StateManagerInternal 
+     */
+    protected StateManagerInternal getStateManager (Object oid, Class pcClass) {
+        if (debugging())
+            debug ("getStateManager " + oid + " for: " + pcClass.getName()); // NOI18N
+
+        StateManagerInternal sm = null;
+        // Check weak cache to find SM:
+        synchronized (_weakCache) {
+            // Need to keep a reference to the value in the cache as it is a weak
+            // cache and the value might be removed otherwise.
+            Object o = _weakCache.get(oid);
+            if (o == null) {
+                // Nothing found
+                sm  = createNewSM(null, oid, pcClass);
+            } else {
+                // Prepare Hollow instance if its class type was not
+                // known before. 
+                sm = (StateManagerInternal)o;
+                sm.setPCClass(pcClass);
+            }
+        }
+
+        if (debugging())
+            debug ("return from getStateManager: " + sm); // NOI18N
+
+        return sm;
+    }
+
+    /**
+    * The ObjectId returned by this method represents the JDO identity of
+    * the instance.  The ObjectId is a copy (clone) of the internal state
+    * of the instance, and changing it does not affect the JDO identity of
+    * the instance.
+    * Delegates actual execution to the internal method.
+    * @param pc the PersistenceCapable instance
+    * @param transactional true if transactional Id is requested
+    * @return the ObjectId of the instance
+    */
+    protected Object getExternalObjectId (PersistenceCapable pc,
+                                          boolean transactional) {
+        StateManagerInternal sm = pm.findStateManager(pc);
+
+        Object oid = null;
+        if (_weakCache.containsValue(sm)) {
+            if (transactional)
+                oid = sm.getTransactionalObjectId(pc);
+            else
+                oid = sm.getExternalObjectId();
+        }
+
+        return oid;
+    }
+
+    /** Make the transient instance persistent in this PersistenceManager.
+     * This method must be called in an active transaction.
+     * The PersistenceManager assigns an ObjectId to the instance and
+     * transitions it to persistent-new.
+     * The instance will be managed in the Extent associated with its Class.
+     * The instance will be put into the data store at commit.
+     * @param pc a transient instance of a Class that implements
+     * PersistenceCapable
+     */
+    protected void makePersistent (PersistenceCapable pc) {
+
+        StateManagerInternal sm = pm.findStateManager(pc);
+        if (sm == null) {
+            sm = StateManagerFactory.newInstance(pc, pm);
+        }
+
+        sm.makePersistent();
+    }
+
+    /** Make the transient or persistent instance transactional in
+     * this PersistenceManager.
+     * @see javax.jdo.PersistenceManager#makeTransactional(Object pc)
+     */
+    protected void makeTransactional(PersistenceCapable pc) {
+        StateManagerInternal sm = pm.findStateManager(pc);
+        if (sm == null) {
+            sm = StateManagerFactory.newInstance(pc, pm);
+        }
+        sm.makeTransactional();
+    }
+
+
+    /** Make the transient or persistent instance transactional in
+     * this PersistenceManager.
+     * @see javax.jdo.PersistenceManager#makeNontransactional(Object pc)
+     */
+    protected void makeNontransactional(PersistenceCapable pc) {
+        StateManagerInternal sm = pm.findStateManager(pc);
+        if (sm == null) {
+            throw new JDOUserException(msg.msg(
+                    "EXC_NonTransactional")); // NOI18N
+        }
+        sm.makeNontransactional();
+    }
+
+
+    /** Make the persistent instance transient in this PersistenceManager.
+     * @see javax.jdo.PersistenceManager#makeTransient(Object pc)
+     */
+    protected void makeTransient(PersistenceCapable pc) {
+        StateManagerInternal sm = pm.findStateManager(pc);
+        if (sm != null) {
+            sm.makeTransient();
+        }
+    }
+
+    /** Make persistent instance hollow in this PersistenceManager.
+     * @see javax.jdo.PersistenceManager#evict(Object pc)
+     */
+    protected void evict(PersistenceCapable pc) {
+        StateManagerInternal sm = pm.findStateManager(pc);
+        if (sm != null) {
+            sm.evictInstance();
+        }
+    }
+
+    /** Make all non-dirty persistent instances in the cache hollow in 
+     * this PersistenceManager.
+     * @see javax.jdo.PersistenceManager#evictAll()
+     */
+    protected void evictAll() {
+        StateManagerInternal sm = null;
+
+        Iterator it = _weakCache.entrySet().iterator();
+        while (it.hasNext()) {
+            sm = (StateManagerInternal) ((Map.Entry)it.next()).getValue();
+            sm.evictInstance();
+        }
+    }
+
+    /** Retrieve Hollow persistent instance in this PersistenceManager.
+     * @see javax.jdo.PersistenceManager#retrieve(Object pc)
+     */
+    protected void retrieve(PersistenceCapable pc) {
+        StateManagerInternal sm = pm.findStateManager(pc);
+        if (sm != null) {
+            sm.retrieve();
+        }
+    }
+
+    /** Refresh dirty persistent instance in this PersistenceManager.
+     * @see javax.jdo.PersistenceManager#refresh(Object pc)
+     */
+    protected void refresh(PersistenceCapable pc) {
+        StateManagerInternal sm = pm.findStateManager(pc);
+        if (sm != null) {
+            sm.refreshInstance();
+        }
+    }
+
+    /** Refresh dirty persistent instances in the transactional cache 
+     * of this PersistenceManager. Called in an active transaction.
+     * @see javax.jdo.PersistenceManager#refreshAll()
+     */
+    protected void refreshAllTransactional() {
+        StateManagerInternal sm = null;
+
+        Iterator it = _txCache.iterator();
+        while(it.hasNext()) {
+            sm = (StateManagerInternal)it.next();
+            sm.refreshInstance();
+        }
+    }
+
+    /** Refresh  nontransactional instances in the weak cache
+     * of this PersistenceManager. Called outside an active transaction.
+     * @see javax.jdo.PersistenceManager#refreshAll()
+     */
+    protected void refreshAllNontransactional() {
+        StateManagerInternal sm = null;
+
+        Iterator it = _weakCache.entrySet().iterator();
+        while (it.hasNext()) {
+            sm = (StateManagerInternal) ((Map.Entry)it.next()).getValue();
+            sm.refreshInstance();
+        }
+    }
+
+    /**
+     * Register transient instance in the transient cache
+     */
+    protected void registerTransient(StateManagerInternal sm) {
+        Iterator it = _transientCache.iterator();
+        while(it.hasNext()) {
+            Object o = ((WeakReference)it.next()).get();
+            if ((StateManagerInternal)o == sm) {
+                // The same SM is found - nothing to do.
+                return;
+            }
+        }
+        _transientCache.add(new WeakReference(sm));
+    }
+
+    /**
+     * Register persistent instance in the transactional cache
+     */
+    protected void register(StateManagerInternal sm, Object oid, 
+            boolean transactional, boolean throwDuplicateException) {
+        if (oid == null) {
+            oid = sm.getInternalObjectId();
+        }
+
+        //register in both caches for transactional instances only
+
+        if (! _weakCache.containsKey(oid)) {
+            deregisterTransient(sm);
+            _weakCache.put(oid, sm);  
+
+        } else if (throwDuplicateException) {
+            throw new JDOUserException(msg.msg(
+                "EXC_ObjectExistsInCache")); // NOI18N
+        }
+
+        if (pm.currentTransaction().isActive() && transactional) {
+            // Register in both caches for convenience.
+            if (! _flushedCache.contains(sm)) {
+                _flushedCache.add(sm); 
+            }
+            if (! _txCache.contains(sm)) {
+                _txCache.add(sm); 
+                if (sm.isNew()) 
+                    _newInstances.add(sm.getObject());
+            }
+        }
+
+        if (!transactional) {
+            // Remove from transactional caches if instance became
+            // nontransactional
+            _txCache.remove(sm); 
+            _flushedCache.remove(sm);
+        }
+    }
+
+    /**
+     * Remove transient instance from the transient cache
+     */
+    protected void deregisterTransient(Object sm) {
+        Iterator it = _transientCache.iterator();
+        while(it.hasNext()) {
+            WeakReference wr = (WeakReference)it.next();
+            if ((StateManagerInternal)wr.get() == sm) {
+                _transientCache.remove(wr);
+                break;
+            }
+        }
+    }
+
+    /**
+     * Remove persistent instance from all caches
+     */
+    protected void deregister(Object oid) {
+        if (oid != null) {
+            //deregister the instance from all the caches
+            Object o = _weakCache.remove(oid);
+
+            // No need to do anything outside an active transaction.
+            if (pm.currentTransaction().isActive()) {
+                _txCache.remove(o);
+                _flushedCache.remove(o);
+            }
+        }
+    }
+
+    /**  
+     * @see PersistenceManagerInternal#replaceObjectId(Object oldId,
+     * Object newId)
+     */  
+    protected void replaceObjectId(Object oldId, Object newId) {
+        if (debugging())
+            debug ("replaceObjectId"); // NOI18N
+
+        synchronized(_weakCache) {
+            if (_weakCache.containsKey(newId)) {
+                throw new JDOFatalInternalException(msg.msg(
+                    "EXC_ObjectIdExistsInCache", newId)); // NOI18N
+            }
+            Object o = _weakCache.remove(oldId);
+            if (o == null) {
+                throw new JDOFatalInternalException(msg.msg(
+                    "EXC_ObjectIdNotExistsInCache", newId)); // NOI18N
+            }
+            _weakCache.put(newId, o);
+        }
+    }
+
+    /**  
+     * @see PersistenceManagerInternal#markAsFlushed(StateManagerInternal sm)
+     */  
+    protected void markAsFlushed(StateManagerInternal sm) { 
+        _txCache.remove(sm);
+    }
+
+    /**
+     * Called by Transaction#commit(), Transaction#beforeCompletion(), or
+     * Transaction#internalFlush().
+     * Processes instances for the reachability algorithm, then calls
+     * StoreManager to iterate over transactional cache and to call flush() 
+     * for each StateManager in it.
+     */
+    protected void flushInstances() {
+        StateManagerInternal sm = null;
+
+        Object[] e = _txCache.toArray();
+        boolean commit = pm.insideCommit();
+
+        for (int i = 0; i < e.length; i++) {
+            sm = (StateManagerInternal)e[i];
+
+            //
+            // NOTE: handleRelationships has the side-effect of adding
+            // more objects to the transaction cache.
+            //
+            sm.handleReachability(commit);
+        }
+
+        StoreManager srm = pm.getStoreManager();
+        Iterator it = _txCache.iterator();
+
+        srm.flush(it, pm);
+
+        _txCache.clear();
+    }
+
+    /**
+     * Called by Transaction commit() or rollback()
+     * cleans up transactional cache
+     * @param    abort 
+     */
+    protected void afterCompletion(boolean abort) {
+        boolean retainValues = pm.currentTransaction().getRetainValues();
+        boolean restoreValues = pm.currentTransaction().getRestoreValues();
+
+        // Need to process transient instances also
+        Iterator it = _transientCache.iterator();
+        while(it.hasNext()) {
+            Object o = ((WeakReference)it.next()).get();
+
+            if (o == null) { 
+                // It has been GC'd and should be removed from _transientCache. 
+                it.remove(); 
+            } else {
+                _flushedCache.add(o);
+            }
+        }
+
+        int len = _flushedCache.size();
+        for ( int i = 0; i < len; i++) {
+            StateManagerInternal sm = (StateManagerInternal)_flushedCache.get(i);
+            sm.afterCompletion(abort, retainValues, restoreValues);
+        }
+
+        // Now clean the flushed cache
+        _flushedCache.clear();
+        _newInstances.clear();
+
+        // Just in case beforeCompletion failed or it was a rollback
+        _txCache.clear();
+    }
+
+    /**
+     * Returns a Collection of instances that has been made persistent
+     * or become persistent through persistence-by-reachability
+     * algorithm in this transaction. Called by the Extent.iterator.
+     * @see PersistenceManagerInternal#getInsertedInstances
+     * @return Collection of Persistent-New instances.
+     */
+    protected Collection getInsertedInstances() {
+        if (debugging())
+            debug("getInsertedInstances"); // NOI18N
+
+        return _newInstances;
+    }
+
+    /** --------------Private Methods--------------  */
+
+    /**
+     * Returns StateManager instance associated with this instance of ObjectId
+     * @see #getObjectById(Object oid, boolean validate)
+     * @param oid an ObjectId
+     * @param validate if the existence of the instance is to be validated
+     */
+    private StateManagerInternal getStateManager (Object oid, boolean validate) {
+
+        Object o = null;
+        StoreManager srm = pm.getStoreManager();
+        Class candidateClassType = srm.getPCClassForOid(oid, pm);
+        if (candidateClassType == null) {
+            // not found, report an error
+            throw new JDOUserException(msg.msg(
+                "EXC_NotOID"),// NOI18N
+                 oid);
+        }
+
+        Object internalOid = srm.getInternalObjectId(oid, pm);
+        if (debugging())
+            debug ("getStateManager internal oid: " + internalOid); // NOI18N
+
+        StateManagerInternal sm = null;
+
+        // Check weak cache to find SM:
+        synchronized (_weakCache) {
+            if((o = _weakCache.get(internalOid)) == null) {
+                // Nothing found
+                if (debugging())
+                    debug ("getStateManager oid not found."); // NOI18N
+
+                sm  = createNewSM(oid, internalOid, candidateClassType);
+                // Always reload from the DB to resolve actual classType
+                if (validate || !srm.hasActualPCClass(internalOid))
+                    sm.reload();
+                return sm;
+
+            } else  if (validate && !_flushedCache.contains(o)) {
+                // Found but NOT in the transactional cache. Reload.
+                if (debugging())
+                    debug ("getStateManager oid found - reload."); // NOI18N
+
+                sm = (StateManagerInternal)o;
+                sm.reload();
+                return sm;
+            }
+        }
+        return (StateManagerInternal)o;
+    }
+
+    /**
+     * Creates new StateManager instance associated with this instance
+     * of ObjectId.
+     * @see #getObjectById(Object oid, boolean validate)
+     * @param UserOid a user provided ObjectId
+     * @param internalOid an internal ObjectId
+     * @param candidateClassType super class of a Hollow instance to be created.
+     */
+    private StateManagerInternal createNewSM(Object UserOid, Object internalOid,
+                                                      Class candidateClassType) {
+        try {
+            return StateManagerFactory.newInstance(UserOid, internalOid, 
+                pm, candidateClassType);
+
+        } catch (JDOUserException e) {
+            throw e;
+            // XXX Possible jikes bug
+            //
+            // The following catch phrase causes jikes to complain (Caution:
+            // This try block cannot throw a "checked exception" (JLS section
+            // 14.7) that can be caught here. You may have intended to catch
+            // a RuntimeException instead of an Exception.)  But this try
+            // block is *not* here throwing any checked exceptions!  That's
+            // why I think it's a jikes bug (Sun's javac does not complain.)
+        } catch (Exception e) {
+            throw new JDOUserException(msg.msg("EXC_NotOID"), e, UserOid); // NOI18N
+        }
+    }
+
+    /**
+     * Tracing method
+     * @param msg String to display
+     */  
+    private void debug(String msg) {
+        logger.debug("In CacheManagerImpl " + msg); // NOI18N
+    }
+    /**
+     * Verifies if debugging is enabled.
+     * @return true if debugging is enabled.
+     */
+    private boolean debugging() {
+        return logger.isDebugEnabled();
+    }
+
+}



Mime
View raw message