use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.
the class ParticleBinder method getSpecDefaultName.
/**
* Computes a name from unnamed model group by following the spec.
*
* Taking first three elements and combine them.
*
* @param repeated
* if the said model group is repeated more than once
*
* @exception ParseException
* If the method cannot generate a name. For example, when
* a model group doesn't contain any element reference/declaration
* at all.
*/
protected final String getSpecDefaultName(XSModelGroup mg, final boolean repeated) throws ParseException {
final StringBuilder name = new StringBuilder();
mg.visit(new XSTermVisitor() {
/**
* Count the number of tokens we combined.
* We will concat up to 3.
*/
private int count = 0;
/**
* Is the current particple/term repeated?
*/
private boolean rep = repeated;
@Override
public void wildcard(XSWildcard wc) {
append("any");
}
@Override
public void modelGroupDecl(XSModelGroupDecl mgd) {
modelGroup(mgd.getModelGroup());
}
@Override
public void modelGroup(XSModelGroup mg) {
String operator;
if (mg.getCompositor() == XSModelGroup.CHOICE)
operator = "Or";
else
operator = "And";
int size = mg.getSize();
for (int i = 0; i < size; i++) {
XSParticle p = mg.getChild(i);
boolean oldRep = rep;
rep |= p.isRepeated();
p.getTerm().visit(this);
rep = oldRep;
// we have enough
if (count == 3)
return;
if (i != size - 1)
name.append(operator);
}
}
@Override
public void elementDecl(XSElementDecl ed) {
append(ed.getName());
}
private void append(String token) {
if (count < 3) {
name.append(makeJavaName(rep, token));
count++;
}
}
});
if (name.length() == 0)
throw new ParseException("no element", -1);
return name.toString();
}
use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.
the class SimpleTypeBuilder method checkRefererCustomization.
/**
* Checks if the referer has a conversion customization or not.
* If it does, use it to bind this simple type. Otherwise
* return null;
*/
private TypeUse checkRefererCustomization(XSSimpleType type) {
// assertion check. referer must be set properly
// before the build method is called.
// since the handling of the simple type point-of-reference
// customization is very error prone, it deserves a strict
// assertion check.
// UGLY CODE WARNING
XSComponent top = getReferer();
if (top instanceof XSElementDecl) {
// if the parent is element type, its content type must be us.
XSElementDecl eref = (XSElementDecl) top;
assert eref.getType() == type;
// for elements, you can't use <property>,
// so we allow javaType to appear directly.
BindInfo info = builder.getBindInfo(top);
BIConversion conv = info.get(BIConversion.class);
if (conv != null) {
conv.markAsAcknowledged();
// the conversion is given.
return conv.getTypeUse(type);
}
detectJavaTypeCustomization();
} else if (top instanceof XSAttributeDecl) {
XSAttributeDecl aref = (XSAttributeDecl) top;
assert aref.getType() == type;
detectJavaTypeCustomization();
} else if (top instanceof XSComplexType) {
XSComplexType tref = (XSComplexType) top;
assert tref.getBaseType() == type || tref.getContentType() == type;
detectJavaTypeCustomization();
} else if (top == type) {
// this means the simple type is built by itself and
// not because it's referenced by something.
} else
// unexpected referer type.
assert false;
// now we are certain that the referer is OK.
// see if it has a conversion customization.
BIConversion conv = getRefererCustomization();
if (conv != null) {
conv.markAsAcknowledged();
// the conversion is given.
return conv.getTypeUse(type);
} else
// not found
return null;
}
use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.
the class DefaultClassBinder method getSoleElementReferer.
/**
* If only one global {@link XSElementDecl} is refering to {@link XSType},
* return that element, otherwise null.
*/
@Nullable
private XSElementDecl getSoleElementReferer(@NotNull XSType t) {
Set<XSComponent> referer = builder.getReferer(t);
XSElementDecl sole = null;
for (XSComponent r : referer) {
if (r instanceof XSElementDecl) {
XSElementDecl x = (XSElementDecl) r;
if (!x.isGlobal())
// by the property, or by the JAXBElement (for things like mixed contents)
continue;
if (sole == null)
sole = x;
else
// more than one
return null;
} else {
// this type has a sub-type, so type substitution is possible now.
return null;
}
}
return sole;
}
use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.
the class DefaultClassBinder method elementDecl.
@Override
public CElement elementDecl(XSElementDecl decl) {
CElement r = allow(decl, decl.getName());
if (r == null) {
QName tagName = getName(decl);
CCustomizations custs = builder.getBindInfo(decl).toCustomizationList();
if (decl.isGlobal()) {
if (isCollapsable(decl)) {
// so the binding cannot be delayed.
return selector.bindToType(decl.getType().asComplexType(), decl, true);
} else {
String className = null;
if (getGlobalBinding().isGenerateElementClass())
className = deriveName(decl);
// otherwise map global elements to JAXBElement
CElementInfo cei = new CElementInfo(model, tagName, selector.getClassScope(), className, custs, decl.getLocator());
selector.boundElements.put(decl, cei);
// referer is element
stb.refererStack.push(decl);
cei.initContentType(selector.bindToType(decl.getType(), decl), decl, decl.getDefaultValue());
stb.refererStack.pop();
r = cei;
}
}
}
// have the substitution member derive from the substitution head
XSElementDecl top = decl.getSubstAffiliation();
if (top != null) {
CElement topci = selector.bindToType(top, decl);
if (r instanceof CClassInfo && topci instanceof CClassInfo)
((CClassInfo) r).setBaseClass((CClassInfo) topci);
if (r instanceof CElementInfo && topci instanceof CElementInfo)
((CElementInfo) r).setSubstitutionHead((CElementInfo) topci);
}
return r;
}
use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.
the class SchemaTreeTraverser method schema.
/* (non-Javadoc)
* @see com.sun.xml.xsom.visitor.XSVisitor#schema(com.sun.xml.xsom.XSSchema)
*/
public void schema(XSSchema s) {
// QUICK HACK: don't print the built-in components
if (s.getTargetNamespace().equals(Const.schemaNamespace)) {
return;
}
SchemaTreeNode newNode = new SchemaTreeNode("Schema " + s.getLocator().getSystemId(), s.getLocator());
this.currNode = newNode;
this.model.addSchemaNode(newNode);
for (XSAttGroupDecl groupDecl : s.getAttGroupDecls().values()) {
attGroupDecl(groupDecl);
}
for (XSAttributeDecl attrDecl : s.getAttributeDecls().values()) {
attributeDecl(attrDecl);
}
for (XSComplexType complexType : s.getComplexTypes().values()) {
complexType(complexType);
}
for (XSElementDecl elementDecl : s.getElementDecls().values()) {
elementDecl(elementDecl);
}
for (XSModelGroupDecl modelGroupDecl : s.getModelGroupDecls().values()) {
modelGroupDecl(modelGroupDecl);
}
for (XSSimpleType simpleType : s.getSimpleTypes().values()) {
simpleType(simpleType);
}
}
Aggregations