use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDImpl method isTypeDerivedFrom.
/**
* Adapted from protected static boolean isTypeDerivedFrom(XSDTypeDefinition
* typedef, String namespace, String localName) in class XSDSchemaQueryTools
* found in org.eclipse.xsd plugin.
*
* Recursive worker method to find typeDefinitions that derive from a named
* type.
*
* @see #findTypesDerivedFrom(XSDSchema, String, String)
* @param typeDef
* to see if it's derived from
* @param namespace
* for the type derived from
* @param localName
* for the type derived from
* @return true if it is; false otherwise
*/
protected static boolean isTypeDerivedFrom(XSDTypeDefinition typedef, String namespace, String localName) {
// Walk the baseTypes from this typedef seeing if any
// of them match the requested one
XSDTypeDefinition baseType = typedef.getBaseType();
if (baseType == null) {
// typedef is a root type like xsd:anyType, so it has no base
return false;
}
// As this convenience method if our parameters match
if (baseType.hasNameAndTargetNamespace(localName, namespace)) {
return true;
}
XSDTypeDefinition rootType = typedef.getRootType();
if (rootType == baseType) {
// If we've hit the root, we aren't derived from it
return false;
} else {
// This method should be replaced with XSDConstants.isOrIsDerivedFrom(baseType, localName, namespace);
if (rootType.isCircular()) {
return true;
}
// Otherwise continue to traverse upwards
return isTypeDerivedFrom(baseType, namespace, localName);
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDElementDeclarationSection method fillTypesCombo.
private void fillTypesCombo() {
IEditorPart editor = getActiveEditor();
ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDTypeReferenceEditManager.class);
if (manager != null) {
ComponentSpecification[] items = manager.getQuickPicks();
typeCombo.removeAll();
typeCombo.add(Messages._UI_COMBO_BROWSE);
typeCombo.add(Messages._UI_COMBO_NEW);
for (int i = 0; i < items.length; i++) {
typeCombo.add(items[i].getName());
}
// Add the current Type of this element if needed
XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getResolvedElementDeclaration();
XSDTypeDefinition td = namedComponent.getType();
if (td != null) {
String currentTypeName = td.getQName(xsdSchema);
if (// anonymous type
currentTypeName == null)
currentTypeName = "**Anonymous**";
ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName, manager);
if (// not in quickPick
ret == null && currentTypeName != null) {
typeCombo.add(currentTypeName);
}
}
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDFacetSection method updateInput.
private void updateInput() {
previousPrimitiveType = currentPrimitiveType;
if (input instanceof XSDFeature) {
xsdFeature = (XSDFeature) input;
typeDefinition = xsdFeature.getResolvedFeature().getType();
XSDTypeDefinition anonymousTypeDefinition = null;
if (xsdFeature instanceof XSDElementDeclaration) {
xsdElementDeclaration = (XSDElementDeclaration) xsdFeature;
anonymousTypeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getAnonymousTypeDefinition();
} else if (xsdFeature instanceof XSDAttributeDeclaration) {
xsdAttributeDeclaration = (XSDAttributeDeclaration) xsdFeature;
anonymousTypeDefinition = xsdAttributeDeclaration.getResolvedAttributeDeclaration().getAnonymousTypeDefinition();
}
if (typeDefinition instanceof XSDSimpleTypeDefinition) {
xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) typeDefinition;
}
if (anonymousTypeDefinition instanceof XSDSimpleTypeDefinition) {
xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) anonymousTypeDefinition;
}
if (xsdSimpleTypeDefinition != null) {
if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) {
XSDSimpleTypeDefinition basePrimitiveType = xsdSimpleTypeDefinition.getBaseTypeDefinition();
String basePrimitiveTypeString = basePrimitiveType != null ? basePrimitiveType.getName() : "";
currentPrimitiveType = basePrimitiveType;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + basePrimitiveTypeString;
} else {
currentPrimitiveType = xsdSimpleTypeDefinition;
titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName());
}
}
} else if (input instanceof XSDSimpleTypeDefinition) {
xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) input;
currentPrimitiveType = xsdSimpleTypeDefinition;
// $NON-NLS-1$ //$NON-NLS-2$
titleString = Messages._UI_LABEL_TYPE + (xsdSimpleTypeDefinition.getName() == null ? "(localType)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + xsdSimpleTypeDefinition.getBaseTypeDefinition().getName();
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils method getInputXSDAnnotation.
public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
XSDAnnotation xsdAnnotation = null;
XSDFactory factory = XSDFactory.eINSTANCE;
if (input instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDNotationDeclaration) {
XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDXPathDefinition) {
XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroup) {
XSDModelGroup xsdComp = (XSDModelGroup) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDWildcard) {
XSDWildcard xsdComp = (XSDWildcard) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDSchema) {
XSDSchema xsdComp = (XSDSchema) input;
List list = xsdComp.getAnnotations();
if (list.size() > 0) {
xsdAnnotation = (XSDAnnotation) list.get(0);
} else {
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
if (xsdComp.getContents() != null) {
xsdComp.getContents().add(0, xsdAnnotation);
}
}
}
return xsdAnnotation;
} else if (input instanceof XSDFacet) {
XSDFacet xsdComp = (XSDFacet) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDTypeDefinition) {
XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDInclude) {
XSDInclude xsdComp = (XSDInclude) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDImport) {
XSDImport xsdComp = (XSDImport) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDRedefine) {
XSDRedefine xsdComp = (XSDRedefine) input;
List contents = xsdComp.getContents();
for (int i = 0; i < contents.size(); i++) {
Object content = contents.get(i);
if (content instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) content;
break;
}
}
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
contents.add(0, xsdAnnotation);
}
return xsdAnnotation;
} else if (input instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) input;
}
if (createIfNotExist) {
formatAnnotation(xsdAnnotation);
}
return xsdAnnotation;
}
use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.
the class TypesHelper method getUserSimpleTypes.
public java.util.List getUserSimpleTypes() {
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.add(typeDefinition);
// items.add(typeDefinition.getQName(xsdSchema));
}
}
// We need to add the anyType
// items.add(getPrefix(xsdSchema.getSchemaForSchemaNamespace(), true) + "anyType");
// items = addExternalImportedUserSimpleTypes(items);
// items = (Vector) sortList(items);
}
return items;
}
Aggregations