Hi,
please have a look at the attached patch file. It allows to the
enhancer20 subproject to depend on api20 (instead of api11).
Here are some details:
- The enhancer adds methods jdoIsDetached and jdoGetVersion to a pc class.
- The enhancer adds a method jdoNewObjectIdInstance with an Object
argument (instead of String).
- Commented out exception thrown by XML parser when detecting unknown
attribute.
Please note, the above method are not yet implemented. The enhancer
generated method bodies throw an UnsupportedOperationException.
Regards Michael
--
Michael Bouschen [EMAIL PROTECTED] Engineering GmbH
mailto:[EMAIL PROTECTED] http://www.tech.spree.de/
Tel.:++49/30/235 520-33 Buelowstr. 66
Fax.:++49/30/2175 2012 D-10783 Berlin
Index: enhancer20/project.properties
===================================================================
--- enhancer20/project.properties (revision 208869)
+++ enhancer20/project.properties (working copy)
@@ -17,7 +17,7 @@
maven.checkstyle.properties = ${basedir}/../jdo_checks.xml
# dependencies
-jdo.jdoapi.jarfile = ${pom.getDependencyPath('apache-jdo:jdo1-api')}
+jdo.jdoapi.jarfile = ${pom.getDependencyPath('apache-jdo:jdo2-api')}
jdo.jdocore.jarfile = ${pom.getDependencyPath('apache-jdo:jdo2-core')}
logging.jarfile = ${pom.getDependencyPath('commons-logging')}
xmlparser =
Index: enhancer20/project.xml
===================================================================
--- enhancer20/project.xml (revision 208869)
+++ enhancer20/project.xml (working copy)
@@ -37,7 +37,7 @@
<dependencies>
<dependency>
<groupId>apache-jdo</groupId>
- <artifactId>jdo1-api</artifactId>
+ <artifactId>jdo2-api</artifactId>
<version>SNAPSHOT</version>
</dependency>
<dependency>
Index:
enhancer20/src/java/org/apache/jdo/impl/enhancer/generator/ImplHelper.java
===================================================================
--- enhancer20/src/java/org/apache/jdo/impl/enhancer/generator/ImplHelper.java
(revision 208869)
+++ enhancer20/src/java/org/apache/jdo/impl/enhancer/generator/ImplHelper.java
(working copy)
@@ -104,6 +104,8 @@
= "jdoGetObjectId";
static final String METHODNAME_JDO_GET_TRANSACTIONAL_OBJECT_ID
= "jdoGetTransactionalObjectId";
+ static final String METHODNAME_JDO_GET_VERSION
+ = "jdoGetVersion";
static final String METHODNAME_JDO_IS_PERSISTENT
= "jdoIsPersistent";
static final String METHODNAME_JDO_IS_TRANSACTIONAL
@@ -114,6 +116,8 @@
= "jdoIsDirty";
static final String METHODNAME_JDO_IS_DELETED
= "jdoIsDeleted";
+ static final String METHODNAME_JDO_IS_DETACHED
+ = "jdoIsDetached";
static final String METHODNAME_JDO_COPY_KEY_FIELDS_TO_OID
= "jdoCopyKeyFieldsToObjectId";
static final String METHODNAME_JDO_COPY_KEY_FIELDS_FROM_OID
@@ -385,14 +389,12 @@
}
static List getJDONewOidInstanceImpl(String oidclassname,
- String str)
+ String o)
{
final List impl = new ArrayList(5);
- if (oidclassname == null) {
- impl.add("return null;");
- } else {
- impl.add("return new " + oidclassname + "(" + str + ");");
- }
+ // TODO: generate real method body
+ String msg = "Method jdoNewObjectIdInstance not yet supported";
+ impl.add("throw new UnsupportedOperationException(\"" + msg + "\");");
return impl;
}
@@ -936,6 +938,14 @@
return impl;
}
+ static List getNotYetImplemented(String methodName)
+ {
+ final List impl = new ArrayList(5);
+ String msg = "Method " + methodName + " not yet implemented";
+ impl.add("throw new UnsupportedOperationException(\"" + msg + "\");");
+ return impl;
+ }
+
static private boolean isPrimitiveClass(String classname)
{
return (classname.equals("int")
Index: enhancer20/src/java/org/apache/jdo/impl/enhancer/generator/Main.java
===================================================================
--- enhancer20/src/java/org/apache/jdo/impl/enhancer/generator/Main.java
(revision 208869)
+++ enhancer20/src/java/org/apache/jdo/impl/enhancer/generator/Main.java
(working copy)
@@ -615,6 +615,16 @@
ImplHelper.getJDOStateManagerObjectDelegationImpl("getTransactionalObjectId(this)"),
ImplHelper.COMMENT_ENHANCER_ADDED);
+ // jdoGetVersion
+ writer.writeMethod(
+ ImplHelper.METHODNAME_JDO_GET_VERSION,
+ Modifier.PUBLIC | Modifier.FINAL,
+ Object.class.getName(), null, null, null,
+ // TODO: generate real method body
+ ImplHelper.getNotYetImplemented(
+ ImplHelper.METHODNAME_JDO_GET_VERSION),
+ ImplHelper.COMMENT_ENHANCER_ADDED);
+
// is-methods
writer.writeMethod(
ImplHelper.METHODNAME_JDO_IS_PERSISTENT,
@@ -651,6 +661,15 @@
ImplHelper.getJDOStateManagerBooleanDelegationImpl("isDirty(this)"),
ImplHelper.COMMENT_ENHANCER_ADDED);
+ writer.writeMethod(
+ ImplHelper.METHODNAME_JDO_IS_DETACHED,
+ Modifier.PUBLIC | Modifier.FINAL,
+ "boolean", null, null, null,
+ // TODO: generate real method body
+ ImplHelper.getNotYetImplemented(
+ ImplHelper.METHODNAME_JDO_IS_DETACHED),
+ ImplHelper.COMMENT_ENHANCER_ADDED);
+
// makeDirty
writer.writeMethod(
ImplHelper.METHODNAME_JDO_MAKE_DIRTY,
@@ -922,11 +941,11 @@
ImplHelper.METHODNAME_JDO_NEW_OID_INSTANCE,
Modifier.PUBLIC,
Object.class.getName(),
- new String[]{ "str" },
- new String[]{ "String" },
+ new String[]{ "o" },
+ new String[]{ "Object" },
null,
ImplHelper.getJDONewOidInstanceImpl(oidClassName,
- "str"),
+ "o"),
ImplHelper.COMMENT_ENHANCER_ADDED);
// jdoCopyKeyFieldsTo/FromOid
Index:
enhancer20/src/java/org/apache/jdo/impl/enhancer/core/EnhancerConstants.java
===================================================================
---
enhancer20/src/java/org/apache/jdo/impl/enhancer/core/EnhancerConstants.java
(revision 208869)
+++
enhancer20/src/java/org/apache/jdo/impl/enhancer/core/EnhancerConstants.java
(working copy)
@@ -386,6 +386,15 @@
String JAVA_IllegalArgumentException_Type
= NameHelper.typeForPath(JAVA_IllegalArgumentException_Path);
+ String JAVA_UnsupportedOperationException_Name
+ = "UnsupportedOperationException";
+ String JAVA_UnsupportedOperationException_Path
+ =
NameHelper.javaLangPathForType(JAVA_UnsupportedOperationException_Name);
+ String JAVA_UnsupportedOperationException_Sig
+ = NameHelper.sigForPath(JAVA_UnsupportedOperationException_Path);
+ String JAVA_UnsupportedOperationException_Type
+ = NameHelper.typeForPath(JAVA_UnsupportedOperationException_Path);
+
String JAVA_IllegalStateException_Name
= "IllegalStateException";
String JAVA_IllegalStateException_Path
@@ -707,6 +716,14 @@
int JDO_PC_jdoGetTransactionalObjectId_Mods
= (ACCPublic | ACCFinal);
+ // Object jdoGetVersion()
+ String JDO_PC_jdoGetVersion_Name
+ = "jdoGetVersion";
+ String JDO_PC_jdoGetVersion_Sig
+ = "()" + JAVA_Object_Sig;
+ int JDO_PC_jdoGetVersion_Mods
+ = (ACCPublic | ACCFinal);
+
// boolean jdoIsPersistent()
String JDO_PC_jdoIsPersistent_Name
= "jdoIsPersistent";
@@ -747,6 +764,14 @@
int JDO_PC_jdoIsDirty_Mods
= (ACCPublic | ACCFinal);
+ // boolean jdoIsDetached()
+ String JDO_PC_jdoIsDetached_Name
+ = "jdoIsDetached";
+ String JDO_PC_jdoIsDetached_Sig
+ = "()Z";
+ int JDO_PC_jdoIsDetached_Mods
+ = (ACCPublic | ACCFinal);
+
// void jdoMakeDirty(String)
String JDO_PC_jdoMakeDirty_Name
= "jdoMakeDirty";
@@ -887,12 +912,12 @@
int JDO_PC_jdoNewObjectIdInstance_Mods
= (ACCPublic);
- // Object jdoNewObjectIdInstance(String)
- String JDO_PC_jdoNewObjectIdInstance_String_Name
+ // Object jdoNewObjectIdInstance(Object)
+ String JDO_PC_jdoNewObjectIdInstance_Object_Name
= "jdoNewObjectIdInstance";
- String JDO_PC_jdoNewObjectIdInstance_String_Sig
- = "(" + JAVA_String_Sig + ")" + JAVA_Object_Sig;
- int JDO_PC_jdoNewObjectIdInstance_String_Mods
+ String JDO_PC_jdoNewObjectIdInstance_Object_Sig
+ = "(" + JAVA_Object_Sig + ")" + JAVA_Object_Sig;
+ int JDO_PC_jdoNewObjectIdInstance_Object_Mods
= (ACCPublic);
// void jdoCopyKeyFieldsToObjectId(Object)
Index: enhancer20/src/java/org/apache/jdo/impl/enhancer/core/Builder.java
===================================================================
--- enhancer20/src/java/org/apache/jdo/impl/enhancer/core/Builder.java
(revision 208869)
+++ enhancer20/src/java/org/apache/jdo/impl/enhancer/core/Builder.java
(working copy)
@@ -993,6 +993,17 @@
}
/**
+ * Build an interrogative method for the class.
+ */
+ public void addJDOIsDetachedMethod()
+ {
+ // TODO: generate real method body
+ addNotYetImplementedMethod(JDO_PC_jdoIsDetached_Name,
+ JDO_PC_jdoIsDetached_Sig,
+ JDO_PC_jdoIsDetached_Mods);
+ }
+
+ /**
* Build an interrogative method named methodName for the class.
*
* public boolean isXXX() {
@@ -1097,6 +1108,17 @@
/**
* Build an object query method for the class.
+ */
+ public void addJDOGetVersionMethod()
+ {
+ // TODO: generate real method body
+ addNotYetImplementedMethod(JDO_PC_jdoGetVersion_Name,
+ JDO_PC_jdoGetVersion_Sig,
+ JDO_PC_jdoGetVersion_Mods);
+ }
+
+ /**
+ * Build an object query method for the class.
*
* public final XXX jdoGetYYY()
* {
@@ -3007,67 +3029,19 @@
/**
* Build the jdoNewObjectIdInstance method for the class.
*
- * public java.lang.Object jdoNewObjectIdInstance(String str)
+ * public java.lang.Object jdoNewObjectIdInstance(Object o)
* {
- * return new XXX(str);
+ * throw new UnsupportedOperationException(
+ * "Method jdoNewObjectIdInstance not yet implemented");
* }
*/
- public void addJDONewObjectIdInstanceStringMethod()
+ public void addJDONewObjectIdInstanceObjectMethod()
{
- final String methodName = JDO_PC_jdoNewObjectIdInstance_String_Name;
- final String methodSig = JDO_PC_jdoNewObjectIdInstance_String_Sig;
- final int accessFlags = JDO_PC_jdoNewObjectIdInstance_String_Mods;
- final ExceptionsAttribute exceptAttr = null;
-
- // begin of method body
- final InsnTarget begin = new InsnTarget();
- Insn insn = begin;
-
- // generate empty method in case of datastore identity
- final String keyClassName = analyzer.getKeyClassName();
- if (keyClassName == null){
- // end of method body
- insn = insn.append(Insn.create(opc_aconst_null));
- insn = insn.append(Insn.create(opc_areturn));
-
- final CodeAttribute codeAttr
- = new CodeAttribute(getCodeAttributeUtf8(),
- 1, // maxStack
- 2, // maxLocals
- begin,
- new ExceptionTable(),
- new AttributeVector());
- augmenter.addMethod(methodName, methodSig, accessFlags,
- codeAttr, exceptAttr);
- return;
- }
- affirm(keyClassName != null);
-
- // push a newly created an instance of this class
- insn = insn.append(
- Insn.create(opc_new,
- pool.addClass(keyClassName)));
- insn = insn.append(Insn.create(opc_dup));
- insn = insn.append(Insn.create(opc_aload_1));
- insn = insn.append(
- Insn.create(opc_invokespecial,
- pool.addMethodRef(
- keyClassName,
- NameHelper.constructorName(),
- NameHelper.constructorSig(JAVA_String_Sig))));
-
- // end of method body
- insn = insn.append(Insn.create(opc_areturn));
-
- final CodeAttribute codeAttr
- = new CodeAttribute(getCodeAttributeUtf8(),
- 3, // maxStack
- 2, // maxLocals
- begin,
- new ExceptionTable(),
- new AttributeVector());
- augmenter.addMethod(methodName, methodSig, accessFlags,
- codeAttr, exceptAttr);
+ final String methodName = JDO_PC_jdoNewObjectIdInstance_Object_Name;
+ final String methodSig = JDO_PC_jdoNewObjectIdInstance_Object_Sig;
+ final int accessFlags = JDO_PC_jdoNewObjectIdInstance_Object_Mods;
+ // TODO: generate real method body
+ addNotYetImplementedMethod(methodName, methodSig, accessFlags);
}
// ----------------------------------------------------------------------
@@ -4713,4 +4687,40 @@
augmenter.addMethod(methodName, methodSig, accessFlags,
codeAttr, exceptAttr);
}
+
+ /**
+ * Builds a method throwing an UnsupportedOperationException.
+ *
+ * public void XXX() {
+ * throw new UnsupportedOperationException(
+ * "Method XXX not yet implemented");
+ * }
+ */
+ public void addNotYetImplementedMethod(final String methodName,
+ final String methodSig,
+ final int accessFlags)
+ {
+ // assumed nonstatic call; otherwise subtract 'this' from maxStack
+ affirm((accessFlags & ACCStatic) == 0);
+ final ExceptionsAttribute exceptAttr = null;
+
+ // begin of method body
+ final InsnTarget begin = new InsnTarget();
+ Insn insn = begin;
+
+ insn = appendThrowJavaException(
+ insn, JAVA_UnsupportedOperationException_Path,
+ "Method " + methodName + " not yet implemented");
+
+ final CodeAttribute codeAttr
+ = new CodeAttribute(getCodeAttributeUtf8(),
+ 3, // maxStack
+ countMethodArgWords(methodSig), // maxLocals
+ begin,
+ new ExceptionTable(),
+ new AttributeVector());
+ augmenter.addMethod(methodName, methodSig, accessFlags,
+ codeAttr, exceptAttr);
+ }
+
}
Index: enhancer20/src/java/org/apache/jdo/impl/enhancer/core/Augmenter.java
===================================================================
--- enhancer20/src/java/org/apache/jdo/impl/enhancer/core/Augmenter.java
(revision 208869)
+++ enhancer20/src/java/org/apache/jdo/impl/enhancer/core/Augmenter.java
(working copy)
@@ -296,11 +296,13 @@
builder.addJDOIsNewMethod();
builder.addJDOIsDeletedMethod();
builder.addJDOIsDirtyMethod();
+ builder.addJDOIsDetachedMethod();
builder.addJDOMakeDirtyMethod();
builder.addJDOPreSerializeMethod();
builder.addJDOGetPersistenceManagerMethod();
builder.addJDOGetObjectIdMethod();
builder.addJDOGetTransactionalObjectIdMethod();
+ builder.addJDOGetVersionMethod();
builder.addJDOReplaceStateManager();
builder.addJDOProvideFieldsMethod();
builder.addJDOReplaceFieldsMethod();
@@ -340,7 +342,7 @@
if (analyzer.isAugmentableAsRoot()
|| analyzer.getKeyClassName() != null) {
builder.addJDONewObjectIdInstanceMethod();
- builder.addJDONewObjectIdInstanceStringMethod();
+ builder.addJDONewObjectIdInstanceObjectMethod();
builder.addJDOCopyKeyFieldsToObjectIdMethod();
builder.addJDOCopyKeyFieldsFromObjectIdMethod();
builder.addJDOCopyKeyFieldsToObjectIdOIFSMethod();
Index:
enhancer20/src/java/org/apache/jdo/impl/enhancer/util/AugmentationTest.java
===================================================================
--- enhancer20/src/java/org/apache/jdo/impl/enhancer/util/AugmentationTest.java
(revision 208869)
+++ enhancer20/src/java/org/apache/jdo/impl/enhancer/util/AugmentationTest.java
(working copy)
@@ -331,7 +331,7 @@
affirm(ERROR < NEGATIVE && NEGATIVE < AFFIRMATIVE);
affirm(classObject);
- final int nofFeatures = 16;
+ final int nofFeatures = 18;
final int[] r = new int[nofFeatures];
{
int i = 0;
@@ -388,6 +388,13 @@
r[i++] = hasMethod(
out,
Modifier.PUBLIC | Modifier.FINAL,
+ Object.class,
+ "jdoGetVersion",
+ new Class[]{});
+
+ r[i++] = hasMethod(
+ out,
+ Modifier.PUBLIC | Modifier.FINAL,
boolean.class,
"jdoIsPersistent",
new Class[]{});
@@ -415,6 +422,12 @@
boolean.class,
"jdoIsDirty",
new Class[]{});
+ r[i++] = hasMethod(
+ out,
+ Modifier.PUBLIC | Modifier.FINAL,
+ boolean.class,
+ "jdoIsDetached",
+ new Class[]{});
r[i++] = hasMethod(
out,
@@ -593,7 +606,7 @@
Modifier.PUBLIC,
Object.class,
"jdoNewObjectIdInstance",
- new Class[]{String.class});
+ new Class[]{Object.class});
r[i++] = hasMethod(
out,
Index: core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java
===================================================================
--- core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java
(revision 208869)
+++ core20/src/java/org/apache/jdo/impl/model/jdo/xml/JDOHandlerImpl.java
(working copy)
@@ -212,6 +212,8 @@
}
}
else {
+ /* JDO2 metadata not yet fully supported =>
+ do not throw exception now
SAXException e = new SAXException(
msg.msg("EXC_UnknownAttribute", "<class>", //NOI18N
name, value));
@@ -219,6 +221,10 @@
logger.trace("Throwing exception in " + //NOI18N
"JDOHandlerImpl.start_class:", e);
//NOI18N
throw e;
+ */
+ if (trace)
+ logger.trace(msg.msg("EXC_UnknownAttribute", //NOI18N
+ "<class>", name, value)); //NOI18N
}
}
}
@@ -303,6 +309,8 @@
Boolean.valueOf(value).booleanValue());
}
else {
+ /* JDO2 metadata not yet fully supported =>
+ do not throw exception now
SAXException e = new SAXException(
msg.msg("EXC_UnknownAttribute", "<field>", //NOI18N
name, value));
@@ -310,6 +318,10 @@
logger.trace("Throwing exception in " + //NOI18N
"JDOHandlerImpl.start_field:", e);
//NOI18N
throw e;
+ */
+ if (trace)
+ logger.trace(msg.msg("EXC_UnknownAttribute", //NOI18N
+ "<field>", name, value)); //NOI18N
}
}
}
@@ -369,6 +381,8 @@
Boolean.valueOf(value).booleanValue());
}
else {
+ /* JDO2 metadata not yet fully supported =>
+ do not throw exception now
SAXException e = new SAXException(
msg.msg("EXC_UnknownAttribute", "<collection>",
//NOI18N
name, value));
@@ -376,6 +390,10 @@
logger.trace("Throwing exception in " + //NOI18N
"JDOHandlerImpl.start_collection:", e);
//NOI18N
throw e;
+ */
+ if (trace)
+ logger.trace(msg.msg("EXC_UnknownAttribute", //NOI18N
+ "<collection>", name, value));
//NOI18N
}
}
}
@@ -432,6 +450,8 @@
Boolean.valueOf(value).booleanValue());
}
else {
+ /* JDO2 metadata not yet fully supported =>
+ do not throw exception now
SAXException e = new SAXException(
msg.msg("EXC_UnknownAttribute", "<array>", //NOI18N
name, value));
@@ -439,6 +459,10 @@
logger.trace("Throwing exception in " + //NOI18N
"JDOHandlerImpl.start_array:", e);
//NOI18N
throw e;
+ */
+ if (trace)
+ logger.trace(msg.msg("EXC_UnknownAttribute", //NOI18N
+ "<array>", name, value)); //NOI18N
}
}
}
@@ -504,6 +528,8 @@
Boolean.valueOf(value).booleanValue());
}
else {
+ /* JDO2 metadata not yet fully supported =>
+ do not throw exception now
SAXException e = new SAXException(
msg.msg("EXC_UnknownAttribute", "<map>", //NOI18N
name, value));
@@ -511,6 +537,10 @@
logger.trace("Throwing exception in " + //NOI18N
"JDOHandlerImpl.start_map:", e); //NOI18N
throw e;
+ */
+ if (trace)
+ logger.trace(msg.msg("EXC_UnknownAttribute", //NOI18N
+ "<map>", name, value)); //NOI18N
}
}
}
@@ -573,6 +603,8 @@
jdoExtension.setValue(value);
}
else {
+ /* JDO2 metadata not yet fully supported =>
+ do not throw exception now
SAXException e = new SAXException(
msg.msg("EXC_UnknownAttribute", "<extension>", //NOI18N
name, value));
@@ -580,6 +612,10 @@
logger.trace("Throwing exception in " + //NOI18N
"JDOHandlerImpl.start_extension:", e);
//NOI18N
throw e;
+ */
+ if (trace)
+ logger.trace(msg.msg("EXC_UnknownAttribute", //NOI18N
+ "<extension>", name, value));
//NOI18N
}
}
}