use of org.eclipse.xsd.XSDComplexTypeDefinition 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.XSDComplexTypeDefinition 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;
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-studio-se by Talend.
the class Util method updateReferenceToXSDTypeDefinition.
/**
* update reference to newType
*
* @param elem
* @param newType
* @param provider
*/
public static void updateReferenceToXSDTypeDefinition(Object elem, XSDTypeDefinition newType, IStructuredContentProvider provider) {
if (newType instanceof XSDComplexTypeDefinition) {
updateChildrenReferenceToComplexType((XSDComplexTypeDefinition) newType);
}
List<Object> objList = new ArrayList<Object>();
Object[] allNodes = getAllObject(elem, objList, provider);
for (Object node : allNodes) {
if (node instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElem = (XSDElementDeclaration) node;
if (xsdElem.getTypeDefinition() == newType) {
xsdElem.setTypeDefinition(newType);
}
} else if (node instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) node;
if (particle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup group = (XSDModelGroup) particle.getTerm();
EList<XSDParticle> elist = group.getContents();
for (XSDParticle pt : elist) {
if (pt.getContent() instanceof XSDElementDeclaration) {
if (((XSDElementDeclaration) pt.getContent()).getTypeDefinition() == newType) {
((XSDElementDeclaration) pt.getContent()).setTypeDefinition(newType);
}
}
}
} else if (particle.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdElem = (XSDElementDeclaration) particle.getTerm();
if (xsdElem.getTypeDefinition() == newType) {
xsdElem.setTypeDefinition(newType);
}
}
}
}
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-studio-se by Talend.
the class Util method getTopParent.
public static List<Object> getTopParent(Object son) {
if (!((son instanceof XSDElementDeclaration))) {
return null;
}
XSDElementDeclaration elem = null;
elem = (XSDElementDeclaration) son;
if (elem.getSchema() == null) {
return null;
}
EList<XSDSchemaContent> parentList = elem.getSchema().getContents();
List<Object> list = new ArrayList<Object>();
for (XSDSchemaContent top : parentList) {
list.clear();
if (!(top instanceof XSDElementDeclaration)) {
continue;
}
XSDElementDeclaration decl = (XSDElementDeclaration) top;
if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
String primaryKey = getTopElement(decl, elem);
if (!"".equalsIgnoreCase(primaryKey)) {
// $NON-NLS-1$
EList<XSDIdentityConstraintDefinition> idtylist = decl.getIdentityConstraintDefinitions();
for (XSDIdentityConstraintDefinition idty : idtylist) {
EList<XSDXPathDefinition> fields = idty.getFields();
for (XSDXPathDefinition path : fields) {
if ((path.getValue()).equals(primaryKey)) {
list.add(idty);
list.add(path);
return list;
}
}
}
}
}
}
return null;
}
use of org.eclipse.xsd.XSDComplexTypeDefinition in project tmdm-studio-se by Talend.
the class XSDDeleteConceptWrapAction method doAction.
@Override
public IStatus doAction() {
List<IStatus> results = new ArrayList<IStatus>();
try {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
if (delObjs.isEmpty()) {
return Status.CANCEL_STATUS;
} else {
boolean sameType = checkInSameClassType(delObjs.toArray(), delObjs.get(0).getClass());
String deleteLabel = Messages.DelLabel1;
String elemDesc = ((Action) clsAction.get(delObjs.get(0).getClass())).getText();
// $NON-NLS-1$
int backPos = elemDesc.indexOf(" ");
if (delObjs.size() > 1) {
deleteLabel += elemDesc.substring(0, backPos) + Messages.DelLabel2 + delObjs.size() + Messages.DelLabel2A + (!sameType ? Messages.DelLabel2B : elemDesc.substring(backPos + 1));
if (deleteLabel.endsWith("y")) {
// $NON-NLS-1$
deleteLabel = deleteLabel.substring(0, deleteLabel.length() - 1) + Messages.DelLabel3;
} else {
deleteLabel = deleteLabel + Messages.XSDDeleteXX_DelLabel4;
}
} else {
deleteLabel += elemDesc.substring(0, backPos) + Messages.XSDDeleteXX_DelLabel5 + (!sameType ? Messages.XSDDeleteXX_DelLabel5A : elemDesc.substring(backPos + 1));
}
if (!MessageDialog.openConfirm(page.getSite().getShell(), Messages.XSDDeleteXX_DialogTitle, deleteLabel)) {
return Status.CANCEL_STATUS;
}
}
for (Iterator iterator = delObjs.iterator(); iterator.hasNext(); ) {
Object toDel = iterator.next();
UndoAction delExecute = null;
boolean isElem = true;
if (toDel instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) toDel;
EList l = decl.getIdentityConstraintDefinitions();
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
isElem = false;
break;
}
}
}
if (toDel instanceof XSDXPathDefinition) {
XSDXPathDefinition xpath = (XSDXPathDefinition) toDel;
if (!xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
continue;
}
}
delExecute = clsAction.get(toDel.getClass());
if (isElem && toDel instanceof XSDElementDeclaration) {
delExecute = clsAction.get(null);
}
if (delExecute instanceof XSDDeleteConceptAction && toDel instanceof XSDElementDeclaration) {
((XSDDeleteConceptAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
} else if (delExecute instanceof XSDDeleteElementAction && toDel instanceof XSDElementDeclaration) {
((XSDDeleteElementAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
} else if (delExecute instanceof XSDDeleteParticleAction && toDel instanceof XSDParticle) {
((XSDDeleteParticleAction) delExecute).setXSDTODel((XSDParticle) toDel);
} else if (delExecute instanceof XSDDeleteXPathAction && toDel instanceof XSDXPathDefinition) {
((XSDDeleteXPathAction) delExecute).setXSDTODel((XSDXPathDefinition) toDel);
} else if (delExecute instanceof XSDDeleteIdentityConstraintAction && toDel instanceof XSDIdentityConstraintDefinition) {
((XSDDeleteIdentityConstraintAction) delExecute).setXSDTODel((XSDIdentityConstraintDefinition) toDel);
} else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDComplexTypeDefinition) {
((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDComplexTypeDefinition) toDel);
} else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDSimpleTypeDefinition) {
((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDSimpleTypeDefinition) toDel);
} else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeUse) {
((XSDDeleteAttributeAction) delExecute).setXSDAttributeUse((XSDAttributeUse) toDel);
} else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeDeclaration) {
((XSDDeleteAttributeAction) delExecute).setXSDAttribute((XSDAttributeDeclaration) toDel);
} else {
return Status.CANCEL_STATUS;
}
results.add(delExecute.execute());
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteXX_ErrorMsg, e.getLocalizedMessage()));
return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
}
return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
}
Aggregations