001: package org.geotools.maven.xmlcodegen.templates;
002:
003: import java.util.*;
004: import org.eclipse.xsd.*;
005: import org.geotools.xml.*;
006: import org.geotools.maven.xmlcodegen.*;
007:
008: public class BindingInterfaceTemplate {
009: protected static String nl;
010:
011: public static synchronized BindingInterfaceTemplate create(
012: String lineSeparator) {
013: nl = lineSeparator;
014: BindingInterfaceTemplate result = new BindingInterfaceTemplate();
015: nl = null;
016: return result;
017: }
018:
019: protected final String NL = nl == null ? (System.getProperties()
020: .getProperty("line.separator")) : nl;
021: protected final String TEXT_1 = NL
022: + "import javax.xml.namespace.QName;"
023: + NL
024: + ""
025: + NL
026: + "/**"
027: + NL
028: + " * This interface contains the qualified names of all the types,elements, and "
029: + NL + " * attributes in the ";
030: protected final String TEXT_2 = " schema." + NL + " *" + NL
031: + " * @generated" + NL + " */" + NL + "public interface ";
032: protected final String TEXT_3 = " {" + NL + "" + NL
033: + "\t/** @generated */" + NL
034: + "\tpublic static final String NAMESPACE = \"";
035: protected final String TEXT_4 = "\";" + NL + "\t" + NL
036: + "\t/* Type Definitions */";
037: protected final String TEXT_5 = NL + "\t/** @generated */" + NL
038: + "\tpublic static final QName ";
039: protected final String TEXT_6 = " = " + NL + "\t\tnew QName(\"";
040: protected final String TEXT_7 = "\",\"";
041: protected final String TEXT_8 = "\");";
042: protected final String TEXT_9 = NL + NL + "\t/* Elements */";
043: protected final String TEXT_10 = NL + "\t/** @generated */" + NL
044: + "\tpublic static final QName ";
045: protected final String TEXT_11 = " = " + NL + "\t\tnew QName(\"";
046: protected final String TEXT_12 = "\",\"";
047: protected final String TEXT_13 = "\");";
048: protected final String TEXT_14 = NL + NL + "\t/* Attributes */"
049: + NL + "\t";
050: protected final String TEXT_15 = NL + "\t/** @generated */" + NL
051: + "\tpublic static final QName ";
052: protected final String TEXT_16 = " = " + NL + "\t\tnew QName(\"";
053: protected final String TEXT_17 = "\",\"";
054: protected final String TEXT_18 = "\");";
055: protected final String TEXT_19 = NL + NL + "}" + NL + "\t";
056:
057: public String generate(Object argument) {
058: final StringBuffer stringBuffer = new StringBuffer();
059:
060: XSDSchema schema = (XSDSchema) argument;
061: String ns = schema.getTargetNamespace();
062: String prefix = Schemas.getTargetPrefix(schema);
063:
064: stringBuffer.append(TEXT_1);
065: stringBuffer.append(schema.getTargetNamespace());
066: stringBuffer.append(TEXT_2);
067: stringBuffer.append(prefix.toUpperCase());
068: stringBuffer.append(TEXT_3);
069: stringBuffer.append(ns);
070: stringBuffer.append(TEXT_4);
071:
072: List types = GeneratorUtils.allTypes(schema);
073: for (Iterator itr = types.iterator(); itr.hasNext();) {
074: XSDTypeDefinition type = (XSDTypeDefinition) itr.next();
075: if (type.getName() == null)
076: continue;
077: if (!ns.equals(type.getTargetNamespace()))
078: continue;
079:
080: stringBuffer.append(TEXT_5);
081: stringBuffer.append(type.getName());
082: stringBuffer.append(TEXT_6);
083: stringBuffer.append(ns);
084: stringBuffer.append(TEXT_7);
085: stringBuffer.append(type.getName());
086: stringBuffer.append(TEXT_8);
087:
088: }
089:
090: stringBuffer.append(TEXT_9);
091:
092: List elements = schema.getElementDeclarations();
093: for (Iterator itr = elements.iterator(); itr.hasNext();) {
094: XSDElementDeclaration element = (XSDElementDeclaration) itr
095: .next();
096: if (element.getName() == null)
097: continue;
098: if (!ns.equals(element.getTargetNamespace()))
099: continue;
100:
101: stringBuffer.append(TEXT_10);
102: stringBuffer.append(element.getName());
103: stringBuffer.append(TEXT_11);
104: stringBuffer.append(ns);
105: stringBuffer.append(TEXT_12);
106: stringBuffer.append(element.getName());
107: stringBuffer.append(TEXT_13);
108:
109: }
110:
111: stringBuffer.append(TEXT_14);
112:
113: List attributes = schema.getAttributeDeclarations();
114: for (Iterator itr = attributes.iterator(); itr.hasNext();) {
115: XSDAttributeDeclaration attribute = (XSDAttributeDeclaration) itr
116: .next();
117: if (attribute.getName() == null)
118: continue;
119: if (!ns.equals(attribute.getTargetNamespace()))
120: continue;
121:
122: stringBuffer.append(TEXT_15);
123: stringBuffer.append(attribute.getName());
124: stringBuffer.append(TEXT_16);
125: stringBuffer.append(ns);
126: stringBuffer.append(TEXT_17);
127: stringBuffer.append(attribute.getName());
128: stringBuffer.append(TEXT_18);
129:
130: }
131:
132: stringBuffer.append(TEXT_19);
133: return stringBuffer.toString();
134: }
135: }
|