use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class XSDUtil method isPrimaryKeyElement.
public static boolean isPrimaryKeyElement(XSDParticle particle) {
if (isSimpleTypeElement(particle)) {
Map<XSDElementDeclaration, List<XSDComplexTypeDefinition>> entityMapComplexTypes = buildEntityUsedComplexTypeMap((XSDSchema) particle.getRootContainer());
Iterator<XSDElementDeclaration> iterator = entityMapComplexTypes.keySet().iterator();
while (iterator.hasNext()) {
XSDElementDeclaration concept = iterator.next();
List<String> keyFields = getKeyFields(concept);
if (keyFields.contains(((XSDElementDeclaration) particle.getTerm()).getName())) {
List<XSDComplexTypeDefinition> ctypes = entityMapComplexTypes.get(concept);
for (XSDComplexTypeDefinition ctype : ctypes) {
XSDComplexTypeContent ctypeContent = ctype.getContent();
if (ctypeContent instanceof XSDParticle) {
XSDParticle typeParticle = (XSDParticle) ctypeContent;
XSDParticleContent particleContent = typeParticle.getContent();
if (particleContent instanceof XSDModelGroup) {
XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
if (particleGroup.getContents().contains(particle)) {
return true;
}
}
}
}
}
}
}
return false;
}
use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class XSDUtil method isFirstLevelChild.
public static boolean isFirstLevelChild(XSDParticle particle) {
XSDSchema schema = (XSDSchema) particle.getRootContainer();
Map<XSDElementDeclaration, List<XSDComplexTypeDefinition>> entityMapComplexTypes = buildEntityUsedComplexTypeMap(schema);
Iterator<XSDElementDeclaration> iterator = entityMapComplexTypes.keySet().iterator();
while (iterator.hasNext()) {
XSDElementDeclaration concept = iterator.next();
List<XSDComplexTypeDefinition> ctypes = entityMapComplexTypes.get(concept);
for (XSDComplexTypeDefinition ctype : ctypes) {
XSDComplexTypeContent ctypeContent = ctype.getContent();
if (ctypeContent instanceof XSDParticle) {
XSDParticle typeParticle = (XSDParticle) ctypeContent;
XSDParticleContent particleContent = typeParticle.getContent();
if (particleContent instanceof XSDModelGroup) {
XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
if (particleGroup.getContents().contains(particle)) {
return true;
}
}
}
}
}
return false;
}
use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class Util method getComplexTypeGroupType.
public static XSDCompositor getComplexTypeGroupType(XSDComplexTypeDefinition type) {
if (type == null || !(type.getContent() instanceof XSDParticle) || !(((XSDParticle) type.getContent()).getContent() instanceof XSDModelGroup)) {
return null;
}
XSDParticle groupParticle = (XSDParticle) type.getContent();
XSDModelGroup group = (XSDModelGroup) groupParticle.getContent();
return group.getCompositor();
}
use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class Util method findOutAllSonElements.
private static List<XSDElementDeclaration> findOutAllSonElements(XSDElementDeclaration decl, Set<XSDConcreteComponent> complexTypes) {
List<XSDElementDeclaration> holder = new ArrayList<XSDElementDeclaration>();
if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) decl.getTypeDefinition();
if (complexTypes.contains(type)) {
return holder;
}
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();
boolean addComplexType = false;
for (XSDParticle pt : elist) {
if (pt.getContent() instanceof XSDElementDeclaration) {
XSDElementDeclaration elem = (XSDElementDeclaration) pt.getContent();
if (!addComplexType) {
complexTypes.add(type);
addComplexType = true;
}
if (StringUtils.equals(elem.getName(), decl.getName())) {
if (ObjectUtils.equals(elem.getType(), decl.getType())) {
if (StringUtils.equals(elem.getTargetNamespace(), decl.getTargetNamespace())) {
continue;
}
}
}
holder.add(elem);
}
}
}
}
}
return holder;
}
use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class Util method getAllComplexTypeChildren.
/**
* get all complex types's complextype children
*
* @param complexTypeDefinition
* @return
*/
public static ArrayList<Object> getAllComplexTypeChildren(XSDElementDeclaration declaration) {
XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) declaration.getTypeDefinition();
XSDComplexTypeContent xsdComplexTypeContent = complexTypeDefinition.getContent();
ArrayList<Object> list = new ArrayList<Object>();
// Now determine whether ref. If ref look at the base Type definition
if (xsdComplexTypeContent == null) {
XSDTypeDefinition typeDefinition = complexTypeDefinition.getBaseTypeDefinition();
if (typeDefinition instanceof XSDComplexTypeDefinition) {
list.add(((XSDComplexTypeDefinition) typeDefinition).getContent());
}
}
// check if we are extending a complex Definition
if ("extension".equals(complexTypeDefinition.getDerivationMethod().getName())) {
// $NON-NLS-1$
if (complexTypeDefinition.getBaseTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition complex = (XSDComplexTypeDefinition) complexTypeDefinition.getBaseTypeDefinition();
XSDParticle particle = (XSDParticle) complex.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();
if (typeDef instanceof XSDComplexTypeDefinition) {
list.addAll(getAllComplexTypeChildren((XSDElementDeclaration) pt.getContent()));
}
}
}
}
}
}
// now check what we have in the content
// if (xsdComplexTypeContent instanceof XSDComplexTypeDefinition) {
list.add(declaration);
if (xsdComplexTypeContent instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) xsdComplexTypeContent;
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();
if (typeDef instanceof XSDComplexTypeDefinition) {
list.addAll(getAllComplexTypeChildren((XSDElementDeclaration) pt.getContent()));
}
}
}
}
}
return list;
}
Aggregations