use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class XSDParser method loadAndPrint.
/**
* Load the XML Schema file and print the documentation based on it.
*
* @param xsdFile the name of an XML Schema file.
*/
public void loadAndPrint(String xsd) throws Exception {
// XSDFactory xsdFactory = XSDFactory.eINSTANCE;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setValidating(false);
InputSource source = new InputSource(new StringReader(xsd));
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(source);
XSDSchema xsdSchema = XSDSchemaImpl.createSchema(document.getDocumentElement());
// Create a resource set and load the main schema file into it.
//
/*
* ResourceSet resourceSet = new ResourceSetImpl(); XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet
* .getResource(URI.createFileURI(xsdFile), true);
*
* XSDResourceImpl res = new XSDResourceImpl();
*
* XSDSchema xsdSchema = xsdResource.getSchema();
*/
// $NON-NLS-1$
String elementContentHeaderDocumentation = getContentDocumentation("element-header");
if (elementContentHeaderDocumentation != null) {
System.out.println(elementContentHeaderDocumentation);
}
List all = new ArrayList(xsdSchema.getElementDeclarations());
for (Iterator iter = all.iterator(); iter.hasNext(); ) {
XSDElementDeclaration concept = (XSDElementDeclaration) iter.next();
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("CONCEPT: " + concept.getName() + "-- " + concept.getContainer().getClass().getName());
// name of the concept in English
XSDAnnotation annotation = concept.getAnnotation();
if (annotation != null) {
EList list = annotation.getApplicationInformation();
for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
Element appinfo = (Element) iterator.next();
// $NON-NLS-1$
String language = appinfo.getAttribute("source");
if ("EN".equals(language.toUpperCase())) {
// $NON-NLS-1$
if (appinfo.getFirstChild() != null)
// $NON-NLS-1$
System.out.println(" " + appinfo.getFirstChild().getNodeValue());
}
}
}
// children
XSDTypeDefinition typedef = concept.getTypeDefinition();
if (typedef instanceof XSDComplexTypeDefinition) {
XSDComplexTypeContent xsdContent = ((XSDComplexTypeDefinition) typedef).getContent();
XSDParticle xsdParticle = (XSDParticle) xsdContent;
// $NON-NLS-1$
String ident = " ";
processParticle(xsdParticle, ident);
}
}
// for elements
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class XSDUtil method iterateParticle.
private static void iterateParticle(XSDParticle particle, IXPathSelectionFilter filter, Set<String> paths, String prefix) {
XSDTerm term = particle.getTerm();
if (term instanceof XSDModelGroup) {
EList<XSDParticle> contents = ((XSDModelGroup) term).getContents();
for (XSDParticle p : contents) {
XSDTerm t = p.getTerm();
if (t instanceof XSDElementDeclaration) {
XSDElementDeclaration element = ((XSDElementDeclaration) t);
FilterResult r = filter.check(p);
if (r == FilterResult.ENABLE) {
String path = prefix + element.getName();
paths.add(path);
} else {
XSDTypeDefinition type = element.getType();
if (type instanceof XSDComplexTypeDefinition) {
String nextPrefix = prefix + element.getName() + DIVIDE;
XSDParticle cp = type.getComplexType();
iterateParticle(cp, filter, paths, nextPrefix);
}
}
}
}
}
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class XSDUtil method getValidElementPaths.
public static Set<String> getValidElementPaths(XSDElementDeclaration ed, IXPathSelectionFilter filter) {
String curPrefix = ed.getName() + DIVIDE;
XSDTypeDefinition type = ed.getType();
Set<String> paths = new HashSet<String>();
if (type instanceof XSDComplexTypeDefinition) {
XSDParticle particle = type.getComplexType();
iterateParticle(particle, filter, paths, curPrefix);
}
return paths;
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class Util method getAllObject.
public static Object[] getAllObject(Object elem, List<Object> objList, IStructuredContentProvider provider) {
Object[] elems = provider.getElements(elem);
for (Object obj : elems) {
if (obj == null) {
continue;
}
if (obj instanceof XSDModelGroup || obj instanceof XSDElementDeclaration || obj instanceof XSDParticle || obj instanceof XSDTypeDefinition) {
if (!objList.contains(obj)) {
objList.add(obj);
getAllObject(obj, objList, provider);
}
}
}
return objList.toArray();
}
use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.
the class Util method getComplexChilds.
/**
* use the map from path to XSDParticle,path is separated by '/' or '//'
*/
private static Map<String, XSDParticle> getComplexChilds(String parentxpath, XSDComplexTypeDefinition ctype, boolean onlyTopLevel, final Set<Object> visited) throws Exception {
Map<String, XSDParticle> childDecls = new HashMap<String, XSDParticle>();
if (ctype.getContent() instanceof XSDParticle) {
XSDParticleImpl particle = (XSDParticleImpl) ctype.getContent();
if (particle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup group = (XSDModelGroup) particle.getTerm();
EList<XSDParticle> particles = group.getParticles();
for (XSDParticle part : particles) {
if (part.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration el = (XSDElementDeclaration) part.getTerm();
if (el.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
// $NON-NLS-1$
String child = parentxpath.length() == 0 ? el.getName() : parentxpath + "/" + el.getName();
childDecls.put(child, part);
} else {
String complexTypeChildPath = parentxpath.length() == 0 ? "//" + el.getName() : // $NON-NLS-1$
parentxpath + "//" + // $NON-NLS-1$
el.getName();
childDecls.put(complexTypeChildPath, part);
if (!onlyTopLevel && el.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
// $NON-NLS-1$
String child = parentxpath.length() == 0 ? el.getName() : parentxpath + "/" + el.getName();
childDecls.putAll(getChildElements(child, (XSDComplexTypeDefinition) el.getTypeDefinition(), onlyTopLevel, visited));
}
}
}
}
}
}
return childDecls;
}
Aggregations