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, "
+ (this.canSearchParents
? "true"
: "false") + ");");
pw.println();
pw.println(" static {");
pw.println(" typeDesc.setXmlType("
+ Utils.getNewQName(type.getQName()) + ");");
// Add attribute and element field descriptors
if ((attributes != null) || (elementMetaData != null)) {
if (attributes != null) {
boolean wroteAttrDecl = false;
for (int i = 0; i < attributes.size(); i++) {
ContainedAttribute attr = (ContainedAttribute) attributes.get(i);
TypeEntry te = attr.getType();
QName attrName = attr.getQName();
String fieldName = getAsFieldName(attr.getName());
QName attrXmlType = te.getQName();
pw.print(" ");
if (!wroteAttrDecl) {
pw.print("org.apache.axis.description.AttributeDesc ");
wroteAttrDecl = true;
}
pw.println(
"attrField = new org.apache.axis.description.AttributeDesc();");
pw.println(" attrField.setFieldName(\"" + fieldName
+ "\");");
pw.println(" attrField.setXmlName("
+ Utils.getNewQNameWithLastLocalPart(attrName) + ");");
if (attrXmlType != null) {
pw.println(" attrField.setXmlType("
+ Utils.getNewQName(attrXmlType) + ");");
}
pw.println(" typeDesc.addFieldDesc(attrField);");
}
}
if (elementMetaData != null) {
boolean wroteElemDecl = false;
for (int i = 0; i < elementMetaData.size(); i++) {
ElementDecl elem =
(ElementDecl) elementMetaData.elementAt(i);
if (elem.getAnyElement()) {
continue;
}
String fieldName = getAsFieldName(elem.getName());
QName xmlName = elem.getQName();
// Some special handling for arrays.
TypeEntry elemType = elem.getType();
QName xmlType = null;
if ((elemType.getDimensions().length() > 1)
&& (elemType.getClass() == DefinedType.class)) {
// If we have a DefinedType with dimensions, it must
// be a SOAP array derived type. In this case, use
// the refType's QName for the metadata.
xmlType = elemType.getRefType().getQName();
} else {
// Otherwise, use the type at the end of the ref
// chain.
while (elemType.getRefType() != null) {
elemType = elemType.getRefType();
}
xmlType = elemType.getQName();
}
pw.print(" ");
if (!wroteElemDecl) {
pw.print("org.apache.axis.description.ElementDesc ");
wroteElemDecl = true;
}
pw.println(
"elemField = new org.apache.axis.description.ElementDesc();");
pw.println(" elemField.setFieldName(\"" + fieldName
+ "\");");
pw.println(" elemField.setXmlName("
+ Utils.getNewQNameWithLastLocalPart(xmlName) + ");");
if (xmlType != null) {
pw.println(" elemField.setXmlType("
+ Utils.getNewQName(xmlType) + ");");
}
if (elem.getMinOccursIs0()) {
pw.println(" elemField.setMinOccurs(0);");
}
if (elem.getNillable()) {
pw.println(" elemField.setNillable(true);");
}
pw.println(" typeDesc.addFieldDesc(elemField);");
}