Apologies for my confusing attempts at communicating my situation, but thanks
for your reply.
You say I must know about MyKnownDocument in order to make the cast described
below, but I was wanting to dynamically derive MyKnownDocument from
MyKnownDocumentImpl such that I can then make the cast from one to the other.
This is because a) I cannot use xxxDocumentImpl for the next step in my
processing, but rather the Interface type xxxDocument itself, and b) there is
no way to know what types are available for the casting at the time the code is
written.
But it sounds like this is not possible. I suppose I can go through the
contents of the jar file created from scomp and do a comparison of Classes/
types until I find a match ('instanceof' ) for xobj then do the cast.
Any other suggestions are welcome, thanks again.
aj
-------------- Original message ----------------------
> - if the root element of your document is "known" by XmlBeans, the the
> returned XmlObject is of the correct instance class, you don't need to
> do anything else: xobj.getClass() should return
> MyKnownDocumentImpl.class
> - you can find out which document SchemaType it is by doing
> "xobj.schemaType()"
>
> Beyond this, in Java in general, if you want to write a cast like
> "(MyKnownDocument) xobj" then you must of course know at the time you
> write your code about MyKnownDocument...
>
> Radu
>
> ________________________________
>
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, May 22, 2007 2:10 PM
> To: [email protected]
> Subject: XmlBeans processing - brick wall
>
>
> I will rephrase my earlier question as it may have been a bit much:
>
>
> I have seen this...
>
> XmlObject xobj = XmlObject.Factory.parse(myDocument);
>
> if (xobj instanceof MyKnownDocument ) {
>
> MyKnownDocument mydoc = (MyKnownDocument )xobj;
>
> if (!xobj.validate())
> System.out.println("Not a valid my-order document");
> }
>
> ...which is fine if you have knowledge of MyKnownDocument to begin with.
> If you do not know it, is it possible to extract the document type
> associated with myDocument/xobj, and then cast xobj to that? The
> myDocument is an instance of
> _some_ kind of Document, I just need to find out _which_ Document, then
> cast it similar to the above so I can then pass xobj along for further
> processing.
>
> Are there examples of this?
>
> Thanks,
>
> AJ
>
> Notice: This email message, together with any attachments, may contain
> information of BEA Systems, Inc., its subsidiaries and affiliated
> entities, that may be confidential, proprietary, copyrighted and/or
> legally
> privileged, and is intended solely for the use of the individual or entity
> named
> in this message. If you are not the intended recipient, and have received
> this
message in error, please immediately return this by email and then delete it.
--- Begin Message ---
Actually, I still am a bit confused but let me tell you a
couple of things to see if they are of any help:
- if the root element of your document is "known" by
XmlBeans, the the returned XmlObject is of the correct instance class, you don't
need to do anything else: xobj.getClass() should return
MyKnownDocumentImpl.class
- you can find out which document SchemaType it is by doing
"xobj.schemaType()"
Beyond this, in Java in general, if you want to write a
cast like "(MyKnownDocument) xobj" then you must of course know at the time
you write your code about MyKnownDocument...
Radu
I will rephrase my earlier question as it may have been a bit much:
I have seen this...
XmlObject xobj = XmlObject.Factory.parse(myDocument);
if (xobj instanceof MyKnownDocument ) {
MyKnownDocument mydoc = (MyKnownDocument
)xobj;
if
(!xobj.validate())
System.out.println("Not a valid my-order document");
}
...which is fine if you have knowledge of MyKnownDocument to begin with. If
you do not know it, is it possible to extract the document type associated with
myDocument/xobj, and then cast xobj to that? The myDocument is an instance of
_some_ kind of Document, I just need to find out _which_ Document, then
cast it similar to the above so I can then pass xobj along for further
processing.
Are there examples of this?
Thanks,
AJ
Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
--- End Message ---
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]