use of org.eclipse.xsd.XSDImport in project tmdm-studio-se by Talend.
the class Util method importSchema.
private static void importSchema(XSDSchema xsdSchema, List<XSDImport> imports, Map<String, Integer> schemaMonitor) {
EList<XSDSchemaContent> list = xsdSchema.getContents();
for (XSDSchemaContent schemaCnt : list) {
if (schemaCnt instanceof XSDImport) {
XSDImportImpl xsdImpl = (XSDImportImpl) schemaCnt;
if (xsdImpl.getNamespace() == null || xsdImpl.getNamespace().trim().equals("")) {
// $NON-NLS-1$
URI fileURI = URI.createFileURI(xsdImpl.getSchemaLocation());
// $NON-NLS-1$//$NON-NLS-2$
xsdImpl.setNamespace(fileURI.toFileString().replaceAll("[\\W]", ""));
}
if (xsdImpl.getSchemaLocation() == null) {
continue;
}
((XSDImportImpl) schemaCnt).importSchema();
imports.add(((XSDImportImpl) schemaCnt));
} else if (schemaCnt instanceof XSDInclude) {
XSDIncludeImpl xsdInclude = (XSDIncludeImpl) schemaCnt;
((XSDSchemaImpl) xsdSchema).included(xsdInclude);
}
}
}
use of org.eclipse.xsd.XSDImport in project tmdm-studio-se by Talend.
the class Util method createXsdSchema.
public static XSDSchema createXsdSchema(String xsd, TreeObject treeObj) throws Exception {
List<XSDImport> imports = new ArrayList<XSDImport>();
List<Exception> exceptons = new ArrayList<Exception>();
Map<String, Integer> schemaMonitor = new HashMap<String, Integer>();
// no import or include using old getXsdschema()
// if (Util.getNodeList(doc.getDocumentElement(),"//xsd:import").getLength() ==0
// || Util.getNodeList(doc.getDocumentElement(),
// "//xsd:include").getLength() ==0)
// {
// return Util.getXSDSchema(xsd);
// }
// replace the old roles with the new role scheme
String xsdCpy = new String(xsd);
for (Map.Entry<String, String> pair : ICoreConstants.rolesConvert.oldRoleToNewRoleMap.entrySet()) {
xsdCpy = xsdCpy.replaceAll(pair.getKey().toString(), pair.getValue().toString());
}
XSDSchema xsdSchema = Util.getXSDSchema(null, xsdCpy, imports, treeObj, false, exceptons, schemaMonitor);
if (exceptons.size() > 0) {
throw exceptons.get(0);
} else if (schemaMonitor.containsValue(new Integer(-1))) {
throw new Exception(Messages.Util_44);
}
addImport(xsdSchema, imports);
return xsdSchema;
}
use of org.eclipse.xsd.XSDImport in project webtools.sourceediting by eclipse.
the class AddXSDImportCommand method execute.
public void execute() {
try {
super.execute();
// Add this after if we don't have a DOM Node yet
beginRecording(xsdSchema.getElement());
XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport();
xsdSchema.getContents().add(findNextPositionToInsert(), xsdImport);
addedXSDConcreteComponent = xsdImport;
formatChild(xsdSchema.getElement());
} finally {
endRecording();
}
}
use of org.eclipse.xsd.XSDImport in project webtools.sourceediting by eclipse.
the class XSDImportSection method refresh.
public void refresh() {
setListenerEnabled(false);
errorText.setText("");
Element element = null;
if (input instanceof XSDImport) {
element = ((XSDImport) input).getElement();
// $NON-NLS-1$
String namespace = element.getAttribute("namespace");
// $NON-NLS-1$
String schemaLocation = element.getAttribute("schemaLocation");
TypesHelper helper = new TypesHelper(xsdSchema);
String prefix = helper.getPrefix(element.getAttribute(XSDConstants.NAMESPACE_ATTRIBUTE), false);
if (namespace == null) {
// $NON-NLS-1$
namespace = "";
}
if (prefix == null) {
// $NON-NLS-1$
prefix = "";
}
if (schemaLocation == null) {
// $NON-NLS-1$
schemaLocation = "";
}
namespaceText.setText(namespace);
prefixText.setText(prefix);
schemaLocationText.setText(schemaLocation);
oldPrefixValue = prefixText.getText();
}
setListenerEnabled(true);
}
use of org.eclipse.xsd.XSDImport in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils method getInputXSDAnnotation.
public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
XSDAnnotation xsdAnnotation = null;
XSDFactory factory = XSDFactory.eINSTANCE;
if (input instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDNotationDeclaration) {
XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDXPathDefinition) {
XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroup) {
XSDModelGroup xsdComp = (XSDModelGroup) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDWildcard) {
XSDWildcard xsdComp = (XSDWildcard) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDSchema) {
XSDSchema xsdComp = (XSDSchema) input;
List list = xsdComp.getAnnotations();
if (list.size() > 0) {
xsdAnnotation = (XSDAnnotation) list.get(0);
} else {
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
if (xsdComp.getContents() != null) {
xsdComp.getContents().add(0, xsdAnnotation);
}
}
}
return xsdAnnotation;
} else if (input instanceof XSDFacet) {
XSDFacet xsdComp = (XSDFacet) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDTypeDefinition) {
XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDInclude) {
XSDInclude xsdComp = (XSDInclude) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDImport) {
XSDImport xsdComp = (XSDImport) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDRedefine) {
XSDRedefine xsdComp = (XSDRedefine) input;
List contents = xsdComp.getContents();
for (int i = 0; i < contents.size(); i++) {
Object content = contents.get(i);
if (content instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) content;
break;
}
}
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
contents.add(0, xsdAnnotation);
}
return xsdAnnotation;
} else if (input instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) input;
}
if (createIfNotExist) {
formatAnnotation(xsdAnnotation);
}
return xsdAnnotation;
}
Aggregations