One thing to definitely check for is how you are parsing the Schema files. By 
default, XMLBeans uses the context classloader to look for types (like in 
Factory.parse()). In a std Java app, the context and current classloaders are 
the same, but in Ant they are not.

Try this when parsing the Schema:

        SchemaTypeLoader loader = 
XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());
        loader.parse(...)

Radu

> -----Original Message-----
> From: Adam Flinton [mailto:[email protected]] 
> Sent: Wednesday, June 17, 2009 6:32 AM
> To: [email protected]
> Subject: Schema weirdness running in ant task vs main
> 
> Dear All,
> 
> Using the latest & greatest XMLBeans I have re-written the :
> 
> org.apache.xmlbeans.impl.xsd2inst.SchemaInstanceGenerator as 
> an ant task.
> 
> When running the code as a std java app e.g.
> 
>     public static void main(String args[]) {
> 
>         GenerateInstance gi = new GenerateInstance();
>         gi.schema =
> "D:/Data/Java/workspaces/3.3/CodeSystemWebV2-oht/ExportSchema/
> CTS_XML.xsd";
>         gi.rootElementName = "CodeSystemRoot";
>         gi.outFile =
> "D:/Data/Java/workspaces/3.3/CodeSystemWebV2-oht/ExportSchema/
> ExampleXML/CTS_XMLExample.xml";
>         gi.execute();
> 
>         
> /*ax.setOutputFolder("D:/Data/ATestXML/test/ArchGenTest/Test/log");
>         ax.rightFile = 
> "D:/Data/ATestXML/test/ArchGenTest/Test/JavaXML";
>         ax.leftFile = 
> "D:/Data/ATestXML/test/ArchGenTest/Test/OceanXML";
>         ax.execute();*/
>     }
> 
>     public void execute() {
> 
>         if (schema == null || schema.length() == 0) {
>             throw new BuildException("No Schema set.");
>         }
>         if (rootElementName == null || 
> rootElementName.length() == 0) {
>             throw new BuildException("No rootElementName set.");
>         }
>         checkFile();
>         process();
> 
>     }
> 
> The it runs fine & generates me some example xml etc e.g. 
> from system.out:
> 
> getFileAsArray filename =
> D:/Data/Java/workspaces/3.3/CodeSystemWebV2-oht/ExportSchema/C
> TS_XML.xsd
> getFileAsArray result size =  1
> <CodeSystemRoot id="string" guid="string" name="string" 
> exportDate="string">
>   <Publications>
>     <!--1 or more repetitions:-->
>     <Publication id="string" guid="string" version="string"
> publicationDate="string"/>
>   </Publications>
>   <CodeSystems>
> etc...
> 
> However then running the exact same code as an ant task.... I 
> get an error:
> "org.apache.xmlbeans.XmlException: Thread main: The 0th 
> supplied input is not a schema document: its type is N="
> 
> e.g.:
> 
> Buildfile:
> D:\Data\Java\workspaces\3.3\AntTask-GenerateXML\TestGenerateXML.xml
> init-clean:
>      [echo] schema =
> D:/Data/Java/workspaces/3.3/CodeSystemWebV2-oht/ExportSchema/C
> TS_XML.xsd
>      [echo] schemaPath =
> D:\Data\Java\workspaces\3.3\CodeSystemWebV2-oht\ExportSchema\C
> TS_XML.xsd
>      [echo] rootElementName = CodeSystemRoot
>      [echo] outFilePath =
> D:\Data\Java\workspaces\3.3\CodeSystemWebV2-oht\ExportSchema\E
> xampleXML\CTS_XMLExample.xml
> init:
> test:
> [generateXML] setSchema schema =
> D:/Data/Java/workspaces/3.3/CodeSystemWebV2-oht/ExportSchema/C
> TS_XML.xsd
> [generateXML] getFileAsArray filename =
> D:/Data/Java/workspaces/3.3/CodeSystemWebV2-oht/ExportSchema/C
> TS_XML.xsd
> [generateXML] getFileAsArray result size =  1 [generateXML] 
> org.apache.xmlbeans.XmlException: Thread main: The 0th 
> supplied input is not a schema document: its type is N=
> [generateXML]     at
> org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler.compi
> le(SchemaTypeSystemCompiler.java:211)
> [generateXML]     at 
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
> [generateXML]     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccess
> orImpl.java:39)
> [generateXML]     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth
> odAccessorImpl.java:25)
> [generateXML]     at java.lang.reflect.Method.invoke(Method.java:597)
> [generateXML]     at
> org.apache.xmlbeans.XmlBeans.compileXmlBeans(XmlBeans.java:667)
> [generateXML]     at
> org.apache.xmlbeans.XmlBeans.compileXsd(XmlBeans.java:553)
> [generateXML]     at
> org.xmlprocess.ant.xmlGen.GenerateInstance.process(GenerateIns
> tance.java:121)
> [generateXML]     at
> org.xmlprocess.ant.xmlGen.GenerateInstance.execute(GenerateIns
> tance.java:63)
> [generateXML]     at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
> [generateXML]     at 
> sun.reflect.GeneratedMethodAccessor1.invoke(Unknown
> Source)
> [generateXML]     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth
> odAccessorImpl.java:25)
> [generateXML]     at java.lang.reflect.Method.invoke(Method.java:597)
> [generateXML]     at
> org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUt
> ils.java:105)
> [generateXML]     at org.apache.tools.ant.Task.perform(Task.java:348)
> [generateXML]     at 
> org.apache.tools.ant.Target.execute(Target.java:357)
> [generateXML]     at
> org.apache.tools.ant.Target.performTasks(Target.java:385)
> [generateXML]     at
> org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
> [generateXML]     at
> org.apache.tools.ant.Project.executeTarget(Project.java:1298)
> [generateXML]     at
> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(Def
> aultExecutor.java:41)
> [generateXML]     at
> org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.
> executeTargets(EclipseDefaultExecutor.java:32)
> [generateXML]     at
> org.apache.tools.ant.Project.executeTargets(Project.java:1181)
> [generateXML]     at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(I
> nternalAntRunner.java:423)
> [generateXML]     at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(
> InternalAntRunner.java:137)
> [generateXML] Schema compilation errors:
> [generateXML] No Schemas to process.
> 
> 
> 
> Any ideas? There is nothing wrong with the schema (evidenced 
> in part by the fact that when running as a Java app via a 
> call to main it runs perfectly).
> 
> 
> Adam
> 
> **************************************************************
> ******************************************************
> 
> This message may contain confidential information. If you are 
> not the intended recipient please inform the sender that you 
> have received the message in error before deleting it.
> Please do not disclose, copy or distribute information in 
> this e-mail or take any action in reliance on its contents:
> to do so is strictly prohibited and may be unlawful.
> 
> Thank you for your co-operation.
> 
> NHSmail is the secure email and directory service available 
> for all NHS staff in England and Scotland NHSmail is approved 
> for exchanging patient data and other sensitive information 
> with NHSmail and GSI recipients NHSmail provides an email 
> address for your career in the NHS and can be accessed 
> anywhere For more information and to find out how you can 
> switch, visit www.connectingforhealth.nhs.uk/nhsmail
> 
> **************************************************************
> ******************************************************
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to