{
final StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(TEXT_1);
Object[] arguments = (Object[]) argument;
Schema schema = (Schema) arguments[0];
String prefix = (String) arguments[1];
prefix = prefix.toUpperCase();
SchemaGenerator sg = (SchemaGenerator) arguments[2];
List<AttributeType> types = sg.sort();
stringBuffer.append(TEXT_2);
Map<String, String> ns2import = new HashMap<String, String>();
for (Schema imported : sg.getImports()) {
String fullClassName = imported.getClass().getName();
String className = fullClassName.substring(fullClassName.lastIndexOf(".")+1);
ns2import.put(imported.getURI(), className);
stringBuffer.append(TEXT_3);
stringBuffer.append(fullClassName);
stringBuffer.append(TEXT_4);
}
stringBuffer.append(TEXT_5);
stringBuffer.append(prefix);
stringBuffer.append(TEXT_6);
Map<Name, String> typeBindings = sg.getTypeBindings();
for (AttributeType type : types) {
Name name = type.getName();
stringBuffer.append(TEXT_7);
XSDTypeDefinition xsdType = sg.getXSDType(type);
StringWriter writer = new StringWriter();
SAXTransformerFactory txFactory =
(SAXTransformerFactory) SAXTransformerFactory.newInstance();
TransformerHandler xmls;
try {
xmls = txFactory.newTransformerHandler();
} catch (TransformerConfigurationException e) {
throw new RuntimeException(e);
}
xmls.getTransformer().setOutputProperty(OutputKeys.METHOD, "XML");
xmls.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true");
xmls.getTransformer().setOutputProperty(OutputKeys.INDENT, "true");
try {
xmls.getTransformer().transform(new DOMSource(xsdType.getElement()), new StreamResult(writer));
}
catch (Exception e) {
e.printStackTrace();
return null;
}
String[] lines = writer.getBuffer().toString().split("\n");
for (int i = 0; i < lines.length; i++) {
stringBuffer.append(TEXT_8);
stringBuffer.append(lines[i].replaceAll("<","<").replaceAll(">",">"));
}
stringBuffer.append(TEXT_9);
String uri = name.getNamespaceURI();
String local = name.getLocalPart();
String binding;
if (typeBindings.containsKey(name)) {
binding = typeBindings.get(name) + ".class";
} else {
binding = type.getBinding().getName() + ".class";
}
String isIdentified = type.isIdentified() ? "true" : "false";
String isAbstract = type.isAbstract() ? "true" : "false";
String restrictions = "null";
String superType = "null";
if (type.getSuper() != null) {
superType = type.getSuper().getName()
.getLocalPart().toUpperCase() + "_TYPE";
String superURI = type.getSuper().getName().getNamespaceURI();
if (!uri.equals(superURI)) {
superType = ns2import.get(superURI) + "." + superType;
}
}
String description = "null";
if (type instanceof ComplexType && !typeBindings.containsKey(name)) {
stringBuffer.append(TEXT_10);
stringBuffer.append(name.getLocalPart().toUpperCase());
stringBuffer.append(TEXT_11);
stringBuffer.append(name.getLocalPart().toUpperCase());
stringBuffer.append(TEXT_12);
stringBuffer.append(name.getLocalPart().toUpperCase());
stringBuffer.append(TEXT_13);
stringBuffer.append(uri);
stringBuffer.append(TEXT_14);
stringBuffer.append(local);
stringBuffer.append(TEXT_15);
stringBuffer.append(TEXT_16);
stringBuffer.append(isIdentified);
stringBuffer.append(TEXT_17);
stringBuffer.append(isAbstract);
stringBuffer.append(TEXT_18);
stringBuffer.append(restrictions);
stringBuffer.append(TEXT_19);
stringBuffer.append(description);
stringBuffer.append(TEXT_20);
} else {
stringBuffer.append(TEXT_21);
stringBuffer.append(name.getLocalPart().toUpperCase());
stringBuffer.append(TEXT_22);
stringBuffer.append(name.getLocalPart().toUpperCase());
stringBuffer.append(TEXT_23);
stringBuffer.append(name.getLocalPart().toUpperCase());
stringBuffer.append(TEXT_24);
stringBuffer.append(uri);
stringBuffer.append(TEXT_25);
stringBuffer.append(local);
stringBuffer.append(TEXT_26);
stringBuffer.append(TEXT_27);
stringBuffer.append(binding);
stringBuffer.append(TEXT_28);
stringBuffer.append(isIdentified);
stringBuffer.append(TEXT_29);
stringBuffer.append(isAbstract);
stringBuffer.append(TEXT_30);
stringBuffer.append(restrictions);
stringBuffer.append(TEXT_31);
stringBuffer.append(description);
stringBuffer.append(TEXT_32);
}
stringBuffer.append(TEXT_33);
stringBuffer.append(superType);
stringBuffer.append(TEXT_34);
if (type instanceof ComplexType && !typeBindings.containsKey(name)) {
ComplexType cType = (ComplexType)type;
stringBuffer.append(TEXT_35);
if (cType.getDescriptors().isEmpty()) {
stringBuffer.append(TEXT_36);
} else {
stringBuffer.append(TEXT_37);
for (PropertyDescriptor pd : cType.getDescriptors()) {
if ( !(pd instanceof AttributeDescriptor) ) {
continue;
}
AttributeDescriptor ad = (AttributeDescriptor) pd;
AttributeType adType = ad.getType();
String adTypeName = adType.getName().getLocalPart().toUpperCase() +
"_TYPE";
String adTypeURI = adType.getName().getNamespaceURI();
if (!uri.equals(adTypeURI)) {
adTypeName = ns2import.get(adTypeURI) + "." + adTypeName;
}
String adName;
if (ad.getName().getNamespaceURI() == null) {
adName = "new NameImpl(\"" + ad.getName().getLocalPart() + "\")";
} else {
adName = "new NameImpl(\"" + ad.getName().getNamespaceURI() +
"\",\"" + ad.getName().getLocalPart() + "\")";
}
String min = ad.getMinOccurs() + "";
String max = ad.getMaxOccurs() + "";
String isNillable = ad.isNillable() ? "true" : "false";
stringBuffer.append(TEXT_38);
stringBuffer.append(TEXT_39);
stringBuffer.append(adTypeName);
stringBuffer.append(TEXT_40);
stringBuffer.append(TEXT_41);
stringBuffer.append(adName);
stringBuffer.append(TEXT_42);
stringBuffer.append(TEXT_43);
stringBuffer.append(min);
stringBuffer.append(TEXT_44);
stringBuffer.append(max);
stringBuffer.append(TEXT_45);
stringBuffer.append(isNillable);
stringBuffer.append(TEXT_46);
}
stringBuffer.append(TEXT_47);
}
stringBuffer.append(TEXT_48);
}
stringBuffer.append(TEXT_49);
if (!type.getUserData().isEmpty()) {
//attributes
for (Map.Entry<Object, Object> entry : type.getUserData().entrySet()) {
PropertyDescriptor pd = (PropertyDescriptor) entry.getValue();
PropertyType pdType = pd.getType();
String pdTypeName = pdType.getName().getLocalPart().toUpperCase() +
"_TYPE";
if (ns2import.containsKey(pdType.getName().getNamespaceURI())) {
String importClassName = (String) ns2import.get(pdType.getName().getNamespaceURI());
pdTypeName = importClassName + "." + pdTypeName;
}
String pdName = "new NameImpl(\"" + pd.getName().getNamespaceURI() +
"\",\"" + pd.getName().getLocalPart() + "\")";
stringBuffer.append(TEXT_50);
stringBuffer.append(pdName);
stringBuffer.append(TEXT_51);
stringBuffer.append(pdTypeName);
stringBuffer.append(TEXT_52);
}
}
stringBuffer.append(TEXT_53);
}
stringBuffer.append(TEXT_54);
stringBuffer.append(prefix);
stringBuffer.append(TEXT_55);
stringBuffer.append(schema.getURI());
stringBuffer.append(TEXT_56);
for (AttributeType type : types) {
stringBuffer.append(TEXT_57);