Author: bbrodt
Date: 2011-04-09 13:58:42 -0400 (Sat, 09 Apr 2011)
New Revision: 30459
Modified:
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/EmfModelQuery.java
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/helpers/ModelQueryImpl.java
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/model/IModelQuery.java
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/rules/ProcessValidator.java
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/rules/messages.properties
Log:
https://issues.jboss.org/browse/JBIDE-8088
added missing functionality to validate conflicting XSD definitions
Modified:
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/EmfModelQuery.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/EmfModelQuery.java 2011-04-09
13:15:17 UTC (rev 30458)
+++
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/EmfModelQuery.java 2011-04-09
17:58:42 UTC (rev 30459)
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.bpel.validator;
+import java.util.ArrayList;
import java.util.List;
import javax.xml.XMLConstants;
@@ -457,9 +458,10 @@
*
* @param eObj
* @return the root object
+ * @see
https://issues.jboss.org/browse/JBIDE-8088 - made public
*/
@SuppressWarnings("nls")
- static EObject getRoot ( EObject eObj ) {
+ public static EObject getRoot ( EObject eObj ) {
assertTrue(eObj != null, CONTEXT_MSG );
EObject top = eObj;
@@ -503,6 +505,39 @@
return null;
}
+ /**
+ * Search all process imports for the given QName reference
+ *
+ * @param process
+ * @param qname
+ * @param refType
+ * @return list of Imports
+ * @see
https://issues.jboss.org/browse/JBIDE-8088 - added
+ */
+ public static List<Import> scanAllImports ( Process process, QName qname , String
refType ) {
+
+ List<Import> imports = new ArrayList<Import>();
+ EObject result = null;
+
+ for(Object n : process.getImports()) {
+ Import imp = (Import) n;
+ if (imp.getLocation() == null ) {
+ continue;
+ }
+
+ ImportResolver[] resolvers =
ImportResolverRegistry.INSTANCE.getResolvers(imp.getImportType());
+ for(ImportResolver r : resolvers) {
+ result = r.resolve(imp, qname, null, refType);
+ if (result != null) {
+ imports.add(imp);
+ }
+ }
+
+ }
+
+ return imports;
+ }
+
public static EObject resolveProxy( Process process, EObject obj) {
if (obj instanceof MessageProxy) {
return scanImports ( process, ((MessageProxy)obj).getQName(), WSDLUtil.WSDL_MESSAGE
);
Modified:
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/helpers/ModelQueryImpl.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/helpers/ModelQueryImpl.java 2011-04-09
13:15:17 UTC (rev 30458)
+++
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/helpers/ModelQueryImpl.java 2011-04-09
17:58:42 UTC (rev 30459)
@@ -15,10 +15,14 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.List;
import java.util.Stack;
import javax.xml.namespace.QName;
+import org.eclipse.bpel.model.Import;
+import org.eclipse.bpel.model.Process;
+import org.eclipse.bpel.model.util.XSDUtil;
import org.eclipse.bpel.validator.EmfModelQuery;
import org.eclipse.bpel.validator.model.Filters;
import org.eclipse.bpel.validator.model.IConstants;
@@ -31,6 +35,9 @@
import org.eclipse.bpel.validator.model.Selector;
import org.eclipse.bpel.validator.model.UndefinedNode;
import org.eclipse.bpel.validator.model.XNotImplemented;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDTypeDefinition;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -957,6 +964,81 @@
return gModelQuery;
}
+ /**
+ * Searches all imports in the given Process for conflicting XSD definitions
+ *
+ * @param process the containing Process
+ * @param node the XSD element reference
+ * @return the list of Imports that contain conflicting definitions or null
+ * if there are no conflicts.
+ * @see
https://issues.jboss.org/browse/JBIDE-8088
+ */
+ @Override
+ public List<Import> findConflictingXSD(Process process, INode node) {
+
+ EObject o1 = adapt(node, EObject.class, ADAPT_HINT_NONE);
+ List<Import> imports = null;
+ List<Import> conflicts = new ArrayList<Import>();
+ QName qname = null;
+
+ if (o1 instanceof XSDTypeDefinition) {
+ qname = this.createQName(node, ((XSDTypeDefinition) o1).getName());
+ if ("".equals(qname.getNamespaceURI())) {
+ qname = new QName(((XSDTypeDefinition) o1).getTargetNamespace(),
qname.getLocalPart());
+ }
+ imports = emfModelQuery.scanAllImports(process, qname, XSDUtil.XSD_TYPE_DEFINITION);
+ } else if (o1 instanceof XSDElementDeclaration) {
+ qname = this.createQName(node, ((XSDElementDeclaration) o1).getName());
+ if ("".equals(qname.getNamespaceURI())) {
+ qname = new QName(((XSDElementDeclaration) o1).getTargetNamespace(),
qname.getLocalPart());
+ }
+ imports = emfModelQuery.scanAllImports(process, qname,
XSDUtil.XSD_ELEMENT_DECLARATION);
+ }
+
+ if (imports != null && imports.size() > 1) {
+ EObject o2 = null;
+ o1 = null;
+ for (Import imp : imports) {
+ EObject resolvedImport = emfModelQuery.lookupImport(imp, null);
+ if (o1 == null) {
+ if (o1 instanceof XSDTypeDefinition) {
+ o1 = emfModelQuery.lookupXSDType(resolvedImport, qname);
+ } else {
+ o1 = emfModelQuery.lookupXSDElement(resolvedImport, qname);
+ }
+ conflicts.add(imp);
+ } else {
+ if (o2 instanceof XSDTypeDefinition) {
+ o2 = emfModelQuery.lookupXSDType(resolvedImport, qname);
+ } else {
+ o2 = emfModelQuery.lookupXSDElement(resolvedImport, qname);
+ }
+ if (!emfModelQuery.compatibleType(o1, o2)) {
+ conflicts.add(imp);
+ }
+ }
+ }
+ }
+
+ return conflicts.size()>1 ? conflicts : null;
+ }
+
+
+ /**
+ * Returns the Process that corresponds to the given node
+ *
+ * @param node the Process element
+ * @return the Process or null
+ * @see
https://issues.jboss.org/browse/JBIDE-8088
+ */
+ @Override
+ public Process lookupProcess(INode node) {
+ EObject root = emfModelQuery.getRoot( adapt(node, EObject.class, ADAPT_HINT_NONE) );
+ if (root instanceof Process)
+ return (Process) root;
+ return null;
+ }
+
}
Modified:
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/model/IModelQuery.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/model/IModelQuery.java 2011-04-09
13:15:17 UTC (rev 30458)
+++
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/model/IModelQuery.java 2011-04-09
17:58:42 UTC (rev 30459)
@@ -10,8 +10,13 @@
*******************************************************************************/
package org.eclipse.bpel.validator.model;
+import java.util.List;
+
import javax.xml.namespace.QName;
+import org.eclipse.bpel.model.Import;
+import org.eclipse.bpel.model.Process;
+
/**
* This interface represents the query interface that the validator uses to ask
* of items in the model.
@@ -166,4 +171,23 @@
public QName createQName ( INode context, String name ) ;
+ /**
+ * Searches all imports in the given Process for conflicting XSD definitions
+ *
+ * @param process the containing Process
+ * @param node the XSD element reference
+ * @return the list of Imports that contain conflicting definitions or null
+ * if there are no conflicts.
+ * @see
https://issues.jboss.org/browse/JBIDE-8088
+ */
+ public List<Import> findConflictingXSD(Process process, INode node);
+
+ /**
+ * Returns the Process that corresponds to the given node
+ *
+ * @param node the Process element
+ * @return the Process or null
+ * @see
https://issues.jboss.org/browse/JBIDE-8088
+ */
+ public Process lookupProcess(INode node);
}
Modified:
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/rules/ProcessValidator.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/rules/ProcessValidator.java 2011-04-09
13:15:17 UTC (rev 30458)
+++
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/rules/ProcessValidator.java 2011-04-09
17:58:42 UTC (rev 30459)
@@ -20,6 +20,11 @@
import java.util.LinkedList;
import java.util.List;
+import javax.xml.namespace.QName;
+
+import org.eclipse.bpel.model.Import;
+import org.eclipse.bpel.model.Process;
+import org.eclipse.bpel.validator.helpers.DOMNodeAdapter;
import org.eclipse.bpel.validator.model.Filters;
import org.eclipse.bpel.validator.model.IConstants;
import org.eclipse.bpel.validator.model.IModelQueryLookups;
@@ -27,6 +32,10 @@
import org.eclipse.bpel.validator.model.IProblem;
import org.eclipse.bpel.validator.model.ARule;
import org.eclipse.bpel.validator.model.NodeAttributeValueFilter;
+import org.eclipse.emf.ecore.EObject;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
@@ -348,13 +357,33 @@
tag = "pass2",
order = 300
)
-
+ //
https://issues.jboss.org/browse/JBIDE-8088
+ // implemented missing code
public void CheckReferencedTypes () {
- // TODO: Add support for that in the model query mechanism.
+ IProblem problem;
+
for(INode node : fTypeToCheckList) {
- //if (mModelQuery.check(IModelQueryLookups.TEST_CONFLICTING_XSD, node, null)) {
- //
- //}
+
+ Process process = (Process) mModelQuery.lookupProcess(mNode);
+ List<Import> conflicts = mModelQuery.findConflictingXSD(process, node);
+ if (conflicts!=null) {
+
+ String conflicting = null;
+ for (int i=1; i<conflicts.size(); ++i) {
+ if (conflicting == null)
+ conflicting = conflicts.get(i).getLocation();
+ else
+ conflicting += ", " + conflicts.get(i).getLocation();
+ }
+ problem = createError(node);
+ problem.fill("BPELC_XSD__CONFLICTING_DEFINITION",
+ node.getAttribute(AT_NAME),
+ conflicts.get(0).getLocation(),
+ conflicting
+
+ );
+
+ }
}
}
Modified:
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/rules/messages.properties
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/rules/messages.properties 2011-04-09
13:15:17 UTC (rev 30458)
+++
trunk/bpel/plugins/org.eclipse.bpel.validator/src/org/eclipse/bpel/validator/rules/messages.properties 2011-04-09
17:58:42 UTC (rev 30459)
@@ -847,7 +847,18 @@
compatible with {4} "{5}" of type "{6}"
BPELC_XSD__INCOMPATIBLE_TYPE.fix = Type must be compatible.
#
+# ------------- Conflicting XSD type definitions ---------------------
+# BPELC_UNKNOWN__ELEMENT
+# {0}: node
+# {1}: namespace URI
#
+#
https://issues.jboss.org/browse/JBIDE-8088
+BPELC_XSD__CONFLICTING_DEFINITION.summary = Conflicting XSD element <{0}>
definitions.
+BPELC_XSD__CONFLICTING_DEFINITION = XSD element <{0}> in import {1} conflicts with
element of the same name in {2}.
+BPELC_XSD__CONFLICTING_DEFINITION.fix = Resolve the conflict by removing the conflicting
definitions, or ensuring that all definitions are identical.
+
+#
+#
# -------------------- Copy ------------------------------------
# BPELC_COPY__INCOMPATIBLE
# {0}: node