use of org.eclipse.xsd.XSDParticleContent in project tmdm-studio-se by Talend.
the class XSDUtilTest method testIsPrimaryKeyElement.
@Test
public void testIsPrimaryKeyElement() 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 ctypeContent = ctypeDefinition.getContent();
if (ctypeContent instanceof XSDParticle) {
XSDParticle typeParticle = (XSDParticle) ctypeContent;
XSDParticleContent particleContent = typeParticle.getContent();
if (particleContent instanceof XSDModelGroup) {
XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
for (XSDParticle particle : particleGroup.getContents()) {
if (particle.getContent() instanceof XSDElementDeclaration && ((XSDElementDeclaration) particle.getContent()).getName().equals("Id")) {
// $NON-NLS-1$
assertTrue(XSDUtil.isPrimaryKeyElement(particle));
} else {
assertFalse(XSDUtil.isPrimaryKeyElement(particle));
}
}
}
}
}
}
use of org.eclipse.xsd.XSDParticleContent in project webtools.sourceediting by eclipse.
the class XSDComplexTypeDefinitionAdapter method getChildren.
public ITreeElement[] getChildren() {
XSDComplexTypeDefinition xsdComplexTypeDefinition = getXSDComplexTypeDefinition();
List list = new ArrayList();
// Add attributes
for (Iterator i = xsdComplexTypeDefinition.getAttributeContents().iterator(); i.hasNext(); ) {
Object obj = i.next();
if (obj instanceof XSDAttributeUse) {
list.add(((XSDAttributeUse) obj).getAttributeDeclaration());
} else if (obj instanceof XSDAttributeGroupDefinition) {
getAttributeUses((XSDAttributeGroupDefinition) obj, list);
}
}
// Add enumerations
boolean canHaveEnumerations = xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition && XSDDerivationMethod.RESTRICTION_LITERAL.equals(xsdComplexTypeDefinition.getDerivationMethod());
if (canHaveEnumerations) {
Object contentType = getContentType();
if (contentType != null) {
for (Iterator iterator = ((XSDSimpleTypeDefinition) contentType).getEnumerationFacets().iterator(); iterator.hasNext(); ) {
XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) iterator.next();
list.add(enumerationFacet);
}
}
}
XSDWildcard anyAttr = xsdComplexTypeDefinition.getAttributeWildcard();
if (anyAttr != null)
list.add(anyAttr);
// get immediate XSD Model Group of this complex type
if (xsdComplexTypeDefinition.getContent() != null) {
XSDComplexTypeContent xsdComplexTypeContent = xsdComplexTypeDefinition.getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
if (particleContent instanceof XSDModelGroup) {
list.add(particleContent);
}
}
}
// get inherited XSD Model Group of this complex type
boolean showInheritedContent = XSDEditorPlugin.getPlugin().getShowInheritedContent();
if (showInheritedContent) {
XSDTypeDefinition typeDef = xsdComplexTypeDefinition.getBaseTypeDefinition();
if (typeDef instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition baseCT = (XSDComplexTypeDefinition) typeDef;
if (baseCT.getTargetNamespace() != null && !baseCT.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) {
if (baseCT.getContent() != null) {
XSDComplexTypeContent xsdComplexTypeContent = baseCT.getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
if (particleContent instanceof XSDModelGroup) {
list.add(particleContent);
}
}
}
}
}
}
List adapterList = new ArrayList();
populateAdapterList(list, adapterList);
return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
use of org.eclipse.xsd.XSDParticleContent in project webtools.sourceediting by eclipse.
the class XSDModelGroupAdapter method getChildren.
public ITreeElement[] getChildren() {
XSDModelGroup xsdModelGroup = getXSDModelGroup();
List list = new ArrayList();
for (Iterator i = xsdModelGroup.getContents().iterator(); i.hasNext(); ) {
Object object = i.next();
XSDParticleContent particle = ((XSDParticle) object).getContent();
if (particle instanceof XSDElementDeclaration) {
list.add(particle);
} else if (particle instanceof XSDWildcard) {
list.add(particle);
} else if (particle instanceof XSDModelGroup) {
list.add(particle);
} else if (particle instanceof XSDModelGroupDefinition) {
// list.add(((XSDModelGroupDefinition)particle).getResolvedModelGroupDefinition());
list.add(particle);
}
}
List adapterList = new ArrayList();
populateAdapterList(list, adapterList);
return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
use of org.eclipse.xsd.XSDParticleContent in project webtools.sourceediting by eclipse.
the class MultiplicitySection method updateMaxAttribute.
protected void updateMaxAttribute() {
setErrorMessage(null);
XSDParticle particle = null;
if (input instanceof XSDParticleContent) {
particle = getAssociatedParticle((XSDParticleContent) input);
}
if (particle != null) {
String newValue = maxCombo.getText().trim();
if (newValue.length() == 0) {
particle.unsetMaxOccurs();
return;
}
try {
int newMax = 1;
if (// $NON-NLS-1$ //$NON-NLS-2$
newValue.equals("unbounded") || newValue.equals("*")) {
newMax = XSDParticle.UNBOUNDED;
} else {
if (newValue.length() > 0) {
newMax = Integer.parseInt(newValue);
}
}
setListenerEnabled(false);
UpdateMaxOccursCommand command = new UpdateMaxOccursCommand(Messages._UI_ACTION_CHANGE_MAXIMUM_OCCURRENCE, particle, newMax);
getCommandStack().execute(command);
setListenerEnabled(true);
} catch (NumberFormatException e) {
setErrorMessage(Messages._UI_ERROR_INVALID_VALUE_FOR_MAXIMUM_OCCURRENCE);
}
}
}
use of org.eclipse.xsd.XSDParticleContent in project webtools.sourceediting by eclipse.
the class MultiplicitySection method refreshMinMax.
protected void refreshMinMax() {
boolean refreshMinText = true;
boolean refreshMaxText = true;
if (minCombo.isFocusControl()) {
refreshMinText = false;
}
if (maxCombo.isFocusControl()) {
refreshMaxText = false;
}
if (refreshMinText) {
// $NON-NLS-1$
minCombo.setText("");
}
if (refreshMaxText) {
// $NON-NLS-1$
maxCombo.setText("");
}
if (input != null) {
if (input instanceof XSDParticleContent) {
XSDParticle particle = getAssociatedParticle((XSDParticleContent) input);
if (particle != null) {
// minText.setText(String.valueOf(particle.getMinOccurs()));
// maxText.setText(String.valueOf(particle.getMaxOccurs()));
Element element = particle.getElement();
if (element != null) {
if (element.hasAttribute(XSDConstants.MINOCCURS_ATTRIBUTE) && refreshMinText) {
String min = element.getAttribute(XSDConstants.MINOCCURS_ATTRIBUTE);
minCombo.setText(min);
}
if (element.hasAttribute(XSDConstants.MAXOCCURS_ATTRIBUTE) && refreshMaxText) {
String max = element.getAttribute(XSDConstants.MAXOCCURS_ATTRIBUTE);
maxCombo.setText(max);
}
}
}
}
}
}
Aggregations