Have you looked at the SchemaTypeLoader APIs
http://xmlbeans.apache.org/docs/2.2.0/reference/org/apache/xmlbeans/SchemaTypeLoader.html#newInstance(org.apache.xmlbeans.SchemaType,%20org.apache.xmlbeans.XmlOptions)
-jacobd
On 10/22/07, Cory Virok <[EMAIL PROTECTED]> wrote:
>
> Given only a SchemaType object, is there a way to instantiate a new
> XmlObject
> that the SchemaType represents?
> I have it working but my solution is clunky and uses reflection... There's
> gotta be a better way!
>
> I want to do something like this:
>
> SchemaType someType = getFooSchemaType();
> Foo foo = (Foo) newInstanceFromSchemaType(someType);
>
> Currently, I have this:
>
> <code>
> //children[i] is an SchemaParticle
>
> //objClass is now the Class obj that represents the *interface* to
> the object I really want...
> Class objClass = children[i].getType().getJavaClass();
> // Make the assumption that XMLbeans will always
> // create an inner "Factory" class!
> Class innerFactory = objClass.getClasses()[0];
> Method newInstanceMeth =
> innerFactory.getDeclaredMethod("newInstance",
>
> new Class[0]);
>
> XmlObject childObj = (XmlObject) newInstanceMeth.invoke(null,
> null);
> </code>
>
> Thanks,
> cory
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>