use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.
the class TypesLabelProvider method getText.
@Override
public String getText(Object obj) {
if (obj instanceof XSDElementDeclaration) {
String name = ((XSDElementDeclaration) obj).getName();
if (((XSDElementDeclaration) obj).isAbstract()) {
name += Messages.TypesLabelProvider_0;
}
String tail = ((XSDElementDeclaration) obj).getTargetNamespace() == null ? "" : // $NON-NLS-1$//$NON-NLS-2$
" : " + ((XSDElementDeclaration) obj).getTargetNamespace();
return name + tail;
}
if (obj instanceof XSDParticle) {
XSDParticle xsdParticle = (XSDParticle) obj;
XSDParticleContent content = xsdParticle.getContent();
XSDTerm xsdTerm = xsdParticle.getTerm();
// $NON-NLS-1$
String name = "";
if (content instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) content;
// $NON-NLS-1$
name += (decl.getName() == null ? "" : decl.getName());
if (decl.getTypeDefinition() == null) {
// $NON-NLS-1$//$NON-NLS-2$
name += " [" + ((XSDElementDeclaration) xsdTerm).getName() + "]";
}
} else if (content instanceof XSDModelGroup) {
// System.out.println("SHOULD NOT HAPPEN????");
if (xsdParticle.getContainer() instanceof XSDComplexTypeDefinition) {
String ctdName = ((XSDComplexTypeDefinition) xsdParticle.getContainer()).getName();
// $NON-NLS-1$
name = (ctdName != null ? ctdName : "");
}
/*
* int type = ((XSDModelGroup)xsdTerm).getCompositor().getValue(); switch (type) { case
* XSDCompositor.ALL: name= ""; break; case XSDCompositor.CHOICE: name= ""; break; case
* XSDCompositor.SEQUENCE: name= ""; break; }
*/
} else {
// $NON-NLS-1$
name = "[Any]";
}
if (!((xsdParticle.getMinOccurs() == 1) && (xsdParticle.getMaxOccurs() == 1))) {
// $NON-NLS-1$
name += " [";
name += xsdParticle.getMinOccurs();
// $NON-NLS-1$
name += "...";
// $NON-NLS-1$//$NON-NLS-2$
name += (xsdParticle.getMaxOccurs() == -1) ? "many" : "" + xsdParticle.getMaxOccurs();
// $NON-NLS-1$
name += "]";
}
return name;
}
if (obj instanceof XSDSimpleTypeDefinition) {
return getSimpleTypeDefinition((XSDSimpleTypeDefinition) obj);
}
if (obj instanceof XSDComplexTypeDefinition) {
return getComplexTypeDefinition((XSDComplexTypeDefinition) obj);
}
if (obj instanceof XSDModelGroup) {
// return the name of the complex type definition
XSDParticle particle = (XSDParticle) (((XSDModelGroup) obj).getContainer());
XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) particle.getContainer();
String name = complexTypeDefinition.getName();
if (name == null) {
// $NON-NLS-1$
name = "";
}
// return the occurrence
if (!((particle.getMinOccurs() == 1) && (particle.getMaxOccurs() == 1))) {
// $NON-NLS-1$
name += " [";
name += particle.getMinOccurs();
// $NON-NLS-1$
name += "...";
// $NON-NLS-1$//$NON-NLS-2$
name += (particle.getMaxOccurs() == -1) ? "many" : "" + particle.getMaxOccurs();
// $NON-NLS-1$
name += "]";
}
XSDTypeDefinition extendType = complexTypeDefinition.getBaseTypeDefinition();
// $NON-NLS-1$
String extendTypeName = "";
if (extendType != null && extendType != complexTypeDefinition && !"anyType".equals(extendType.getName())) {
// $NON-NLS-1$
// $NON-NLS-1$
extendTypeName = ":" + extendType.getName();
}
return name + extendTypeName;
}
if (obj instanceof XSDFacet) {
// $NON-NLS-1$
return ((XSDFacet) obj).getFacetName() + ": " + ((XSDFacet) obj).getLexicalValue();
}
if (obj instanceof XSDIdentityConstraintDefinition) {
return ((XSDIdentityConstraintDefinition) obj).getName();
}
if (obj instanceof XSDXPathDefinition) {
XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
return xpath.getValue();
}
if (obj instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition attributeGroupDefinition = (XSDAttributeGroupDefinition) obj;
// $NON-NLS-1$
String name = (attributeGroupDefinition.getName() == null ? "" : attributeGroupDefinition.getName());
if (attributeGroupDefinition.getContents().size() == 0) {
// $NON-NLS-1$//$NON-NLS-2$
name += " [" + attributeGroupDefinition.getResolvedAttributeGroupDefinition().getName() + "]";
}
return name;
}
if (obj instanceof XSDAttributeUse) {
XSDAttributeUse attributeUse = (XSDAttributeUse) obj;
String name = attributeUse.getAttributeDeclaration().getName();
if (name == null) {
// $NON-NLS-1$//$NON-NLS-2$
name = " [" + attributeUse.getAttributeDeclaration().getResolvedAttributeDeclaration().getName() + "]";
}
return name;
}
if (obj instanceof XSDAnnotation) {
// $NON-NLS-1$
return "Annotations";
}
if (obj instanceof Element) {
try {
Element e = (Element) obj;
if (e.getLocalName().equals("documentation")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_1 + e.getChildNodes().item(0).getNodeValue();
} else if (e.getLocalName().equals("appinfo")) {
// $NON-NLS-1$
// $NON-NLS-1$
String source = e.getAttribute("source");
if (source != null) {
if (source.startsWith("X_Label_")) {
// $NON-NLS-1$
return Util.iso2lang.get(source.substring(8).toLowerCase()) + Messages.TypesLabelProvider_2 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_ForeignKey")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_3 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_ForeignKey_NotSep")) {
// $NON-NLS-1$
Boolean v = Boolean.valueOf(e.getChildNodes().item(0).getNodeValue());
return Messages.SimpleXpathInputDialog_sepFkTabPanel + Messages.TypesLabelProvider_4 + v;
} else if (source.equals("X_ForeignKeyInfo")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_5 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_ForeignKey_Filter")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_6 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_SourceSystem")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_7 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_TargetSystem")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_8 + e.getChildNodes().item(0).getNodeValue();
} else if (source.startsWith("X_Description_")) {
// $NON-NLS-1$
return Util.iso2lang.get(source.substring(14).toLowerCase()) + Messages.TypesLabelProvider_9 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_Write")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_10 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_Deny_Create")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_11 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_Deny_LogicalDelete")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_12 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_Deny_PhysicalDelete")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_13 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_Hide")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_14 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_AutoExpand")) {
// $NON-NLS-1$
return Messages.TypesLabelProvider_15 + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_Retrieve_FKinfos")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_23, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_FKIntegrity")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_24, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_FKIntegrity_Override")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_25, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_Workflow")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_16, e.getChildNodes().item(0).getNodeValue());
}
if (source.equals("X_ForeignKey_Filter")) {
// $NON-NLS-1$
String nodeValue = e.getChildNodes().item(0).getNodeValue();
if (nodeValue.startsWith("$CFFP:")) {
// $NON-NLS-1$
nodeValue = StringEscapeUtils.unescapeXml(nodeValue).substring(6);
}
return Messages.bind(Messages.XSDTreeLabelProvider_26, nodeValue);
} else {
// $NON-NLS-1$
return source + ": " + Util.nodeToString((Element) obj);
}
} else {
return Util.nodeToString((Element) obj);
}
} else {
return Util.nodeToString((Element) obj);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
if (obj == null) {
// $NON-NLS-1$
return "NULL";
}
// $NON-NLS-1$//$NON-NLS-2$
return "?? " + obj.getClass().getName() + " : " + obj.toString();
}
use of org.eclipse.xsd.XSDModelGroup 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.XSDModelGroup in project tmdm-studio-se by Talend.
the class Util method getforeignKeyOfElement.
/**
* set the list with foreign concept name of in the element
*
* @author ymli
* @param list
* @param element
*/
public static void getforeignKeyOfElement(Set<String> list, XSDElementDeclaration element) {
if (element != null) {
if (element.getAnnotation() != null) {
getForeignKeyofParcle(list, element.getAnnotation());
}
if (element.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) element.getTypeDefinition()).getContent();
if (fromcomplexType instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) fromcomplexType;
if (particle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup modelGroup = ((XSDModelGroup) particle.getTerm());
EList<XSDParticle> fromlist = modelGroup.getContents();
for (XSDParticle el : fromlist.toArray(new XSDParticle[fromlist.size()])) {
XSDTerm term = el.getTerm();
if (term instanceof XSDElementDeclaration) {
if (isReferrenced(element, (XSDElementDeclaration) term)) {
continue;
}
getforeignKeyOfElement(list, (XSDElementDeclaration) term);
}
}
}
}
}
}
}
use of org.eclipse.xsd.XSDModelGroup 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.XSDModelGroup 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>");
}
}
Aggregations