use of org.eclipse.xsd.XSDTerm in project tmdm-studio-se by Talend.
the class Util method isReferrenced.
private static boolean isReferrenced(XSDElementDeclaration element, XSDElementDeclaration term) {
if (element == term) {
return true;
}
if (term.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) term.getTypeDefinition()).getContent();
if (fromcomplexType instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) fromcomplexType;
if (particle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup modelGroup = ((XSDModelGroup) particle.getTerm());
EList<?> fromlist = modelGroup.getContents();
for (Object obj : fromlist) {
XSDTerm t = ((XSDParticle) obj).getTerm();
if (t == element) {
return true;
}
}
}
}
}
return false;
}
use of org.eclipse.xsd.XSDTerm in project tmdm-studio-se by Talend.
the class XSDUtilTest method testGetAnnotationValue.
@Test
public void testGetAnnotationValue() throws Exception {
// $NON-NLS-1$
String fileName = "Product_0.1.xsd";
// $NON-NLS-1$
String elementName = "Family";
// $NON-NLS-1$
String fk = "Store/Id";
String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
assertNotNull(xsdString);
XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
XSDTypeDefinition typeDefinition = element.getTypeDefinition();
if (typeDefinition instanceof XSDComplexTypeDefinition) {
XSDComplexTypeContent xsdComplexTypeContent = ((XSDComplexTypeDefinition) typeDefinition).getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
XSDParticleContent content = ((XSDParticle) xsdComplexTypeContent).getContent();
if (content instanceof XSDModelGroup) {
for (XSDParticle particle : ((XSDModelGroup) content).getParticles()) {
XSDTerm term = particle.getTerm();
if (term instanceof XSDElementDeclaration) {
XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) term;
if (elementDeclaration.getName().equals(elementName)) {
String value = XSDUtil.getAnnotationValue(elementDeclaration, X_FOREIGN_KEY);
assertEquals(fk, value);
return;
}
}
}
}
}
}
}
fail();
}
use of org.eclipse.xsd.XSDTerm in project tmdm-studio-se by Talend.
the class XSDPasteConceptAction method addAnnotationForComplexType.
public void addAnnotationForComplexType(XSDComplexTypeDefinition fromType, XSDComplexTypeDefinition toType) {
XSDComplexTypeContent tocomplexType = toType.getContent();
XSDComplexTypeContent fromcomplexType = fromType.getContent();
if (fromcomplexType instanceof XSDParticle) {
XSDParticle fromxsdParticle = (XSDParticle) fromcomplexType;
XSDParticle toxsdParticle = (XSDParticle) tocomplexType;
if (fromxsdParticle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup frommodelGroup = ((XSDModelGroup) fromxsdParticle.getTerm());
XSDModelGroup tomodelGroup = ((XSDModelGroup) toxsdParticle.getTerm());
EList<XSDParticle> fromlist = frommodelGroup.getContents();
EList<XSDParticle> tolist = tomodelGroup.getContents();
Iterator<XSDParticle> toIt = tolist.iterator();
for (XSDParticle fromel : fromlist.toArray(new XSDParticle[fromlist.size()])) {
XSDParticle toel = toIt.next();
XSDTerm totm = toel.getTerm();
XSDTerm fromtm = fromel.getTerm();
if (fromtm instanceof XSDElementDeclaration) {
XSDAnnotation fromannotation = ((XSDElementDeclaration) fromtm).getAnnotation();
if (fromannotation != null) {
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
addAnnotion(struc, fromannotation);
if (this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
}
addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
}
}
}
}
}
}
use of org.eclipse.xsd.XSDTerm in project tmdm-studio-se by Talend.
the class XSDDeleteParticleAction method doAction.
public IStatus doAction() {
try {
// xsdPartle is to support the multiple delete action on key press,
// which each delete action on particle must be explicit passed a xsd particle to
// delete
XSDParticle particle = (XSDParticle) xsdPartle;
if (particle == null) {
ISelection selection = page.getTreeViewer().getSelection();
particle = (XSDParticle) ((IStructuredSelection) selection).getFirstElement();
}
XSDTerm term = particle.getTerm();
XSDElementDeclaration decl = null;
if (term instanceof XSDElementDeclaration) {
decl = (XSDElementDeclaration) particle.getTerm();
}
if (particle.getContainer() == null) {
return Status.CANCEL_STATUS;
}
XSDIdentityConstraintDefinition identify = null;
XSDXPathDefinition keyPath = null;
List<Object> keyInfo = Util.getKeyInfo(decl);
if (keyInfo != null && keyInfo.size() > 0) {
identify = (XSDIdentityConstraintDefinition) keyInfo.get(0);
keyPath = (XSDXPathDefinition) keyInfo.get(1);
identify.getFields().remove(keyPath);
if (identify.getFields().size() == 0) {
XSDElementDeclaration top = (XSDElementDeclaration) Util.getParent(decl);
top.getIdentityConstraintDefinitions().remove(identify);
}
}
if (!(particle.getContainer() instanceof XSDModelGroup))
throw new XtentisException(Messages.bind(Messages.XSDDeleteParticleAction_ExceptionInfo, particle.getContainer().getClass().getName()));
XSDModelGroup group = (XSDModelGroup) particle.getContainer();
group.getContents().remove(particle);
// if (term instanceof XSDElementDeclaration) {
// //remove type definition is no more used and type is not built in
// XSDTypeDefinition typeDef = decl.getTypeDefinition();
// if ( (typeDef.getName()!=null) && //anonymous type
// (!typeDef.getSchema().getSchemaForSchemaNamespace().equals(typeDef.getTargetNamespace()))
// ){
// if (Util.findElementsUsingType(group.getSchema(),typeDef.getTargetNamespace(),
// typeDef.getName()).size()==0)
// group.getSchema().getContents().remove(typeDef);
// }
// }
group.updateElement();
xsdPartle = null;
page.refresh();
page.markDirty();
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteParticleAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.xsd.XSDTerm in project tmdm-studio-se by Talend.
the class XSDGetXPathAction method doAction.
@Override
public IStatus doAction() {
try {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
XSDParticle particle = (XSDParticle) selection.getFirstElement();
XSDTerm term = particle.getTerm();
if (!(term instanceof XSDElementDeclaration))
return Status.CANCEL_STATUS;
Clipboard clipboard = Util.getClipboard();
// $NON-NLS-1$
String path = "";
TreeItem item = page.getTreeViewer().getTree().getSelection()[0];
do {
XSDConcreteComponent component = (XSDConcreteComponent) item.getData();
if (component instanceof XSDParticle) {
if (((XSDParticle) component).getTerm() instanceof XSDElementDeclaration)
// $NON-NLS-1$
path = "/" + ((XSDElementDeclaration) ((XSDParticle) component).getTerm()).getName() + path;
} else if (component instanceof XSDElementDeclaration) {
path = ((XSDElementDeclaration) component).getName() + path;
}
// System.out.println(" "+path+ " $$"+component.toString()+"$$");
item = item.getParentItem();
} while (item != null);
xpath = path;
clipboard.setContents(new Object[] { path }, new Transfer[] { TextTransfer.getInstance() });
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDGetXPathAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations