use of org.eclipse.xsd.XSDParticle 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.XSDParticle 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);
}
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class XSDGenerateHTML method printParticle.
/**
* Print a particle with markup for the document.
*
* @param xsdParticle a particle.
* @param rootElementDeclarationMarkup the markup.
*/
public void printParticle(XSDParticle xsdParticle, String rootElementDeclarationMarkup) {
int minOccurs = xsdParticle.getMinOccurs();
int maxOccurs = xsdParticle.getMaxOccurs();
XSDTerm xsdTerm = xsdParticle.getTerm();
if (xsdTerm instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) xsdTerm;
String elementDeclarationName = xsdElementDeclaration.getName();
String elementDeclarationMarkup = null;
if (rootElementDeclarationMarkup == null) {
elementDeclarationMarkup = getElementDeclarationMarkup(elementDeclarationName);
}
if (elementDeclarationMarkup != null) {
// $NON-NLS-1$
System.out.print("<span class='");
System.out.print(elementDeclarationMarkup);
// $NON-NLS-1$
System.out.print("'>");
}
// $NON-NLS-1$ //$NON-NLS-2$
System.out.print("<a href='#" + getLocalAnchor(xsdElementDeclaration) + "'>");
System.out.print(elementDeclarationName.charAt(0));
// $NON-NLS-1$
System.out.print("</a>");
System.out.print(elementDeclarationName.substring(1));
if (elementDeclarationMarkup != null) {
// $NON-NLS-1$
System.out.print("</span>");
}
if (minOccurs == 0) {
if (maxOccurs == 1) {
// $NON-NLS-1$
System.out.print("?");
} else {
// $NON-NLS-1$
System.out.print("*");
}
} else if (maxOccurs == -1) {
// $NON-NLS-1$
System.out.print("+");
}
} else if (xsdTerm instanceof XSDModelGroup) {
XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdTerm;
List particles = xsdModelGroup.getParticles();
boolean isRedundant = particles.size() == 1 && minOccurs == 1 && maxOccurs == 1 && ((XSDParticle) particles.get(0)).getTerm() instanceof XSDModelGroup;
if (!isRedundant) {
// ) //$NON-NLS-1$
System.out.print("(");
}
String separator = // $NON-NLS-1$
XSDCompositor.CHOICE_LITERAL == xsdModelGroup.getCompositor() ? // $NON-NLS-1$
" | " : // $NON-NLS-1$ //$NON-NLS-2$
XSDCompositor.SEQUENCE_LITERAL == xsdModelGroup.getCompositor() ? ", " : " & ";
for (Iterator i = xsdModelGroup.getParticles().iterator(); i.hasNext(); ) {
XSDParticle childParticle = (XSDParticle) i.next();
printParticle(childParticle, rootElementDeclarationMarkup);
if (i.hasNext()) {
System.out.print(separator);
}
}
if (!isRedundant) {
// (
// $NON-NLS-1$
System.out.print(")");
if (minOccurs == 0) {
if (maxOccurs == 1) {
// $NON-NLS-1$
System.out.print("?");
} else {
// $NON-NLS-1$
System.out.print("*");
}
} else if (maxOccurs == -1) {
// $NON-NLS-1$
System.out.print("+");
}
}
} else if (xsdTerm instanceof XSDWildcard) {
// $NON-NLS-1$
System.out.print("<em>{any}</em>");
}
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class XSDParser method processParticle.
public void processParticle(XSDParticle xsdParticle, String ident) {
int minOccurs = xsdParticle.getMinOccurs();
int maxOccurs = xsdParticle.getMaxOccurs();
XSDTerm xsdTerm = xsdParticle.getTerm();
if (xsdTerm instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) xsdTerm;
String elementDeclarationName = xsdElementDeclaration.getName();
System.out.print(elementDeclarationName);
if (minOccurs == 0) {
if (maxOccurs == 1) {
// $NON-NLS-1$
System.out.print("?");
} else {
// $NON-NLS-1$
System.out.print("*");
}
} else if (maxOccurs == -1) {
// $NON-NLS-1$
System.out.print("+");
}
System.out.println(// $NON-NLS-1$
" -- root Container: " + ((XSDParticle) xsdElementDeclaration.getContainer()).getTerm().getClass().getName());
} else if (xsdTerm instanceof XSDModelGroup) {
XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdTerm;
List particles = xsdModelGroup.getParticles();
String separator = // $NON-NLS-1$
XSDCompositor.CHOICE_LITERAL == xsdModelGroup.getCompositor() ? // $NON-NLS-1$
"|" : // $NON-NLS-1$ //$NON-NLS-2$
XSDCompositor.SEQUENCE_LITERAL == xsdModelGroup.getCompositor() ? "&" : "a";
for (Iterator it = particles.iterator(); it.hasNext(); ) {
XSDParticle childParticle = (XSDParticle) it.next();
// $NON-NLS-1$ //$NON-NLS-2$
System.out.print(ident + "[" + separator + "]");
// $NON-NLS-1$
processParticle(childParticle, ident + " ");
}
if (minOccurs == 0) {
if (maxOccurs == 1) {
// $NON-NLS-1$
System.out.print("?");
} else {
// $NON-NLS-1$
System.out.print("*");
}
} else if (maxOccurs == -1) {
// $NON-NLS-1$
System.out.print("+");
}
System.out.println();
} else if (xsdTerm instanceof XSDWildcard) {
// $NON-NLS-1$
System.out.print("<em>{any}</em>");
}
}
use of org.eclipse.xsd.XSDParticle 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;
}
Aggregations