%@ jet package="org.geotools.maven.xmlcodegen.templates" imports="java.util.* org.apache.xml.serialize.* org.eclipse.xsd.* java.io.* org.geotools.xml.*" %> <% Object[] arguments = (Object[]) argument; XSDNamedComponent named = (XSDNamedComponent)arguments[0]; Map constructorArgs = (Map) arguments[1]; XSDSchema schema = named.getSchema(); XSDTypeDefinition type = null; String desc = null; if (named instanceof XSDTypeDefinition) { type = (XSDTypeDefinition)named; desc = "type"; } if (named instanceof XSDElementDeclaration) { type = ((XSDElementDeclaration)named).getTypeDefinition(); desc = "element"; } if (named instanceof XSDAttributeDeclaration) { type = ((XSDAttributeDeclaration)named).getTypeDefinition(); desc = "attribute"; } String ns = schema.getTargetNamespace(); String prefix = Schemas.getTargetPrefix( schema ); %> import org.geotools.xml.*; <% if ( constructorArgs != null ) { for ( Iterator i = constructorArgs.values().iterator(); i.hasNext(); ) { Class arg = (Class) i.next(); %> import <%=arg.getName()%>; <% } } %> import javax.xml.namespace.QName; /** * Binding object for the <%=desc%> <%=named.getTargetNamespace()%>:<%=named.getName()%>. * *
*
*
<%
OutputFormat output = new OutputFormat();
output.setOmitXMLDeclaration(true);
output.setIndenting(true);
StringWriter writer = new StringWriter();
XMLSerializer serializer = new XMLSerializer(writer,output);
try {
serializer.serialize(named.getElement());
}
catch (IOException e) {
e.printStackTrace();
return null;
}
String[] lines = writer.getBuffer().toString().split("\n");
for (int i = 0; i < lines.length; i++) {
%>
* <%=lines[i].replaceAll("<","<").replaceAll(">",">")%>
<%
}
%>
*
*
*
*
*
* @generated
*/
<%
String className = named.getName().substring(0,1).toUpperCase() +
named.getName().substring(1) + "Binding";
if (type instanceof XSDSimpleTypeDefinition) {
%>
public class <%=className%> extends AbstractSimpleBinding {
<%
}
else {
%>
public class <%=className%> extends AbstractComplexBinding {
<%
}
%>
<%
if ( constructorArgs != null ) {
List fieldNames = new ArrayList();
StringBuffer constructor = new StringBuffer();
constructor.append("public " + className + "( ");
for ( Iterator i = constructorArgs.entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry) i.next();
String fieldName = (String) entry.getKey();
Class arg = (Class) entry.getValue();
String typeName = arg.getName();
if ( typeName.lastIndexOf( '.' ) != -1 ) {
typeName = typeName.substring( typeName.lastIndexOf( '.') + 1 );
}
fieldNames.add( fieldName );
%>
<%=typeName%> <%=fieldName%>;
<%
constructor.append( typeName + " " + fieldName );
if ( i.hasNext() ) {
constructor.append( "," );
}
}
constructor.append( " ) {\n");
for ( int i = 0; i < fieldNames.size(); i++ ) {
String fieldName = (String)fieldNames.get( i );
constructor.append( "\t\tthis." + fieldName + " = " + fieldName + ";\n");
}
constructor.append( "\t}\n" );
%>
<%=constructor.toString()%>
<%
}
%>
/**
* @generated
*/
public QName getTarget() {
return <%=prefix.toUpperCase()%>.<%=named.getName()%>;
}
/**
*
*
*
* @generated modifiable
*/
public Class getType() {
return null;
}
<%
if (type instanceof XSDSimpleTypeDefinition) {
%>
/**
*
*
*
* @generated modifiable
*/
public Object parse(InstanceComponent instance, Object value)
throws Exception {
//TODO: implement
return null;
}
<%
}
else {
%>
/**
*
*
*
* @generated modifiable
*/
public Object parse(ElementInstance instance, Node node, Object value)
throws Exception {
//TODO: implement
return null;
}
<%
}
%>
}