use of org.eclipse.xsd.XSDSchemaContent in project tmdm-studio-se by Talend.
the class SchemaTreeContentProvider method getXSDSchemaChildren.
protected Object[] getXSDSchemaChildren(XSDSchema schema) {
List<XSDElementDeclaration> declarations = new ArrayList<XSDElementDeclaration>();
List<Object> attributeDeclarations = new ArrayList<Object>();
if (null != xsdSchema) {
for (XSDSchemaContent cnt : xsdSchema.getContents()) {
if (cnt instanceof XSDInclude) {
XSDInclude incu = (XSDInclude) cnt;
String schemaLocation = incu.getSchemaLocation();
XSDSchema schemaInc = createSchema(schemaLocation);
addElementDeclarationFromSchema(schemaInc, declarations);
} else if (cnt instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration attriDec = (XSDAttributeDeclaration) cnt;
attributeDeclarations.add(attriDec);
}
}
}
addElementDeclarationFromSchema(schema, declarations);
Object[] schemaChildren = Util.filterOutDuplicatedElems(declarations.toArray(new XSDNamedComponent[declarations.size()]));
attributeDeclarations.addAll(Arrays.asList(schemaChildren));
return attributeDeclarations.toArray();
}
use of org.eclipse.xsd.XSDSchemaContent in project tmdm-studio-se by Talend.
the class UtilTest method testGetTypeDefinition.
@Test
public void testGetTypeDefinition() {
// $NON-NLS-1$
String s_name = "simpleType";
// $NON-NLS-1$
String c_name = "complexType";
// $NON-NLS-1$
String e_name = "xsdElementDeclaration";
XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema();
XSDSimpleTypeDefinition xsdSimpleTypeDefinition1 = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
XSDSimpleTypeDefinition xsdSimpleTypeDefinition2 = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
XSDComplexTypeDefinition xsdComplexTypeDefinition1 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
XSDComplexTypeDefinition xsdComplexTypeDefinition2 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
xsdSimpleTypeDefinition1.setName(s_name + 1);
xsdSimpleTypeDefinition2.setName(s_name + 2);
xsdComplexTypeDefinition1.setName(c_name + 1);
xsdComplexTypeDefinition2.setName(c_name + 2);
xsdSimpleTypeDefinition1.setBaseTypeDefinition(// $NON-NLS-1$ anyType
xsdSchema.resolveSimpleTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "string"));
xsdSimpleTypeDefinition2.setBaseTypeDefinition(// $NON-NLS-1$
xsdSchema.resolveSimpleTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "string"));
xsdComplexTypeDefinition1.setBaseTypeDefinition(// $NON-NLS-1$
xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
xsdComplexTypeDefinition2.setBaseTypeDefinition(// $NON-NLS-1$
xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
EList<XSDSchemaContent> contents = xsdSchema.getContents();
contents.add(xsdSimpleTypeDefinition1);
contents.add(xsdSimpleTypeDefinition2);
contents.add(xsdComplexTypeDefinition1);
contents.add(xsdComplexTypeDefinition2);
XSDElementDeclaration xsdElementDeclaration = XSDFactory.eINSTANCE.createXSDElementDeclaration();
xsdElementDeclaration.setName(e_name);
contents.add(xsdElementDeclaration);
Map<String, XSDTypeDefinition> typeDefinition = Util.getTypeDefinition(xsdSchema);
assertNotNull(typeDefinition);
assertTrue(typeDefinition.size() == 4);
assertTrue(typeDefinition.keySet().contains(s_name + 1));
assertTrue(typeDefinition.keySet().contains(s_name + 2));
assertTrue(typeDefinition.keySet().contains(c_name + 1));
assertTrue(typeDefinition.keySet().contains(c_name + 2));
assertTrue(typeDefinition.values().contains(xsdSimpleTypeDefinition1));
assertTrue(typeDefinition.values().contains(xsdSimpleTypeDefinition2));
assertTrue(typeDefinition.values().contains(xsdComplexTypeDefinition1));
assertTrue(typeDefinition.values().contains(xsdComplexTypeDefinition2));
}
use of org.eclipse.xsd.XSDSchemaContent in project tmdm-studio-se by Talend.
the class SelectImportedModulesDialog method okPressed.
@Override
protected void okPressed() {
addContent.clear();
Object[] objs = entityViewer.getCheckedElements();
if (null != objs) {
for (Object obj : objs) {
if (obj instanceof XSDSchemaContent) {
addContent.add((XSDSchemaContent) obj);
}
}
}
objs = typeViewer.getCheckedElements();
if (null != objs) {
for (Object obj : objs) {
if (obj instanceof XSDSchemaContent) {
addContent.add((XSDSchemaContent) obj);
}
}
}
super.okPressed();
}
use of org.eclipse.xsd.XSDSchemaContent in project tmdm-studio-se by Talend.
the class DataModelMainPage method save.
public int save(String xsd) {
try {
WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
wsObject.setDescription(desAntionComposite.getText());
String schema = xsd;
if (xsd == null) {
schema = ((SchemaTreeContentProvider) viewer.getContentProvider()).getXSDSchemaAsString();
xsdSchema = ((SchemaTreeContentProvider) viewer.getContentProvider()).getXsdSchema();
}
XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport();
// $NON-NLS-1$
xsdImport.setNamespace("http://www.w3.org/2001/XMLSchema");
if (xsdSchema == null) {
xsdSchema = ((SchemaTreeContentProvider) viewer.getContentProvider()).getXsdSchema();
}
if (xsdSchema == null || (xsd != null && !xsd.equals(wsObject.getXsdSchema())) || (xsd != null && !xsd.equals(getXSDSchemaString()))) {
//
xsdSchema = Util.createXsdSchema(schema, xobject);
//
getSchemaContentProvider().setXsdSchema(xsdSchema);
}
wsObject.setXsdSchema(schema);
EList<XSDSchemaContent> elist = xsdSchema.getContents();
for (XSDSchemaContent cnt : elist) {
if (cnt instanceof XSDImport) {
XSDImport imp = (XSDImport) cnt;
if (imp.getNamespace().equals("http://www.w3.org/2001/XMLSchema")) {
// $NON-NLS-1$
xsdImport = null;
break;
}
}
}
if (xsdImport != null) {
xsdSchema.getContents().add(0, xsdImport);
wsObject.setXsdSchema(schema);
}
validateSchema();
// save to db
doSave(wsObject);
dirty = false;
} catch (Exception e) {
dirty = true;
log.error(e.getMessage(), e);
}
firePropertyChange(PROP_DIRTY);
return dirty ? 1 : 0;
}
use of org.eclipse.xsd.XSDSchemaContent in project tmdm-studio-se by Talend.
the class DataModelMainPage method importSchema.
protected void importSchema(InputSource source, String uri) throws Exception {
// $NON-NLS-1$
String ns = "";
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setValidating(false);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(source);
// $NON-NLS-1$
ns = document.getDocumentElement().getAttribute("targetNamespace");
if (xsdSchema == null) {
xsdSchema = getXSDSchema(Util.nodeToString(document));
} else {
WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
xsdSchema = Util.createXsdSchema(wsObject.getXsdSchema(), xobject);
}
boolean exist = false;
for (int i = 0; i < xsdSchema.getContents().size(); i++) {
XSDSchemaContent xsdComp = xsdSchema.getContents().get(i);
if (ns != null && !ns.equals("")) {
// import xsdschema
if (xsdComp instanceof XSDImport && ((XSDImport) xsdComp).getNamespace().equals(ns)) {
for (Map.Entry entry : xsdSchema.getQNamePrefixToNamespaceMap().entrySet()) {
if (entry.getValue().equals(((XSDImport) xsdComp).getNamespace())) {
exist = true;
break;
}
}
break;
}
} else {
// include xsdschema
if (xsdComp instanceof XSDInclude) {
String xsdLocation = ((XSDInclude) xsdComp).getSchemaLocation();
if (xsdLocation.equals(uri)) {
exist = true;
break;
}
}
}
}
if (!exist) {
if (ns != null && !ns.equals("")) {
// $NON-NLS-1$
// $NON-NLS-1$
int last = ns.lastIndexOf("/");
// $NON-NLS-1$//$NON-NLS-2$
xsdSchema.getQNamePrefixToNamespaceMap().put(ns.substring(last + 1).replaceAll("[\\W]", ""), ns);
XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport();
xsdImport.setNamespace(ns);
xsdImport.setSchemaLocation(uri);
xsdSchema.getContents().add(0, xsdImport);
} else {
XSDInclude xsdInclude = XSDFactory.eINSTANCE.createXSDInclude();
xsdInclude.setSchemaLocation(uri);
xsdSchema.getContents().add(0, xsdInclude);
}
String xsd = Util.nodeToString(xsdSchema.getDocument());
setXsdSchema(xsdSchema);
WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
wsObject.setXsdSchema(xsd);
}
}
Aggregations