typeDefintion =
(QName) context.getComponentInstance("http://geotools.org/typeDefinition");
}
if (typeDefintion != null) {
XSDTypeDefinition type = index.getTypeDefinition(typeDefintion);
if (type == null) {
throw new NullPointerException();
}
//create a mock element declaration
root = XSDFactory.eINSTANCE.createXSDElementDeclaration();
root.setName(name.getLocalPart());
root.setTargetNamespace(name.getNamespaceURI());
root.setTypeDefinition(type);
}
}
if (root == null) {
String msg = "Could not find element declaration for:" + name;
throw new IllegalArgumentException(msg);
}
encoded.add(new EncodingEntry(object, root, null));
while (!encoded.isEmpty()) {
EncodingEntry entry = (EncodingEntry) encoded.peek();
if (entry.encoding != null) {
//element has been started, get the next child
if (!entry.children.isEmpty()) {
Object[] child = (Object[]) entry.children.get(0);
XSDElementDeclaration element = (XSDElementDeclaration) child[0];
Iterator itr = (Iterator) child[1];
if (itr.hasNext()) {
Object next = itr.next();
//here we check for instanceof EncoderDelegate
if ( next instanceof EncoderDelegate ) {
//do not add entry to the stack, just delegate to encode
try {
((EncoderDelegate) next).encode(handler);
}
catch (Exception e) {
throw new RuntimeException( e );
}
}
else {
//add the next object to be encoded to the stack
encoded.push(new EncodingEntry(next, element,entry));
}
} else {
//iterator done, close it
Object source = child[2];
closeIterator(itr,source);
//this child is done, remove from child list
entry.children.remove(0);
}
} else {
// no more children, finish the element
end(entry.encoding, entry.element);
encoded.pop();
//clean up the entry
entry.object = null;
entry.element = null;
entry.encoding = null;
entry.children = null;
entry.parent = null;
}
} else {
//start the encoding of the entry
//first make sure the element is not abstract
if (entry.element.isAbstract()) {
// look for a non abstract substitute - substitution groups are subject to
// changes over time, so we make a copy to avoid being hit with a ConcurrentModificationException
List sub = safeCopy(entry.element.getSubstitutionGroup());
if (sub.size() > 0) {
//match up by type
List matches = new ArrayList();
for (Iterator s = sub.iterator(); s.hasNext();) {
XSDElementDeclaration e = (XSDElementDeclaration) s.next();
if (e == null || e.equals(entry.element)) {
continue;
}
if (e.getName() == null) {
continue;
}
//look up hte binding
Binding binding = bindingLoader.loadBinding(new QName(
e.getTargetNamespace(), e.getName()), context);
if (binding == null) {
//try the type
XSDTypeDefinition type = e.getType();
if (type == null || type.getName() == null) {
continue;
}
binding = bindingLoader.loadBinding(new QName(
type.getTargetNamespace(), type.getName()), context);
}
if (binding == null) {
continue;
}