*/
protected void writeMetaData(PrintWriter pw) throws IOException {
// Collect elementMetaData
if (elements != null) {
for (int i = 0; i < elements.size(); i++) {
ElementDecl elem = (ElementDecl)elements.get(i);
// String elemName = elem.getName().getLocalPart();
// String javaName = Utils.xmlNameToJava(elemName);
// Changed the code to write meta data
// for all of the elements in order to
// support sequences. Defect 9060
// Meta data is needed if the default serializer
// action cannot map the javaName back to the
// element's qname. This occurs if:
// - the javaName and element name local part are different.
// - the javaName starts with uppercase char (this is a wierd
// case and we have several problems with the mapping rules.
// Seems best to gen meta data in this case.)
// - the element name is qualified (has a namespace uri)
// its also needed if:
// - the element has the minoccurs flag set
//if (!javaName.equals(elemName) ||
// Character.isUpperCase(javaName.charAt(0)) ||
//!elem.getName().getNamespaceURI().equals("") ||
//elem.getMinOccursIs0()) {
// If we did some mangling, make sure we'll write out the XML
// the correct way.
if (elementMetaData == null)
elementMetaData = new Vector();
elementMetaData.add(elem);
//}
}
}
pw.println(" // " + Messages.getMessage("typeMeta"));
pw.println(" private static org.apache.axis.description.TypeDesc typeDesc =");
pw.println(" new org.apache.axis.description.TypeDesc(" +
Utils.getJavaLocalName(type.getName()) + ".class);");
pw.println();
// Add attribute and element field descriptors
if (attributes != null || elementMetaData != null) {
boolean wroteFieldType = false;
pw.println(" static {");
if (attributes != null) {
for (int i = 0; i < attributes.size(); i += 2) {
TypeEntry te = (TypeEntry) attributes.get(i);
QName attrName = (QName) attributes.get(i + 1);
String attrLocalName = attrName.getLocalPart();
String fieldName = Utils.xmlNameToJava(attrLocalName);
fieldName = getAsFieldName(fieldName);
QName attrXmlType = te.getQName();
pw.print(" ");
if (!wroteFieldType) {
pw.print("org.apache.axis.description.FieldDesc ");
wroteFieldType = true;
}
pw.println("field = new org.apache.axis.description.AttributeDesc();");
pw.println(" field.setFieldName(\"" + fieldName + "\");");
pw.println(" field.setXmlName(" + Utils.getNewQName(attrName) + ");");
if (attrXmlType != null) {
pw.println(" field.setXmlType(" + Utils.getNewQName(attrXmlType) + ");");
}
pw.println(" typeDesc.addFieldDesc(field);");
}
}
if (elementMetaData != null) {
for (int i=0; i<elementMetaData.size(); i++) {
ElementDecl elem = (ElementDecl) elementMetaData.elementAt(i);
if (elem.getAnyElement()) {
continue;
}
String elemLocalName = elem.getName().getLocalPart();
String fieldName = Utils.xmlNameToJava(elemLocalName);
fieldName = getAsFieldName(fieldName);
QName xmlName = elem.getName();
// Some special handling for arrays
TypeEntry elemType = elem.getType();
while (elemType.getRefType() != null) {
elemType = elemType.getRefType();
}
QName xmlType = elemType.getQName();
if (xmlType != null && xmlType.getLocalPart().indexOf("[") > 0) {
// Skip array types, because they are special
xmlType = null;
}
pw.print(" ");
if (!wroteFieldType) {
pw.print("org.apache.axis.description.FieldDesc ");
wroteFieldType = true;
}
pw.println("field = new org.apache.axis.description.ElementDesc();");
pw.println(" field.setFieldName(\"" + fieldName + "\");");
pw.println(" field.setXmlName(" + Utils.getNewQName(xmlName) + ");");
if (xmlType != null) {
pw.println(" field.setXmlType(" + Utils.getNewQName(xmlType) + ");");
}
if (elem.getMinOccursIs0()) {
pw.println(" field.setMinOccursIs0(true);");
}
pw.println(" typeDesc.addFieldDesc(field);");
}
}