001: package org.geotools.maven.xmlcodegen.templates;
002:
003: import java.util.*;
004: import java.io.*;
005: import org.eclipse.xsd.*;
006: import org.geotools.xml.*;
007:
008: public class ConfigurationTemplate {
009: protected static String nl;
010:
011: public static synchronized ConfigurationTemplate create(
012: String lineSeparator) {
013: nl = lineSeparator;
014: ConfigurationTemplate result = new ConfigurationTemplate();
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 = "import org.eclipse.xsd.util.XSDSchemaLocationResolver;\t"
022: + NL
023: + "import org.geotools.xml.BindingConfiguration;"
024: + NL
025: + "import org.geotools.xml.Configuration;"
026: + NL
027: + ""
028: + NL
029: + "/**" + NL + " * Parser configuration for the ";
030: protected final String TEXT_2 = " schema." + NL + " *" + NL
031: + " * @generated" + NL + " */" + NL + "public class ";
032: protected final String TEXT_3 = "Configuration extends Configuration {"
033: + NL
034: + ""
035: + NL
036: + " /**"
037: + NL
038: + " * Creates a new configuration."
039: + NL
040: + " * "
041: + NL
042: + " * @generated"
043: + NL
044: + " */ "
045: + NL
046: + " public ";
047: protected final String TEXT_4 = "Configuration() {" + NL
048: + " super();" + NL + " " + NL
049: + " //TODO: add dependencies here" + NL + " }"
050: + NL + " " + NL + " /**" + NL
051: + " * @return the schema namespace uri: ";
052: protected final String TEXT_5 = "." + NL + " * @generated" + NL
053: + " */" + NL + " public String getNamespaceURI() {"
054: + NL + " \treturn ";
055: protected final String TEXT_6 = ".NAMESPACE;" + NL + " }" + NL
056: + " " + NL + " /**" + NL
057: + " * @return the uri to the the ";
058: protected final String TEXT_7 = " ."
059: + NL
060: + " * @generated"
061: + NL
062: + " */"
063: + NL
064: + " public String getSchemaFileURL() {"
065: + NL
066: + " return getSchemaLocationResolver().resolveSchemaLocation( "
067: + NL + " null, getNamespaceURI(), \"";
068: protected final String TEXT_8 = "\"" + NL + " );" + NL
069: + " }" + NL + " " + NL + " /**" + NL
070: + " * @return new instanceof {@link ";
071: protected final String TEXT_9 = "BindingConfiguration}."
072: + NL
073: + " */ "
074: + NL
075: + " public BindingConfiguration getBindingConfiguration() {"
076: + NL + " \treturn new ";
077: protected final String TEXT_10 = "BindingConfiguration();" + NL
078: + " }" + NL + "} ";
079:
080: public String generate(Object argument) {
081: final StringBuffer stringBuffer = new StringBuffer();
082:
083: XSDSchema schema = (XSDSchema) argument;
084: String namespace = schema.getTargetNamespace();
085: String prefix = Schemas.getTargetPrefix(schema).toUpperCase();
086:
087: String file = new File(schema.eResource().getURI()
088: .toFileString()).getName();
089:
090: stringBuffer.append(TEXT_1);
091: stringBuffer.append(namespace);
092: stringBuffer.append(TEXT_2);
093: stringBuffer.append(prefix);
094: stringBuffer.append(TEXT_3);
095: stringBuffer.append(prefix);
096: stringBuffer.append(TEXT_4);
097: stringBuffer.append(namespace);
098: stringBuffer.append(TEXT_5);
099: stringBuffer.append(prefix);
100: stringBuffer.append(TEXT_6);
101: stringBuffer.append(file);
102: stringBuffer.append(TEXT_7);
103: stringBuffer.append(file);
104: stringBuffer.append(TEXT_8);
105: stringBuffer.append(prefix);
106: stringBuffer.append(TEXT_9);
107: stringBuffer.append(prefix);
108: stringBuffer.append(TEXT_10);
109: return stringBuffer.toString();
110: }
111: }
|