On 12/03/07, Jacob Danner <[EMAIL PROTECTED]> wrote:
Can we see the stack traces?
<snip>
try {
String clazz1 = "FundDocument";
Object xmlObject = Class.forName(clazz1).newInstance();
} catch (Exception e) {
java.lang.ClassNotFoundException: FundDocument
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at test.ReadXML.main(ReadXML.java:60)
}
try {
String clazz2 = "noNamespace.FundDocument";
Object xmlObject = Class.forName(clazz2).newInstance();
//XmlObject root = ((XmlObject)
xmlObject).Factory.newInstance();
FundDocument fundDoc2 = (FundDocument) Class.forName
(clazz2).newInstance();
} catch (Exception e) {
java.lang.InstantiationException: noNamespace.FundDocument
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at test.ReadXML.main(ReadXML.java:67)
}
<.snip>
Adding Impl to FundDocument (into FundDocumentImpl) gives me the following 2
traces.
java.lang.ClassNotFoundException: FundDocumentImpl
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at test.ReadXML.main(ReadXML.java:60)
java.lang.ClassNotFoundException: noNamespace.FundDocumentImpl
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at test.ReadXML.main(ReadXML.java:67)
If you need something more please let me know.
Tia
> > I haven't tried, but do you have problems with
> > Class.forName(someRootAsString).newInstance() ?
> Correct. Assuming i'm not making some very silly misstake
>
> > The only thing I can think of that might cause problems would be in
> > the lookup of the xsbs.
> > Can you update teh list with what issues you have?
> Here it goes:
>
> <snip>
> ...
> // This bit works just fine so the class in itself is known
> FundDocument fundDoc=
> FundDocument.Factory.newInstance();
>
> try {
> String clazz1 = "Fund"+ "DocumentImpl";
> Object xmlObject = Class.forName(clazz2).newInstance(); //
> Returns a ClassNotFound Exception
>
> String clazz2 = "noNamespace."+ "Fund"+ "Document";
> Object xmlObject = Class.forName(clazz2).newInstance(); //
> Returns an Instantiation Exception
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> ...
> </snip>
>
>
> What i would like to so is use the xmlObject in a generic fashion so i
don't
> have to hardcode.
>
> Is this enough info? If not please let me know.
>
> Tia
>
> Fermin
> >
> > > > I haven't seen a previous post on the list about this topic. That
may
> > > > be why you didn't get an answer :)
> > > Hmm, that would explain it, indeed.
> > >
> > > What problems are you seeing when you try the code you list below?
> > > >
> > > > If I understand your problem correctly, you have something like:
> > > > <el>1</el1> and you want to determine what type that is so you can
> use
> > > > somenamespace.ElDocument as your type. Is this correct?
> > >
> > > No exactly. I think i have to be more clear (always a challenge but
here
> it
> > > goes .. )
> > >
> > > I'v got the big jar that is produced when you run scomp on an xsd.
> > > When using the code in a normal fashion one would just get an
object,
> say
> > > SomeRoot, and use the
> SomeRootDocument.Factory.someMethod()
> > > to accomplish whatever.
> > >
> > > Now, what i want to do is slightly different.
> > > Rather than using SomeDocumentRootDocument explicitly i am looking
for a
> way
> > > to use the
> Class.forName(someRootAsString).newInstance()
> > > method to get my hands on an xmlbeans document that i specify via a
> string.
> > > This way i don't have to hardcode the construction of the xml but i
> could
> > > supply the structure via simple strings, read via a small input
file.
> > > If this is possible one can construct any xml (sub)doc (based on the
> overall
> > > xsd) without having to code for it.
> > >
> > > Does this make sense?
> > >
> > > > Have you tried something like:
> > > > XmlObject xo = XmlObject.Factory.parse("<el>1</el1>");
> > > > and
> > > > xo.type
> > > > xo.type.getName
> > > Since this suggests the string being an xml element i have not
because i
> > > would be looking for a className (the string thereof) to be handed
of
> and
> > > return with an instance of type XmlObject.
> > > Basically i don't know where the xml is going to start so i just
want to
> > > supply a string (name of the element to denote as root of the
document
> to be
> > > build), create the corresponding document and build the rest of the
> xml-doc
> > > in the same fashion.
> > >
> > > > the scan the classes you expect to find a matching type
> > > > if(ElDocument.type.getName == xo.type.getName){
> > > > // do something
> > > > }
> > > >
> > > >
> > > > -Jacobd
> > > >
> > > > On 3/12/07, Fermin Da Costa Gomez <[EMAIL PROTECTED] > wrote:
> > > > > Hi,
> > > > >
> > > > > Just started on Xmlbeans and going through the list has not
yielden
> an
> > > > > answer to my question.
> > > > >
> > > > > Is there a way to get a hold of a SomeDocument object by using
> > > > > Class.forName("namespace.SomeDocument").newInstance() .. ?
> > > > > Or any other way by means of just using a string that refers/
points
> to
> > > the
> > > > > element one is looking for?
> > > > >
> > > > > So i have got the name of a document/ node/ tag in the form of a
> string
> > > and
> > > > > i'm looking for an object based on that string.
> > > > >
> > > > > Tia,
> > > > >
> > > > > Fermin DCG
> > > > >
> > > > >
> > > >
> > > >
> > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > >
> > >
> > >
> > > --
> > > "The reasonable man adapts himself to the world; the unreasonable
one
> > > persists in trying to adapt the world to himself. Therefore all
progress
> > > depends on the unreasonable man."
> > > - George Bernard Shaw (1856 - 1950)
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
>
> --
> "The reasonable man adapts himself to the world; the unreasonable one
> persists in trying to adapt the world to himself. Therefore all progress
> depends on the unreasonable man."
> - George Bernard Shaw (1856 - 1950)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
"The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man."
- George Bernard Shaw (1856 - 1950)