use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class Util method isReferrenced.
private static boolean isReferrenced(XSDElementDeclaration element, XSDElementDeclaration term) {
if (element == term) {
return true;
}
if (term.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) term.getTypeDefinition()).getContent();
if (fromcomplexType instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) fromcomplexType;
if (particle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup modelGroup = ((XSDModelGroup) particle.getTerm());
EList<?> fromlist = modelGroup.getContents();
for (Object obj : fromlist) {
XSDTerm t = ((XSDParticle) obj).getTerm();
if (t == element) {
return true;
}
}
}
}
}
return false;
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class Util method getComplexTypeDefinitionChildren.
public static ArrayList<Object> getComplexTypeDefinitionChildren(XSDComplexTypeDefinition complexTypeDefinition, boolean ignoreRestriction) {
XSDComplexTypeContent xsdComplexTypeContent = complexTypeDefinition.getContent();
ArrayList<Object> list = new ArrayList<Object>();
// Now determine whether ref. If ref look at the base Type definition
XSDTypeDefinition baseTypeDefinition = complexTypeDefinition.getBaseTypeDefinition();
if (xsdComplexTypeContent == null) {
XSDTypeDefinition typeDefinition = baseTypeDefinition;
// if a simple type return the simple type
if (typeDefinition instanceof XSDSimpleTypeDefinition) {
list.add(typeDefinition);
return list;
} else {
}
// it is a complex Type
xsdComplexTypeContent = ((XSDComplexTypeDefinition) typeDefinition).getContent();
}
// check if we are extending a complex Definition
if ("extension".equals(complexTypeDefinition.getDerivationMethod().getName())) {
if (baseTypeDefinition instanceof XSDComplexTypeDefinition && baseTypeDefinition != complexTypeDefinition) {
String name = ((XSDComplexTypeDefinition) baseTypeDefinition).getDerivationMethod().getName();
if (name.equals("restriction") || ignoreRestriction) {
// $NON-NLS-1$
list.addAll(getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) baseTypeDefinition, ignoreRestriction));
//
}
}
}
// Attributes
if (complexTypeDefinition.getAttributeContents() != null) {
list.addAll(complexTypeDefinition.getAttributeContents());
}
// Annotations
if (complexTypeDefinition.getAnnotations() != null) {
list.addAll(complexTypeDefinition.getAnnotations());
}
// simple type return the simple type
if (xsdComplexTypeContent instanceof XSDSimpleTypeDefinition) {
list.add(xsdComplexTypeContent);
return list;
}
// xsd Particle: we have a model group
if (xsdComplexTypeContent instanceof XSDParticle) {
// log.info("Model Group?: "+((XSDParticle)xsdComplexTypeContent).getTerm());
if (((XSDParticle) xsdComplexTypeContent).getTerm() instanceof XSDModelGroup) {
// return the model group
list.add(((XSDParticle) xsdComplexTypeContent).getTerm());
return list;
} else {
// wild card or element declaration '?)
list.add(((XSDParticle) xsdComplexTypeContent).getTerm());
return list;
}
}
// what else could it be ?
list.add(xsdComplexTypeContent);
return list;
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class SelectXPathComposite method getXpath.
private String getXpath() {
// $NON-NLS-1$
String path = "";
// $NON-NLS-1$
String totalXpath = "";
TreeItem item;
TreeItem[] items = tvXPath.getTree().getSelection();
for (int i = 0; i < items.length; i++) {
item = items[i];
XSDConcreteComponent component = (XSDConcreteComponent) item.getData();
if (!(component instanceof XSDParticle) && !(component instanceof XSDElementDeclaration)) {
continue;
}
do {
component = (XSDConcreteComponent) item.getData();
if (component instanceof XSDParticle) {
if (((XSDParticle) component).getTerm() instanceof XSDElementDeclaration) {
// $NON-NLS-1$
path = "/" + ((XSDElementDeclaration) ((XSDParticle) component).getTerm()).getName() + path;
}
} else if (component instanceof XSDElementDeclaration) {
// $NON-NLS-1$//$NON-NLS-2$
path = (isAbsolutePath ? "/" : "") + ((XSDElementDeclaration) component).getName() + path;
}
item = item.getParentItem();
} while (item != null);
if (i == 0) {
totalXpath = path;
} else {
// $NON-NLS-1$
totalXpath += "&" + path;
}
// $NON-NLS-1$
path = "";
}
// for(i=0
if (context != null && conceptName != null) {
if (totalXpath.equals(conceptName)) {
// $NON-NLS-1$
totalXpath = totalXpath.replaceAll(conceptName, "/");
} else {
// $NON-NLS-1$//$NON-NLS-2$
totalXpath = totalXpath.replaceAll(conceptName + "/", "");
}
if (totalXpath.equals(context) || totalXpath.equals(context.replaceAll(conceptName + "/", ""))) {
// $NON-NLS-1$//$NON-NLS-2$
// $NON-NLS-1$
totalXpath = ".";
}
if (// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
totalXpath.indexOf('/') == -1 && !totalXpath.equals(".") && !"/".equals(totalXpath) && !"/".equals(context) && !context.equals(conceptName)) {
// $NON-NLS-1$
totalXpath = "../" + totalXpath;
}
}
return totalXpath;
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class UtilTest method testGetComponentName.
@Test
public void testGetComponentName() {
// $NON-NLS-1$ //$NON-NLS-2$
String prefix = "name=\"", suffix = "\"";
String[] objNames = { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"product_elementdeclaration", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"product_particle", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"p_complextype", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"p_simpletype", "product_identityconstraintdef", // $NON-NLS-1$ //$NON-NLS-2$
"p_xpathdef" };
String[] expectedObjNames = new String[objNames.length];
for (int i = 0; i < objNames.length - 1; i++) {
expectedObjNames[i] = prefix + objNames[i] + suffix;
}
// $NON-NLS-1$
expectedObjNames[objNames.length - 1] = "xpath=\"" + objNames[objNames.length - 1] + suffix;
XSDFactory factory = XSDFactory.eINSTANCE;
try {
XSDElementDeclaration xsdElementDeclaration = factory.createXSDElementDeclaration();
xsdElementDeclaration.setName(objNames[0]);
XSDParticle xsdParticle = factory.createXSDParticle();
XSDElementDeclaration xsdParticleDeclaration = factory.createXSDElementDeclaration();
xsdParticleDeclaration.setName(objNames[1]);
xsdParticle.setTerm(xsdParticleDeclaration);
XSDComplexTypeDefinition xsdComplexTypeDefinition = factory.createXSDComplexTypeDefinition();
xsdComplexTypeDefinition.setName(objNames[2]);
XSDSimpleTypeDefinition xsdSimpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
xsdSimpleTypeDefinition.setName(objNames[3]);
XSDIdentityConstraintDefinition xsdIdConsDef = factory.createXSDIdentityConstraintDefinition();
xsdIdConsDef.setName(objNames[4]);
XSDXPathDefinition xsdPathDefinition = factory.createXSDXPathDefinition();
xsdPathDefinition.setValue(objNames[5]);
String name = Util.getComponentName(xsdElementDeclaration);
assertEquals(expectedObjNames[0], name);
name = Util.getComponentName(xsdParticle);
assertEquals(expectedObjNames[1], name);
name = Util.getComponentName(xsdComplexTypeDefinition);
assertEquals(expectedObjNames[2], name);
name = Util.getComponentName(xsdSimpleTypeDefinition);
assertEquals(expectedObjNames[3], name);
name = Util.getComponentName(xsdIdConsDef);
assertEquals(expectedObjNames[4], name);
name = Util.getComponentName(xsdPathDefinition);
assertEquals(expectedObjNames[5], name);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class UtilTest method testGetParticleReferenceName.
@Test
public void testGetParticleReferenceName() {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) schema.getElementDeclarations().get(0).getTypeDefinition();
XSDModelGroup group = (XSDModelGroup) ((XSDParticle) complexType.getContent()).getTerm();
XSDParticle curXSDParticle = group.getParticles().get(0);
String name = Util.getParticleReferenceName(curXSDParticle);
// $NON-NLS-1$
assertEquals(name, "");
}
Aggregations