use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class TypesContentProvider method getChildren.
public Object[] getChildren(Object parent) {
if (parent instanceof XSDSchema) {
EList xsdElementDeclarations = xsdSchema.getTypeDefinitions();
List<XSDTypeDefinition> list = new ArrayList<XSDTypeDefinition>();
for (XSDTypeDefinition el : (XSDTypeDefinition[]) xsdElementDeclarations.toArray(new XSDTypeDefinition[xsdElementDeclarations.size()])) {
// if( el instanceof XSDComplexTypeDefinition){
boolean exist = false;
for (XSDTypeDefinition type : list) {
if (type.getName().equals(el.getName()) && type.getTargetNamespace() != null && el.getTargetNamespace() != null && type.getTargetNamespace().equals(el.getTargetNamespace())) {
exist = true;
break;
} else if (type.getName().equals(el.getName()) && type.getTargetNamespace() == null && el.getTargetNamespace() == null) {
exist = true;
break;
}
}
if (!exist && (el.getTargetNamespace() != null && !el.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) || el.getTargetNamespace() == null) {
list.add(el);
}
// }
}
// }
return list.toArray(new XSDTypeDefinition[list.size()]);
// return xsdElementDeclarations.toArray(new XSDTypeDefinition[xsdElementDeclarations.size()] );
}
if (parent instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition attributeGroupDefinition = (XSDAttributeGroupDefinition) parent;
if (// a ref
attributeGroupDefinition.getContents().size() == 0)
attributeGroupDefinition = attributeGroupDefinition.getResolvedAttributeGroupDefinition();
return attributeGroupDefinition.getContents().toArray(new Object[attributeGroupDefinition.getContents().size()]);
}
if (parent instanceof XSDParticle) {
// a particle inside a choice or sequence or whatever
XSDParticle xsdParticle = (XSDParticle) parent;
return getXSDParticleChildren(xsdParticle);
}
if (parent instanceof XSDTypeDefinition) {
if (parent instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition std = (XSDSimpleTypeDefinition) parent;
if (std.getVariety().equals(XSDVariety.ATOMIC_LITERAL)) {
ArrayList list = new ArrayList();
// add Base Type if not a pre-defined type
if (std != null && std.getSchema() != null && std.getSchema().getSchemaForSchema() != null)
if (!std.getSchema().getSchemaForSchema().getTypeDefinitions().contains(std))
list.add(std.getBaseTypeDefinition());
list.addAll(std.getFacetContents());
return list.toArray(new Object[list.size()]);
}
if (std.getVariety().equals(XSDVariety.LIST_LITERAL)) {
// FIXME: How do we indicate it is a LIST?
return new XSDSimpleTypeDefinition[] { std.getBaseTypeDefinition() };
}
if (std.getVariety().equals(XSDVariety.UNION_LITERAL))
return (XSDSimpleTypeDefinition[]) (std.getMemberTypeDefinitions().toArray(new XSDSimpleTypeDefinition[std.getMemberTypeDefinitions().size()]));
// return new Object[]{std.getBaseTypeDefinition()};
}
if (parent instanceof XSDComplexTypeDefinition) {
XSDComplexTypeContent xsdComplexTypeContent = ((XSDComplexTypeDefinition) parent).getContent();
ArrayList<Object> list = new ArrayList<Object>();
list.addAll(((XSDComplexTypeDefinition) parent).getAttributeContents());
if (xsdComplexTypeContent == null) {
XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) parent;
list.add(ctd.getBaseTypeDefinition());
return list.toArray(new Object[list.size()]);
} else {
if (xsdComplexTypeContent instanceof XSDSimpleTypeDefinition) {
list.add(xsdComplexTypeContent);
return list.toArray(new Object[list.size()]);
}
if (xsdComplexTypeContent instanceof XSDParticle)
return getXSDParticleChildren((XSDParticle) xsdComplexTypeContent);
// return children
list.add(((XSDComplexTypeDefinition) parent).getContent());
return list.toArray(new Object[list.size()]);
}
}
}
if (parent instanceof XSDModelGroup) {
XSDModelGroup modelGroup = ((XSDModelGroup) parent);
EList list = modelGroup.getContents();
List<XSDParticle> ls = new ArrayList<XSDParticle>();
if (filter != null && !filter.isAll()) {
for (XSDParticle el : (XSDParticle[]) list.toArray(new XSDParticle[list.size()])) {
XSDTerm tm = el.getTerm();
if (tm instanceof XSDElementDeclaration) {
XSDAnnotation annotation = ((XSDElementDeclaration) tm).getAnnotation();
if (isInclude(annotation)) {
ls.add(el);
}
}
}
return ls.toArray(new XSDParticle[ls.size()]);
}
return list.toArray(new Object[list.size()]);
}
if (parent instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition std = (XSDSimpleTypeDefinition) parent;
if (std.getVariety().equals(XSDVariety.ATOMIC_LITERAL)) {
ArrayList list = new ArrayList();
// add Base Type if not a pre-defined type
if (!std.getSchema().getSchemaForSchema().getTypeDefinitions().contains(std))
list.add(std.getBaseTypeDefinition());
list.addAll(std.getFacetContents());
return list.toArray(new Object[list.size()]);
}
if (std.getVariety().equals(XSDVariety.LIST_LITERAL)) {
// FIXME: How do we indicate it is a LIST?
return new XSDSimpleTypeDefinition[] { std.getBaseTypeDefinition() };
}
if (std.getVariety().equals(XSDVariety.UNION_LITERAL))
return std.getMemberTypeDefinitions().toArray(new XSDSimpleTypeDefinition[std.getMemberTypeDefinitions().size()]);
// return new Object[]{std.getBaseTypeDefinition()};
}
if (parent instanceof XSDIdentityConstraintDefinition) {
ArrayList list = new ArrayList();
if (filter != null && !filter.isAll()) {
} else {
list.add(((XSDIdentityConstraintDefinition) parent).getSelector());
list.addAll(((XSDIdentityConstraintDefinition) parent).getFields());
}
return list.toArray(new Object[list.size()]);
}
if (parent instanceof XSDAnnotation) {
ArrayList list = new ArrayList();
if (filter != null && !filter.isAll()) {
} else {
XSDAnnotation annotation = (XSDAnnotation) parent;
list.addAll(annotation.getUserInformation());
list.addAll(annotation.getApplicationInformation());
}
return list.size() == 0 ? new Object[0] : list.toArray(new Object[list.size()]);
}
if (parent instanceof Element) {
// appinfos
return new Object[0];
}
return new Object[0];
}
use of org.eclipse.xsd.XSDElementDeclaration 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.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class UtilTest method testIsBuildInType.
@Test
public void testIsBuildInType() {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) schema.getElementDeclarations().get(0).getTypeDefinition();
XSDModelGroup group = (XSDModelGroup) ((XSDParticle) complexType.getContent()).getTerm();
XSDElementDeclaration el = (XSDElementDeclaration) group.getParticles().get(0).getTerm();
boolean ret = Util.isBuildInType((XSDSimpleTypeDefinition) el.getType());
assertEquals(ret, true);
}
use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class UtilTest method testFindReference.
@Test
public void testFindReference() {
XSDFactory factory = XSDFactory.eINSTANCE;
// $NON-NLS-1$ //$NON-NLS-2$
String conceptName1 = "Product", conceptName2 = "Store";
String refName = conceptName2;
XSDSchema xschema = factory.createXSDSchema();
XSDElementDeclaration referencedEntity = Util.findReference(null, null);
assertNull(referencedEntity);
referencedEntity = Util.findReference(refName, null);
assertNull(referencedEntity);
referencedEntity = Util.findReference(null, xschema);
assertNull(referencedEntity);
referencedEntity = Util.findReference(refName, xschema);
assertNull(referencedEntity);
XSDElementDeclaration concept1 = factory.createXSDElementDeclaration();
concept1.setName(conceptName1);
XSDElementDeclaration concept2 = factory.createXSDElementDeclaration();
concept2.setName(conceptName2);
xschema.getContents().add(concept1);
xschema.getContents().add(concept2);
referencedEntity = Util.findReference(refName, xschema);
assertNotNull(referencedEntity);
assertSame(concept2, referencedEntity);
// $NON-NLS-1$//$NON-NLS-2$
refName = refName + " : " + "fair";
referencedEntity = Util.findReference(refName, xschema);
assertNotNull(referencedEntity);
assertSame(concept2, referencedEntity);
// $NON-NLS-1$
refName = "ProductFamily";
referencedEntity = Util.findReference(refName, xschema);
assertNull(referencedEntity);
}
use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class UtilTest method testGetRealKeyInfos.
@Test
public void testGetRealKeyInfos() throws Exception {
XSDSchema xsdSchema = createSchema();
XSDElementDeclaration elementDeclaration = null;
EList<XSDElementDeclaration> declarations = xsdSchema.getElementDeclarations();
for (XSDElementDeclaration xed : declarations) {
if (xed.getName().equals("opo")) {
// $NON-NLS-1$
elementDeclaration = xed;
break;
}
}
if (elementDeclaration != null) {
XSDComplexTypeDefinition childType = (XSDComplexTypeDefinition) elementDeclaration.getType();
childType = (XSDComplexTypeDefinition) childType.getBaseTypeDefinition();
childType = (XSDComplexTypeDefinition) childType.getBaseTypeDefinition();
XSDParticle xsdParticle = (XSDParticle) childType.getContent();
XSDModelGroup modelGroup = (XSDModelGroup) xsdParticle.getTerm();
EList<XSDParticle> particles = modelGroup.getParticles();
XSDParticle primaryKeyParticle = null;
XSDParticle nonePrimaryKeyParticle = null;
for (XSDParticle particle : particles) {
XSDElementDeclaration term = (XSDElementDeclaration) particle.getTerm();
if (term.getName().equals("Id")) {
// $NON-NLS-1$
primaryKeyParticle = particle;
break;
} else {
nonePrimaryKeyParticle = particle;
}
}
if (nonePrimaryKeyParticle == null) {
nonePrimaryKeyParticle = particles.get(particles.size() - 1);
}
assertNull(Util.getRealKeyInfos(null, null));
assertNull(Util.getRealKeyInfos(elementDeclaration, null));
assertNull(Util.getRealKeyInfos(null, primaryKeyParticle));
assertEquals(Util.getRealKeyInfos(elementDeclaration, nonePrimaryKeyParticle).size(), 0);
List<Object> realKeyInfos = Util.getRealKeyInfos(elementDeclaration, primaryKeyParticle);
assertNotNull(realKeyInfos);
assertEquals(realKeyInfos.size(), 2);
assertTrue((realKeyInfos.get(0) instanceof XSDIdentityConstraintDefinition));
assertTrue((realKeyInfos.get(1) instanceof XSDXPathDefinition));
// $NON-NLS-1$
assertEquals(((XSDXPathDefinition) realKeyInfos.get(1)).getValue(), "Id");
}
}
Aggregations