use of org.eclipse.xsd.XSDVariety in project webtools.sourceediting by eclipse.
the class XSDHyperlinkTargetLocator method caseXSDSimpleTypeDefinition.
public Object caseXSDSimpleTypeDefinition(XSDSimpleTypeDefinition typeDefinition) {
XSDConcreteComponent target = null;
// Simple types can be one of: atomic, list or union.
XSDVariety variety = typeDefinition.getVariety();
int varietyType = variety.getValue();
switch(varietyType) {
case XSDVariety.ATOMIC:
{
target = typeDefinition.getBaseTypeDefinition();
}
break;
case XSDVariety.LIST:
{
target = typeDefinition.getItemTypeDefinition();
}
break;
case XSDVariety.UNION:
{
List memberTypes = typeDefinition.getMemberTypeDefinitions();
if (memberTypes != null && memberTypes.size() > 0) {
// ISSUE: What if there are more than one type?
// This could be a case for multiple hyperlinks at the same
// location.
target = (XSDConcreteComponent) memberTypes.get(0);
}
}
break;
}
if (isFromSchemaForSchema(target)) {
target = null;
}
return target;
}
use of org.eclipse.xsd.XSDVariety in project webtools.sourceediting by eclipse.
the class SetBaseTypeCommand method execute.
public void execute() {
try {
beginRecording(concreteComponent.getElement());
if (concreteComponent instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) concreteComponent;
XSDComplexTypeContent contentType = (baseType instanceof XSDComplexTypeDefinition) ? ((XSDComplexTypeDefinition) baseType).getContentType() : null;
// Complex type simple content
if (baseType instanceof XSDSimpleTypeDefinition || (contentType != null && contentType instanceof XSDSimpleTypeDefinition)) {
if (!(complexType.getContent() instanceof XSDSimpleTypeDefinition)) {
XSDSimpleTypeDefinition simpleContent = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
complexType.setContent(simpleContent);
}
} else // Complex type complex content
if (baseType instanceof XSDComplexTypeDefinition) {
if (!(complexType.getContent() instanceof XSDComplexTypeDefinition)) {
XSDComplexTypeDefinition complexContent = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
complexType.setContent(complexContent.getContent());
}
}
complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
complexType.setBaseTypeDefinition(baseType);
// vb This call should not be needed. The XSD Infoset model should reconcile itself properly.
complexType.updateElement(true);
formatChild(complexType.getElement());
} else if (concreteComponent instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) concreteComponent;
if (baseType instanceof XSDSimpleTypeDefinition) {
XSDVariety variety = simpleType.getVariety();
if (variety.getValue() == XSDVariety.ATOMIC) {
simpleType.setBaseTypeDefinition((XSDSimpleTypeDefinition) baseType);
} else if (variety.getValue() == XSDVariety.UNION) {
simpleType.getMemberTypeDefinitions().add(baseType);
} else if (variety.getValue() == XSDVariety.LIST) {
simpleType.setItemTypeDefinition((XSDSimpleTypeDefinition) baseType);
}
}
}
} finally {
endRecording();
}
}
Aggregations