use of org.eclipse.xsd.XSDComplexTypeContent in project tmdm-studio-se by Talend.
the class XSDUtilTest method testGetAnnotationValue.
@Test
public void testGetAnnotationValue() throws Exception {
// $NON-NLS-1$
String fileName = "Product_0.1.xsd";
// $NON-NLS-1$
String elementName = "Family";
// $NON-NLS-1$
String fk = "Store/Id";
String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
assertNotNull(xsdString);
XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
XSDTypeDefinition typeDefinition = element.getTypeDefinition();
if (typeDefinition instanceof XSDComplexTypeDefinition) {
XSDComplexTypeContent xsdComplexTypeContent = ((XSDComplexTypeDefinition) typeDefinition).getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
XSDParticleContent content = ((XSDParticle) xsdComplexTypeContent).getContent();
if (content instanceof XSDModelGroup) {
for (XSDParticle particle : ((XSDModelGroup) content).getParticles()) {
XSDTerm term = particle.getTerm();
if (term instanceof XSDElementDeclaration) {
XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) term;
if (elementDeclaration.getName().equals(elementName)) {
String value = XSDUtil.getAnnotationValue(elementDeclaration, X_FOREIGN_KEY);
assertEquals(fk, value);
return;
}
}
}
}
}
}
}
fail();
}
use of org.eclipse.xsd.XSDComplexTypeContent in project tmdm-studio-se by Talend.
the class XSDUtilTest method testIsEntity.
@Test
public void testIsEntity() throws Exception {
// $NON-NLS-1$
String fileName = "Product_0.1.xsd";
// $NON-NLS-1$
String elementName = "Product";
String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
assertNotNull(xsdString);
XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
XSDElementDeclaration decl = null;
for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
if (element.getName().equals(elementName)) {
decl = element;
}
assertTrue(XSDUtil.isEntity(element));
}
if (decl != null) {
XSDComplexTypeDefinition ctypeDefinition = (XSDComplexTypeDefinition) decl.getTypeDefinition();
XSDComplexTypeContent content = ctypeDefinition.getContent();
if (content instanceof XSDParticle) {
XSDParticle xsdParticle = (XSDParticle) content;
XSDParticleContent particleContent = xsdParticle.getContent();
if (particleContent instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) particleContent;
EList<XSDParticle> contents = modelGroup.getContents();
for (XSDParticle particle : contents) {
if (particle.getContent() instanceof XSDElementDeclaration) {
assertFalse(XSDUtil.isEntity(particle.getContent()));
}
}
}
}
}
}
use of org.eclipse.xsd.XSDComplexTypeContent in project tmdm-studio-se by Talend.
the class XSDUtilTest method testIsPrimaryKeyElement.
@Test
public void testIsPrimaryKeyElement() throws Exception {
// $NON-NLS-1$
String fileName = "Product_0.1.xsd";
// $NON-NLS-1$
String elementName = "Product";
String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
assertNotNull(xsdString);
XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
XSDElementDeclaration decl = null;
for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
if (element.getName().equals(elementName)) {
decl = element;
}
}
if (decl != null) {
XSDComplexTypeDefinition ctypeDefinition = (XSDComplexTypeDefinition) decl.getTypeDefinition();
XSDComplexTypeContent ctypeContent = ctypeDefinition.getContent();
if (ctypeContent instanceof XSDParticle) {
XSDParticle typeParticle = (XSDParticle) ctypeContent;
XSDParticleContent particleContent = typeParticle.getContent();
if (particleContent instanceof XSDModelGroup) {
XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
for (XSDParticle particle : particleGroup.getContents()) {
if (particle.getContent() instanceof XSDElementDeclaration && ((XSDElementDeclaration) particle.getContent()).getName().equals("Id")) {
// $NON-NLS-1$
assertTrue(XSDUtil.isPrimaryKeyElement(particle));
} else {
assertFalse(XSDUtil.isPrimaryKeyElement(particle));
}
}
}
}
}
}
use of org.eclipse.xsd.XSDComplexTypeContent 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.XSDComplexTypeContent in project webtools.sourceediting by eclipse.
the class AddXSDElementCommand method getModelGroup.
// PORT
public XSDModelGroup getModelGroup(XSDComplexTypeDefinition cType) {
XSDParticle particle = null;
XSDComplexTypeContent xsdComplexTypeContent = cType.getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
particle = (XSDParticle) xsdComplexTypeContent;
}
if (particle == null) {
return null;
}
Object particleContent = particle.getContent();
XSDModelGroup group = null;
if (particleContent instanceof XSDModelGroupDefinition) {
group = ((XSDModelGroupDefinition) particleContent).getResolvedModelGroupDefinition().getModelGroup();
} else if (particleContent instanceof XSDModelGroup) {
group = (XSDModelGroup) particleContent;
}
if (group == null) {
return null;
}
return group;
}
Aggregations