use of org.eclipse.xsd.XSDXPathDefinition in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils method getInputXSDAnnotation.
public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
XSDAnnotation xsdAnnotation = null;
XSDFactory factory = XSDFactory.eINSTANCE;
if (input instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDNotationDeclaration) {
XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDXPathDefinition) {
XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroup) {
XSDModelGroup xsdComp = (XSDModelGroup) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDWildcard) {
XSDWildcard xsdComp = (XSDWildcard) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDSchema) {
XSDSchema xsdComp = (XSDSchema) input;
List list = xsdComp.getAnnotations();
if (list.size() > 0) {
xsdAnnotation = (XSDAnnotation) list.get(0);
} else {
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
if (xsdComp.getContents() != null) {
xsdComp.getContents().add(0, xsdAnnotation);
}
}
}
return xsdAnnotation;
} else if (input instanceof XSDFacet) {
XSDFacet xsdComp = (XSDFacet) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDTypeDefinition) {
XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDInclude) {
XSDInclude xsdComp = (XSDInclude) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDImport) {
XSDImport xsdComp = (XSDImport) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDRedefine) {
XSDRedefine xsdComp = (XSDRedefine) input;
List contents = xsdComp.getContents();
for (int i = 0; i < contents.size(); i++) {
Object content = contents.get(i);
if (content instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) content;
break;
}
}
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
contents.add(0, xsdAnnotation);
}
return xsdAnnotation;
} else if (input instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) input;
}
if (createIfNotExist) {
formatAnnotation(xsdAnnotation);
}
return xsdAnnotation;
}
use of org.eclipse.xsd.XSDXPathDefinition in project tmdm-studio-se by Talend.
the class EntityKeyConfigComposite method getFieldNames.
private List<String> getFieldNames(XSDIdentityConstraintDefinition xsdIdentityConstraintDefinition) {
List<String> fieldNames = new ArrayList<String>();
if (xsdIdentityConstraintDefinition == null) {
EList<XSDIdentityConstraintDefinition> identityConstraintDefinitions = entityWrapper.getSourceEntity().getIdentityConstraintDefinitions();
for (XSDIdentityConstraintDefinition idc : identityConstraintDefinitions) {
EList<XSDXPathDefinition> fields = idc.getFields();
for (XSDXPathDefinition fd : fields) {
fieldNames.add(fd.getValue());
}
}
} else {
XSDIdentityConstraintDefinition idc = xsdIdentityConstraintDefinition;
EList<XSDXPathDefinition> fields = idc.getFields();
for (XSDXPathDefinition fd : fields) {
fieldNames.add(fd.getValue());
}
}
return fieldNames;
}
use of org.eclipse.xsd.XSDXPathDefinition in project tmdm-studio-se by Talend.
the class EntityCommitHandler method commitKeyUpdate_Fields_Removal.
private boolean commitKeyUpdate_Fields_Removal(KeyWrapper keyWrapper) {
boolean hasChanges = false;
for (XSDXPathDefinition eachNeedRemovedField : getNeedRemovedFields(keyWrapper)) {
keyWrapper.getSourceKey().getFields().remove(eachNeedRemovedField);
keyWrapper.getSourceKey().updateElement();
hasChanges = true;
}
return hasChanges;
}
use of org.eclipse.xsd.XSDXPathDefinition in project tmdm-studio-se by Talend.
the class EntityCommitHandler method getNeedRemovedFields.
private XSDXPathDefinition[] getNeedRemovedFields(KeyWrapper keyWrapper) {
List<XSDXPathDefinition> curLeftFields = new ArrayList<XSDXPathDefinition>();
List<XSDXPathDefinition> needRemovedFields = new ArrayList<XSDXPathDefinition>();
for (FieldWrapper eachField : keyWrapper.getFields()) {
if (!eachField.isUserCreated()) {
curLeftFields.add(eachField.getSourceField());
}
}
for (XSDXPathDefinition eachSourceField : keyWrapper.getSourceKey().getFields()) {
if (!curLeftFields.contains(eachSourceField)) {
needRemovedFields.add(eachSourceField);
}
}
return needRemovedFields.toArray(new XSDXPathDefinition[0]);
}
use of org.eclipse.xsd.XSDXPathDefinition in project tmdm-studio-se by Talend.
the class EntityCommitHandler method commitKeyUpdate_Fields_Addition.
private boolean commitKeyUpdate_Fields_Addition(KeyWrapper keyWrapper) {
boolean hasChanges = false;
for (FieldWrapper eachField : keyWrapper.getFields()) {
if (!eachField.isUserCreated()) {
continue;
}
XSDXPathDefinition newXpath = XSDSchemaBuildingTools.getXSDFactory().createXSDXPathDefinition();
newXpath.setValue(eachField.getXPath());
newXpath.setVariety(XSDXPathVariety.FIELD_LITERAL);
keyWrapper.getSourceKey().getFields().add(newXpath);
keyWrapper.getSourceKey().updateElement();
hasChanges = true;
}
return hasChanges;
}
Aggregations