You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ra...@apache.org on 2005/07/21 22:48:00 UTC
svn commit: r220181 - in /xmlbeans/trunk/src:
typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
xmlpublic/org/apache/xmlbeans/XmlBeans.java
Author: radup
Date: Thu Jul 21 13:47:57 2005
New Revision: 220181
URL: http://svn.apache.org/viewcvs?rev=220181&view=rev
Log:
Fix for XMLBEANS-120.
This patch updates the hardcoded SchemaType reference to resolve the TypeSystemHolder by name using a new API on XmlBeans for that purpose. That should resolve the IDE missing class problem if you compile using the -srconly option.
Contributed by Lawrence Jones
Modified:
xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java
Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java?rev=220181&r1=220180&r2=220181&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java Thu Jul 21 13:47:57 2005
@@ -324,10 +324,14 @@
void printStaticTypeDeclaration(SchemaType sType, SchemaTypeSystem system) throws IOException
{
- emit("public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)" +
- indexClassForSystem(system) +
- ".typeSystem.resolveHandle(\"" +
- ((SchemaTypeSystemImpl)system).handleForType(sType) + "\");");
+ String interfaceShortName = sType.getShortJavaName();
+ emit("public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)");
+ indent();
+ emit("org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(" +
+ interfaceShortName + ".class.getClassLoader(), \"" + system.getName() + "\")" +
+ ".resolveHandle(\"" +
+ ((SchemaTypeSystemImpl)system).handleForType(sType) + "\");");
+ outdent();
}
/** @deprecated */
Modified: xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java?rev=220181&r1=220180&r2=220181&view=diff
==============================================================================
--- xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java (original)
+++ xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java Thu Jul 21 13:47:57 2005
@@ -750,6 +750,52 @@
}
}
+ private static final String HOLDER_CLASS_NAME = "TypeSystemHolder";
+ private static final String TYPE_SYSTEM_FIELD = "typeSystem";
+
+ /**
+ * Returns the SchemaTypeSystem of the given name (as returned by
+ * {@link SchemaTypeSystem#getName}) for the given ClassLoader.
+ * <p>
+ * Note: you will almost always need typeLoaderForClassLoader()
+ * instead (see {@link XmlBeans#typeLoaderForClassLoader}).
+ */
+ public static SchemaTypeSystem typeSystemForClassLoader(ClassLoader loader, String stsName)
+ {
+ try
+ {
+ Class clazz = loader.loadClass(stsName + "." + HOLDER_CLASS_NAME);
+ SchemaTypeSystem sts = (SchemaTypeSystem)
+ (clazz.getDeclaredField(TYPE_SYSTEM_FIELD).get(null));
+ if (sts == null)
+ {
+ throw new RuntimeException("SchemaTypeSystem is null for field " +
+ TYPE_SYSTEM_FIELD + " on class with name " + stsName +
+ "." + HOLDER_CLASS_NAME +
+ ". Please verify the version of xbean.jar is correct.");
+ }
+ return sts;
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw causedException(new RuntimeException("Cannot load SchemaTypeSystem. " +
+ "Unable to load class with name " + stsName + "." + HOLDER_CLASS_NAME +
+ ". Make sure the generated binary files are on the classpath."), e);
+ }
+ catch (NoSuchFieldException e)
+ {
+ throw causedException(new RuntimeException("Cannot find field " +
+ TYPE_SYSTEM_FIELD + " on class " + stsName + "." + HOLDER_CLASS_NAME +
+ ". Please verify the version of xbean.jar is correct."), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw causedException(new RuntimeException("Field " +
+ TYPE_SYSTEM_FIELD + " on class " + stsName + "." + HOLDER_CLASS_NAME +
+ "is not accessible. Please verify the version of xbean.jar is correct."), e);
+ }
+ }
+
/**
* Returns a new ResourceLoader for a search path where each component of
* the path is either a directory or a compiled xbean jar.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org