logo       

Re: how do I create a generic object creator?: msg#00037

text.xml.xmlbeans.user

Subject: Re: how do I create a generic object creator?

Don't follow what you want from DAO (where do usersDAO et. al. come from?), but
this may point you in the right
direction. I am having problems setting up the root when I create a new
instance. Always getting xml-fragment.

public void populate(XmlObject pObj)
{
XmlOptions opts;
opts = opts.setDocumentType ( pObj.schemaType() );

XmlObject newInstance = pObj.Factory.newInstance(opts);


...
populate data from DAO
...
}

Wednesday, January 5, 2005, 7:22:07 PM, you wrote:
> Hello folks,

> I'm trying to create a generic method which will create an instance of a
> document based on the type of document passed.

> For example, I have two XMLBean generated documents, say Users & Depts.
> I'd like to create instances of these objects in the following manner:
> UsersDocument users = UsersDocument.Factory.newInstance();
> DeptsDocument depts = DeptsDocument.Factory.newInstance();
> GenericClass gcUsers = new GenericClass(usersDAO); //usersDAO has users
> information taken from a database
> GenericClass gcDepts = new GenericClass(deptsDAO); //ditto
> gcUsers.populate(users);
> gcDepts.populate(depts);

> GenericClass would have the following interface...
> public void populate(XmlObject pObj)
> {
> //pObj.addNewUsers() or pObj.addNewDepts() according to document type
> ...
> populate data from DAO
> ...
> }

> I'm struggling to work out what I should do inside this method.
> I know I can have a set if then else statements (pObj instanceof
> UsersDocument, instanceof DeptsDocument) but that's just too clumsy (and
> a pain to extend).

> I've also considered using Java reflection to call the relevant add
> method, but again that just seems too clumsy.

> I've got a feeling that the answer lies in the SOM API
> (pObj.schemaType()...) but I can't work-out how best to use it.

> Any advice would be much appreciated.

> Regards,
> Jim





> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
> For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise