db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r158175 [4/4] - in incubator/jdo/trunk/api11: ./ src/ src/dtd/ src/dtd/javax/ src/dtd/javax/jdo/ src/java/ src/java/javax/ src/java/javax/jdo/ src/java/javax/jdo/spi/ test/ test/java/ test/java/javax/ test/java/javax/jdo/ test/java/javax/jdo/pc/ test/java/javax/jdo/spi/ test/java/javax/jdo/util/ xdocs/
Date Sat, 19 Mar 2005 00:53:55 GMT
Added: incubator/jdo/trunk/api11/src/java/javax/jdo/spi/StateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/src/java/javax/jdo/spi/StateManager.java?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/src/java/javax/jdo/spi/StateManager.java (added)
+++ incubator/jdo/trunk/api11/src/java/javax/jdo/spi/StateManager.java Fri Mar 18 16:53:48 2005
@@ -0,0 +1,462 @@
+/*
+ * 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 javax.jdo.spi;
+
+import javax.jdo.PersistenceManager;
+
+/** This interface is the point of contact between managed instances of
+ * <code>PersistenceCapable</code> classes and the JDO implementation.  It contains
+ * the methods used by <code>PersistenceCapable</code> instances to delegate behavior to 
+ * the JDO implementation.
+ *<P>Each managed <code>PersistenceCapable</code> instance contains a reference to a
+ * <code>StateManager</code>.  A <code>StateManager</code> might manage one or multiple instances of
+ * <code>PersistenceCapable</code> instances, at the choice of the implementation.
+ *
+ * @author  Craig Russell
+ * @version 1.0
+ *
+ */
+public interface StateManager {
+    
+    /** The owning <code>StateManager</code> uses this method to supply the 
+     * value of the flags to the <code>PersistenceCapable</code> instance.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return the value of <code>jdoFlags</code> to be stored in the <code>PersistenceCapable</code> instance
+     */
+    byte replacingFlags(PersistenceCapable pc);
+
+    /** Replace the current value of <code>jdoStateManager</code>.
+     * <P>
+     * This method is called by the <code>PersistenceCapable</code> whenever
+     * <code>jdoReplaceStateManager</code> is called and there is already
+     * an owning <code>StateManager</code>.  This is a security precaution
+     * to ensure that the owning <code>StateManager</code> is the only
+     * source of any change to its reference in the <code>PersistenceCapable</code>.
+     * @return the new value for the <code>jdoStateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param sm the proposed new value for the <code>jdoStateManager</code>
+     */ 
+    StateManager replacingStateManager (PersistenceCapable pc, StateManager sm);
+    
+    /** Tests whether this object is dirty.
+     *
+     * Instances that have been modified, deleted, or newly 
+     * made persistent in the current transaction return <code>true</code>.
+     *
+     *<P>Transient nontransactional instances return <code>false</code>.
+     *<P>
+     * @see PersistenceCapable#jdoMakeDirty(String fieldName)
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> if this instance has been modified in the current transaction.
+     */
+    boolean isDirty(PersistenceCapable pc);
+
+    /** Tests whether this object is transactional.
+     *
+     * Instances that respect transaction boundaries return <code>true</code>.  These instances
+     * include transient instances made transactional as a result of being the
+     * target of a <code>makeTransactional</code> method call; newly made persistent or deleted
+     * persistent instances; persistent instances read in data store
+     * transactions; and persistent instances modified in optimistic transactions.
+     *
+     *<P>Transient nontransactional instances return <code>false</code>.
+     *<P>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> if this instance is transactional.
+     */
+    boolean isTransactional(PersistenceCapable pc);
+
+    /** Tests whether this object is persistent.
+     *
+     * Instances whose state is stored in the data store return <code>true</code>.
+     *
+     *<P>Transient instances return <code>false</code>.
+     *<P>
+     * @see PersistenceManager#makePersistent(Object pc)
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> if this instance is persistent.
+     */
+    boolean isPersistent(PersistenceCapable pc);
+
+    /** Tests whether this object has been newly made persistent.
+     *
+     * Instances that have been made persistent in the current transaction 
+     * return <code>true</code>.
+     *
+     *<P>Transient instances return <code>false</code>.
+     *<P>
+     * @see PersistenceManager#makePersistent(Object pc)
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> if this instance was made persistent
+     * in the current transaction.
+     */
+    boolean isNew(PersistenceCapable pc);
+
+    /** Tests whether this object has been deleted.
+     *
+     * Instances that have been deleted in the current transaction return <code>true</code>.
+     *
+     *<P>Transient instances return <code>false</code>.
+     *<P>
+     * @see PersistenceManager#deletePersistent(Object pc)
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return <code>true</code> if this instance was deleted
+     * in the current transaction.
+     */
+    boolean isDeleted(PersistenceCapable pc);
+    
+    /** Return the <code>PersistenceManager</code> that owns this instance.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return the <code>PersistenceManager</code> that owns this instance
+     */
+    PersistenceManager getPersistenceManager (PersistenceCapable pc);
+    
+    /** Mark the associated <code>PersistenceCapable</code> field dirty.
+     * <P>The <code>StateManager</code> will make a copy of the field
+     * so it can be restored if needed later, and then mark
+     * the field as modified in the current transaction.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param fieldName the name of the field
+     */    
+    void makeDirty (PersistenceCapable pc, String fieldName);
+    
+    /** Return the object representing the JDO identity 
+     * of the calling instance.  If the JDO identity is being changed in
+     * the current transaction, this method returns the identity as of
+     * the beginning of the transaction.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return the object representing the JDO identity of the calling instance
+     */    
+    Object getObjectId (PersistenceCapable pc);
+
+    /** Return the object representing the JDO identity 
+     * of the calling instance.  If the JDO identity is being changed in
+     * the current transaction, this method returns the current identity as
+     * changed in the transaction.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @return the object representing the JDO identity of the calling instance
+     */    
+    Object getTransactionalObjectId (PersistenceCapable pc);
+
+    /** Return <code>true</code> if the field is cached in the calling
+     * instance.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @return whether the field is cached in the calling instance
+     */    
+    boolean isLoaded (PersistenceCapable pc, int field);
+    
+    /** Guarantee that the serializable transactional and persistent fields
+     * are loaded into the instance.  This method is called by the generated
+     * <code>jdoPreSerialize</code> method prior to serialization of the
+     * instance.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     */    
+    void preSerialize (PersistenceCapable pc);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    boolean getBooleanField (PersistenceCapable pc, int field, boolean currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    char getCharField (PersistenceCapable pc, int field, char currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    byte getByteField (PersistenceCapable pc, int field, byte currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    short getShortField (PersistenceCapable pc, int field, short currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    int getIntField (PersistenceCapable pc, int field, int currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    long getLongField (PersistenceCapable pc, int field, long currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    float getFloatField (PersistenceCapable pc, int field, float currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    double getDoubleField (PersistenceCapable pc, int field, double currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    String getStringField (PersistenceCapable pc, int field, String currentValue);
+    
+    /** Return the value for the field.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     * @return the new value for the field
+     */    
+    Object getObjectField (PersistenceCapable pc, int field, Object currentValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setBooleanField (PersistenceCapable pc, int field, boolean currentValue, boolean newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setCharField (PersistenceCapable pc, int field, char currentValue, char newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setByteField (PersistenceCapable pc, int field, byte currentValue, byte newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setShortField (PersistenceCapable pc, int field, short currentValue, short newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setIntField (PersistenceCapable pc, int field, int currentValue, int newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setLongField (PersistenceCapable pc, int field, long currentValue, long newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setFloatField (PersistenceCapable pc, int field, float currentValue, float newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setDoubleField (PersistenceCapable pc, int field, double currentValue, double newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setStringField (PersistenceCapable pc, int field, String currentValue, String newValue);
+
+    /** Mark the field as modified by the user.
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @param currentValue the current value of the field
+     * @param newValue the proposed new value of the field */    
+    void setObjectField (PersistenceCapable pc, int field, Object currentValue, Object newValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedBooleanField (PersistenceCapable pc, int field, boolean currentValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedCharField (PersistenceCapable pc, int field, char currentValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedByteField (PersistenceCapable pc, int field, byte currentValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedShortField (PersistenceCapable pc, int field, short currentValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedIntField (PersistenceCapable pc, int field, int currentValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedLongField (PersistenceCapable pc, int field, long currentValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedFloatField (PersistenceCapable pc, int field, float currentValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedDoubleField (PersistenceCapable pc, int field, double currentValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedStringField (PersistenceCapable pc, int field, String currentValue);
+
+    /** The value of the field requested to be provided to the <code>StateManager</code>
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @param currentValue the current value of the field
+     */    
+    void providedObjectField (PersistenceCapable pc, int field, Object currentValue);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number
+     * @return the new value for the field
+     */    
+    boolean replacingBooleanField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    char replacingCharField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    byte replacingByteField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    short replacingShortField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    int replacingIntField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    long replacingLongField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    float replacingFloatField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    double replacingDoubleField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    String replacingStringField (PersistenceCapable pc, int field);
+
+    /** The replacing value of the field in the calling instance
+     * @param pc the calling <code>PersistenceCapable</code> instance
+     * @param field the field number 
+     * @return the new value for the field
+     */    
+    Object replacingObjectField (PersistenceCapable pc, int field);
+
+}
+

Added: incubator/jdo/trunk/api11/src/java/javax/jdo/spi/package.html
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/src/java/javax/jdo/spi/package.html?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/src/java/javax/jdo/spi/package.html (added)
+++ incubator/jdo/trunk/api11/src/java/javax/jdo/spi/package.html Fri Mar 18 16:53:48 2005
@@ -0,0 +1,47 @@
+<!--
+ 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>JDO Service Provider Interface package</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+
+<body bgcolor="#FFFFFF">
+<P>This package contains the interfaces and classes used by JDO implementations. 
+<P>JDO defines interfaces and classes to be used by application programmers 
+when using classes whose instances are to be stored in persistent storage 
+(persistence-capable classes), and specifies the contracts between 
+suppliers of persistence-capable classes and the 
+runtime environment (which is part of the JDO implementation).
+<P>The PersistenceCapable interface is implemented by all classes
+whose instances are to be made persistent.  The implementation might be
+done by a combination of techniques, as determined by the JDO vendor:
+<ul>
+<li>Pre-processing .java files
+<li>Post-processing .class files
+<li>Generating .java or .class files directly from an abstraction
+</ul
+<P>The StateManager interface is the implementation's contact point with
+the PersistenceCapable instances.  It defines methods that are called by 
+the PersistenceCapable instances to implement the required PersistenceCapable
+behavior for persistent and transactional instances.
+<P>The JDOPermission class is used to manage security controls on JDO implementations.
+<P>The RegisterClassEvent class and RegisterClassListener interface are used
+by JDO implementations that need access to metadata of PersistenceCapable classes.
+<P>The JDOImplHelper class contains helper methods for JDO implementations.
+</body>
+</html>

Added: incubator/jdo/trunk/api11/test/java/javax/jdo/JDOHelperTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/javax/jdo/JDOHelperTest.java?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/test/java/javax/jdo/JDOHelperTest.java (added)
+++ incubator/jdo/trunk/api11/test/java/javax/jdo/JDOHelperTest.java Fri Mar 18 16:53:48 2005
@@ -0,0 +1,142 @@
+/*
+ * 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 javax.jdo;
+
+import java.util.Properties;
+
+import javax.jdo.pc.PCPoint;
+import javax.jdo.util.AbstractTest;
+import javax.jdo.util.BatchTestRunner;
+
+/**
+ * Tests class javax.jdo.JDOHelper.
+ * <p>
+ * TBD: implementation of testMakeDirty, 
+ * TBD: testing interrogative methods for persistent instances
+ * TBD: getPMF for valid PMF class
+ */
+public class JDOHelperTest extends AbstractTest {
+    
+    /** */
+    public static void main(String args[]) {
+        BatchTestRunner.run(JDOHelperTest.class);
+    }
+
+    /** */
+    public void testGetPM() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.getPersistenceManager(p) != null) {
+            fail("JDOHelper.getPersistenceManager should return null pm for non-persistent instance");
+        }
+
+        // TBD: test for persistent instance
+    }
+
+    /** */
+    public void testMakeDirty() {
+        // TBD: test JDOHelper.makeDirty(pc, fieldName);
+    }
+
+    /** */
+    public void testGetObjectId() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.getObjectId(p) != null) {
+            fail("JDOHelper.getObjectId should return null ObjectId for non-persistent instance");
+        }
+
+        // TBD test JDOHelper.getObjectId(pc) for persistent instance
+    }
+
+    /** */
+    public void testGetTransactionObjectId() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.getObjectId(p) != null) {
+            fail("JDOHelper.getTransactionalObjectId should return null ObjectId for non-persistent instance");
+        }
+
+        // TBD test JDOHelper.getTransactionalObjectId(pc) for persistent instance
+    }
+
+    /** */
+    public void testIsDirty() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.isDirty(p)) {
+            fail("JDOHelper.isDirty should return false for non-persistent instance");
+        }
+
+        // TBD test JDOHelper.isDirty(pc) for persistent instance
+    }
+
+    /** */
+    public void testIsTransactional() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.isTransactional(p)) {
+            fail("JDOHelper.isTransactional should return false for non-persistent instance");
+        }
+
+        // TBD test JDOHelper.isTransactional(pc) for persistent instance
+    }
+
+    /** */
+    public void testIsPersistent() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.isPersistent(p)) {
+            fail("JDOHelper.isPersistent should return false for non-persistent instance");
+        }
+
+        // TBD test JDOHelper.isPersistent(pc) for persistent instance
+    }
+
+    /** */
+    public void testIsNew() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.isNew(p)) {
+            fail("JDOHelper.isNew should return false for non-persistent instance");
+        }
+
+        // TBD test JDOHelper.isNew(pc) for persistent instance
+    }
+
+
+    /** */
+    public void testIsDeleted() {
+        PCPoint p = new PCPoint(1, new Integer(1));
+        if (JDOHelper.isDeleted(p)) {
+            fail("JDOHelper.isDeleted should return false for non-persistent instance");
+        }
+
+        // TBD test JDOHelper.isDeleted(pc) for persistent instance
+    }
+
+    /** */
+    public void testGetPMF() {
+        // test missing property javax.jdo.PersistenceManagerFactoryClass
+        PersistenceManagerFactory pmf = null;
+        try {
+            pmf = JDOHelper.getPersistenceManagerFactory(new Properties());
+            fail("Missing property PersistenceManagerFactoryClass should result in JDOFatalUserException ");
+        }
+        catch (JDOFatalUserException ex) {
+            if (verbose)
+                println("Caught expected exception " + ex);
+        }
+
+        // TBD: valid PMF class
+    }
+
+}
+

Added: incubator/jdo/trunk/api11/test/java/javax/jdo/pc/PCPoint.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/javax/jdo/pc/PCPoint.java?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/test/java/javax/jdo/pc/PCPoint.java (added)
+++ incubator/jdo/trunk/api11/test/java/javax/jdo/pc/PCPoint.java Fri Mar 18 16:53:48 2005
@@ -0,0 +1,448 @@
+/*
+ * 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 javax.jdo.pc;
+
+import java.io.*;
+import java.util.*;
+import javax.jdo.PersistenceManager;
+import javax.jdo.spi.*;
+
+import javax.jdo.spi.PersistenceCapable;
+
+/**
+ * This is a hand-enhanced version of a simple class with two fields. The
+ * enhanced code assumes datastore identity.
+ *
+ * @author Michael Bouschen
+ */
+public class PCPoint 
+    implements PersistenceCapable
+{
+    public int x;
+    public Integer y;
+
+    // JDO generated fields
+    protected transient StateManager jdoStateManager;
+    protected transient byte jdoFlags;
+    private static final int jdoInheritedFieldCount = 0;
+    private static final String jdoFieldNames[] = { "x", "y" };
+    private static final Class jdoFieldTypes[]; 
+    private static final byte jdoFieldFlags[] = { 
+        (byte)(PersistenceCapable.CHECK_READ + PersistenceCapable.CHECK_WRITE + 
+               PersistenceCapable.SERIALIZABLE), 
+        (byte)(PersistenceCapable.CHECK_READ + PersistenceCapable.CHECK_WRITE + 
+               PersistenceCapable.SERIALIZABLE), 
+    }; 
+    private static final Class jdoPersistenceCapableSuperclass; 
+
+    static 
+    {
+        jdoFieldTypes = (new Class[] {
+            Integer.TYPE, sunjdo$classForName$("java.lang.Integer")
+        });
+        jdoPersistenceCapableSuperclass = null;
+        JDOImplHelper.registerClass(
+            sunjdo$classForName$("javax.jdo.pc.PCPoint"), 
+            jdoFieldNames, jdoFieldTypes, jdoFieldFlags, 
+            jdoPersistenceCapableSuperclass, new PCPoint());
+    }
+
+    /** JDO required no-args constructor. */
+    public PCPoint() { }
+
+    /** Constructor. */
+    public PCPoint(int x, Integer y) {
+        jdoSetx(this, x);
+        jdoSety(this, y);
+    }
+
+    /** */
+    public void setX(int x) {
+        jdoSetx(this, x);
+    }
+
+    /** */
+    public int getX() {
+        return jdoGetx(this);
+    }
+
+    /** */
+    public void setY(Integer y) {
+        jdoSety(this, y);
+    }
+
+    /** */
+    public Integer getY() {
+        return jdoGety(this);
+    }
+
+    /** */
+    public boolean equals(Object o) {
+        if (o == null || !(o instanceof PCPoint))
+            return false;
+        PCPoint other = (PCPoint)o;
+        if (jdoGetx(this) != jdoGetx(other))
+            return false;
+        if (jdoGety(this) == null)
+            return jdoGety(other) == null;
+        if (jdoGety(other) == null)
+            return jdoGety(this) == null;
+        else
+            return jdoGety(this).intValue() == jdoGety(other).intValue();
+    }
+
+    /** */
+    public int hashCode() {
+        int code = getX();
+        if (getY() != null) {
+            code += getY().intValue();
+        }
+        return code;
+    }
+    
+    /** */
+    public String toString() {
+        return "PCPoint(x: " + getX() + ", y: " + getY() + ")";
+    }
+    
+
+    // Generated methods in least-derived PersistenceCapable class
+
+    public final boolean jdoIsPersistent() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            return statemanager.isPersistent(this);
+        else
+            return false;
+    }
+
+    public final boolean jdoIsTransactional() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            return statemanager.isTransactional(this);
+        else
+            return false;
+    }
+
+    public final boolean jdoIsNew() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            return statemanager.isNew(this);
+        else
+            return false;
+    }
+
+    public final boolean jdoIsDirty() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            return statemanager.isDirty(this);
+        else
+            return false;
+    }
+
+    public final boolean jdoIsDeleted() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            return statemanager.isDeleted(this);
+        else
+            return false;
+    }
+
+    public final void jdoMakeDirty(String s) {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            statemanager.makeDirty(this, s);
+    }
+
+    public final PersistenceManager jdoGetPersistenceManager() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            return statemanager.getPersistenceManager(this);
+        else
+            return null;
+    }
+
+    public final Object jdoGetObjectId() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            return statemanager.getObjectId(this);
+        else
+            return null;
+    }
+
+    public final Object jdoGetTransactionalObjectId() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            return statemanager.getTransactionalObjectId(this);
+        else
+            return null;
+    }
+
+    public final synchronized void jdoReplaceStateManager(
+        StateManager statemanager) {
+        StateManager statemanager1 = jdoStateManager;
+        if (statemanager1 != null) {
+            jdoStateManager = statemanager1.replacingStateManager(
+                this, statemanager);
+            return;
+        } 
+        else {
+            JDOImplHelper.checkAuthorizedStateManager(statemanager);
+            jdoStateManager = statemanager;
+            jdoFlags = PersistenceCapable.LOAD_REQUIRED;
+            return;
+        }
+    }
+    
+    public final void jdoReplaceFlags() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            jdoFlags = statemanager.replacingFlags(this);
+    }
+
+    public final void jdoReplaceFields(int fields[]) {
+        if (fields == null)
+            throw new IllegalArgumentException("fields is null");
+        int i = fields.length;
+        for(int j = 0; j < i; j++)
+            jdoReplaceField(fields[j]);
+
+    }
+
+    public final void jdoProvideFields(int fields[]) {
+        if (fields == null)
+            throw new IllegalArgumentException("fields is null");
+        int i = fields.length;
+        for(int j = 0; j < i; j++)
+            jdoProvideField(fields[j]);
+
+    }
+
+    protected final void jdoPreSerialize() {
+        StateManager statemanager = jdoStateManager;
+        if (statemanager != null)
+            statemanager.preSerialize(this);
+    }
+
+    // Generated methods in PersistenceCapable root classes and all classes
+    // that declare objectid-class in xml metadata:
+
+    public void jdoCopyKeyFieldsToObjectId(
+        PersistenceCapable.ObjectIdFieldSupplier objectidfieldsupplier, 
+        Object obj) { }
+
+    public void jdoCopyKeyFieldsToObjectId(Object obj) {
+    }
+    
+    public void jdoCopyKeyFieldsFromObjectId(
+        PersistenceCapable.ObjectIdFieldConsumer objectidfieldconsumer, 
+        Object obj) { }
+
+    protected void jdoCopyKeyFieldsFromObjectId(Object obj) {
+    }
+
+    public Object jdoNewObjectIdInstance() {
+        return null;
+    }
+
+    public Object jdoNewObjectIdInstance(String s) {
+        return null;
+    }
+    
+    // Generated methods in all PersistenceCapable classes
+
+    public PersistenceCapable jdoNewInstance(StateManager statemanager) {
+        PCPoint pcpoint = new PCPoint();
+        pcpoint.jdoFlags = PersistenceCapable.LOAD_REQUIRED;
+        pcpoint.jdoStateManager = statemanager;
+        return pcpoint;
+    }
+
+    public PersistenceCapable jdoNewInstance(
+        StateManager statemanager, Object obj) {
+        PCPoint pcpoint = new PCPoint();
+        pcpoint.jdoCopyKeyFieldsFromObjectId(obj);
+        pcpoint.jdoFlags = PersistenceCapable.LOAD_REQUIRED;
+        pcpoint.jdoStateManager = statemanager;
+        return pcpoint;
+    }
+
+    protected static int jdoGetManagedFieldCount() {
+        return 2;
+    }
+
+     public static final int jdoGetx(PCPoint pcpoint) {
+        if (pcpoint.jdoFlags <= PersistenceCapable.READ_WRITE_OK)
+            return pcpoint.x;
+        StateManager statemanager = pcpoint.jdoStateManager;
+        if (statemanager == null)
+            return pcpoint.x;
+        if (statemanager.isLoaded(pcpoint, jdoInheritedFieldCount + 0))
+            return pcpoint.x;
+        else
+            return statemanager.getIntField(
+                pcpoint, jdoInheritedFieldCount + 0, pcpoint.x);
+    }
+
+    public static final Integer jdoGety(PCPoint pcpoint) {
+        if (pcpoint.jdoFlags <= PersistenceCapable.READ_WRITE_OK)
+            return pcpoint.y;
+        StateManager statemanager = pcpoint.jdoStateManager;
+        if (statemanager == null)
+            return pcpoint.y;
+        if (statemanager.isLoaded(pcpoint, jdoInheritedFieldCount + 1))
+            return pcpoint.y;
+        else
+            return (Integer)statemanager.getObjectField(
+                pcpoint, jdoInheritedFieldCount + 1, pcpoint.y);
+    }
+
+    public static final void jdoSetx(PCPoint pcpoint, int i) {
+        if (pcpoint.jdoFlags == PersistenceCapable.READ_WRITE_OK) {
+            pcpoint.x = i;
+            return;
+        }
+        StateManager statemanager = pcpoint.jdoStateManager;
+        if (statemanager == null) {
+            pcpoint.x = i;
+            return;
+        } 
+        else {
+            statemanager.setIntField(
+                pcpoint, jdoInheritedFieldCount + 0, pcpoint.x, i);
+            return;
+        }
+    }
+
+    public static final void jdoSety(PCPoint pcpoint, Integer integer) {
+        if (pcpoint.jdoFlags == PersistenceCapable.READ_WRITE_OK) {
+            pcpoint.y = integer;
+            return;
+        }
+        StateManager statemanager = pcpoint.jdoStateManager;
+        if (statemanager == null) {
+            pcpoint.y = integer;
+            return;
+        } 
+        else {
+            statemanager.setObjectField(pcpoint, jdoInheritedFieldCount + 1, pcpoint.y, integer);
+            return;
+        }
+    }
+
+    public void jdoReplaceField(int field) {
+        StateManager statemanager = jdoStateManager;
+        switch(field - jdoInheritedFieldCount) {
+        case 0: 
+            if (statemanager == null) {
+                throw new IllegalStateException("jdoStateManager is null");
+            } 
+            else {
+                x = statemanager.replacingIntField(this, field);
+                return;
+            }
+        case 1:
+            if (statemanager == null) {
+                throw new IllegalStateException("jdoStateManager is null");
+            } 
+            else {
+                y = (Integer)statemanager.replacingObjectField(this, field);
+                return;
+            }
+        }
+        throw new IllegalArgumentException("field number out of range");
+    }
+
+    public void jdoProvideField(int field) {
+        StateManager statemanager = jdoStateManager;
+        switch(field - jdoInheritedFieldCount) {
+        case 0:
+            if (statemanager == null) {
+                throw new IllegalStateException("jdoStateManager is null");
+            } 
+            else {
+                statemanager.providedIntField(this, field, x);
+                return;
+            }
+        case 1: 
+            if (statemanager == null) {
+                throw new IllegalStateException("jdoStateManager is null");
+            } 
+            else {
+                statemanager.providedObjectField(this, field, y);
+                return;
+            }
+        }
+        throw new IllegalArgumentException("field number out of range");
+    }
+
+    public void jdoCopyFields(Object obj, int fieldNumbers[]) {
+        if (jdoStateManager == null)
+            throw new IllegalStateException("jdoStateManager is null");
+        if (!(obj instanceof PCPoint))
+            throw new ClassCastException(obj.getClass().getName());
+        if (fieldNumbers == null)
+            throw new IllegalArgumentException("fieldNumber is null");
+        PCPoint pcpoint = (PCPoint)obj;
+        if (pcpoint.jdoStateManager != jdoStateManager)
+            throw new IllegalArgumentException("wrong jdoStateManager");
+        int i = fieldNumbers.length;
+        for(int j = 0; j < i; j++)
+            jdoCopyField(pcpoint, fieldNumbers[j]);
+    }
+
+    protected final void jdoCopyField(PCPoint pcpoint, int fieldNumber)
+    {
+        switch(fieldNumber - jdoInheritedFieldCount) {
+        case 0: 
+            if (pcpoint == null) {
+                throw new IllegalArgumentException("pcpoint is null");
+            } 
+            else {
+                x = pcpoint.x;
+                return;
+            }
+        case 1: 
+            if (pcpoint == null) {
+                throw new IllegalArgumentException("pcpoint is null");
+            } 
+            else {
+                y = pcpoint.y;
+                return;
+            }
+        }
+        throw new IllegalArgumentException("field number out of range");
+    }
+
+    private void writeObject(java.io.ObjectOutputStream out)
+        throws java.io.IOException {
+        jdoPreSerialize();
+        out.defaultWriteObject();
+    }
+    
+    protected static final Class sunjdo$classForName$(String s) {
+        try {
+            return Class.forName(s);
+        }
+        catch(ClassNotFoundException ex) {
+            throw new NoClassDefFoundError(ex.getMessage());
+        }
+    }
+    
+    
+
+}

Added: incubator/jdo/trunk/api11/test/java/javax/jdo/spi/JDOImplHelperTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/javax/jdo/spi/JDOImplHelperTest.java?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/test/java/javax/jdo/spi/JDOImplHelperTest.java (added)
+++ incubator/jdo/trunk/api11/test/java/javax/jdo/spi/JDOImplHelperTest.java Fri Mar 18 16:53:48 2005
@@ -0,0 +1,202 @@
+/*
+ * 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 javax.jdo.spi;
+
+import java.util.Collection;
+
+import javax.jdo.pc.PCPoint;
+import javax.jdo.util.AbstractTest;
+import javax.jdo.util.BatchTestRunner;
+
+/** 
+ * Tests class javax.jdo.spi.JDOImplHelper.
+ * <p>
+ * Missing: testNewInstance + testNewObjectIdInstance
+ * Missing: tests for JDOImplHelper methods: copyKeyFieldsToObjectId and 
+ * copyKeyFieldsFromObjectId.
+ */
+public class JDOImplHelperTest extends AbstractTest {
+    
+    /** */
+    private RegisterClassEvent event;
+
+    /** */
+    public static void main(String args[]) {
+        BatchTestRunner.run(JDOImplHelperTest.class);
+    }
+
+    /** */
+    public void testGetFieldNames() {
+        JDOImplHelper implHelper = JDOImplHelper.getInstance();
+        String[] fieldNames = implHelper.getFieldNames(PCPoint.class);
+        if (fieldNames == null) {
+            fail("array of field names is null");
+        }
+        if (fieldNames.length != 2) {
+            fail("Unexpected length of fieldNames; expected 2, got " + 
+                 fieldNames.length);
+        }
+        if (!fieldNames[0].equals("x")) {
+            fail("Unexpected field; expected x, got " + fieldNames[0]);
+        }
+        if (!fieldNames[1].equals("y")) {
+            fail("Unexpected field; expected y, got " + fieldNames[1]);
+        }
+    }
+
+    /** */
+    public void testGetFieldTypes() {
+        JDOImplHelper implHelper = JDOImplHelper.getInstance();
+        Class[] fieldTypes = implHelper.getFieldTypes(PCPoint.class);
+        if (fieldTypes == null) {
+            fail("array of field types is null");
+        }
+        if (fieldTypes.length != 2) {
+            fail("Unexpected length of fieldTypes; expected 2, got " + 
+                 fieldTypes.length);
+        }
+        if (fieldTypes[0] != int.class) {
+            fail("Unexpected field type; expected int, got " + 
+                 fieldTypes[0]);
+        }
+        if (fieldTypes[1] != Integer.class) {
+            fail("Unexpected field type; expected Integer, got " + 
+                 fieldTypes[1]);
+        }
+    }
+    
+    /** */
+    public void testGetFieldFlags() {
+        byte expected = (byte) (PersistenceCapable.CHECK_READ +
+            PersistenceCapable.CHECK_WRITE + PersistenceCapable.SERIALIZABLE);
+            
+        JDOImplHelper implHelper = JDOImplHelper.getInstance();
+        byte[] fieldFlags = implHelper.getFieldFlags(PCPoint.class);
+        if (fieldFlags == null) {
+            fail("array of field flags is null");
+        }
+        if (fieldFlags.length != 2) {
+            fail("Unexpected length of fieldFlags; expected 2, got " + 
+                 fieldFlags.length);
+        }
+        if (fieldFlags[0] != expected) {
+            fail("Unexpected field flag; expected " + expected + 
+                 ", got " + fieldFlags[0]);
+        }
+        if (fieldFlags[1] != expected) {
+            fail("Unexpected field flag; expected " + expected + 
+                 ", got " + fieldFlags[1]);
+        }
+    }
+
+    /** */
+    public void testGetPCSuperclass() {
+        JDOImplHelper implHelper = JDOImplHelper.getInstance();
+        Class pcSuper = 
+            implHelper.getPersistenceCapableSuperclass(PCPoint.class);
+        if (pcSuper != null) {
+            fail("Wrong pc superclass of PCPoint; expected null, got " + 
+                 pcSuper);
+        }
+    }
+
+    /** */
+    public void testNewInstance() {
+        // TBD: test JDOImplHelper.newInstance(pcClass, sm) and
+        // JDOImplHelper.newInstance(pcClass, sm, oid)  
+    }
+
+    /** */
+    public void testNewObjectIdInstance() {
+        // TBD: test JDOImplHelper.newObjectIdInstance(pcClass)
+    }
+    
+    /** */
+    public void testClassRegistration() {
+        JDOImplHelper implHelper = JDOImplHelper.getInstance();
+        // make sure PCClass is loaded
+        PCPoint p = new PCPoint(1, new Integer(1));
+
+        Collection registeredClasses = implHelper.getRegisteredClasses();
+        // test whether PCPoint is registered
+        if (!registeredClasses.contains(PCPoint.class)) {
+            fail("Missing registration of pc class PCPoint");
+        }
+
+        // Save registered meta data for restoring
+        String[] fieldNames = implHelper.getFieldNames(PCPoint.class);
+        Class[] fieldTypes = implHelper.getFieldTypes(PCPoint.class);
+        byte[] fieldFlags = implHelper.getFieldFlags(PCPoint.class);
+        Class pcSuperclass = implHelper.getPersistenceCapableSuperclass(PCPoint.class);
+        
+        // test unregisterClass with null parameter
+        try {
+            implHelper.unregisterClass(null);
+            fail("Missing exception when calling unregisterClass(null)");
+        }
+        catch (NullPointerException ex) {
+            // expected exception => OK
+        }
+
+        // test unregister PCPoint class
+        implHelper.unregisterClass(PCPoint.class);
+        registeredClasses = implHelper.getRegisteredClasses();
+        if (registeredClasses.contains(PCPoint.class)) {
+            fail("PCPoint still registered");
+        }
+
+        // register PCPoint again
+        JDOImplHelper.registerClass(PCPoint.class, fieldNames, fieldTypes, 
+                                    fieldFlags, pcSuperclass, new PCPoint());
+    }
+
+    /** */
+    public void testClassListenerRegistration() {
+        JDOImplHelper implHelper = JDOImplHelper.getInstance();
+
+        // add listener and check event
+        event = null;
+        RegisterClassListener listener = new SimpleListener();
+        implHelper.addRegisterClassListener(listener);
+        JDOImplHelper.registerClass(JDOImplHelperTest.class, new String[0], 
+                                    new Class[0], new byte[0], null, null);
+        if (event == null) {
+            fail("Missing event "); 
+        }
+
+        // remove listener and check event
+        event = null;
+        implHelper.removeRegisterClassListener(listener);
+        JDOImplHelper.registerClass(JDOImplHelperTest.class, new String[0], 
+                                    new Class[0], new byte[0], null, null);
+        if (event != null) {
+            fail("Unexpected event " + event);
+        }
+    }
+
+    /** */
+    class SimpleListener implements RegisterClassListener {
+
+        /** */
+        public void registerClass(RegisterClassEvent event) {
+            JDOImplHelperTest.this.event = event;
+        }
+        
+    }
+    
+}
+

Added: incubator/jdo/trunk/api11/test/java/javax/jdo/util/AbstractTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/javax/jdo/util/AbstractTest.java?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/test/java/javax/jdo/util/AbstractTest.java (added)
+++ incubator/jdo/trunk/api11/test/java/javax/jdo/util/AbstractTest.java Fri Mar 18 16:53:48 2005
@@ -0,0 +1,47 @@
+/*
+ * 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 javax.jdo.util;
+
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+
+/** */
+public class AbstractTest extends TestCase {
+
+    /** */
+    protected static PrintStream out = System.out;
+    
+    /** If true, print extra messages. */
+    protected boolean verbose;
+
+    /**
+     * Construct and initialize from properties.
+     */
+    protected AbstractTest() {
+        super(null);
+        verbose = Boolean.getBoolean("verbose");
+    }
+    
+    /**
+     */
+    protected void println(String s) {
+        if (verbose) 
+            out.println(s);
+    }
+}
+

Added: incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchResultPrinter.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchResultPrinter.java?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchResultPrinter.java (added)
+++ incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchResultPrinter.java Fri Mar 18 16:53:48 2005
@@ -0,0 +1,103 @@
+/*
+ * 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 javax.jdo.util;
+
+import java.io.PrintStream;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+import junit.textui.ResultPrinter;
+
+/**
+ * Default result printer implementation for running tests in batch mode.
+ * 
+ * @author Michael Bouschen
+ */
+public class BatchResultPrinter
+    extends ResultPrinter
+{
+    /** */
+    public BatchResultPrinter(PrintStream writer) {
+        super(writer);
+    }
+        
+    /** Called in case of a test error. */
+    public void addError(Test test, Throwable t) {
+        getWriter().print("   ERROR");
+    }
+        
+    /** Called in case of a test failure. */ 
+    public void addFailure(Test test, AssertionFailedError t) {
+        getWriter().print("   FAILURE");
+    }
+        
+    /** Called when a test case is finished. */
+    public void endTest(Test test) {
+        getWriter().println();
+    }
+        
+    /** Called when a test case is started. */
+    public void startTest(Test test) {
+        String testName;
+        if (test instanceof TestCase) {
+            testName = getClassBaseName(test) + "." + ((TestCase)test).getName();
+        }
+        else {
+            testName = test.toString();
+        }
+        getWriter().print("RUN " + testName);
+    }
+        
+    /** */
+    protected void printHeader(long runTime) {
+        getWriter().println("Time: "+elapsedTimeAsString(runTime));
+    }
+        
+    /** */
+    protected void printFooter(TestResult result) {
+        if (result.wasSuccessful()) {
+            getWriter().print("OK");
+            getWriter().println (" (" + result.runCount() + " test" + (result.runCount() == 1 ? "": "s") + ")");
+                
+        } else {
+            getWriter().println("FAILURES!!!");
+            getWriter().println("Tests run: "+result.runCount()+ 
+                                ",  Failures: "+result.failureCount()+
+                                ",  Errors: "+result.errorCount());
+        }
+    }
+        
+    // helper method
+        
+    /** 
+     * @return Name of the class of the given object without package prefix
+     */
+    private String getClassBaseName(Object obj) {
+        if (obj == null) return null;
+        String className = obj.getClass().getName();
+        int index = className.lastIndexOf('.');
+        if (index != -1) {
+            className = className.substring(index + 1);
+        }
+        return className;
+    }
+        
+}
+
+

Added: incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchTestRunner.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchTestRunner.java?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchTestRunner.java (added)
+++ incubator/jdo/trunk/api11/test/java/javax/jdo/util/BatchTestRunner.java Fri Mar 18 16:53:48 2005
@@ -0,0 +1,163 @@
+/*
+ * 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 javax.jdo.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.io.PrintStream;
+
+import junit.framework.Test;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+import junit.textui.ResultPrinter;
+import junit.textui.TestRunner;
+
+/**
+ * TestRunner class for running a single test or a test suite in batch
+ * mode. The format of the test output is specified by the result printer
+ * class. The main method sets an exit code according to the test result:
+ * <ul>
+ * <li><code>0</code>: success
+ * <li><code>1</code>: failure, the test shows an unexpected behavior
+ * <li><code>2</code>: exception, the test throws an unhandled excption 
+ * </ul>
+ * 
+ * @author Michael Bouschen
+ */
+public class BatchTestRunner
+    extends TestRunner
+{
+    /** Name of the system property to specify the result printer class. */
+    public static final String RESULTPRINTER_PROPERTY = "ResultPrinterClass"; 
+    
+    /** Default of the system property ResultPrinterClass. */
+    public static final String RESULTPRINTER_DEFAULT = BatchResultPrinter.class.getName();
+    
+    /** 
+     * Constructor. 
+     * It creates a result printer instance based on the system property
+     * and delegates to the constructor taking a result printer argument. 
+     */
+    public BatchTestRunner() {
+    	super();
+        setPrinter(getResultPrinter());
+    }
+    
+    /**  
+     * Constructor. USes teh specified resultPrinter to format the test result.
+     */
+    public BatchTestRunner(ResultPrinter resultPrinter) {
+        super(resultPrinter);
+    }
+
+    /** Runs all test methods from the specified class. */
+    public static void run(Class clazz) {
+        run(new TestSuite(clazz));
+    }
+    
+    /** Runs the specified test. */
+    public static TestResult run(Test test) {
+		return new BatchTestRunner().doRun(test);
+    }
+
+	/**	Runs the specified test and waits until the user types RETURN. */
+	public static void runAndWait(Test suite) {
+		new BatchTestRunner().doRun(suite, true);
+	}
+
+	/** 
+     * Runs in batch mode and sets an exit code. If the specified String
+     * array includes a single fully qualified class name, this test class
+     * is executed. If it is empty it runs the TestListSuite.
+     */
+    public static void main(String args[]) {
+		BatchTestRunner aTestRunner= new BatchTestRunner();
+		try {
+            /*
+            if ((args == null) || args.length == 0)
+                args = new String[] { TestListSuite.class.getName() };
+            */
+			TestResult r = aTestRunner.start(args);
+			if (!r.wasSuccessful()) 
+				System.exit(FAILURE_EXIT);
+			System.exit(SUCCESS_EXIT);
+		} catch(Exception e) {
+			System.err.println(e.getMessage());
+			System.exit(EXCEPTION_EXIT);
+		}
+	}
+    
+    /** Returns a result printer instance. n instance of tCheck the system property */
+    protected ResultPrinter getResultPrinter() {
+      	String className =  System.getProperty(RESULTPRINTER_PROPERTY);
+        if (className != null) {
+            className = className.trim();
+            if (className.length() != 0) {
+                String msg = null;
+                try {
+                    // get class instance
+                    Class clazz = Class.forName(className);
+                    // constructor taking PrintStream arg
+                    Constructor ctor = clazz.getConstructor(
+                        new Class[] { PrintStream.class } );
+                    // create instance
+                    return (ResultPrinter)ctor.newInstance(
+                        new Object[] { System.out });
+                }
+                catch (ClassNotFoundException ex) {
+                    // specified ResultPrinter class not 
+                    msg = "Cannot find specified result printer class " + 
+                        className + ".";
+                }
+                catch (NoSuchMethodException ex) {
+                    msg = "Class " + className + 
+                        " does not provide constructor taking a PrintStream.";
+                }
+                catch (InstantiationException ex) {
+                    msg = "Class " + className + " is abstract.";
+                }
+                catch (IllegalAccessException ex) {
+                    msg = "Constructor taking a PrintStream of class " + 
+                        className + " is not accessible.";
+                }
+                catch (InvocationTargetException ex) {
+                    msg = "Constructor call results in exception " + ex + ".";
+                }
+
+                // ResultPrinter class specified, but not avaiable
+                System.out.println(msg);
+                ResultPrinter printer = getDefaultResultPrinter();
+                System.out.println("Using default result printer of class " + 
+                                   printer.getClass().getName());
+            }
+        }
+        
+        // ResultPrinter class not specified => use default
+        return getDefaultResultPrinter();
+    }
+
+    /** 
+     * Returns an instance of the default result printer class
+     * BatchResultPrinter.
+     */
+    protected ResultPrinter getDefaultResultPrinter() {
+        return new BatchResultPrinter(System.out);
+    }
+    
+
+}
+

Added: incubator/jdo/trunk/api11/xdocs/index.xml
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/xdocs/index.xml?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/xdocs/index.xml (added)
+++ incubator/jdo/trunk/api11/xdocs/index.xml Fri Mar 18 16:53:48 2005
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+
+<document>
+
+  <properties>
+    <title>JDO API</title>
+    <author email="mbo.tech@spree.de">Michael Bouschen</author>
+  </properties>
+
+  <body>
+
+    <section name="JDO API">
+      <p>The Java Data Objects (JDO) API is a standard interface-based 
+Java model abstraction of persistence, developed as 
+<a href="http://www.jcp.org/en/jsr/detail?id=12">Java Specification 
+Request 12</a> under the auspices of the <a href="http://www.jcp.org">
+Java Community Process</a>.
+      </p>
+      <p>
+This project implements the public interfaces, helper classes and exceptions 
+as specified in the JDO specification. They are indented to be shared by all 
+JDO implementations. 
+      </p>
+    </section>
+
+  </body>
+</document>

Added: incubator/jdo/trunk/api11/xdocs/navigation.xml
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api11/xdocs/navigation.xml?view=auto&rev=158175
==============================================================================
--- incubator/jdo/trunk/api11/xdocs/navigation.xml (added)
+++ incubator/jdo/trunk/api11/xdocs/navigation.xml Fri Mar 18 16:53:48 2005
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project name="JDO API">
+
+  <title>JDO API</title>
+
+  <body>
+    <menu name="JCP Links">
+      <item name="JDO 1.0 JSR-12" href="http://www.jcp.org/en/jsr/detail?id=12"/>
+      <item name="JDO 2.0 JSR-243" href="http://www.jcp.org/en/jsr/detail?id=243"/>
+    </menu>
+  </body>
+</project>



Mime
View raw message