summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/definitions/src
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-08-10 12:29:51 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-08-10 12:29:51 +0000
commitd5e64539010bf1fcc2351a2dc87ee8f7797a1cc1 (patch)
treec9d83c54072826011a222525384fac925aafa09d /java/sca/modules/definitions/src
parent650715987b8fb89e2bfc6ca27790cc9beba5eabd (diff)
TUSCANY-3020 - when definitions are aggregated together check that there are no duplicates. DOne here rather than later at the resolve phase as there is a better chance of reporting some sensible context to the user about which definitions.xml file is in error.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@802762 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/definitions/src')
-rw-r--r--java/sca/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/DefinitionsUtil.java73
-rw-r--r--java/sca/modules/definitions/src/main/resources/definitions-validation-messages.properties25
2 files changed, 93 insertions, 5 deletions
diff --git a/java/sca/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/DefinitionsUtil.java b/java/sca/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/DefinitionsUtil.java
index 2e9775e955..ba5a792c64 100644
--- a/java/sca/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/DefinitionsUtil.java
+++ b/java/sca/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/DefinitionsUtil.java
@@ -19,7 +19,14 @@
package org.apache.tuscany.sca.definitions.util;
+import java.util.HashSet;
+
import org.apache.tuscany.sca.definitions.Definitions;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.BindingType;
+import org.apache.tuscany.sca.policy.ImplementationType;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
/**
* Some utility functions to deal with SCADefinitions
@@ -28,11 +35,67 @@ import org.apache.tuscany.sca.definitions.Definitions;
*/
public class DefinitionsUtil {
- public static void aggregate(Definitions source, Definitions target) {
- target.getIntents().addAll(source.getIntents());
- target.getPolicySets().addAll(source.getPolicySets());
- target.getBindingTypes().addAll(source.getBindingTypes());
- target.getImplementationTypes().addAll(source.getImplementationTypes());
+ /**
+ * Add the source set of definitions into the target set of definitions checking that
+ * definitions artifacts are unique in the process
+ *
+ * @param source the input definitions collection
+ * @param target the definition collection into which source will aggregated
+ */
+ public static void aggregate(Definitions source, Definitions target, Monitor monitor) {
+
+ HashSet<Intent> intents = new HashSet<Intent>(target.getIntents());
+ for(Intent intent : source.getIntents()){
+ if (intents.contains(intent)){
+ Monitor.error(monitor,
+ target,
+ "definitions-validation-messages",
+ "DuplicateIntent",
+ intent.getName().toString());
+ } else {
+ target.getIntents().add(intent);
+ }
+ }
+
+ HashSet<PolicySet> policySets = new HashSet<PolicySet>(target.getPolicySets());
+ for(PolicySet policySet : source.getPolicySets()){
+ if (policySets.contains(policySet)){
+ Monitor.error(monitor,
+ target,
+ "definitions-validation-messages",
+ "DuplicatePolicySet",
+ policySet.getName().toString());
+ } else {
+ target.getPolicySets().add(policySet);
+ }
+ }
+
+ HashSet<BindingType> bindingTypes = new HashSet<BindingType>(target.getBindingTypes());
+ for(BindingType bindingType : source.getBindingTypes()){
+ if (bindingTypes.contains(bindingType)){
+ Monitor.error(monitor,
+ target,
+ "definitions-validation-messages",
+ "DuplicateBindingType",
+ bindingType.getType().toString());
+ } else {
+ target.getBindingTypes().add(bindingType);
+ }
+ }
+
+ HashSet<ImplementationType> implementationTypes = new HashSet<ImplementationType>(target.getImplementationTypes());
+ for(ImplementationType implementationType : source.getImplementationTypes()){
+ if (implementationTypes.contains(implementationType)){
+ Monitor.error(monitor,
+ target,
+ "definitions-validation-messages",
+ "DuplicateImplementationType",
+ implementationType.getType().toString());
+ } else {
+ target.getImplementationTypes().add(implementationType);
+ }
+ }
+
target.getBindings().addAll(source.getBindings());
}
diff --git a/java/sca/modules/definitions/src/main/resources/definitions-validation-messages.properties b/java/sca/modules/definitions/src/main/resources/definitions-validation-messages.properties
new file mode 100644
index 0000000000..4cf9c01da5
--- /dev/null
+++ b/java/sca/modules/definitions/src/main/resources/definitions-validation-messages.properties
@@ -0,0 +1,25 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+DuplicateIntent = Duplicate intent {0} found in domain
+DuplicatePolicysSet = Duplicate policy set {0} found in domain
+DuplicateImplementationType = Duplicate implementation type {0} found in domain
+DuplicateBindingType = Duplicate binding type {0} found in domain