AW: Inheritance problem, instance gets always super type

Oliver Pfau <[email protected]>
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <[email protected]>
Hi,

I figured out that the problem is not in the xsd definitions. In the main method of a test class all works. In my application no more. I assume it is because it is an osgi application. Someone an idea what I can do ?

Regards
Oliver



-----Ursprüngliche Nachricht-----
Von: Oliver Pfau 
Gesendet: Dienstag, 6. Oktober 2009 10:31
An: '[email protected]'
Betreff: Inheritance problem, instance gets always super type

 Hi , instance gets always super type


Hi,
 
I have a problem using xmlbeans with inherited types with java. In my commons.xsd there is a complex type Operation and some other types which are extending Operation. In a MoreSpecifix.xsd is commons.xsd imported and a complex type Config is declared. This type Config does declare a sequence of Operation. So it should be possible to add all types which extend Operation to the sequence in Config.
 
After the generation of the java classes I run into the following problems:
 
First try:
final ConfigDocument configDocument = ConfigDocument.Factory.newInstance();
final Config newConfig = configDocument.addNewConfig();

final Operation[] ops = new OperationType[1];

ops[0] = createConcreteOperationDummy();

newConfig.setOperationArray(ops);

With the last line my concrete operation instance gets the type from the super class Operation and I can no more access the extended fields.

Second try:

final ConfigDocument configDocument = ConfigDocument.Factory.newInstance();

final Config newConfig = configDocument.addNewConfig();

final Operation newOperation = newConfig.addNewOperation();

final ConcreteOperation concreteOp = (ConcreteOperation) newOperation.changeType(ConcreteOperation.type);

On the last line I get a ClassCastException. 

Has someone an idea what is wrong ? Probably the xsd definitions (made with XMLSpy) ?

Regards,

Oliver
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.