use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDRedefineAdapter method notifyChanged.
public void notifyChanged(final Notification msg) {
class CategoryNotification extends NotificationImpl {
protected Object category;
public CategoryNotification(Object category) {
super(msg.getEventType(), msg.getOldValue(), msg.getNewValue(), msg.getPosition());
this.category = category;
}
public Object getNotifier() {
return category;
}
public Object getFeature() {
return msg.getFeature();
}
}
if (children == null) {
getChildren();
}
Object newValue = msg.getNewValue();
Object oldValue = msg.getOldValue();
if (XSDPackage.eINSTANCE.getXSDRedefine_Contents() == msg.getFeature()) {
if ((newValue instanceof XSDAttributeGroupDefinition) || oldValue instanceof XSDAttributeGroupDefinition) {
CategoryAdapter adapter = getCategory(CategoryAdapter.ATTRIBUTES);
Assert.isTrue(adapter != null);
List list = getCategoryChildren(CategoryAdapter.ATTRIBUTES);
adapter.setChildren(list);
adapter.setAllChildren(list);
if (adapter.getModel() instanceof XSDSchemaAdapter) {
XSDSchemaAdapter schemaAdapter = (XSDSchemaAdapter) adapter.getModel();
schemaAdapter.notifyChanged(msg);
}
notifyListeners(new CategoryNotification(adapter), adapter.getText());
return;
} else if ((newValue instanceof XSDComplexTypeDefinition || newValue instanceof XSDSimpleTypeDefinition) || (oldValue instanceof XSDComplexTypeDefinition || oldValue instanceof XSDSimpleTypeDefinition)) {
CategoryAdapter adapter = getCategory(CategoryAdapter.TYPES);
Assert.isTrue(adapter != null);
List types = getCategoryChildren(CategoryAdapter.TYPES);
adapter.setChildren(types);
adapter.setAllChildren(types);
if (adapter.getModel() instanceof XSDSchemaAdapter) {
XSDSchemaAdapter schemaAdapter = (XSDSchemaAdapter) adapter.getModel();
schemaAdapter.notifyChanged(msg);
}
notifyListeners(new CategoryNotification(adapter), adapter.getText());
return;
} else if (newValue instanceof XSDModelGroupDefinition || oldValue instanceof XSDModelGroupDefinition) {
CategoryAdapter adapter = getCategory(CategoryAdapter.GROUPS);
Assert.isTrue(adapter != null);
List list = getCategoryChildren(CategoryAdapter.GROUPS);
adapter.setChildren(list);
adapter.setAllChildren(list);
if (adapter.getModel() instanceof XSDSchemaAdapter) {
XSDSchemaAdapter schemaAdapter = (XSDSchemaAdapter) adapter.getModel();
schemaAdapter.notifyChanged(msg);
}
notifyListeners(new CategoryNotification(adapter), adapter.getText());
return;
} else if (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_Annotations()) {
return;
}
}
super.notifyChanged(msg);
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition 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.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDComplexTypeDefinitionAdapter method getActions.
public String[] getActions(Object object) {
List list = new ArrayList();
Object schema = getEditorSchema();
XSDComplexTypeDefinition complexType = getXSDComplexTypeDefinition();
Object contentType = getContentType();
XSDDerivationMethod derivation = complexType.getDerivationMethod();
if (contentType instanceof XSDSimpleTypeDefinition) {
List fields = getFields();
boolean hasSimpleContentAttributes = false;
for (Iterator iterator = fields.iterator(); iterator.hasNext(); ) {
Object field = iterator.next();
// We have attributes, so we need to add the compartment for housing the attributes
if (field instanceof XSDAttributeDeclarationAdapter) {
hasSimpleContentAttributes = true;
break;
}
}
if (hasSimpleContentAttributes || XSDDerivationMethod.EXTENSION_LITERAL.equals(derivation)) {
list.add(AddXSDAttributeDeclarationAction.ID);
} else if (XSDDerivationMethod.RESTRICTION_LITERAL.equals(derivation)) {
list.add(AddXSDEnumerationFacetAction.ID);
}
list.add(BaseSelectionAction.SEPARATOR_ID);
list.add(SetBaseTypeAction.ID);
list.add(BaseSelectionAction.SEPARATOR_ID);
list.add(DeleteAction.ID);
list.add(BaseSelectionAction.SEPARATOR_ID);
} else {
list.add(AddXSDElementAction.ID);
list.add(AddXSDElementAction.REF_ID);
list.add(AddXSDAnyElementAction.ID);
list.add(BaseSelectionAction.SEPARATOR_ID);
list.add(AddXSDAttributeDeclarationAction.ID);
list.add(AddXSDAttributeDeclarationAction.REF_ID);
list.add(AddXSDAttributeGroupDefinitionAction.REF_ID);
list.add(AddXSDAnyAttributeAction.ID);
list.add(BaseSelectionAction.SEPARATOR_ID);
list.add(AddXSDModelGroupAction.SEQUENCE_ID);
list.add(AddXSDModelGroupAction.CHOICE_ID);
list.add(AddXSDModelGroupAction.ALL_ID);
list.add(BaseSelectionAction.SEPARATOR_ID);
list.add(DeleteAction.ID);
list.add(BaseSelectionAction.SEPARATOR_ID);
list.add(SetBaseTypeAction.ID);
list.add(BaseSelectionAction.SEPARATOR_ID);
}
if (complexType.getSchema() == schema) {
XSDConcreteComponent container = complexType.getContainer();
if (container == schema || container instanceof XSDRedefine) {
list.add(SetInputToGraphView.ID);
}
} else {
list.add(OpenInNewEditor.ID);
}
list.add(BaseSelectionAction.SEPARATOR_ID);
list.add(ShowPropertiesViewAction.ID);
String[] result = new String[list.size()];
list.toArray(result);
return result;
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition 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]);
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class TypesHelper method getUserSimpleTypeNamesList.
public java.util.List getUserSimpleTypeNamesList() {
Vector items = new Vector();
if (xsdSchema != null) {
updateExternalImportGlobals();
Iterator i = xsdSchema.getTypeDefinitions().iterator();
while (i.hasNext()) {
XSDTypeDefinition typeDefinition = (XSDTypeDefinition) i.next();
if (typeDefinition instanceof XSDSimpleTypeDefinition) {
items.addAll(getPrefixedNames(typeDefinition.getTargetNamespace(), typeDefinition.getName()));
}
}
items = (Vector) sortList(items);
}
return items;
}
Aggregations