use of org.eclipse.xsd.XSDParticleContent in project tmdm-studio-se by Talend.
the class Util method collectElementPaths.
public static void collectElementPaths(IStructuredContentProvider provider, Object input, XSDParticle toSearch, Set<String> paths, String inputPath) {
if (input == null || paths == null || provider == null) {
return;
}
Object[] elems = provider.getElements(input);
if (elems != null && elems.length > 0) {
for (Object obj : elems) {
if (obj == null) {
continue;
}
String curPath = inputPath;
if (obj instanceof XSDElementDeclaration) {
String name = ((XSDElementDeclaration) obj).getName();
if (curPath == null) {
curPath = name;
} else {
// $NON-NLS-1$
curPath += "/" + name;
}
}
if (obj instanceof XSDParticle) {
XSDParticleContent content = ((XSDParticle) obj).getContent();
if (content instanceof XSDElementDeclaration) {
String name = ((XSDElementDeclaration) content).getName();
// $NON-NLS-1$
curPath += "/" + name;
}
if (obj == toSearch) {
paths.add(curPath);
break;
}
}
collectElementPaths(provider, obj, toSearch, paths, curPath);
}
}
}
use of org.eclipse.xsd.XSDParticleContent in project tmdm-studio-se by Talend.
the class XSDTreeLabelProvider method getText.
@Override
public String getText(Object obj) {
if (obj instanceof XSDElementDeclaration) {
String name = ((XSDElementDeclaration) obj).getName();
if (((XSDElementDeclaration) obj).isAbstract()) {
name += Messages.XSDTreeLabelProvider_0;
}
String tail = ((XSDElementDeclaration) obj).getTargetNamespace() != null ? // $NON-NLS-1$
" : " + ((XSDElementDeclaration) obj).getTargetNamespace() : // $NON-NLS-1$
"";
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) {
// log.info("SHOULD NOT HAPPEN????");
if (xsdParticle.getContainer() instanceof XSDComplexTypeDefinition) {
String ctdName = ((XSDComplexTypeDefinition) xsdParticle.getContainer()).getName();
// $NON-NLS-1$
name = (ctdName != null ? ctdName : "");
}
} 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 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 = "anonymous type ";
}
// 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 += "]";
}
// get extend type
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();
}
XSDSchema schema = particle.getSchema();
// $NON-NLS-1$
String tail = "";
if (schema != null && schema.getTargetNamespace() != null) {
tail = // $NON-NLS-1$
" : " + schema.getTargetNamespace();
}
return name + tail + 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 XSDAttributeDeclaration) {
XSDAttributeDeclaration attributeDec = (XSDAttributeDeclaration) obj;
String name = attributeDec.getName();
if (name == null) {
name = attributeDec.getAliasName();
if (name == null) {
// $NON-NLS-1$
name = " [null]";
}
}
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 "Documentation: " + 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 Messages.bind(Messages.XSDTreeLabelProvider_1, Util.iso2lang.get(source.substring(8).toLowerCase()), e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_ForeignKey")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_2, 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.bind(Messages.XSDTreeLabelProvider_3, Messages.SimpleXpathInputDialog_sepFkTabPanel, v);
} else if (source.equals("X_Visible_Rule")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_4, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_Default_Value_Rule")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_5, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_ForeignKeyInfo")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_6, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_ForeignKeyInfoFormat")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_20, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_PrimaryKeyInfo")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_7, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_SourceSystem")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_8, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_TargetSystem")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_9, e.getChildNodes().item(0).getNodeValue());
} else if (source.startsWith("X_Description_")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_10, Util.iso2lang.get(source.substring(14).toLowerCase()), e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_Write")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_11, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_Deny_Create")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_12, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_Deny_LogicalDelete")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_13, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_Deny_PhysicalDelete")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_14, e.getChildNodes().item(0).getNodeValue());
} else if (source.equals("X_Lookup_Field")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_15, 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());
} else if (source.equals("X_Hide")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_17, e.getChildNodes().item(0).getNodeValue());
// add by ymli; bugId 0009157
} else if (source.equals("X_AutoExpand")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_18, e.getChildNodes().item(0).getNodeValue());
} else if (source.startsWith("X_Facet")) {
// $NON-NLS-1$
return Messages.bind(Messages.XSDTreeLabelProvider_19, source.substring(2, 7), source.substring(8), e.getChildNodes().item(0).getNodeValue());
// made schematron show:Schematron: schematron
} else if (source.startsWith("X_Display_Format_")) {
// $NON-NLS-1$
return source + ": " + e.getChildNodes().item(0).getNodeValue();
} else if (source.equals("X_Schematron")) {
// $NON-NLS-1$
// $NON-NLS-1$
String pattern = (String) e.getFirstChild().getUserData("pattern_name");
if (pattern == null) {
Element el = Util.parse(e.getChildNodes().item(0).getNodeValue()).getDocumentElement();
if (el.getAttributes().getNamedItem("name") != null) {
// $NON-NLS-1$
// $NON-NLS-1$
pattern = el.getAttributes().getNamedItem("name").getTextContent();
}
}
return Messages.bind(Messages.XSDTreeLabelProvider_21, // e.getChildNodes().item(0).getNodeValue();
(pattern == null ? Messages.XSDTreeLabelProvider_22 : pattern));
// end
} 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());
}
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.XSDParticleContent in project tmdm-studio-se by Talend.
the class XSDUtilTest method testIsFirstLevelChild.
@Test
public void testIsFirstLevelChild() throws Exception {
// $NON-NLS-1$
String fileName = "Product_0.1.xsd";
// $NON-NLS-1$
String elementName = "Product";
String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
assertNotNull(xsdString);
XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
XSDElementDeclaration decl = null;
for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
if (element.getName().equals(elementName)) {
decl = element;
}
}
if (decl != null) {
XSDComplexTypeDefinition ctypeDefinition = (XSDComplexTypeDefinition) decl.getTypeDefinition();
XSDComplexTypeContent content = ctypeDefinition.getContent();
if (content instanceof XSDParticle) {
XSDParticle xsdParticle = (XSDParticle) content;
XSDParticleContent particleContent = xsdParticle.getContent();
if (particleContent instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) particleContent;
EList<XSDParticle> contents = modelGroup.getContents();
for (XSDParticle particle : contents) {
assertTrue(XSDUtil.isFirstLevelChild(particle));
if (particle.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElementDecl = (XSDElementDeclaration) particle.getTerm();
XSDTypeDefinition typeDefinition = xsdElementDecl.getTypeDefinition();
if (typeDefinition instanceof XSDComplexTypeDefinition) {
XSDParticle childPart = (XSDParticle) ((XSDComplexTypeDefinition) typeDefinition).getContent();
XSDModelGroup childModelGroup = (XSDModelGroup) childPart.getContent();
for (XSDParticle childParticle : childModelGroup.getContents()) {
assertFalse(XSDUtil.isFirstLevelChild(childParticle));
}
}
}
}
}
}
}
}
use of org.eclipse.xsd.XSDParticleContent in project webtools.sourceediting by eclipse.
the class MoveXSDElementAction method run.
/*
* @see IAction#run()
*/
public void run() {
int originalIndex = 0;
for (Iterator particles = parentModelGroup.getContents().iterator(); particles.hasNext(); ) {
XSDParticle particle = (XSDParticle) particles.next();
XSDParticleContent particleContent = particle.getContent();
if (particleContent == selected) {
parentModelGroup.getContents().remove(particle);
break;
}
originalIndex++;
}
int index = 0;
boolean addedBack = false;
if (insertType == INSERT_DIRECT) {
XSDConcreteComponent container = selected.getContainer();
if (container != null) {
XSDConcreteComponent container2 = container.getContainer();
if (container2 instanceof XSDModelGroup) {
((XSDModelGroup) container2).getContents().remove(container);
}
if (insertAtEnd)
parentModelGroup.getContents().add(container);
else
parentModelGroup.getContents().add(0, container);
addedBack = true;
}
return;
}
List particles = parentModelGroup.getContents();
for (Iterator iterator = particles.iterator(); iterator.hasNext(); ) {
XSDParticle particle = (XSDParticle) iterator.next();
XSDParticleContent particleContent = particle.getContent();
if (insertType == INSERT_BEFORE) {
if (particleContent == nextRefComponent) {
parentModelGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
if (selected == nextRefComponent && originalIndex == index) {
parentModelGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
} else if (insertType == INSERT_AFTER) {
if (particleContent == previousRefComponent) {
parentModelGroup.getContents().add(index + 1, selected.getContainer());
addedBack = true;
break;
}
if (selected == previousRefComponent && originalIndex == index) {
parentModelGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
}
index++;
}
if (particles.size() == 0) {
parentModelGroup.getContents().add(selected.getContainer());
addedBack = true;
}
if (!addedBack) {
parentModelGroup.getContents().add(originalIndex, selected.getContainer());
}
}
use of org.eclipse.xsd.XSDParticleContent in project webtools.sourceediting by eclipse.
the class MultiplicitySection method updateMinAttribute.
protected void updateMinAttribute() {
setErrorMessage(null);
XSDParticle particle = null;
if (input instanceof XSDParticleContent) {
particle = getAssociatedParticle((XSDParticleContent) input);
}
if (particle != null) {
String newValue = minCombo.getText();
if (newValue.length() == 0) {
particle.unsetMinOccurs();
}
try {
int newMin = 1;
if (// $NON-NLS-1$ //$NON-NLS-2$
newValue.equals("unbounded") || newValue.equals("*")) {
newMin = XSDParticle.UNBOUNDED;
} else {
newMin = Integer.parseInt(newValue);
}
UpdateMinOccursCommand command = new UpdateMinOccursCommand(Messages._UI_ACTION_CHANGE_MINIMUM_OCCURRENCE, particle, newMin);
getCommandStack().execute(command);
} catch (NumberFormatException e) {
}
}
}
Aggregations