I use Castor 0.9.5 / 0.9.5.2 source generator with default settings to
create java classes from the following XSD (complete XSD see attachment)
<xs:complexType name="MD_MetadataType">
<xs:sequence>
<xs:element name="hierarchyLevel" type="adv:MD_ScopeCodeType"
minOccurs="0" maxOccurs="unbounded" default="dataset"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="MD_ScopeCodeType">
<xs:restriction base="xs:string">
<xs:enumeration value="attribute"/>
<xs:enumeration value="dataset"/>
</xs:restriction>
</xs:simpleType>
The source generator produces 4 java classes, 2 of them are descriptor
classes, wich I do not attach to this email.
The initialisation of the element 'hierarchyLevel' leads to a java
exception, because a java.util.Vector is about to be initialized with an object
MD_ScopeCodeType.
/**
* Field _hierarchyLevelList
*/
private java.util.Vector _hierarchyLevelList =
ibr.test.nascastorbug.types.MD_ScopeCodeType.valueOf("dataset");
In my opinion, the Vector has to be generated without initialization using
the '=' at declaration ...
private java.util.Vector _hierarchyLevelList;
...but it has to be initialized by adding the 'default' element "dataset" in
the
constructor:
_hierarchyLevelList.add(ibr.test.nascastorbug.types.MD_ScopeCodeType.valueOf("dataset"));
Source generator seems not to be able to handle elements with unbounded
'MaxOccurs' and a default value correctly.
Any comment and/or help? In the moment I correct the declaration line by
hand and add the "vector.add(...)" line to the constrcutor.
Thanks, Ulf
--
NEU F�R ALLE - GMX MediaCenter - f�r Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gru�, GMX FotoService
Jetzt kostenlos anmelden unter http://www.gmx.net
+++ GMX - die erste Adresse f�r Mail, Message, More! +++<?xml version="1.0" encoding="UTF-8"?>
<!--
Normbasierte Austauschschnittstelle NAS - ISO19100-Basisschema (Metadaten)
Erstellt: 24.05.2003 16:26:41
-->
<xs:schema
targetNamespace="http://www.adv-online.de/namespaces/adv"
xmlns:adv="http://www.adv-online.de/namespaces/adv"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
version="2.0">
<!--PART 2 - Type declarations-->
<xs:complexType name="MD_MetadataType">
<xs:sequence>
<xs:element name="hierarchyLevel" type="adv:MD_ScopeCodeType" minOccurs="0" maxOccurs="unbounded" default="dataset"/>
<xs:element name="hierarchyLevelName" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="MD_ScopeCodeType">
<xs:restriction base="xs:string">
<xs:enumeration value="attribute"/>
<xs:enumeration value="attributeType"/>
<xs:enumeration value="collectionHardware"/>
<xs:enumeration value="collectionSession"/>
<xs:enumeration value="dataset"/>
<xs:enumeration value="series"/>
<xs:enumeration value="nonGeographicDataset"/>
<xs:enumeration value="dimensionGroup"/>
<xs:enumeration value="feature"/>
<xs:enumeration value="featureType"/>
<xs:enumeration value="propertyType"/>
<xs:enumeration value="fieldSession"/>
<xs:enumeration value="software"/>
<xs:enumeration value="service"/>
<xs:enumeration value="model"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
/*
* This class was automatically generated with
*
Castor 0.9.4.3, using an XML
* Schema.
* $Id$
*/
package ibr.test.nascastorbug;
//---------------------------------/
//- Imported classes and packages -/
//---------------------------------/
import ibr.test.nascastorbug.types.MD_ScopeCodeType;
import java.io.Reader;
import java.io.Serializable;
import java.io.Writer;
import java.util.Enumeration;
import java.util.Vector;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
/**
* Class MD_MetadataType.
*
* @version $Revision$ $Date$
*/
public abstract class MD_MetadataType implements java.io.Serializable {
//--------------------------/
//- Class/Member Variables -/
//--------------------------/
/**
* Field _hierarchyLevelList
*/
private java.util.Vector _hierarchyLevelList = ibr.test.nascastorbug.types.MD_ScopeCodeType.valueOf("dataset");
/**
* Field _hierarchyLevelNameList
*/
private java.util.Vector _hierarchyLevelNameList;
//----------------/
//- Constructors -/
//----------------/
public MD_MetadataType() {
super();
_hierarchyLevelList = new Vector();
_hierarchyLevelNameList = new Vector();
} //-- ibr.test.nascastorbug.MD_MetadataType()
//-----------/
//- Methods -/
//-----------/
/**
* Method addHierarchyLevel
*
* @param vHierarchyLevel
*/
public void addHierarchyLevel(ibr.test.nascastorbug.types.MD_ScopeCodeType vHierarchyLevel)
throws java.lang.IndexOutOfBoundsException
{
_hierarchyLevelList.addElement(vHierarchyLevel);
} //-- void addHierarchyLevel(ibr.test.nascastorbug.types.MD_ScopeCodeType)
/**
* Method addHierarchyLevel
*
* @param index
* @param vHierarchyLevel
*/
public void addHierarchyLevel(int index, ibr.test.nascastorbug.types.MD_ScopeCodeType vHierarchyLevel)
throws java.lang.IndexOutOfBoundsException
{
_hierarchyLevelList.insertElementAt(vHierarchyLevel, index);
} //-- void addHierarchyLevel(int, ibr.test.nascastorbug.types.MD_ScopeCodeType)
/**
* Method addHierarchyLevelName
*
* @param vHierarchyLevelName
*/
public void addHierarchyLevelName(java.lang.String vHierarchyLevelName)
throws java.lang.IndexOutOfBoundsException
{
_hierarchyLevelNameList.addElement(vHierarchyLevelName);
} //-- void addHierarchyLevelName(java.lang.String)
/**
* Method addHierarchyLevelName
*
* @param index
* @param vHierarchyLevelName
*/
public void addHierarchyLevelName(int index, java.lang.String vHierarchyLevelName)
throws java.lang.IndexOutOfBoundsException
{
_hierarchyLevelNameList.insertElementAt(vHierarchyLevelName, index);
} //-- void addHierarchyLevelName(int, java.lang.String)
/**
* Method enumerateHierarchyLevel
*/
public java.util.Enumeration enumerateHierarchyLevel()
{
return _hierarchyLevelList.elements();
} //-- java.util.Enumeration enumerateHierarchyLevel()
/**
* Method enumerateHierarchyLevelName
*/
public java.util.Enumeration enumerateHierarchyLevelName()
{
return _hierarchyLevelNameList.elements();
} //-- java.util.Enumeration enumerateHierarchyLevelName()
/**
* Method getHierarchyLevel
*
* @param index
*/
public ibr.test.nascastorbug.types.MD_ScopeCodeType getHierarchyLevel(int index)
throws java.lang.IndexOutOfBoundsException
{
//-- check bounds for index
if ((index < 0) || (index > _hierarchyLevelList.size())) {
throw new IndexOutOfBoundsException();
}
return (ibr.test.nascastorbug.types.MD_ScopeCodeType) _hierarchyLevelList.elementAt(index);
} //-- ibr.test.nascastorbug.types.MD_ScopeCodeType getHierarchyLevel(int)
/**
* Method getHierarchyLevel
*/
public ibr.test.nascastorbug.types.MD_ScopeCodeType[] getHierarchyLevel()
{
int size = _hierarchyLevelList.size();
ibr.test.nascastorbug.types.MD_ScopeCodeType[] mArray = new ibr.test.nascastorbug.types.MD_ScopeCodeType[size];
for (int index = 0; index < size; index++) {
mArray[index] = (ibr.test.nascastorbug.types.MD_ScopeCodeType) _hierarchyLevelList.elementAt(index);
}
return mArray;
} //-- ibr.test.nascastorbug.types.MD_ScopeCodeType[] getHierarchyLevel()
/**
* Method getHierarchyLevelCount
*/
public int getHierarchyLevelCount()
{
return _hierarchyLevelList.size();
} //-- int getHierarchyLevelCount()
/**
* Method getHierarchyLevelName
*
* @param index
*/
public java.lang.String getHierarchyLevelName(int index)
throws java.lang.IndexOutOfBoundsException
{
//-- check bounds for index
if ((index < 0) || (index > _hierarchyLevelNameList.size())) {
throw new IndexOutOfBoundsException();
}
return (String)_hierarchyLevelNameList.elementAt(index);
} //-- java.lang.String getHierarchyLevelName(int)
/**
* Method getHierarchyLevelName
*/
public java.lang.String[] getHierarchyLevelName()
{
int size = _hierarchyLevelNameList.size();
java.lang.String[] mArray = new java.lang.String[size];
for (int index = 0; index < size; index++) {
mArray[index] = (String)_hierarchyLevelNameList.elementAt(index);
}
return mArray;
} //-- java.lang.String[] getHierarchyLevelName()
/**
* Method getHierarchyLevelNameCount
*/
public int getHierarchyLevelNameCount()
{
return _hierarchyLevelNameList.size();
} //-- int getHierarchyLevelNameCount()
/**
* Method isValid
*/
public boolean isValid()
{
try {
validate();
}
catch (org.exolab.castor.xml.ValidationException vex) {
return false;
}
return true;
} //-- boolean isValid()
/**
* Method removeAllHierarchyLevel
*/
public void removeAllHierarchyLevel()
{
_hierarchyLevelList.removeAllElements();
} //-- void removeAllHierarchyLevel()
/**
* Method removeAllHierarchyLevelName
*/
public void removeAllHierarchyLevelName()
{
_hierarchyLevelNameList.removeAllElements();
} //-- void removeAllHierarchyLevelName()
/**
* Method removeHierarchyLevel
*
* @param index
*/
public ibr.test.nascastorbug.types.MD_ScopeCodeType removeHierarchyLevel(int index)
{
java.lang.Object obj = _hierarchyLevelList.elementAt(index);
_hierarchyLevelList.removeElementAt(index);
return (ibr.test.nascastorbug.types.MD_ScopeCodeType) obj;
} //-- ibr.test.nascastorbug.types.MD_ScopeCodeType removeHierarchyLevel(int)
/**
* Method removeHierarchyLevelName
*
* @param index
*/
public java.lang.String removeHierarchyLevelName(int index)
{
java.lang.Object obj = _hierarchyLevelNameList.elementAt(index);
_hierarchyLevelNameList.removeElementAt(index);
return (String)obj;
} //-- java.lang.String removeHierarchyLevelName(int)
/**
* Method setHierarchyLevel
*
* @param index
* @param vHierarchyLevel
*/
public void setHierarchyLevel(int index, ibr.test.nascastorbug.types.MD_ScopeCodeType vHierarchyLevel)
throws java.lang.IndexOutOfBoundsException
{
//-- check bounds for index
if ((index < 0) || (index > _hierarchyLevelList.size())) {
throw new IndexOutOfBoundsException();
}
_hierarchyLevelList.setElementAt(vHierarchyLevel, index);
} //-- void setHierarchyLevel(int, ibr.test.nascastorbug.types.MD_ScopeCodeType)
/**
* Method setHierarchyLevel
*
* @param hierarchyLevelArray
*/
public void setHierarchyLevel(ibr.test.nascastorbug.types.MD_ScopeCodeType[] hierarchyLevelArray)
{
//-- copy array
_hierarchyLevelList.removeAllElements();
for (int i = 0; i < hierarchyLevelArray.length; i++) {
_hierarchyLevelList.addElement(hierarchyLevelArray[i]);
}
} //-- void setHierarchyLevel(ibr.test.nascastorbug.types.MD_ScopeCodeType)
/**
* Method setHierarchyLevelName
*
* @param index
* @param vHierarchyLevelName
*/
public void setHierarchyLevelName(int index, java.lang.String vHierarchyLevelName)
throws java.lang.IndexOutOfBoundsException
{
//-- check bounds for index
if ((index < 0) || (index > _hierarchyLevelNameList.size())) {
throw new IndexOutOfBoundsException();
}
_hierarchyLevelNameList.setElementAt(vHierarchyLevelName, index);
} //-- void setHierarchyLevelName(int, java.lang.String)
/**
* Method setHierarchyLevelName
*
* @param hierarchyLevelNameArray
*/
public void setHierarchyLevelName(java.lang.String[] hierarchyLevelNameArray)
{
//-- copy array
_hierarchyLevelNameList.removeAllElements();
for (int i = 0; i < hierarchyLevelNameArray.length; i++) {
_hierarchyLevelNameList.addElement(hierarchyLevelNameArray[i]);
}
} //-- void setHierarchyLevelName(java.lang.String)
/**
* Method validate
*/
public void validate()
throws org.exolab.castor.xml.ValidationException
{
org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
validator.validate(this);
} //-- void validate()
}
/*
* This class was automatically generated with
*
Castor 0.9.4.3, using an XML
* Schema.
* $Id$
*/
package ibr.test.nascastorbug.types;
//---------------------------------/
//- Imported classes and packages -/
//---------------------------------/
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
/**
* Class MD_ScopeCodeType.
*
* @version $Revision$ $Date$
*/
public class MD_ScopeCodeType implements java.io.Serializable {
//--------------------------/
//- Class/Member Variables -/
//--------------------------/
/**
* The attribute type
*/
public static final int ATTRIBUTE_TYPE = 0;
/**
* The instance of the attribute type
*/
public static final MD_ScopeCodeType ATTRIBUTE = new MD_ScopeCodeType(ATTRIBUTE_TYPE, "attribute");
/**
* The attributeType type
*/
public static final int ATTRIBUTETYPE_TYPE = 1;
/**
* The instance of the attributeType type
*/
public static final MD_ScopeCodeType ATTRIBUTETYPE = new MD_ScopeCodeType(ATTRIBUTETYPE_TYPE, "attributeType");
/**
* The collectionHardware type
*/
public static final int COLLECTIONHARDWARE_TYPE = 2;
/**
* The instance of the collectionHardware type
*/
public static final MD_ScopeCodeType COLLECTIONHARDWARE = new MD_ScopeCodeType(COLLECTIONHARDWARE_TYPE, "collectionHardware");
/**
* The collectionSession type
*/
public static final int COLLECTIONSESSION_TYPE = 3;
/**
* The instance of the collectionSession type
*/
public static final MD_ScopeCodeType COLLECTIONSESSION = new MD_ScopeCodeType(COLLECTIONSESSION_TYPE, "collectionSession");
/**
* The dataset type
*/
public static final int DATASET_TYPE = 4;
/**
* The instance of the dataset type
*/
public static final MD_ScopeCodeType DATASET = new MD_ScopeCodeType(DATASET_TYPE, "dataset");
/**
* The series type
*/
public static final int SERIES_TYPE = 5;
/**
* The instance of the series type
*/
public static final MD_ScopeCodeType SERIES = new MD_ScopeCodeType(SERIES_TYPE, "series");
/**
* The nonGeographicDataset type
*/
public static final int NONGEOGRAPHICDATASET_TYPE = 6;
/**
* The instance of the nonGeographicDataset type
*/
public static final MD_ScopeCodeType NONGEOGRAPHICDATASET = new MD_ScopeCodeType(NONGEOGRAPHICDATASET_TYPE, "nonGeographicDataset");
/**
* The dimensionGroup type
*/
public static final int DIMENSIONGROUP_TYPE = 7;
/**
* The instance of the dimensionGroup type
*/
public static final MD_ScopeCodeType DIMENSIONGROUP = new MD_ScopeCodeType(DIMENSIONGROUP_TYPE, "dimensionGroup");
/**
* The feature type
*/
public static final int FEATURE_TYPE = 8;
/**
* The instance of the feature type
*/
public static final MD_ScopeCodeType FEATURE = new MD_ScopeCodeType(FEATURE_TYPE, "feature");
/**
* The featureType type
*/
public static final int FEATURETYPE_TYPE = 9;
/**
* The instance of the featureType type
*/
public static final MD_ScopeCodeType FEATURETYPE = new MD_ScopeCodeType(FEATURETYPE_TYPE, "featureType");
/**
* The propertyType type
*/
public static final int PROPERTYTYPE_TYPE = 10;
/**
* The instance of the propertyType type
*/
public static final MD_ScopeCodeType PROPERTYTYPE = new MD_ScopeCodeType(PROPERTYTYPE_TYPE, "propertyType");
/**
* The fieldSession type
*/
public static final int FIELDSESSION_TYPE = 11;
/**
* The instance of the fieldSession type
*/
public static final MD_ScopeCodeType FIELDSESSION = new MD_ScopeCodeType(FIELDSESSION_TYPE, "fieldSession");
/**
* The software type
*/
public static final int SOFTWARE_TYPE = 12;
/**
* The instance of the software type
*/
public static final MD_ScopeCodeType SOFTWARE = new MD_ScopeCodeType(SOFTWARE_TYPE, "software");
/**
* The service type
*/
public static final int SERVICE_TYPE = 13;
/**
* The instance of the service type
*/
public static final MD_ScopeCodeType SERVICE = new MD_ScopeCodeType(SERVICE_TYPE, "service");
/**
* The model type
*/
public static final int MODEL_TYPE = 14;
/**
* The instance of the model type
*/
public static final MD_ScopeCodeType MODEL = new MD_ScopeCodeType(MODEL_TYPE, "model");
/**
* Field _memberTable
*/
private static java.util.Hashtable _memberTable = init();
/**
* Field type
*/
private int type = -1;
/**
* Field stringValue
*/
private java.lang.String stringValue = null;
//----------------/
//- Constructors -/
//----------------/
private MD_ScopeCodeType(int type, java.lang.String value) {
super();
this.type = type;
this.stringValue = value;
} //-- ibr.test.nascastorbug.types.MD_ScopeCodeType(int, java.lang.String)
//-----------/
//- Methods -/
//-----------/
/**
* Method enumerateReturns an enumeration of all possible
* instances of MD_ScopeCodeType
*/
public static java.util.Enumeration enumerate()
{
return _memberTable.elements();
} //-- java.util.Enumeration enumerate()
/**
* Method getTypeReturns the type of this MD_ScopeCodeType
*/
public int getType()
{
return this.type;
} //-- int getType()
/**
* Method init
*/
private static java.util.Hashtable init()
{
Hashtable members = new Hashtable();
members.put("attribute", ATTRIBUTE);
members.put("attributeType", ATTRIBUTETYPE);
members.put("collectionHardware", COLLECTIONHARDWARE);
members.put("collectionSession", COLLECTIONSESSION);
members.put("dataset", DATASET);
members.put("series", SERIES);
members.put("nonGeographicDataset", NONGEOGRAPHICDATASET);
members.put("dimensionGroup", DIMENSIONGROUP);
members.put("feature", FEATURE);
members.put("featureType", FEATURETYPE);
members.put("propertyType", PROPERTYTYPE);
members.put("fieldSession", FIELDSESSION);
members.put("software", SOFTWARE);
members.put("service", SERVICE);
members.put("model", MODEL);
return members;
} //-- java.util.Hashtable init()
/**
* Method toStringReturns the String representation of this
* MD_ScopeCodeType
*/
public java.lang.String toString()
{
return this.stringValue;
} //-- java.lang.String toString()
/**
* Method valueOfReturns a new MD_ScopeCodeType based on the
* given String value.
*
* @param string
*/
public static ibr.test.nascastorbug.types.MD_ScopeCodeType valueOf(java.lang.String string)
{
java.lang.Object obj = null;
if (string != null) obj = _memberTable.get(string);
if (obj == null) {
String err = "'" + string + "' is not a valid MD_ScopeCodeType";
throw new IllegalArgumentException(err);
}
return (MD_ScopeCodeType) obj;
} //-- ibr.test.nascastorbug.types.MD_ScopeCodeType valueOf(java.lang.String)
}