Hi, I’m generating a very large number of types from some schema we have here. I’m finding that for the most part this works very well, but for a relatively small number of types I find that despite making mappings in castorbuilder.properties to tell castor in which Java package to place the generated classes (based on the namespace of the source type) that it leaves some classes in the default package where (at least I think) it shouldn’t. This leads to compilation errors naturally as these types are used in other generated classes and cannot be found from within that package (where they should have gone).

 

I’ve had a close look at all the types that failed to make it into the target packages and the only thing that strikes me is that it is always a complex type, which contains an element which contains a complex type – that is an “inlined” complex type – not a reference to a pre-defined complex type.

 

An example might help!

 

Say I’ve got a complex type called Animals. Inside Animals, I have several elements; say giraffes, monkeys and dogs. Giraffes and dogs are pretty basic, for example:

 

<xs:element name="Dog" type="animal" nillable="true"/>

 

But Monkey is more complex – it contains an “inlined” complex type definition within itself.

 

The result appears to be that all these classes get generated, but Monkey doesn’t get the right package statement placed in the source – it gets no package statement and is hence in the default package.

 

Here is a standalone example that demonstrates the problem I have:

 

<xs:schema targetNamespace="http://www.mycompany.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">

    <xs:complexType name="MainTypeDefinition">

        <xs:annotation>

            <xs:documentation>Testing mapping namespaces to packages</xs:documentation>

        </xs:annotation>

        <xs:sequence>

            <xs:element name="FirstBrokenType" minOccurs="0" maxOccurs="unbounded">

                <xs:complexType>

                    <xs:sequence>

                        <xs:element name="WorkingType1" type="xs:string" minOccurs="0"/>

                        <xs:element name="WorkingType2" type="xs:string" minOccurs="0"/>

                        <xs:element name="WorkingType3" type="xs:string" minOccurs="0"/>

                        <xs:element name="SecondBrokenType">

                            <xs:complexType>

                                <xs:simpleContent>

                                    <xs:extension base="xs:string">

                                        <xs:attribute name="code" type="xs:string" use="required"/>

                                    </xs:extension>

                                </xs:simpleContent>

                            </xs:complexType>

                        </xs:element>

                        <xs:element name="WorkingType4" type="xs:string" minOccurs="0"/>

                    </xs:sequence>

                </xs:complexType>

            </xs:element>

        </xs:sequence>

    </xs:complexType>

</xs:schema>

 

When I generate the source using the following SourceGenerator using the following namespace mapping:

 

org.exolab.castor.builder.nspackages=http://www.mycompany.com=com.mycompany

 

Then the upshot is that MainTypeDefinition.java goes into the com/mycompany directory (and package) as expected; however, FirstBrokenType.java and SecondBrokenType.java are placed in the / directory with no package assigned to them. It’s not a huge problem for me, but it means I have to spend 20 minutes in Eclipse shifting classes around packages!

 

I did try forcing the target package using the –package option, and this placed the two “broken” types above into the package I told it to, but MainTypeDefinition.java doesn’t reference these correctly, the type names are unqualified in MainTypeDefinition.java

 

I’m running Castor 0.9.5.

 

Many thanks in advance for any help.

 

Kind regards, Keith.

 

 

Reply via email to