use of org.eclipse.xsd.XSDSchemaContent 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.XSDSchemaContent in project tmdm-studio-se by Talend.
the class Util method getParent.
public static Object getParent(Object son) {
if (!((son instanceof XSDElementDeclaration) || (son instanceof XSDParticle))) {
return null;
}
XSDElementDeclaration elem = null;
if (son instanceof XSDParticle) {
elem = (XSDElementDeclaration) ((XSDParticle) son).getContent();
} else if (son instanceof XSDElementDeclaration) {
elem = (XSDElementDeclaration) son;
}
if (elem == null || elem.getSchema() == null) {
return null;
}
EList<XSDSchemaContent> parentList = elem.getSchema().getContents();
for (XSDSchemaContent top : parentList) {
if (!(top instanceof XSDElementDeclaration) && !(top instanceof XSDComplexTypeDefinition)) {
continue;
}
if (top instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) top;
if (decl == son) {
return decl;
}
if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) decl.getTypeDefinition();
if (type.getContent() instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) type.getContent();
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()) == elem) {
return decl;
}
}
Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
XSDElementDeclaration spec = findOutSpecialSonElement((XSDElementDeclaration) pt.getContent(), elem, complexTypes);
if (spec != null) {
return spec;
}
}
}
}
}
} else {
XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) top;
if (type.getContent() instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) type.getContent();
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()) == elem) {
return top;
}
}
if (pt.getContent() instanceof XSDElementDeclaration) {
Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
XSDElementDeclaration spec = findOutSpecialSonElement((XSDElementDeclaration) pt.getContent(), elem, complexTypes);
if (spec != null) {
return spec;
}
}
}
}
}
}
}
return null;
}
use of org.eclipse.xsd.XSDSchemaContent in project tmdm-studio-se by Talend.
the class XSDUtil method getAllPKXpaths.
public static List<String> getAllPKXpaths(XSDSchema schema) {
List<String> entity2xpaths = new LinkedList<String>();
if (schema != null) {
for (XSDSchemaContent content : schema.getContents()) {
if (isEntity(content)) {
XSDElementDeclaration concept = (XSDElementDeclaration) content;
List<String> keyFields = getKeyFields(concept);
entity2xpaths.add(0, concept.getName());
for (String pkfield : keyFields) {
// $NON-NLS-1$
entity2xpaths.add(concept.getName() + "/" + pkfield);
}
}
}
}
return entity2xpaths;
}
use of org.eclipse.xsd.XSDSchemaContent 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.XSDSchemaContent in project tmdm-studio-se by Talend.
the class DataModelMainPage method doImportSchema.
protected void doImportSchema(final Collection<XSDSchemaContent> addtional) {
if (null == addtional || addtional.isEmpty()) {
return;
}
try {
int flag = ConflictDialog.NONE;
boolean dialogPopup = false;
List<XSDSchemaContent> contents = xsdSchema.getContents();
List<XSDSchemaContent> exists = new ArrayList<XSDSchemaContent>(contents);
for (XSDSchemaContent content : addtional) {
XSDSchemaContent exist = getContainedSchemaContent(exists, content);
if (null == exist) {
Node importElement = xsdSchema.getDocument().importNode(content.getElement(), true);
xsdSchema.getElement().appendChild(importElement);
} else {
if (!dialogPopup) {
String type = null;
if (exist instanceof XSDElementDeclaration) {
type = Messages.DataModelMainPage_entity;
} else if (exist instanceof XSDTypeDefinition) {
type = Messages.DataModelMainPage_type;
} else {
continue;
}
LabelProvider provider = getContentLabelProvider(exist);
String message = Messages.bind(Messages.conflict_messages, type, provider.getText(exist));
ConflictDialog dialog = new ConflictDialog(getSite().getShell(), message);
if (dialog.open() == Dialog.OK) {
flag = dialog.getStatus();
dialogPopup = dialog.applyAll;
} else {
popupImportDialog();
return;
}
}
if (flag == ConflictDialog.OVERWRITE) {
contents.remove(exist);
Node importElement = xsdSchema.getDocument().importNode(content.getElement(), true);
xsdSchema.getElement().appendChild(importElement);
}
}
}
//
validateSchema();
markDirtyWithoutCommit();
setXsdSchema(xsdSchema);
getSchemaRoleFilterFromSchemaTree().setDataModelFilter(dataModelFilter);
// refresh types
viewer.setInput(getSite());
typesViewer.setInput(getSite());
MessageDialog.openInformation(getSite().getShell(), Messages.ImportXSDSche, Messages.ImportingXSDSchemaCompleted);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
// $NON-NLS-1$
String detail = "";
if (ex.getMessage() != null && !ex.getMessage().equals("")) {
// $NON-NLS-1$
// $NON-NLS-1$
detail += " , " + Messages.bind(Messages.Dueto, ex.getMessage());
}
MessageDialog.openError(getSite().getShell(), Messages._Error, Messages.bind(Messages.ImportingXSDSchemaFailed, detail));
}
}
Aggregations