use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.
the class TypesLabelProvider method getImage.
@Override
public Image getImage(Object obj) {
if (obj instanceof XSDElementDeclaration) {
// top declaration
XSDElementDeclaration decl = (XSDElementDeclaration) obj;
// check if concept or "just" element
boolean isConcept = false;
EList l = decl.getIdentityConstraintDefinitions();
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
isConcept = true;
break;
}
}
// display approprite image
if (isConcept) {
return ImageCache.getCreatedImage(EImage.CONCEPT.getPath());
} else {
return ImageCache.getCreatedImage(EImage.ELEMENT_ONLY.getPath());
/*
* if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) return
* PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_FOLDER); else
* return ImageCache.getCreatedImage( "icons/elements_obj_+.gif");
*/
}
}
if (obj instanceof XSDParticle) {
XSDParticle xsdParticle = (XSDParticle) obj;
XSDTerm xsdTerm = xsdParticle.getTerm();
if (xsdTerm instanceof XSDElementDeclaration) {
// get Type of Parent Group
// if (Util.getKeyInfo(xsdTerm) != null && Util.getKeyInfo(xsdTerm).size() > 0) {
// return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
// }
XSDConcreteComponent xsdConcreteComponent = xsdParticle.getContainer();
if (XSDUtil.hasFKInfo((XSDElementDeclaration) xsdTerm)) {
return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
}
if (xsdConcreteComponent instanceof XSDModelGroup) {
return ImageCache.getCreatedImage(EImage.SCHEMAELEMENT.getPath());
}
/*
* if(((XSDElementDeclaration) xsdTerm).getAnonymousTypeDefinition() instanceof
* XSDComplexTypeDefinition) return ImageCache.getCreatedImage( EImage.COMPLEXTYPE.getPath()); else
* return ImageCache.getCreatedImage( EImage.SIMPLETYPE.getPath());
*/
} else if (xsdTerm instanceof XSDModelGroup) {
int type = ((XSDModelGroup) xsdTerm).getCompositor().getValue();
switch(type) {
case XSDCompositor.ALL:
return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
case XSDCompositor.CHOICE:
return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
case XSDCompositor.SEQUENCE:
return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
}
} else if (xsdTerm instanceof XSDWildcard) {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/wildcard.gif");
} else {
log.info(Messages.TypesLabelProvider_16 + xsdTerm.getClass().getName());
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/error.gif");
}
}
if (obj instanceof XSDSimpleTypeDefinition) {
return ImageCache.getCreatedImage(EImage.SIMPLETYPE.getPath());
}
if (obj instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) obj;
XSDComplexTypeContent ctc = ctd.getContent();
if (ctc instanceof XSDParticle) {
if (((XSDParticle) ctc).getTerm() instanceof XSDModelGroup) {
int type = ((XSDModelGroup) ((XSDParticle) ctc).getTerm()).getCompositor().getValue();
switch(type) {
case XSDCompositor.ALL:
return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
case XSDCompositor.CHOICE:
return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
case XSDCompositor.SEQUENCE:
return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
}
}
} else {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/error.gif");
}
}
if (obj instanceof XSDModelGroup) {
int type = ((XSDModelGroup) obj).getCompositor().getValue();
switch(type) {
case XSDCompositor.ALL:
return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
case XSDCompositor.CHOICE:
return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
case XSDCompositor.SEQUENCE:
return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
}
}
if (obj instanceof XSDFacet) {
return ImageCache.getCreatedImage(EImage.FACET.getPath());
}
if (obj instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition identity = (XSDIdentityConstraintDefinition) obj;
if (identity.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
return ImageCache.getCreatedImage(EImage.KEYS.getPath());
}
return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
}
if (obj instanceof XSDXPathDefinition) {
XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/field.gif");
}
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/selector.gif");
}
if (obj instanceof XSDAttributeGroupDefinition) {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/attribute_group.gif");
}
if (obj instanceof XSDAttributeUse) {
XSDAttributeUse att = (XSDAttributeUse) obj;
if ("xmlns".equals(att.getAttributeDeclaration().getTargetNamespace())) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
}
if (att.getUse().equals(XSDAttributeUseCategory.REQUIRED_LITERAL)) {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/attribute_mandatory.gif");
} else {
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/attribute.gif");
}
}
if (obj instanceof XSDAnnotation) {
return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
}
if (obj instanceof Element) {
try {
Element e = (Element) obj;
if (e.getLocalName().equals("documentation")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
} else if (e.getLocalName().equals("appinfo")) {
// $NON-NLS-1$
// $NON-NLS-1$
String source = e.getAttribute("source");
if (source != null) {
if (source.startsWith("X_Label_")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.LABEL.getPath());
} else if (source.equals("X_ForeignKey")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
} else if (source.equals("X_ForeignKeyInfo")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
} else if (source.equals("X_FKIntegrity")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
} else if (source.equals("X_FKIntegrity_Override")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
} else if (source.equals("X_SourceSystem")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SOURCESYSTEM.getPath());
} else if (source.equals("X_TargetSystem")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.TARGETSYSTEM.getPath());
} else if (source.startsWith("X_Description_")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
} else if (source.equals("X_Write")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_Hide")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_Deny_Create")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_Deny_LogicalDelete")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_Deny_PhysicalDelete")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
} else if (source.equals("X_AutoExpand")) {
// $NON-NLS-1$
return ImageCache.getCreatedImage(EImage.DEFAULT.getPath());
} else {
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
}
} else {
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
}
} else {
return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
// $NON-NLS-1$
return ImageCache.getCreatedImage("icons/tree_object.gif");
// return PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_ELEMENT);
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.
the class UtilTest method testGetTypeDefinition.
@Test
public void testGetTypeDefinition() {
// $NON-NLS-1$
String s_name = "simpleType";
// $NON-NLS-1$
String c_name = "complexType";
// $NON-NLS-1$
String e_name = "xsdElementDeclaration";
XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema();
XSDSimpleTypeDefinition xsdSimpleTypeDefinition1 = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
XSDSimpleTypeDefinition xsdSimpleTypeDefinition2 = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
XSDComplexTypeDefinition xsdComplexTypeDefinition1 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
XSDComplexTypeDefinition xsdComplexTypeDefinition2 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
xsdSimpleTypeDefinition1.setName(s_name + 1);
xsdSimpleTypeDefinition2.setName(s_name + 2);
xsdComplexTypeDefinition1.setName(c_name + 1);
xsdComplexTypeDefinition2.setName(c_name + 2);
xsdSimpleTypeDefinition1.setBaseTypeDefinition(// $NON-NLS-1$ anyType
xsdSchema.resolveSimpleTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "string"));
xsdSimpleTypeDefinition2.setBaseTypeDefinition(// $NON-NLS-1$
xsdSchema.resolveSimpleTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "string"));
xsdComplexTypeDefinition1.setBaseTypeDefinition(// $NON-NLS-1$
xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
xsdComplexTypeDefinition2.setBaseTypeDefinition(// $NON-NLS-1$
xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
EList<XSDSchemaContent> contents = xsdSchema.getContents();
contents.add(xsdSimpleTypeDefinition1);
contents.add(xsdSimpleTypeDefinition2);
contents.add(xsdComplexTypeDefinition1);
contents.add(xsdComplexTypeDefinition2);
XSDElementDeclaration xsdElementDeclaration = XSDFactory.eINSTANCE.createXSDElementDeclaration();
xsdElementDeclaration.setName(e_name);
contents.add(xsdElementDeclaration);
Map<String, XSDTypeDefinition> typeDefinition = Util.getTypeDefinition(xsdSchema);
assertNotNull(typeDefinition);
assertTrue(typeDefinition.size() == 4);
assertTrue(typeDefinition.keySet().contains(s_name + 1));
assertTrue(typeDefinition.keySet().contains(s_name + 2));
assertTrue(typeDefinition.keySet().contains(c_name + 1));
assertTrue(typeDefinition.keySet().contains(c_name + 2));
assertTrue(typeDefinition.values().contains(xsdSimpleTypeDefinition1));
assertTrue(typeDefinition.values().contains(xsdSimpleTypeDefinition2));
assertTrue(typeDefinition.values().contains(xsdComplexTypeDefinition1));
assertTrue(typeDefinition.values().contains(xsdComplexTypeDefinition2));
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.
the class UtilMockTest method testGetComplexTypes.
@Test
public void testGetComplexTypes() {
XSDFactory factory = XSDFactory.eINSTANCE;
XSDSchema xSchema = factory.createXSDSchema();
List<XSDComplexTypeDefinition> complexTypes = Util.getComplexTypes(xSchema);
assertNotNull(complexTypes);
assertTrue(complexTypes.isEmpty());
XSDSimpleTypeDefinition simpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
simpleTypeDefinition.setBaseTypeDefinition(// $NON-NLS-1$ );
xSchema.resolveSimpleTypeDefinition(xSchema.getSchemaForSchemaNamespace(), "string"));
xSchema.getContents().add(simpleTypeDefinition);
complexTypes = Util.getComplexTypes(xSchema);
assertNotNull(complexTypes);
assertTrue(complexTypes.isEmpty());
XSDComplexTypeDefinition baseComplexTypeDefinition = xSchema.resolveComplexTypeDefinition(xSchema.getSchemaForSchemaNamespace(), // $NON-NLS-1$
"anyType");
XSDComplexTypeDefinition complexType1 = factory.createXSDComplexTypeDefinition();
complexType1.setBaseTypeDefinition(baseComplexTypeDefinition);
complexType1.setTargetNamespace(null);
// $NON-NLS-1$
complexType1.setName("ctype1");
XSDComplexTypeDefinition complexType2 = factory.createXSDComplexTypeDefinition();
// $NON-NLS-1$
complexType2.setTargetNamespace("targetNameSpace");
// $NON-NLS-1$
complexType2.setName("ctype2");
complexType2.setBaseTypeDefinition(baseComplexTypeDefinition);
XSDComplexTypeDefinition complexType3 = factory.createXSDComplexTypeDefinition();
complexType3.setTargetNamespace(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
// $NON-NLS-1$
complexType3.setName("topLevelComplexType");
complexType3.setBaseTypeDefinition(baseComplexTypeDefinition);
EList<XSDTypeDefinition> contents = new BasicEList<XSDTypeDefinition>();
contents.add(complexType1);
contents.add(complexType2);
contents.add(complexType3);
XSDSchema spySchema = spy(xSchema);
when(spySchema.getTypeDefinitions()).thenReturn(contents);
complexTypes = Util.getComplexTypes(spySchema);
assertNotNull(complexTypes);
assertTrue(complexTypes.size() == 2);
assertTrue(complexTypes.contains(complexType1));
assertTrue(complexTypes.contains(complexType2));
assertFalse(complexTypes.contains(complexType3));
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project tmdm-studio-se by Talend.
the class UtilMockTest method testGetSimpleTypeDefinitionChildren.
@Test
public void testGetSimpleTypeDefinitionChildren() {
// $NON-NLS-1$
String methodToExpect = "isBuildInType";
// $NON-NLS-1$
String methodToExecute = "getSimpleTypeDefinitionChildren";
XSDFactory factory = XSDFactory.eINSTANCE;
XSDSimpleTypeDefinition simpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
PowerMockito.mockStatic(Util.class);
try {
PowerMockito.when(Util.class, methodToExecute, any(XSDSimpleTypeDefinition.class)).thenCallRealMethod();
//
PowerMockito.when(Util.class, methodToExpect, any(XSDSimpleTypeDefinition.class)).thenReturn(true);
List<Object> children = Util.getSimpleTypeDefinitionChildren(simpleTypeDefinition);
assertNotNull(children);
assertTrue(children.size() == 1);
assertTrue(children.contains(simpleTypeDefinition));
//
PowerMockito.when(Util.class, methodToExpect, any(XSDSimpleTypeDefinition.class)).thenReturn(false);
children = Util.getSimpleTypeDefinitionChildren(simpleTypeDefinition);
assertNotNull(children);
assertTrue(children.size() == 1);
assertTrue(children.contains(simpleTypeDefinition));
//
XSDAnnotation annotation1 = factory.createXSDAnnotation();
XSDAnnotation annotation2 = factory.createXSDAnnotation();
simpleTypeDefinition.getAnnotations().add(annotation1);
simpleTypeDefinition.getAnnotations().add(annotation2);
children = Util.getSimpleTypeDefinitionChildren(simpleTypeDefinition);
assertNotNull(children);
assertTrue(children.size() == 3);
assertTrue(children.contains(simpleTypeDefinition));
assertTrue(children.contains(annotation1));
assertTrue(children.contains(annotation2));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDTypeReferenceEditManager method modifyComponentReference.
public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
XSDConcreteComponent concreteComponent = null;
if (referencingObject instanceof Adapter) {
Adapter adpater = (Adapter) referencingObject;
if (adpater.getTarget() instanceof XSDConcreteComponent) {
concreteComponent = (XSDConcreteComponent) adpater.getTarget();
}
} else if (referencingObject instanceof XSDConcreteComponent) {
concreteComponent = (XSDConcreteComponent) referencingObject;
}
if (concreteComponent != null) {
if (component.isNew()) {
XSDTypeDefinition td = null;
if (// This means we set to anonymous type
component.getName() == null && concreteComponent instanceof XSDElementDeclaration) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) concreteComponent;
// with the proper undo descriptions
if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
XSDComplexTypeDefinition complexType = factory.createXSDComplexTypeDefinition();
elementDeclaration.setAnonymousTypeDefinition(complexType);
} else {
XSDSimpleTypeDefinition simpleType = factory.createXSDSimpleTypeDefinition();
simpleType.setBaseTypeDefinition(// $NON-NLS-1$
elementDeclaration.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
elementDeclaration.setAnonymousTypeDefinition(simpleType);
}
// TODO use external literal string
elementDeclaration.getElement().removeAttribute("type");
} else if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
AddXSDComplexTypeDefinitionCommand command = new AddXSDComplexTypeDefinitionCommand(Messages._UI_ACTION_ADD_COMPLEX_TYPE, concreteComponent.getSchema());
command.setNameToAdd(component.getName());
command.execute();
td = command.getCreatedComplexType();
} else {
AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, concreteComponent.getSchema());
command.setNameToAdd(component.getName());
command.execute();
td = command.getCreatedSimpleType();
}
if (td != null) {
Command command = new UpdateTypeReferenceCommand(concreteComponent, td);
command.setLabel(Messages._UI_ACTION_SET_TYPE);
command.execute();
}
XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
} else {
Command command = new UpdateTypeReferenceAndManageDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
command.setLabel(Messages._UI_ACTION_SET_TYPE);
command.execute();
}
}
}
Aggregations