use of com.sun.xml.xsom.XSElementDecl in project jolie by jolie.
the class XmlUtils method _valueToDocument.
private static void _valueToDocument(Value value, Element element, Document doc, XSModelGroup modelGroup) {
String name;
XSModelGroup.Compositor compositor = modelGroup.getCompositor();
if (compositor.equals(XSModelGroup.SEQUENCE)) {
Value v;
ValueVector vec;
for (XSParticle particle : modelGroup.getChildren()) {
XSTerm currTerm = particle.getTerm();
if (currTerm.isElementDecl()) {
XSElementDecl currElementDecl = currTerm.asElementDecl();
name = currElementDecl.getName();
Element childElement = null;
if ((vec = value.children().get(name)) != null) {
int k = 0;
while (vec.isEmpty() == false && (particle.getMaxOccurs() == XSParticle.UNBOUNDED || particle.getMaxOccurs() > k)) {
childElement = doc.createElement(getElementNameWithPrefix(vec.get(0), name));
element.appendChild(childElement);
v = vec.remove(0);
_valueToDocument(v, childElement, doc, currElementDecl.getType());
k++;
}
}
// TODO throw an error if the following condition occurs here
// else if( children[ i ].getMinOccurs() > 0 ) {
// // TODO throw some error here
// }
} else if (currTerm.isModelGroupDecl()) {
_valueToDocument(value, element, doc, currTerm.asModelGroupDecl().getModelGroup());
} else if (currTerm.isModelGroup()) {
_valueToDocument(value, element, doc, currTerm.asModelGroup());
}
}
} else if (compositor.equals(XSModelGroup.CHOICE)) {
XSParticle[] children = modelGroup.getChildren();
XSTerm currTerm;
XSElementDecl currElementDecl;
Value v;
ValueVector vec;
boolean found = false;
for (int i = 0; i < children.length && !found; i++) {
currTerm = children[i].getTerm();
if (currTerm.isElementDecl()) {
currElementDecl = currTerm.asElementDecl();
name = currElementDecl.getName();
Element childElement = null;
if ((vec = value.children().get(name)) != null) {
childElement = doc.createElement(getElementNameWithPrefix(vec.get(0), name));
element.appendChild(childElement);
found = true;
v = vec.remove(0);
_valueToDocument(v, childElement, doc, currElementDecl.getType());
}
// TODO throw error if following condition occurs
// else if( children[ i ].getMinOccurs() > 0 ) {
// // TODO throw some error here
// }
} else if (currTerm.isModelGroupDecl()) {
_valueToDocument(value, element, doc, currTerm.asModelGroupDecl().getModelGroup());
} else if (currTerm.isModelGroup()) {
_valueToDocument(value, element, doc, currTerm.asModelGroup());
}
}
}
}
use of com.sun.xml.xsom.XSElementDecl in project jolie by jolie.
the class SchemaWriter method schema.
public void schema(XSSchema s) {
// QUICK HACK: don't print the built-in components
if (s.getTargetNamespace().equals(Const.schemaNamespace))
return;
println(MessageFormat.format("<schema targetNamespace=\"{0}\">", new Object[] { s.getTargetNamespace() }));
indent++;
Iterator itr;
itr = s.iterateAttGroupDecls();
while (itr.hasNext()) attGroupDecl((XSAttGroupDecl) itr.next());
itr = s.iterateAttributeDecls();
while (itr.hasNext()) attributeDecl((XSAttributeDecl) itr.next());
itr = s.iterateComplexTypes();
while (itr.hasNext()) complexType((XSComplexType) itr.next());
itr = s.iterateElementDecls();
while (itr.hasNext()) elementDecl((XSElementDecl) itr.next());
itr = s.iterateModelGroupDecls();
while (itr.hasNext()) modelGroupDecl((XSModelGroupDecl) itr.next());
itr = s.iterateSimpleTypes();
while (itr.hasNext()) simpleType((XSSimpleType) itr.next());
indent--;
println("</schema>");
}
use of com.sun.xml.xsom.XSElementDecl in project jolie by jolie.
the class SchemaTreeTraverser method particle.
/* (non-Javadoc)
* @see com.sun.xml.xsom.visitor.XSContentTypeVisitor#particle(com.sun.xml.xsom.XSParticle)
*/
public void particle(XSParticle part) {
int i;
StringBuffer buf = new StringBuffer();
i = part.getMaxOccurs();
if (i == XSParticle.UNBOUNDED) {
buf.append(" maxOccurs=\"unbounded\"");
} else {
if (i != 1) {
buf.append(" maxOccurs=\"" + i + "\"");
}
}
i = part.getMinOccurs();
if (i != 1) {
buf.append(" minOccurs=\"" + i + "\"");
}
final String extraAtts = buf.toString();
part.getTerm().visit(new XSTermVisitor() {
public void elementDecl(XSElementDecl decl) {
if (decl.isLocal()) {
SchemaTreeTraverser.this.elementDecl(decl, extraAtts);
} else {
// reference
SchemaTreeNode newNode = new SchemaTreeNode(MessageFormat.format("Element ref=\"'{'{0}'}'{1}\"{2}", new Object[] { decl.getTargetNamespace(), decl.getName(), extraAtts }), decl.getLocator());
currNode.add(newNode);
}
}
public void modelGroupDecl(XSModelGroupDecl decl) {
// reference
SchemaTreeNode newNode = new SchemaTreeNode(MessageFormat.format("Group ref=\"'{'{0}'}'{1}\"{2}", new Object[] { decl.getTargetNamespace(), decl.getName(), extraAtts }), decl.getLocator());
currNode.add(newNode);
}
public void modelGroup(XSModelGroup group) {
SchemaTreeTraverser.this.modelGroup(group, extraAtts);
}
public void wildcard(XSWildcard wc) {
SchemaTreeTraverser.this.wildcard(wc, extraAtts);
}
});
}
use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.
the class SchemaTreeTraverser method particle.
/* (non-Javadoc)
* @see com.sun.xml.xsom.visitor.XSContentTypeVisitor#particle(com.sun.xml.xsom.XSParticle)
*/
public void particle(XSParticle part) {
BigInteger i;
StringBuilder buf = new StringBuilder();
i = part.getMaxOccurs();
if (i.equals(BigInteger.valueOf(XSParticle.UNBOUNDED))) {
buf.append(" maxOccurs=\"unbounded\"");
} else {
if (!i.equals(BigInteger.ONE)) {
buf.append(" maxOccurs=\"").append(i).append("\"");
}
}
i = part.getMinOccurs();
if (!i.equals(BigInteger.ONE)) {
buf.append(" minOccurs=\"").append(i).append("\"");
}
final String extraAtts = buf.toString();
part.getTerm().visit(new XSTermVisitor() {
public void elementDecl(XSElementDecl decl) {
if (decl.isLocal()) {
SchemaTreeTraverser.this.elementDecl(decl, extraAtts);
} else {
// reference
SchemaTreeNode newNode = new SchemaTreeNode(MessageFormat.format("Element ref=\"'{'{0}'}'{1}\"{2}", decl.getTargetNamespace(), decl.getName(), extraAtts), decl.getLocator());
currNode.add(newNode);
}
}
public void modelGroupDecl(XSModelGroupDecl decl) {
// reference
SchemaTreeNode newNode = new SchemaTreeNode(MessageFormat.format("Group ref=\"'{'{0}'}'{1}\"{2}", decl.getTargetNamespace(), decl.getName(), extraAtts), decl.getLocator());
currNode.add(newNode);
}
public void modelGroup(XSModelGroup group) {
SchemaTreeTraverser.this.modelGroup(group, extraAtts);
}
public void wildcard(XSWildcard wc) {
SchemaTreeTraverser.this.wildcard(wc, extraAtts);
}
});
}
use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.
the class SchemaWriter method schema.
public void schema(XSSchema s) {
// QUICK HACK: don't print the built-in components
if (s.getTargetNamespace().equals(Const.schemaNamespace))
return;
println(MessageFormat.format("<schema targetNamespace=\"{0}\">", s.getTargetNamespace()));
indent++;
Iterator itr;
itr = s.iterateAttGroupDecls();
while (itr.hasNext()) attGroupDecl((XSAttGroupDecl) itr.next());
itr = s.iterateAttributeDecls();
while (itr.hasNext()) attributeDecl((XSAttributeDecl) itr.next());
itr = s.iterateComplexTypes();
while (itr.hasNext()) complexType((XSComplexType) itr.next());
itr = s.iterateElementDecls();
while (itr.hasNext()) elementDecl((XSElementDecl) itr.next());
itr = s.iterateModelGroupDecls();
while (itr.hasNext()) modelGroupDecl((XSModelGroupDecl) itr.next());
itr = s.iterateSimpleTypes();
while (itr.hasNext()) simpleType((XSSimpleType) itr.next());
indent--;
println("</schema>");
}
Aggregations