use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class Util method findElementsUsingType.
/**
* Find elementDeclarations that use any types derived from a named type.
*
* <p>
* This shows one way to query the schema for elementDeclarations and then how to find specific kinds of
* typeDefinitions.
* </p>
*
* @param objList collection set to search for elemDecls
* @param localName for the type used
* @return Boolean indicate any XSDElementDeclarations is found or not
*/
public static boolean findElementsUsingType(List<Object> objList, XSDTypeDefinition localTypedef) {
for (Object obj : objList) {
if (obj == localTypedef) {
continue;
}
if (obj instanceof XSDParticle || obj instanceof XSDElementDeclaration || obj instanceof XSDTypeDefinition) {
XSDTypeDefinition typedef = null;
if (obj instanceof XSDParticle) {
XSDParticle xsdParticle = (XSDParticle) obj;
if (xsdParticle.getTerm() instanceof XSDElementDeclaration) {
obj = xsdParticle.getTerm();
}
}
if (obj instanceof XSDElementDeclaration) {
XSDElementDeclaration elem = (XSDElementDeclaration) obj;
if (elem.getAnonymousTypeDefinition() != null) {
typedef = elem.getAnonymousTypeDefinition();
} else if (elem.getTypeDefinition() != null) {
typedef = elem.getTypeDefinition();
} else {
// thus it's not using our type
continue;
}
} else {
typedef = (XSDTypeDefinition) obj;
}
if (typedef instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) typedef;
if (localTypedef.getName().equals(type.getName()) && (localTypedef instanceof XSDComplexTypeDefinition)) {
return true;
}
if (type.getContent() instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) type.getContent();
if (particle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup group = (XSDModelGroup) particle.getTerm();
EList<XSDParticle> elist = group.getContents();
for (XSDParticle pt : elist) {
if (pt.getContent() instanceof XSDElementDeclaration) {
XSDTypeDefinition typeDef = ((XSDElementDeclaration) pt.getContent()).getTypeDefinition();
boolean sameType = (typeDef instanceof XSDComplexTypeDefinition && localTypedef instanceof XSDComplexTypeDefinition) || (typeDef instanceof XSDSimpleTypeDefinition && localTypedef instanceof XSDSimpleTypeDefinition);
if (typeDef != null && typeDef.getName() != null && sameType) {
if ((localTypedef.getName().equals(typeDef.getName()))) {
return true;
}
}
}
}
}
}
} else if (typedef instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition type = (XSDSimpleTypeDefinition) typedef;
XSDSimpleTypeDefinition baseType = type.getBaseTypeDefinition();
if (baseType != null && baseType.getName().equals(localTypedef.getName()) && localTypedef instanceof XSDSimpleTypeDefinition) {
return true;
}
}
}
}
return false;
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class Util method isTypeDerivedFrom.
/**
*******************************************************************
* XSD Utils
********************************************************************
*/
public 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();
// As this convenience method if our parameters match
if (baseType.hasNameAndTargetNamespace(localName, namespace)) {
return true;
}
// If not, check to see if we've run up to the top
// Performance note: this is horribly inefficient,
// re-calling this same method every time; but it
// serves as a good example
XSDTypeDefinition rootType = typedef.getRootType();
if (rootType == baseType) {
// If we've hit the root, we aren't derived from it
return false;
} else {
// Otherwise continue to traverse upwards
return isTypeDerivedFrom(baseType, namespace, localName);
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class Util method getAllSuperComplexTypes.
/**
* contains childType itself
*/
public static List<XSDComplexTypeDefinition> getAllSuperComplexTypes(XSDComplexTypeDefinition childType) {
if (childType == null) {
return new ArrayList<XSDComplexTypeDefinition>();
}
XSDTypeDefinition rootType = childType.getRootType();
XSDTypeDefinition typeDefinition = childType;
List<XSDComplexTypeDefinition> hierarchyComplexTypes = new ArrayList<XSDComplexTypeDefinition>();
while (typeDefinition != null && typeDefinition instanceof XSDComplexTypeDefinition) {
hierarchyComplexTypes.add((XSDComplexTypeDefinition) typeDefinition);
if (typeDefinition.equals(rootType)) {
break;
}
typeDefinition = typeDefinition.getBaseType();
}
return hierarchyComplexTypes;
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class XSDAnnotationsStructure method setAutoExpand.
/**
**************************************************************************
* Auto Expand
* @throws Exception
***************************************************************************
*/
public boolean setAutoExpand(String value) throws Exception {
if (!(declaration.getTypeDefinition() instanceof XSDComplexTypeDefinition)) {
return false;
}
XSDSchema xsd = schema != null ? schema : declaration.getSchema();
// $NON-NLS-1$
String auto = "X_AutoExpand";
String xsdString = Util.nodeToString(xsd.getDocument().getDocumentElement());
ArrayList<Object> objs = Util.getAllComplexTypeChildren(declaration);
for (Object obj : objs) {
if (obj instanceof XSDElementDeclaration || obj instanceof XSDParticle) {
boolean isImported = false;
if (obj instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) obj;
if (particle.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
if (Util.IsAImporedElement(decl, xsdString)) {
XSDTypeDefinition typeDef = decl.getTypeDefinition();
if (Util.IsAImporedElement(typeDef, xsdString)) {
isImported = true;
}
}
}
} else if (obj instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) obj;
if (Util.IsAImporedElement(decl, xsdString)) {
isImported = true;
}
}
if (!isImported) {
XSDAnnotationsStructure annotion = new XSDAnnotationsStructure((XSDComponent) obj);
annotion.setAppInfo(auto, value, true);
}
}
}
return true;
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class XSDAnnotationsStructure method setAccessRole.
/**
**************************************************************************
* WRITE ACCESS
*
* @throws XtentisException
***************************************************************************
*/
public boolean setAccessRole(Collection<String> roles, boolean recursive, IStructuredContentProvider provider, String access) throws Exception {
XSDSchema xsd = schema != null ? schema : declaration.getSchema();
String xsdString = Util.nodeToString(xsd.getDocument().getDocumentElement());
if (recursive) {
ArrayList<Object> objList = new ArrayList<Object>();
XSDComponent component = declaration;
if (declaration == null) {
component = this.componet;
}
Object[] objs = Util.getAllObject(component, objList, provider);
while (objs.length > 0) {
Object[] objCpys = objs;
for (Object obj : objCpys) {
if (obj instanceof XSDElementDeclaration || obj instanceof XSDParticle) {
boolean isImported = false;
if (obj instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) obj;
if (particle.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
if (Util.IsAImporedElement(decl, xsdString)) {
XSDTypeDefinition typeDef = decl.getTypeDefinition();
if (Util.IsAImporedElement(typeDef, xsdString)) {
isImported = true;
}
}
}
} else if (obj instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) obj;
if (Util.IsAImporedElement(decl, xsdString)) {
isImported = true;
}
}
if (!isImported) {
XSDAnnotationsStructure annotion = new XSDAnnotationsStructure((XSDComponent) obj);
// see 7993, if UUID/AUTO_INCREMENT ,should not add write access
if (obj instanceof XSDParticle) {
XSDParticle o = (XSDParticle) obj;
// String name=Util.getFirstTextNode(o.getElement(), "@name");
// $NON-NLS-1$
String type = Util.getFirstTextNode(o.getElement(), "@type");
if (EUUIDCustomType.AUTO_INCREMENT.equals(type) || EUUIDCustomType.UUID.equals(type)) {
objList.remove(obj);
objs = objList.toArray();
continue;
}
}
// X_Write
annotion.removeAppInfos(access);
for (Iterator<String> iter = roles.iterator(); iter.hasNext(); ) {
String role = iter.next();
annotion.addAppInfo(access, role);
}
}
}
objList.remove(obj);
objs = objList.toArray();
}
}
return setAccessRole(roles, access);
} else {
if (Util.IsAImporedElement(declaration, xsdString)) {
return false;
}
return setAccessRole(roles, access);
}
}
Aggregations