use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.
the class AnnotationOrderedListsDialog method getConceptElements.
private List<String> getConceptElements() {
DataModelMainPage page = parentPage;
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
List<String> childNames = new ArrayList<String>();
XSDElementDeclaration decl = null;
if (selection.getFirstElement() instanceof XSDElementDeclaration) {
decl = (XSDElementDeclaration) selection.getFirstElement();
// childNames = Util.getChildElementNames(decl.getElement());
} else if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
XSDComponent xSDCom = null;
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation) {
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
break;
}
}
decl = (XSDElementDeclaration) xSDCom.getContainer();
}
try {
childNames = Util.getChildElementNames(decl.getName(), decl);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return childNames;
}
use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.
the class XSDAnnotationsStructure method inputChanged.
protected void inputChanged(Object component) {
if (component instanceof XSDAnnotation) {
annotation = (XSDAnnotation) component;
if (annotation.getContainer() instanceof XSDElementDeclaration) {
declaration = (XSDElementDeclaration) annotation.getContainer();
} else if (annotation.getContainer() instanceof XSDComplexTypeDefinition) {
complexTypeDef = (XSDComplexTypeDefinition) annotation.getContainer();
}
}
if (component instanceof XSDElementDeclaration) {
declaration = (XSDElementDeclaration) component;
if (declaration.getAnnotation() == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
annotation = factory.createXSDAnnotation();
} else {
annotation = declaration.getAnnotation();
}
}
if (component instanceof XSDComplexTypeDefinition) {
complexTypeDef = (XSDComplexTypeDefinition) component;
componet = complexTypeDef;
if (complexTypeDef.getAnnotation() == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
annotation = factory.createXSDAnnotation();
} else {
annotation = complexTypeDef.getAnnotation();
}
}
if (component instanceof XSDModelGroup) {
XSDModelGroup group = (XSDModelGroup) component;
if (group.getContainer().getContainer() instanceof XSDComplexTypeDefinition) {
complexTypeDef = (XSDComplexTypeDefinition) group.getContainer().getContainer();
if (complexTypeDef.getAnnotation() == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
annotation = factory.createXSDAnnotation();
} else {
annotation = complexTypeDef.getAnnotation();
}
}
}
if (component instanceof XSDParticle) {
XSDTerm term = ((XSDParticle) component).getTerm();
if (term instanceof XSDElementDeclaration) {
declaration = (XSDElementDeclaration) term;
if (declaration.getAnnotation() == null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
annotation = factory.createXSDAnnotation();
} else {
annotation = declaration.getAnnotation();
}
}
}
}
use of org.eclipse.xsd.XSDAnnotation 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.XSDAnnotation in project tmdm-studio-se by Talend.
the class XSDAddComplexTypeElementAction method createParticle.
private XSDParticle createParticle() {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDElementDeclaration resultElementDeclaration = factory.createXSDElementDeclaration();
resultElementDeclaration.setName(elementName);
resultElementDeclaration.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), defaultTypeName));
XSDParticle resultParticle = factory.createXSDParticle();
resultParticle.setContent(resultElementDeclaration);
resultParticle.setMinOccurs(this.minOccurs);
XSDModelGroup group = modelGroup;
if (maxOccurs > -1) {
resultParticle.setMaxOccurs(this.maxOccurs);
group.getContents().add(group.getContents().size(), resultParticle);
group.updateElement();
} else {
resultParticle.setMaxOccurs(this.maxOccurs);
group.getContents().add(group.getContents().size(), resultParticle);
group.updateElement();
if (resultParticle.getElement().getAttributeNode("maxOccurs") != null) {
// $NON-NLS-1$
// $NON-NLS-1$//$NON-NLS-2$
resultParticle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
} else {
// $NON-NLS-1$//$NON-NLS-2$
resultParticle.getElement().setAttribute("maxOccurs", "unbounded");
}
}
Util.changeElementTypeToSequence(resultElementDeclaration, maxOccurs);
if (dialogR.isInherit()) {
XSDTerm totm = resultParticle.getTerm();
XSDElementDeclaration concept = null;
Object parent = Util.getParent(resultParticle);
if (parent instanceof XSDElementDeclaration) {
concept = (XSDElementDeclaration) parent;
} else {
concept = (XSDElementDeclaration) resultParticle.getContent();
}
XSDAnnotation fromannotation = null;
if (concept != null) {
fromannotation = concept.getAnnotation();
}
if (fromannotation != null) {
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
if (((XSDElementDeclaration) totm).getType() != null) {
addAnnotion(struc, fromannotation);
}
}
}
return resultParticle;
}
use of org.eclipse.xsd.XSDAnnotation in project tmdm-studio-se by Talend.
the class XSDAnnotationLookupFieldsAction method doAction.
public IStatus doAction() {
try {
IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation)
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
} else
xSDCom = (XSDComponent) selection.getFirstElement();
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
struc.setXSDSchema(schema);
// (XSDComponent) selection.getFirstElement());
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDAnnotationLookupFieldsAction_ExceptionInfo, xSDCom.getClass().getName()));
}
dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getLookupFields().values()), new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
dlg.close();
}
}, page.getSite().getShell(), Messages.XSDAnnotationLookupFieldsAction_SetLookupFields, Messages.XSDAnnotationLookupFieldsAction_LookupFields, page, AnnotationOrderedListsDialog.AnnotationLookupField_ActionType, null);
dlg.setBlockOnOpen(true);
int ret = dlg.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
struc.setAccessRole(dlg.getXPaths(), false, (IStructuredContentProvider) page.getTreeViewer().getContentProvider(), // $NON-NLS-1$
"X_Lookup_Field");
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDAnnotationLookupFieldsAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations