use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class ComplexTypeInputDialogR method valid.
private boolean valid() {
elementName = elementNameText.getText().trim();
if (((elementName == null) || ("".equals(elementName)))) {
// $NON-NLS-1$
MessageDialog.openError(this.getShell(), Messages._Error, Messages._BusinessNameCannotEmpty);
setReturnCode(-1);
elementNameText.setFocus();
return false;
}
if (elementName.replaceAll("\\s", "").length() != elementName.length()) {
// $NON-NLS-1$//$NON-NLS-2$
MessageDialog.openError(this.getShell(), Messages._Error, Messages._BusinessNameCannotContainEmpty);
setReturnCode(-1);
elementNameText.setFocus();
return false;
}
if ("".equals(minOccursText.getText()) && "".equals(maxOccursText.getText())) {
// $NON-NLS-1$//$NON-NLS-2$
minOccurs = 1;
maxOccurs = 1;
return false;
}
try {
minOccurs = Integer.parseInt(minOccursText.getText());
} catch (Exception e1) {
MessageDialog.openError(this.getShell(), Messages._Error, Messages._MinNoLessThanZero);
setReturnCode(-1);
minOccursText.setFocus();
return false;
}
if (minOccurs < 0) {
MessageDialog.openError(this.getShell(), Messages._Error, Messages._MinNoLessThanZero);
setReturnCode(-1);
minOccursText.setFocus();
return false;
}
if ("".equals(maxOccursText.getText())) {
// $NON-NLS-1$
maxOccurs = -1;
} else {
try {
maxOccurs = Integer.parseInt(maxOccursText.getText());
} catch (Exception e2) {
MessageDialog.openError(this.getShell(), Messages._Error, Messages._MaxOccBeNum);
setReturnCode(-1);
maxOccursText.setFocus();
return false;
}
if ((maxOccurs < minOccurs) || (maxOccurs <= 0)) {
maxOccurs = -1;
}
}
// get position of the selected particle in the container
for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext(); ) {
XSDParticle p = iter.next();
if (p.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration thisDecl = (XSDElementDeclaration) p.getTerm();
if (thisDecl.getName().equals(elementName)) {
MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages._BusinessEle, elementName));
return false;
}
}
}
// for
String typeName = getTypeName();
if (!"".equals(typeName)) {
// $NON-NLS-1$
EList<XSDTypeDefinition> list = xsdSchema.getTypeDefinitions();
for (Iterator<XSDTypeDefinition> iter = list.iterator(); iter.hasNext(); ) {
XSDTypeDefinition td = iter.next();
if (td.getName().equals(typeName)) {
if (td instanceof XSDSimpleTypeDefinition) {
MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages._ThisType, typeName));
return false;
}
}
}
}
return true;
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class DOMViewDialog method collectKeyWords.
private void collectKeyWords(XSDElementDeclaration elementDeclaration, Set<String> keys) {
String elementName = elementDeclaration.getName();
keys.add(elementName);
XSDTypeDefinition typeDefinition = elementDeclaration.getType();
if (typeDefinition instanceof XSDComplexTypeDefinition) {
XSDParticle particle = (XSDParticle) ((XSDComplexTypeDefinition) typeDefinition).getContent();
XSDTerm term = particle.getTerm();
if (term instanceof XSDModelGroup) {
EList<XSDParticle> particles = ((XSDModelGroup) term).getContents();
for (XSDParticle p : particles) {
XSDTerm childTerm = p.getTerm();
if (childTerm instanceof XSDElementDeclaration) {
collectKeyWords((XSDElementDeclaration) childTerm, keys);
}
}
}
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class NewConceptOrElementDialog method validateType.
private void validateType(String typeName, boolean forConcept) {
getButton(IDialogConstants.OK_ID).setEnabled(true);
// $NON-NLS-1$
infoLabel.setText("");
for (XSDTypeDefinition specType : schema.getTypeDefinitions()) {
if (forConcept && specType instanceof XSDSimpleTypeDefinition) {
continue;
} else if (!forConcept && specType instanceof XSDComplexTypeDefinition) {
continue;
}
String typeToCompare = typeName;
// $NON-NLS-1$
int delimiter = typeToCompare.indexOf(" : ");
if (delimiter != -1) {
typeToCompare = typeToCompare.substring(0, delimiter);
}
if (typeToCompare.equals(specType.getName())) {
infoLabel.setText(Messages.NewConceptOrElementDialog_SameTypeNameAlreadyExists);
getButton(IDialogConstants.OK_ID).setEnabled(false);
return;
}
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class Util method getChildElements.
public static Map<String, XSDParticle> getChildElements(String parentxpath, XSDComplexTypeDefinition ctype, boolean onlyTopLevel, final Set<Object> visited) throws Exception {
if (visited == null || ctype == null) {
throw new IllegalArgumentException();
}
if (parentxpath == null) {
// $NON-NLS-1$
parentxpath = "";
}
Map<String, XSDParticle> childElements = new HashMap<String, XSDParticle>();
XSDTypeDefinition baseType = ctype.getBaseType();
if (!visited.contains(ctype)) {
visited.add(ctype);
if (baseType instanceof XSDComplexTypeDefinition && baseType != ctype) {
XSDComplexTypeDefinition cmpType = (XSDComplexTypeDefinition) baseType;
childElements.putAll(getChildElements(parentxpath, cmpType, onlyTopLevel, visited));
}
childElements.putAll(getComplexChilds(parentxpath, ctype, onlyTopLevel, visited));
}
return childElements;
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class Util method getComplexTypes.
public static List<XSDComplexTypeDefinition> getComplexTypes(XSDSchema xsd) {
EList<XSDTypeDefinition> contents = xsd.getTypeDefinitions();
List<XSDComplexTypeDefinition> complexs = new ArrayList<XSDComplexTypeDefinition>();
for (XSDTypeDefinition type : contents) {
if (type instanceof XSDComplexTypeDefinition) {
boolean exist = false;
for (XSDComplexTypeDefinition xsdEl : complexs) {
if (xsdEl.getName().equals(type.getName()) && xsdEl.getTargetNamespace() != null && type.getTargetNamespace() != null && xsdEl.getTargetNamespace().equals(type.getTargetNamespace())) {
exist = true;
break;
} else if (xsdEl.getTargetNamespace() == null && type.getTargetNamespace() == null && xsdEl.getName().equals(type.getName())) {
exist = true;
break;
}
}
if (!exist && ((type.getTargetNamespace() != null && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) || type.getTargetNamespace() == null)) {
complexs.add((XSDComplexTypeDefinition) type);
}
}
}
return complexs;
}
Aggregations