Method from org.apache.xmlbeans.impl.inst2xsd.util.TypeSystemHolder Detail: |
public void addGlobalAttribute(Attribute attribute) {
assert attribute.isGlobal() && !attribute.isRef();
_globalAttributes.put(attribute.getName(), attribute);
}
|
public void addGlobalElement(Element element) {
assert element.isGlobal() && !element.isRef();
_globalElements.put(element.getName(), element);
}
|
public void addGlobalType(Type type) {
assert type.isGlobal() && type.getName()!=null : "type must be a global type before being added.";
_globalTypes.put(type.getName(), type);
}
|
protected void fillUpContentForComplexType(Type type,
ComplexType sComplexType,
String tns) {
if (type.getContentType()==Type.COMPLEX_TYPE_SIMPLE_CONTENT)
{
org.apache.xmlbeans.impl.xb.xsdschema.SimpleContentDocument.SimpleContent simpleContent = sComplexType.addNewSimpleContent();
assert type.getExtensionType()!=null && type.getExtensionType().getName()!=null : "Extension type must exist and be named for a COMPLEX_TYPE_SIMPLE_CONTENT";
org.apache.xmlbeans.impl.xb.xsdschema.SimpleExtensionType ext = simpleContent.addNewExtension();
ext.setBase(type.getExtensionType().getName());
fillUpAttributesInComplexTypesSimpleContent(type, ext, tns);
}
else
{
if (type.getContentType()==Type.COMPLEX_TYPE_MIXED_CONTENT)
{
sComplexType.setMixed(true);
}
org.apache.xmlbeans.impl.xb.xsdschema.ExplicitGroup explicitGroup;
if (type.getContentType()==Type.COMPLEX_TYPE_EMPTY_CONTENT)
explicitGroup = null;
else if (type.getTopParticleForComplexOrMixedContent()==Type.PARTICLE_SEQUENCE)
{
explicitGroup = sComplexType.addNewSequence();
}
else if (type.getTopParticleForComplexOrMixedContent()==Type.PARTICLE_CHOICE_UNBOUNDED)
{
explicitGroup = sComplexType.addNewChoice();
explicitGroup.setMaxOccurs("unbounded");
explicitGroup.setMinOccurs(new BigInteger("0"));
}
else { throw new IllegalStateException("Unknown particle type in complex and mixed content"); }
for (int i = 0; i < type.getElements().size(); i++)
{
Element child = (Element) type.getElements().get(i);
assert !child.isGlobal();
org.apache.xmlbeans.impl.xb.xsdschema.LocalElement childLocalElement = explicitGroup.addNewElement();
fillUpLocalElement(child, childLocalElement, tns);
}
fillUpAttributesInComplexTypesComplexContent(type, sComplexType, tns);
}
}
|
protected void fillUpLocalAttribute(Attribute att,
Attribute sAttribute,
String tns) {
if (att.isRef())
{
sAttribute.setRef(att.getRef().getName());
}
else
{
assert att.getName().getNamespaceURI()==tns || att.getName().getNamespaceURI().equals("");
sAttribute.setType(att.getType().getName());
sAttribute.setName(att.getName().getLocalPart());
if (att.isOptional())
sAttribute.setUse(org.apache.xmlbeans.impl.xb.xsdschema.Attribute.Use.OPTIONAL);
}
}
|
protected void fillUpLocalElement(Element element,
LocalElement localSElement,
String tns) {
fillUpElementDocumentation(localSElement, element.getComment());
if (!element.isRef())
{
assert element.getName().getNamespaceURI().equals(tns) ||
element.getName().getNamespaceURI().length() == 0;
fillUpTypeOnElement(element.getType(), localSElement, tns);
localSElement.setName(element.getName().getLocalPart());
}
else
{
localSElement.setRef(element.getName());
assert !element.isNillable();
}
if (element.getMaxOccurs()==Element.UNBOUNDED)
{
localSElement.setMaxOccurs("unbounded");
}
if (element.getMinOccurs()!=1)
{
localSElement.setMinOccurs(new BigInteger("" + element.getMinOccurs()));
}
if (element.isNillable())
localSElement.setNillable(element.isNillable());
}
|
public Attribute getGlobalAttribute(QName name) {
return (Attribute)_globalAttributes.get(name);
}
|
public Attribute[] getGlobalAttributes() {
Collection col = _globalAttributes.values();
return (Attribute[])col.toArray(new Attribute[col.size()]);
}
|
public Element getGlobalElement(QName name) {
return (Element)_globalElements.get(name);
}
|
public Element[] getGlobalElements() {
Collection col = _globalElements.values();
return (Element[])col.toArray(new Element[col.size()]);
}
|
public Type getGlobalType(QName name) {
return (Type)_globalTypes.get(name);
}
|
public Type[] getGlobalTypes() {
Collection col = _globalTypes.values();
return (Type[])col.toArray(new Type[col.size()]);
}
|
public SchemaDocument[] getSchemaDocuments() {
// recompute everything, should cache it and track changes
Map nsToSchemaDocs = new LinkedHashMap();
for (Iterator iterator = _globalElements.keySet().iterator(); iterator.hasNext();)
{
QName globalElemName = (QName) iterator.next();
String tns = globalElemName.getNamespaceURI();
SchemaDocument schDoc = getSchemaDocumentForTNS(nsToSchemaDocs, tns);
fillUpGlobalElement((Element)_globalElements.get(globalElemName), schDoc, tns);
}
for (Iterator iterator = _globalAttributes.keySet().iterator(); iterator.hasNext();)
{
QName globalAttName = (QName) iterator.next();
String tns = globalAttName.getNamespaceURI();
SchemaDocument schDoc = getSchemaDocumentForTNS(nsToSchemaDocs, tns);
fillUpGlobalAttribute((Attribute)_globalAttributes.get(globalAttName), schDoc, tns);
}
for (Iterator iterator = _globalTypes.keySet().iterator(); iterator.hasNext();)
{
QName globalTypeName = (QName) iterator.next();
String tns = globalTypeName.getNamespaceURI();
SchemaDocument schDoc = getSchemaDocumentForTNS(nsToSchemaDocs, tns);
fillUpGlobalType((Type)_globalTypes.get(globalTypeName), schDoc, tns);
}
Collection schDocColl = nsToSchemaDocs.values();
return (SchemaDocument[])schDocColl.toArray(new SchemaDocument[schDocColl.size()]);
}
|
public String toString() {
return "TypeSystemHolder{" +
"\n\n_globalElements=" + _globalElements +
"\n\n_globalAttributes=" + _globalAttributes +
"\n\n_globalTypes=" + _globalTypes +
"\n}";
}
|