use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDVisitor method visitSchema.
public void visitSchema(XSDSchema schema) {
this.schema = schema;
for (Iterator iterator = schema.getAttributeDeclarations().iterator(); iterator.hasNext(); ) {
XSDAttributeDeclaration attr = (XSDAttributeDeclaration) iterator.next();
visitAttributeDeclaration(attr);
}
for (Iterator iterator = schema.getTypeDefinitions().iterator(); iterator.hasNext(); ) {
XSDTypeDefinition type = (XSDTypeDefinition) iterator.next();
visitTypeDefinition(type);
}
for (Iterator iterator = schema.getElementDeclarations().iterator(); iterator.hasNext(); ) {
XSDElementDeclaration element = (XSDElementDeclaration) iterator.next();
visitElementDeclaration(element);
}
for (Iterator iterator = schema.getIdentityConstraintDefinitions().iterator(); iterator.hasNext(); ) {
XSDIdentityConstraintDefinition identityConstraint = (XSDIdentityConstraintDefinition) iterator.next();
visitIdentityConstraintDefinition(identityConstraint);
}
for (Iterator iterator = schema.getModelGroupDefinitions().iterator(); iterator.hasNext(); ) {
XSDModelGroupDefinition modelGroup = (XSDModelGroupDefinition) iterator.next();
visitModelGroupDefinition(modelGroup);
}
for (Iterator iterator = schema.getAttributeGroupDefinitions().iterator(); iterator.hasNext(); ) {
XSDAttributeGroupDefinition attributeGroup = (XSDAttributeGroupDefinition) iterator.next();
visitAttributeGroupDefinition(attributeGroup);
}
for (Iterator iterator = schema.getNotationDeclarations().iterator(); iterator.hasNext(); ) {
XSDNotationDeclaration element = (XSDNotationDeclaration) iterator.next();
visitNotationDeclaration(element);
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDElementDeclarationAdapter method getChildren.
public ITreeElement[] getChildren() {
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) target;
List list = new ArrayList();
XSDTypeDefinition type = null;
if (xsdElementDeclaration.isElementDeclarationReference()) {
type = xsdElementDeclaration.getResolvedElementDeclaration().getTypeDefinition();
} else {
type = xsdElementDeclaration.getAnonymousTypeDefinition();
if (type == null) {
type = xsdElementDeclaration.getTypeDefinition();
}
}
if (type instanceof XSDComplexTypeDefinition && type.getTargetNamespace() != null && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) {
XSDComplexTypeDefinition ctType = (XSDComplexTypeDefinition) type;
if (ctType != null) {
if (xsdElementDeclaration.isGlobal())
list.add(ctType);
}
}
List adapterList = new ArrayList();
populateAdapterList(list, adapterList);
return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDImpl method getEnumeratedValuesForType.
public static String[] getEnumeratedValuesForType(XSDTypeDefinition type) {
List result = new ArrayList();
// type with simple content
if (type instanceof XSDComplexTypeDefinition) {
type = ((XSDComplexTypeDefinition) type).getSimpleType();
}
if (type instanceof XSDSimpleTypeDefinition) {
if (TYPE_NAME_BOOLEAN.equals(type.getName()) && type.getSchema().getSchemaForSchema() == type.getSchema()) {
result.add(TYPE_VALUE_TRUE);
result.add(TYPE_VALUE_FALSE);
} else {
// Simple types can be one of: atomic, list or union.
int varietyType = ((XSDSimpleTypeDefinition) type).getVariety().getValue();
switch(varietyType) {
case XSDVariety.ATOMIC:
{
XSDTypeDefinition baseType = type.getBaseType();
if (baseType != null && !(type.getSchema().getSchemaForSchema() == baseType.getSchema())) {
getEnumeratedValuesForSimpleType(baseType, result);
// If there are none, then we should be able to add the enumerations for the current type
if (result.isEmpty()) {
getEnumeratedValuesForSimpleType(type, result);
} else // There are enumerations on the base type
{
// If there are enumerations on the current type also, then we should just add the ones from the current type
// since we're restricting the values
List enumerationsForCurrentType = new ArrayList();
getEnumeratedValuesForSimpleType(type, enumerationsForCurrentType);
if (!enumerationsForCurrentType.isEmpty()) {
result.clear();
result.addAll(enumerationsForCurrentType);
}
// Otherwise, just use the enumerations on the base type
}
} else {
getEnumeratedValuesForSimpleType(type, result);
}
}
break;
case XSDVariety.LIST:
{
XSDSimpleTypeDefinition itemTypeDefinition = ((XSDSimpleTypeDefinition) type).getItemTypeDefinition();
String[] values = getEnumeratedValuesForType(itemTypeDefinition);
for (int j = 0; j < values.length; j++) {
if (result.indexOf(values[j]) == -1) {
result.add(values[j]);
}
}
}
break;
case XSDVariety.UNION:
{
List memberTypes = ((XSDSimpleTypeDefinition) type).getMemberTypeDefinitions();
if (memberTypes != null && memberTypes.size() > 0) {
Iterator i = memberTypes.iterator();
while (i.hasNext()) {
XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) i.next();
String[] values = getEnumeratedValuesForType(simpleType);
for (int j = 0; j < values.length; j++) {
if (result.indexOf(values[j]) == -1) {
result.add(values[j]);
}
}
}
}
}
break;
}
}
}
String[] array = new String[result.size()];
result.toArray(array);
return array;
}
use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDVisitor method visitSchema.
public void visitSchema(XSDSchema schema) {
this.schema = schema;
for (Iterator iterator = schema.getAttributeDeclarations().iterator(); iterator.hasNext(); ) {
XSDAttributeDeclaration attr = (XSDAttributeDeclaration) iterator.next();
visitAttributeDeclaration(attr);
}
for (Iterator iterator = schema.getTypeDefinitions().iterator(); iterator.hasNext(); ) {
XSDTypeDefinition type = (XSDTypeDefinition) iterator.next();
visitTypeDefinition(type);
}
for (Iterator iterator = schema.getElementDeclarations().iterator(); iterator.hasNext(); ) {
XSDElementDeclaration element = (XSDElementDeclaration) iterator.next();
visitElementDeclaration(element);
}
for (Iterator iterator = schema.getIdentityConstraintDefinitions().iterator(); iterator.hasNext(); ) {
XSDIdentityConstraintDefinition identityConstraint = (XSDIdentityConstraintDefinition) iterator.next();
visitIdentityConstraintDefinition(identityConstraint);
}
for (Iterator iterator = schema.getModelGroupDefinitions().iterator(); iterator.hasNext(); ) {
XSDModelGroupDefinition modelGroup = (XSDModelGroupDefinition) iterator.next();
visitModelGroupDefinition(modelGroup);
}
for (Iterator iterator = schema.getAttributeGroupDefinitions().iterator(); iterator.hasNext(); ) {
XSDAttributeGroupDefinition attributeGroup = (XSDAttributeGroupDefinition) iterator.next();
visitAttributeGroupDefinition(attributeGroup);
}
for (Iterator iterator = schema.getNotationDeclarations().iterator(); iterator.hasNext(); ) {
XSDNotationDeclaration element = (XSDNotationDeclaration) iterator.next();
visitNotationDeclaration(element);
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDComplexTypeDefinitionAdapter method getChildren.
public ITreeElement[] getChildren() {
XSDComplexTypeDefinition xsdComplexTypeDefinition = getXSDComplexTypeDefinition();
List list = new ArrayList();
// Add attributes
for (Iterator i = xsdComplexTypeDefinition.getAttributeContents().iterator(); i.hasNext(); ) {
Object obj = i.next();
if (obj instanceof XSDAttributeUse) {
list.add(((XSDAttributeUse) obj).getAttributeDeclaration());
} else if (obj instanceof XSDAttributeGroupDefinition) {
getAttributeUses((XSDAttributeGroupDefinition) obj, list);
}
}
// Add enumerations
boolean canHaveEnumerations = xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition && XSDDerivationMethod.RESTRICTION_LITERAL.equals(xsdComplexTypeDefinition.getDerivationMethod());
if (canHaveEnumerations) {
Object contentType = getContentType();
if (contentType != null) {
for (Iterator iterator = ((XSDSimpleTypeDefinition) contentType).getEnumerationFacets().iterator(); iterator.hasNext(); ) {
XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) iterator.next();
list.add(enumerationFacet);
}
}
}
XSDWildcard anyAttr = xsdComplexTypeDefinition.getAttributeWildcard();
if (anyAttr != null)
list.add(anyAttr);
// get immediate XSD Model Group of this complex type
if (xsdComplexTypeDefinition.getContent() != null) {
XSDComplexTypeContent xsdComplexTypeContent = xsdComplexTypeDefinition.getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
if (particleContent instanceof XSDModelGroup) {
list.add(particleContent);
}
}
}
// get inherited XSD Model Group of this complex type
boolean showInheritedContent = XSDEditorPlugin.getPlugin().getShowInheritedContent();
if (showInheritedContent) {
XSDTypeDefinition typeDef = xsdComplexTypeDefinition.getBaseTypeDefinition();
if (typeDef instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition baseCT = (XSDComplexTypeDefinition) typeDef;
if (baseCT.getTargetNamespace() != null && !baseCT.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) {
if (baseCT.getContent() != null) {
XSDComplexTypeContent xsdComplexTypeContent = baseCT.getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
if (particleContent instanceof XSDModelGroup) {
list.add(particleContent);
}
}
}
}
}
}
List adapterList = new ArrayList();
populateAdapterList(list, adapterList);
return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
Aggregations