diff options
Diffstat (limited to '')
62 files changed, 2845 insertions, 23 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefaultDefinitionsFactory.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefaultDefinitionsFactory.java new file mode 100644 index 0000000000..156fd0af75 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefaultDefinitionsFactory.java @@ -0,0 +1,32 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.definitions; + +import org.apache.tuscany.sca.definitions.impl.DefinitionsImpl; + +/** + * Default Implementation of DefinitionsFactory + */ +public class DefaultDefinitionsFactory implements DefinitionsFactory { + + public Definitions createDefinitions() { + return new DefinitionsImpl(); + } + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/Definitions.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/Definitions.java new file mode 100644 index 0000000000..979ff7c187 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/Definitions.java @@ -0,0 +1,83 @@ + /* + * 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. + */ +package org.apache.tuscany.sca.definitions; + +import java.util.List; + +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; + + +/** + * Represents SCA Definitions. + * + * @version $Rev$ $Date$ + */ +public interface Definitions { + /** + * Returns the target namespace for this SCA Definition + * @return the target namespace + */ + String getTargetNamespace(); + + /** + * Sets the target names for this SCA Definition. + * + * @param ns the target namespace for this SCA Definition + */ + void setTargetNamespace(String ns); + + /** + * Returns a list of domain wide Policy Intents + * + * @return a list of domain wide Policy Intents + */ + List<Intent> getIntents(); + + /** + * Returns a list of domain wide PolicySets + * + * @return a list of domain wide PolicySets + */ + List<PolicySet> getPolicySets(); + + /** + * Returns a list of domain wide Binding Types + * + * @return a list of domain wide Binding Types + */ + List<BindingType> getBindingTypes(); + + + /** + * Returns a list of domain wide Implementation Types + * + * @return a list of domain wide Implementation Types + */ + List<ImplementationType> getImplementationTypes(); + + /** + * Returns a list of domain wide binding definition objects + * + * @return a list of domain wide binding definition objects + */ + List<Object> getBindings(); +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefinitionsBuilder.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefinitionsBuilder.java new file mode 100644 index 0000000000..5c68c6cbff --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefinitionsBuilder.java @@ -0,0 +1,34 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.definitions; + + +/** + * Interface to abstract building of SCA Definitions for a Domain + * + * @version $Rev$ $Date$ + */ +public interface DefinitionsBuilder { + /** + * Builds the SCA definitions + * + * @param scaDefns + */ + void build(Definitions scaDefns) throws DefinitionsBuilderException; +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefinitionsBuilderException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefinitionsBuilderException.java new file mode 100644 index 0000000000..f45be80888 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefinitionsBuilderException.java @@ -0,0 +1,43 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.definitions; + +/** + * Builder Exception + * + * @version $Rev$ $Date$ + */ +public class DefinitionsBuilderException extends Exception { + private static final long serialVersionUID = 2513219325230252783L; + + public DefinitionsBuilderException() { + } + + public DefinitionsBuilderException(String message) { + super(message); + } + + public DefinitionsBuilderException(Throwable cause) { + super(cause); + } + + public DefinitionsBuilderException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefinitionsFactory.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefinitionsFactory.java new file mode 100644 index 0000000000..616616ae7a --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/DefinitionsFactory.java @@ -0,0 +1,31 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.definitions; + +/** + * Factory interface to create SCA definitions model + * + */ +public interface DefinitionsFactory { + /** + * Create an instance of SCA definitions + * @return a new instance of SCA definitions + */ + Definitions createDefinitions(); +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/impl/DefinitionsBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/impl/DefinitionsBuilderImpl.java new file mode 100644 index 0000000000..d87d45b27a --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/impl/DefinitionsBuilderImpl.java @@ -0,0 +1,307 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.definitions.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.definitions.Definitions; +import org.apache.tuscany.sca.definitions.DefinitionsBuilder; +import org.apache.tuscany.sca.definitions.DefinitionsBuilderException; +import org.apache.tuscany.sca.policy.BindingType; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.ImplementationType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentMap; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.Qualifier; + +/** + * Provides a concrete implementation for a SCADefinitionsBuilder + * + * @version $Rev$ $Date$ + */ +public class DefinitionsBuilderImpl implements DefinitionsBuilder { + + public void build(Definitions scaDefns) throws DefinitionsBuilderException { + Map<QName, Intent> definedIntents = new HashMap<QName, Intent>(); + for (Intent intent : scaDefns.getIntents()) { + definedIntents.put(intent.getName(), intent); + } + + Map<QName, PolicySet> definedPolicySets = new HashMap<QName, PolicySet>(); + for (PolicySet policySet : scaDefns.getPolicySets()) { + definedPolicySets.put(policySet.getName(), policySet); + } + + Map<QName, BindingType> definedBindingTypes = new HashMap<QName, BindingType>(); + for (BindingType bindingType : scaDefns.getBindingTypes()) { + definedBindingTypes.put(bindingType.getType(), bindingType); + } + + Map<QName, ImplementationType> definedImplTypes = new HashMap<QName, ImplementationType>(); + for (ImplementationType implType : scaDefns.getImplementationTypes()) { + definedImplTypes.put(implType.getType(), implType); + } + + //filling up the maps removes all duplicate entries... so fill this unique lists + //into the scaDefns. + scaDefns.getIntents().clear(); + scaDefns.getPolicySets().clear(); + scaDefns.getBindingTypes().clear(); + scaDefns.getImplementationTypes().clear(); + + scaDefns.getIntents().addAll(definedIntents.values()); + scaDefns.getPolicySets().addAll(definedPolicySets.values()); + scaDefns.getBindingTypes().addAll(definedBindingTypes.values()); + scaDefns.getImplementationTypes().addAll(definedImplTypes.values()); + + buildPolicyIntents(scaDefns, definedIntents); + buildPolicySets(scaDefns, definedPolicySets, definedIntents); + buildBindingTypes(scaDefns, definedBindingTypes, definedIntents); + buildImplementationTypes(scaDefns, definedImplTypes, definedIntents); + } + + private void buildBindingTypes(Definitions scaDefns, + Map<QName, BindingType> definedBindingTypes, + Map<QName, Intent> definedIntents) throws DefinitionsBuilderException { + for (BindingType bindingType : scaDefns.getBindingTypes()) { + buildAlwaysProvidedIntents(bindingType, definedIntents); + buildMayProvideIntents(bindingType, definedIntents); + } + + } + + private void buildImplementationTypes(Definitions scaDefns, + Map<QName, ImplementationType> definedImplTypes, + Map<QName, Intent> definedIntents) throws DefinitionsBuilderException { + for (ImplementationType implType : scaDefns.getImplementationTypes()) { + buildAlwaysProvidedIntents(implType, definedIntents); + buildMayProvideIntents(implType, definedIntents); + } + } + + private void buildPolicyIntents(Definitions scaDefns, Map<QName, Intent> definedIntents) + throws DefinitionsBuilderException { + for (Intent policyIntent : scaDefns.getIntents()) { + if (!policyIntent.getRequiredIntents().isEmpty()) { + buildProfileIntent(policyIntent, definedIntents); + } + + if (!policyIntent.getQualifiedIntents().isEmpty()) { + buildQualifiedIntent(policyIntent, definedIntents); + } + } + } + + private void buildPolicySets(Definitions scaDefns, + Map<QName, PolicySet> definedPolicySets, + Map<QName, Intent> definedIntents) throws DefinitionsBuilderException { + + for (PolicySet policySet : scaDefns.getPolicySets()) { + buildProvidedIntents(policySet, definedIntents); + buildIntentsInMappedPolicies(policySet, definedIntents); + buildReferredPolicySets(policySet, definedPolicySets); + } + + for (PolicySet policySet : scaDefns.getPolicySets()) { + for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { + includeReferredPolicySets(policySet, referredPolicySet); + } + } + } + + private void buildProfileIntent(Intent policyIntent, Map<QName, Intent> definedIntents) + throws DefinitionsBuilderException { + //FIXME: Need to check for cyclic references first i.e an A requiring B and then B requiring A... + if (policyIntent != null) { + //resolve all required intents + List<Intent> requiredIntents = new ArrayList<Intent>(); + for (Intent requiredIntent : policyIntent.getRequiredIntents()) { + if (requiredIntent.isUnresolved()) { + Intent resolvedRequiredIntent = definedIntents.get(requiredIntent.getName()); + if (resolvedRequiredIntent != null) { + requiredIntents.add(resolvedRequiredIntent); + } else { + throw new DefinitionsBuilderException("Required Intent - " + requiredIntent + + " not found for ProfileIntent " + + policyIntent); + + } + } else { + requiredIntents.add(requiredIntent); + } + } + policyIntent.getRequiredIntents().clear(); + policyIntent.getRequiredIntents().addAll(requiredIntents); + } + } + + private void buildQualifiedIntent(Intent policyIntent, Map<QName, Intent> definedIntents) + throws DefinitionsBuilderException { + /* + if (policyIntent != null) { + //resolve the qualifiable intent + Intent qualifiableIntent = policyIntent.getQualifiableIntent(); + if (qualifiableIntent.isUnresolved()) { + Intent resolvedQualifiableIntent = definedIntents.get(qualifiableIntent.getName()); + + if (resolvedQualifiableIntent != null) { + policyIntent.setQualifiableIntent(resolvedQualifiableIntent); + } else { + throw new DefinitionsBuilderException("Qualifiable Intent - " + qualifiableIntent + + " not found for QualifiedIntent " + + policyIntent); + } + + } + } + */ + } + + private void buildAlwaysProvidedIntents(ExtensionType extensionType, Map<QName, Intent> definedIntents) + throws DefinitionsBuilderException { + if (extensionType != null) { + // resolve all provided intents + List<Intent> alwaysProvided = new ArrayList<Intent>(); + for (Intent providedIntent : extensionType.getAlwaysProvidedIntents()) { + if (providedIntent.isUnresolved()) { + Intent resolvedProvidedIntent = definedIntents.get(providedIntent.getName()); + if (resolvedProvidedIntent != null) { + alwaysProvided.add(resolvedProvidedIntent); + } else { + throw new DefinitionsBuilderException("Always Provided Intent - " + providedIntent + + " not found for ExtensionType " + + extensionType); + + } + } else { + alwaysProvided.add(providedIntent); + } + } + extensionType.getAlwaysProvidedIntents().clear(); + extensionType.getAlwaysProvidedIntents().addAll(alwaysProvided); + } + } + + private void buildMayProvideIntents(ExtensionType extensionType, Map<QName, Intent> definedIntents) + throws DefinitionsBuilderException { + if (extensionType != null) { + // resolve all provided intents + List<Intent> mayProvide = new ArrayList<Intent>(); + for (Intent providedIntent : extensionType.getMayProvidedIntents()) { + if (providedIntent.isUnresolved()) { + Intent resolvedProvidedIntent = definedIntents.get(providedIntent.getName()); + if (resolvedProvidedIntent != null) { + mayProvide.add(resolvedProvidedIntent); + } else { + throw new DefinitionsBuilderException("May Provide Intent - " + providedIntent + + " not found for ExtensionType " + + extensionType); + + } + } else { + mayProvide.add(providedIntent); + } + } + extensionType.getMayProvidedIntents().clear(); + extensionType.getMayProvidedIntents().addAll(mayProvide); + } + } + + private void buildProvidedIntents(PolicySet policySet, Map<QName, Intent> definedIntents) + throws DefinitionsBuilderException { + if (policySet != null) { + //resolve all provided intents + List<Intent> providedIntents = new ArrayList<Intent>(); + for (Intent providedIntent : policySet.getProvidedIntents()) { + if (providedIntent.isUnresolved()) { + Intent resolvedProvidedIntent = definedIntents.get(providedIntent.getName()); + if (resolvedProvidedIntent != null) { + providedIntents.add(resolvedProvidedIntent); + } else { + throw new DefinitionsBuilderException("Provided Intent - " + providedIntent + + " not found for PolicySet " + + policySet); + + } + } else { + providedIntents.add(providedIntent); + } + } + policySet.getProvidedIntents().clear(); + policySet.getProvidedIntents().addAll(providedIntents); + } + } + + private void buildIntentsInMappedPolicies(PolicySet policySet, Map<QName, Intent> definedIntents) + throws DefinitionsBuilderException { + for (IntentMap intentMap : policySet.getIntentMaps()) { + for (Qualifier qualifier : intentMap.getQualifiers()) { + Intent mappedIntent = qualifier.getIntent(); + if (mappedIntent.isUnresolved()) { + Intent resolvedMappedIntent = definedIntents.get(mappedIntent.getName()); + + if (resolvedMappedIntent != null) { + qualifier.setIntent(resolvedMappedIntent); + } else { + throw new DefinitionsBuilderException("Mapped Intent - " + mappedIntent + + " not found for PolicySet " + + policySet); + + } + } + } + } + } + + private void buildReferredPolicySets(PolicySet policySet, Map<QName, PolicySet> definedPolicySets) + throws DefinitionsBuilderException { + + List<PolicySet> referredPolicySets = new ArrayList<PolicySet>(); + for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { + if (referredPolicySet.isUnresolved()) { + PolicySet resolvedReferredPolicySet = definedPolicySets.get(referredPolicySet.getName()); + if (resolvedReferredPolicySet != null) { + referredPolicySets.add(resolvedReferredPolicySet); + } else { + throw new DefinitionsBuilderException("Referred PolicySet - " + referredPolicySet + + "not found for PolicySet - " + + policySet); + } + } else { + referredPolicySets.add(referredPolicySet); + } + } + policySet.getReferencedPolicySets().clear(); + policySet.getReferencedPolicySets().addAll(referredPolicySets); + } + + private void includeReferredPolicySets(PolicySet policySet, PolicySet referredPolicySet) { + for (PolicySet furtherReferredPolicySet : referredPolicySet.getReferencedPolicySets()) { + includeReferredPolicySets(referredPolicySet, furtherReferredPolicySet); + } + policySet.getPolicies().addAll(referredPolicySet.getPolicies()); + policySet.getIntentMaps().addAll(referredPolicySet.getIntentMaps()); + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/impl/DefinitionsImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/impl/DefinitionsImpl.java new file mode 100644 index 0000000000..1987b39abe --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/impl/DefinitionsImpl.java @@ -0,0 +1,72 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.definitions.impl; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.tuscany.sca.definitions.Definitions; +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; + +/** + * Provides a concrete implementation for SCADefinitions + * + * @version $Rev$ $Date$ + */ +public class DefinitionsImpl implements Definitions { + private String targetNamespace = null; + private List<Intent> intents = new CopyOnWriteArrayList<Intent>(); + private List<PolicySet> policySets = new CopyOnWriteArrayList<PolicySet>(); + private List<BindingType> bindingTypes = new CopyOnWriteArrayList<BindingType>(); + private List<ImplementationType> implementationTypes = new CopyOnWriteArrayList<ImplementationType>(); + private List<Object> bindings = new CopyOnWriteArrayList<Object>(); + + + public List<BindingType> getBindingTypes() { + return bindingTypes; + } + + public List<ImplementationType> getImplementationTypes() { + return implementationTypes; + } + + public List<Intent> getIntents() { + return intents; + } + + public List<PolicySet> getPolicySets() { + return policySets; + } + + public String getTargetNamespace() { + return targetNamespace; + } + + public void setTargetNamespace(String ns) { + this.targetNamespace = ns; + } + + public List<Object> getBindings() { + return bindings; + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/util/DefinitionsUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/util/DefinitionsUtil.java new file mode 100644 index 0000000000..ba5a792c64 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/definitions/util/DefinitionsUtil.java @@ -0,0 +1,102 @@ +/* + * 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. + */ + +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 + * + * @version $Rev$ $Date$ + */ +public class DefinitionsUtil { + + /** + * 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/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java index 247a432330..247a432330 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java index 1f5620c0b9..1f5620c0b9 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java index 70f6d5b403..70f6d5b403 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java index 179dc1755e..179dc1755e 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java index 24f23e255d..24f23e255d 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java index 568a6c595c..568a6c595c 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java index 8dfeb29833..8dfeb29833 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java index f952a86478..f952a86478 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java index 2a273c9a26..2a273c9a26 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java index b19805c5b1..b19805c5b1 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java index 55f00b82c8..55f00b82c8 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java index 6773b29088..6773b29088 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java index c1c8400b71..c1c8400b71 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java index 15581b5e04..15581b5e04 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java index 289fd25594..289fd25594 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java index 67aae7da4d..67aae7da4d 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java index 26144e92cb..26144e92cb 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java index 777fa567f1..777fa567f1 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java index 844b0af509..844b0af509 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java index 54c0a3ec11..54c0a3ec11 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java index 2598dc8545..2598dc8545 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java index 12db460959..12db460959 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java diff --git a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java index 26ecf6e352..26ecf6e352 100644 --- a/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/BindingType.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/BindingType.java new file mode 100644 index 0000000000..f43c428563 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/BindingType.java @@ -0,0 +1,27 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy; + + +/** + * Definition of binding type which extends from sca:binding + */ +public interface BindingType extends ExtensionType { +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java new file mode 100644 index 0000000000..2da41675a1 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java @@ -0,0 +1,30 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy; + +import org.apache.tuscany.sca.policy.impl.PolicyFactoryImpl; + +/** + * A factory for the policy model. + * + * @version $Rev$ $Date$ + */ +public class DefaultPolicyFactory extends PolicyFactoryImpl implements PolicyFactory { + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/ExtensionType.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/ExtensionType.java new file mode 100644 index 0000000000..e7a93c8907 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/ExtensionType.java @@ -0,0 +1,81 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy; + +import java.util.List; + +import javax.xml.namespace.QName; + +/** + * Definition of extension type: binding or implementation + */ +public interface ExtensionType { + QName BINDING_BASE = new QName("http://docs.oasis-open.org/ns/opencsa/sca/200903", "binding"); + QName IMPLEMENTATION_BASE = new QName("http://docs.oasis-open.org/ns/opencsa/sca/200903", "implementation"); + + /** + * The name of the extension type (binding or implementation). The extension type name + * attribute MUST be the QName of an XSD global element definition used for + * binding/implementation elements of that type + * + * @return The QName of this type + */ + QName getType(); + + /** + * Set the QName for this type + * @param type The QName of this type + */ + void setType(QName type); + + QName getBaseType(); + + /** + * A set of intents. The intents in the alwaysProvides set are always + * provided by this extension type, whether the intents are attached + * to the using component or not. + * + * @return A list of intents that are always provided by this type + */ + List<Intent> getAlwaysProvidedIntents(); + + /** + * a set of intents. The intents in the mayProvide set are provided by this + * extension type if the intent in question is attached to the using + * component. + * + * @return A list of intents that may be provided by this type + */ + List<Intent> getMayProvidedIntents(); + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/ImplementationType.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/ImplementationType.java new file mode 100644 index 0000000000..d142015f57 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/ImplementationType.java @@ -0,0 +1,27 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy; + + +/** + * Definition of an implementation type which extends from sca:implementation + */ +public interface ImplementationType extends ExtensionType { +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/Intent.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/Intent.java new file mode 100644 index 0000000000..b79ccdab78 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/Intent.java @@ -0,0 +1,160 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy; + +import java.util.List; + +import javax.xml.namespace.QName; + +/** + * Represents a policy intent. See the Policy Framework specification for a + * description of this element. + * + * @version $Rev$ $Date$ + */ +public interface Intent { + enum Type { + interaction, implementation + }; + + /** + * Returns the intent name. + * + * @return the intent name + */ + QName getName(); + + /** + * Sets the intent name + * + * @param name the intent name + */ + void setName(QName name); + + /** + * Returns the list of SCA constructs that this intent is meant to + * configure. + * + * @return the list of SCA constructs that this intent is meant to configure + */ + List<ExtensionType> getConstrainedTypes(); + + /** + * Return a list of required intents + * @return The list of required intents + */ + List<Intent> getRequiredIntents(); + + /** + * Returns the list of intents which are mutually exclusive with this intent. + * + * @return the list of mutually exclusive intents. + */ + List<Intent> getExcludedIntents(); + + /** + * Returns the list of qualified intents. + * + * @return the list of qualified intents. + */ + List<Intent> getQualifiedIntents(); + + /** + * Get the default qualified intent + * + * @return + */ + Intent getDefaultQualifiedIntent(); + + /** + * Set the default qualified intent + * + * @param qualifiedIntent + */ + void setDefaultQualifiedIntent(Intent qualifiedIntent); + + /** + * Get the intent type: Interaction or Implementation + * @return + */ + Type getType(); + + /** + * Set the intent type + * @param type: Interaction or Implementation + */ + void setType(Type type); + + /** + * If this attribute is present and has a value of true it indicates that + * the qualified intents defined for this intent are mutually exclusive + * + * @return + */ + boolean isMutuallyExclusive(); + + /** + * Set the value of mutuallyExclusive + * @param mutuallyExclusive + */ + void setMutuallyExclusive(boolean mutuallyExclusive); + + /** + * Returns the intent description. + * + * @return the intent description + */ + String getDescription(); + + /** + * Sets the intent description. + * + * @param description the intent description + */ + void setDescription(String description); + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + + /** + * Get the parent intent for a qualified intent. If an intent is not qualified, + * return null. + * @return The parent intent or null if this intent is not qualified + */ + Intent getQualifiableIntent(); + + /** + * Set the parent intent for a qualified intent + * @param intent + */ + void setQualifiableIntent(Intent intent); + + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java new file mode 100644 index 0000000000..efed4bfdb1 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java @@ -0,0 +1,51 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy; + +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; + + +/** + * Map policies to the qualified intents + */ +public interface IntentMap { + /** + * Returns the intent realized by this intent map. + * + * @return the intent realized by this intent map + */ + Intent getProvidedIntent(); + + /** + * Sets the intent realized by this intent map. + * + * @param providedIntent the intent realized by this intent map + */ + void setProvidedIntent(Intent providedIntent); + + /** + * Get a list of qualifiers + * + * @return A list of qualifiers + */ + List<Qualifier> getQualifiers(); +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyAttachment.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyAttachment.java new file mode 100644 index 0000000000..ee4f5b5236 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyAttachment.java @@ -0,0 +1,31 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy; + +import java.util.List; + +/** + * Attach a policySet to a collection of policy subjects + */ +public interface PolicyAttachment { + PolicySet getPolicySet(); + void setPolicySet(PolicySet policySet); + List<PolicySubject> getPolicySubjects(); +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyExpression.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyExpression.java new file mode 100644 index 0000000000..a29f214f98 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyExpression.java @@ -0,0 +1,65 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy; + +import javax.xml.namespace.QName; + +/** + * Interface that will abstract various types of policy specifications + * and attachments for example WS-Policy + * + * @version $Rev$ $Date$ + */ +public interface PolicyExpression { + /** + * Get the QName of the policy expression + * @return the QName of the policy expression + */ + QName getName(); + + /** + * Set the QName of the policy expression + * @param name + */ + void setName(QName name); + + /** + * Get the policy definition in the type of the specific domain + * @return + */ + <T> T getPolicy(); + + /** + * Set the policy definition + * @param expression + */ + <T> void setPolicy(T policy); + + /** + * + * @param unresolved + */ + void setUnresolved(boolean unresolved); + + /** + * + * @return + */ + boolean isUnresolved(); +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java new file mode 100644 index 0000000000..9e7de2f6da --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java @@ -0,0 +1,66 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy; + +/** + * A factory for the policy model. + * + * @version $Rev$ $Date$ + */ +public interface PolicyFactory { + + /** + * Create a new intent. + * + * @return a new intent + */ + Intent createIntent(); + + /** + * Create a new policy set. + * + * @return a new policy set + */ + PolicySet createPolicySet(); + + /** + * Create a new intent map. + * + * @return a new intent map + */ + IntentMap createIntentMap(); + + /** + * create a new Qualifier + * + * @return a Qualifier + */ + Qualifier createQualifier(); + + /** + * Create a new PolicyExpression + * @return + */ + PolicyExpression createPolicyExpression(); + + ExtensionType createExtensionType(); + BindingType createBindingType(); + ImplementationType createImplementationType(); + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java new file mode 100644 index 0000000000..2b5b8458d5 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java @@ -0,0 +1,146 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy; + +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.xpath.XPathExpression; + +/** + * Represents a policy set. See the Policy Framework specification for a + * description of this element. + * + * @version $Rev$ $Date$ + */ +public interface PolicySet { + + /** + * Returns the intent name. + * + * @return the intent name + */ + QName getName(); + + /** + * Sets the intent name + * + * @param name the intent name + */ + void setName(QName name); + + /** + * Returns the list of + * + * @return + */ + List<PolicySet> getReferencedPolicySets(); + + /** + * Returns the list of provided intents + * + * @return + */ + List<Intent> getProvidedIntents(); + + /** + * Returns the list of concrete policies, either WS-Policy policy + * attachments, policy references, or policies expressed in another policy + * language. + * + * @return the list of concrete policies + */ + List<PolicyExpression> getPolicies(); + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + + /** + * Returns the XPath expression that is to be used to evaluate + * if this PolicySet applies to specific policy subject + * + * @return the XPath expression + */ + String getAppliesTo(); + + /** + * Sets the XPath expression that is to be used to evaluate + * if this PolicySet applies to specific policy subject + * + */ + void setAppliesTo(String xpath); + + /** + * A string which is an XPath 1.0 expression identifying one or more + * elements (policy subject) in the Domain. It is used to declare which + * set of elements the policySet is actually attached to. + * + * @return The attachTo XPath + */ + String getAttachTo(); + + /** + * Set the attachTo XPath + * @param xpath + */ + void setAttachTo(String xpath); + + /** + * Get the resolved XPathExpression for attachTo + * @return + */ + XPathExpression getAttachToXPathExpression(); + + /** + * Set the resolved XPathExpression for attachTo + * @param expression + */ + void setAttachToXPathExpression(XPathExpression expression); + + /** + * Returns the policies / policy attachments provided thro intent maps + * + * @return + */ + List<IntentMap> getIntentMaps(); + + /** + * Get the XPath expression for the appliesTo attribute + * @return the XPath expression for the appliesTo attribute + */ + XPathExpression getAppliesToXPathExpression(); + + /** + * Set the XPath expression for the appliesTo attribute + * @param xpathExpression the XPath expression for the appliesTo attribute + */ + void setAppliesToXPathExpression(XPathExpression xpathExpression); + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicySubject.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicySubject.java new file mode 100644 index 0000000000..35a86ceedf --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/PolicySubject.java @@ -0,0 +1,56 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy; + +import java.util.List; + +/** + * A policy subject is an entity in the assembly with which a policy can be + * associated. + * + * For example, a policy subject can be one of the following: + * <ul> + * <li>composite + * <li>component + * <li>implementation + * <li>service + * <li>reference + * <li>binding + * <li>interface + * </ul> + */ +public interface PolicySubject { + /** + * Get a list of required intents + * + * @return + */ + List<Intent> getRequiredIntents(); + + /** + * Get a list of attached policySets + * + * @return A list of policySets + */ + List<PolicySet> getPolicySets(); + + ExtensionType getExtensionType(); + void setExtensionType(ExtensionType type); +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/Qualifier.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/Qualifier.java new file mode 100644 index 0000000000..c1862283c7 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/Qualifier.java @@ -0,0 +1,44 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy; + +import java.util.List; + +/** + * A qualifier provides a list of policies for a qualified intent within the IntentMap + */ +public interface Qualifier { + /** + * Get the qualified intent for this qualifier + * @return The intent + */ + Intent getIntent(); + + /** + * Set the qualified intent for this qualifier + */ + void setIntent(Intent intent); + + /** + * Get the list of policies provided by this qualifier + * @return A list of policies + */ + List<PolicyExpression> getPolicies(); +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java new file mode 100644 index 0000000000..1a2a9c5bad --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java @@ -0,0 +1,38 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.BindingType; + +/** + * Concrete implementation for a BindingType + * + * @version $Rev$ $Date$ + */ +public class BindingTypeImpl extends ExtensionTypeImpl implements BindingType { + protected BindingTypeImpl() { + super(); + } + + public QName getBaseType() { + return BINDING_BASE; + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/ExtensionTypeImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/ExtensionTypeImpl.java new file mode 100644 index 0000000000..97fbc19ced --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/ExtensionTypeImpl.java @@ -0,0 +1,97 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; + +/** + * Concrete implementation for a BindingType + * + * @version $Rev$ $Date$ + */ +public class ExtensionTypeImpl implements ExtensionType { + + private List<Intent> alwaysProvides = new ArrayList<Intent>(); + private List<Intent> mayProvide = new ArrayList<Intent>(); + private QName typeName; + private boolean unResolved = true; + + protected ExtensionTypeImpl() { + + } + + public List<Intent> getAlwaysProvidedIntents() { + return alwaysProvides; + } + + public List<Intent> getMayProvidedIntents() { + return mayProvide; + } + + public QName getType() { + return typeName; + } + + public void setType(QName type) { + this.typeName = type; + } + + public boolean isUnresolved() { + return unResolved; + } + + public void setUnresolved(boolean unresolved) { + this.unResolved = unresolved; + } + + @Override + public int hashCode() { + return String.valueOf(getType()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj instanceof ExtensionTypeImpl) { + if (getType() != null) { + return getType().equals(((ExtensionTypeImpl)obj).getType()); + } else { + return ((ExtensionTypeImpl)obj).getType() == null; + } + } else { + return false; + } + } + + @Override + public String toString() { + return (this.typeName != null) ? getType().toString() : "null"; + } + + public QName getBaseType() { + return null; + } +}; diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java new file mode 100644 index 0000000000..5c285e4d95 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java @@ -0,0 +1,39 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.ImplementationType; + +/** + * Concrete implementation for a Implementation Type + * + * @version $Rev$ $Date$ + */ +public class ImplementationTypeImpl extends ExtensionTypeImpl implements ImplementationType { + protected ImplementationTypeImpl() { + super(); + } + + public QName getBaseType() { + return IMPLEMENTATION_BASE; + } + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java new file mode 100644 index 0000000000..27a77f3ba8 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java @@ -0,0 +1,168 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; + +/** + * Represents a policy intent. + * + * @version $Rev$ $Date$ + */ +public class IntentImpl implements Intent { + + private QName name; + private Type type; + private List<ExtensionType> constrainedTypes = new ArrayList<ExtensionType>(); + private String description; + private List<Intent> qualifiedIntents = new ArrayList<Intent>(); + private Intent defaultQualifiedIntent; + private Intent parent; + private List<Intent> requiredIntents = new ArrayList<Intent>(); + private List<Intent> excludedIntents = new ArrayList<Intent>(); + private boolean mutuallyExclusive; + private boolean unresolved = true; + + protected IntentImpl() { + } + + public QName getName() { + return name; + } + + public void setName(QName name) { + this.name = name; + } + + public List<ExtensionType> getConstrainedTypes() { + return constrainedTypes; + } + + public void setConstrainedTypes(List<ExtensionType> constrainedTypes) { + this.constrainedTypes = constrainedTypes; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Intent getQualifiableIntent() { + return parent; + } + + public void setQualifiableIntent(Intent parent) { + this.parent = parent; + } + + public List<Intent> getQualifiedIntents() { + return qualifiedIntents; + } + + public void setQualifiedIntents(List<Intent> qualifiedIntents) { + this.qualifiedIntents = qualifiedIntents; + } + + public List<Intent> getRequiredIntents() { + return requiredIntents; + } + + public void setRequiredIntents(List<Intent> requiredIntents) { + this.requiredIntents = requiredIntents; + } + + public List<Intent> getExcludedIntents() { + return excludedIntents; + } + + public void setExcludedIntents(List<Intent> excludedIntents) { + this.excludedIntents = excludedIntents; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + + public boolean isMutuallyExclusive() { + return mutuallyExclusive; + } + + public void setMutuallyExclusive(boolean mutuallyExclusive) { + this.mutuallyExclusive = mutuallyExclusive; + } + + public Intent getDefaultQualifiedIntent() { + return defaultQualifiedIntent; + } + + public void setDefaultQualifiedIntent(Intent defaultQualifiedIntent) { + this.defaultQualifiedIntent = defaultQualifiedIntent; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IntentImpl other = (IntentImpl)obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + public String toString() { + return String.valueOf(name); + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java new file mode 100644 index 0000000000..6e2941ff5c --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java @@ -0,0 +1,61 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentMap; +import org.apache.tuscany.sca.policy.Qualifier; + +/** + * Represents an intent map. + * + * @version $Rev$ $Date$ + */ +public class IntentMapImpl implements IntentMap { + + private boolean unresolved; + private Intent providedIntent; + private List<Qualifier> qualifiers = new ArrayList<Qualifier>(); + + protected IntentMapImpl() { + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public Intent getProvidedIntent() { + return providedIntent; + } + + public void setProvidedIntent(Intent providedIntent) { + this.providedIntent = providedIntent; + } + + public List<Qualifier> getQualifiers() { + return qualifiers; + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyExpressionImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyExpressionImpl.java new file mode 100644 index 0000000000..71e5eef6a7 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyExpressionImpl.java @@ -0,0 +1,86 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.PolicyExpression; + +public class PolicyExpressionImpl implements PolicyExpression { + private QName name; + private Object policy; + private boolean unresolved = true; + + protected PolicyExpressionImpl() { + } + + public QName getName() { + return name; + } + + public <T> T getPolicy() { + return (T)policy; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setName(QName name) { + this.name = name; + } + + public <T> void setPolicy(T policy) { + this.policy = policy; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public String toString() { + return String.valueOf(name); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PolicyExpressionImpl other = (PolicyExpressionImpl)obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java new file mode 100644 index 0000000000..c67ff1eab8 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java @@ -0,0 +1,70 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy.impl; + +import org.apache.tuscany.sca.policy.BindingType; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.ImplementationType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentMap; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.Qualifier; + +/** + * A factory for the policy model. + * + * @version $Rev$ $Date$ + */ +public abstract class PolicyFactoryImpl implements PolicyFactory { + + public Intent createIntent() { + return new IntentImpl(); + } + + public PolicySet createPolicySet() { + return new PolicySetImpl(); + } + + public IntentMap createIntentMap() { + return new IntentMapImpl(); + } + + public Qualifier createQualifier() { + return new QualifierImpl(); + } + + public PolicyExpression createPolicyExpression() { + return new PolicyExpressionImpl(); + } + + public BindingType createBindingType() { + return new BindingTypeImpl(); + } + + public ImplementationType createImplementationType() { + return new ImplementationTypeImpl(); + } + + public ExtensionType createExtensionType() { + return new ExtensionTypeImpl(); + } + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java new file mode 100644 index 0000000000..75d1229cd8 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java @@ -0,0 +1,145 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.xpath.XPathExpression; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentMap; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a policy set. + * + * @version $Rev$ $Date$ + */ +public class PolicySetImpl implements PolicySet { + + private QName name; + private String appliesTo; + private String attachTo; + private List<Intent> providedIntents = new ArrayList<Intent>(); + private List<PolicySet> referencedPolicySets = new ArrayList<PolicySet>(); + private boolean unresolved = true; + + private XPathExpression appliesToXPathExpression; + private XPathExpression attachToXPathExpression; + + private List<IntentMap> intentMaps = new ArrayList<IntentMap>(); + private List<PolicyExpression> policies = new ArrayList<PolicyExpression>(); + + public QName getName() { + return name; + } + + public void setName(QName name) { + this.name = name; + } + + public String getAppliesTo() { + return appliesTo; + } + + public void setAppliesTo(String appliesTo) { + this.appliesTo = appliesTo; + } + + public String getAttachTo() { + return attachTo; + } + + public void setAttachTo(String attachTo) { + this.attachTo = attachTo; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public XPathExpression getAppliesToXPathExpression() { + return appliesToXPathExpression; + } + + public void setAppliesToXPathExpression(XPathExpression appliesToXPathExpression) { + this.appliesToXPathExpression = appliesToXPathExpression; + } + + public XPathExpression getAttachToXPathExpression() { + return attachToXPathExpression; + } + + public void setAttachToXPathExpression(XPathExpression attachToXPathExpression) { + this.attachToXPathExpression = attachToXPathExpression; + } + + public List<IntentMap> getIntentMaps() { + return intentMaps; + } + + public List<Intent> getProvidedIntents() { + return providedIntents; + } + + public List<PolicySet> getReferencedPolicySets() { + return referencedPolicySets; + } + + public List<PolicyExpression> getPolicies() { + return policies; + } + + public String toString() { + return String.valueOf(name); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PolicySetImpl other = (PolicySetImpl)obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + +} diff --git a/java/sca/modules/interface/pom.xml b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/QualifierImpl.java index 3b1b59a4fc..102bea8d41 100644 --- a/java/sca/modules/interface/pom.xml +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/impl/QualifierImpl.java @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- +/* * 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 @@ -16,24 +15,34 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. ---> -<project> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-modules</artifactId> - <version>2.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <artifactId>tuscany-interface</artifactId> - <name>Apache Tuscany SCA Interface Model</name> - - <dependencies> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-policy</artifactId> - <version>2.0-SNAPSHOT</version> - </dependency> - </dependencies> - -</project> + */ + +package org.apache.tuscany.sca.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.Qualifier; + +public class QualifierImpl implements Qualifier { + private Intent intent; + private List<PolicyExpression> policies = new ArrayList<PolicyExpression>(); + + protected QualifierImpl() { + } + + public Intent getIntent() { + return intent; + } + + public List<PolicyExpression> getPolicies() { + return policies; + } + + public void setIntent(Intent intent) { + this.intent = intent; + } + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java new file mode 100644 index 0000000000..fe61ce707c --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java @@ -0,0 +1,370 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy.util; + +import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; + +import java.io.InputStream; +import java.io.StringWriter; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; + +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Utility methods used during computation of PolicyIntents and PolicySets sets + * + * @version $Rev$ $Date$ + */ +public class PolicyComputationUtils { + private static final String POLICYSET_PREFIX = "tp_"; + private static final String APPLICABLE_POLICYSET_ATTR_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + private static final String APPLICABLE_POLICYSET_ATTR = "applicablePolicySets"; + private static final String POLICY_SETS_ATTR = "policySets"; + private static final String APPLICABLE_POLICYSET_ATTR_PREFIX = "tuscany"; + private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; + + /** + * This method unconditionally adds intents from the source list to the target list. + * It is used for intermediate intent inheritance between promotion levels + * (e.g. between a composite service and a component service). It does not check + * whether there are conflicting (mutually exclusive) intents. This is because + * promotion cannot override intents. If the resulting target list has conflicting + * intents, this will be detected later during policy computation. + */ + public static void addInheritedIntents(List<Intent> sourceList, List<Intent> targetList) { + if (sourceList != null) { + targetList.addAll(sourceList); + } + } + + public static void addInheritedPolicySets(List<PolicySet> sourceList, + List<PolicySet> targetList, + boolean checkOverrides) { + // check overrides is true when policysets are to be copied from + // componentType to component level + if (checkOverrides) { + // aggregate all the provided intents present in the target + List<Intent> targetProvidedIntents = new ArrayList<Intent>(); + for (PolicySet policySet : targetList) { + targetProvidedIntents.addAll(policySet.getProvidedIntents()); + } + + // for every policy set in the source check if it provides one of + // the intents that is + // already provided by the policysets in the destination and do not + // copy them. + for (PolicySet policySet : sourceList) { + for (Intent sourceProvidedIntent : policySet.getProvidedIntents()) { + if (!targetProvidedIntents.contains(sourceProvidedIntent)) { + targetList.add(policySet); + } + } + } + } else { + targetList.addAll(sourceList); + } + } + + /** + * This method is used to inherit intents and policy sets between hierarchical levels + * within the same composite (e.g. between a component and its services and references). + * In this case the source intents and policy sets provide defaults which are inherited + * into the target lists only when there is no conflict. For example consider a component + * with 3 references. The component level requires intent 'propagatesTransaction'. + * Reference 1 and 2 do not specify an intent, but reference 3 requires 'suspendsTransaction'. + * In this case the 'propagatesTransaction' intent is inherited by reference 1 and 2 + * but not by reference 3. + */ + public static void addDefaultPolicies(List<Intent> sourceIntents, + List<PolicySet> sourcePolicySets, + List<Intent> targetIntents, + List<PolicySet> targetPolicySets) { + // form a list of all intents required by the target + List<Intent> combinedTargetIntents = new ArrayList<Intent>(); + combinedTargetIntents.addAll(findAndExpandProfileIntents(targetIntents)); + for (PolicySet targetPolicySet : targetPolicySets) { + combinedTargetIntents.addAll(findAndExpandProfileIntents(targetPolicySet.getProvidedIntents())); + } + + // inherit intents in the source list that do not conflict with intents already in the target list + for (Intent sourceIntent : findAndExpandProfileIntents(sourceIntents)) { + boolean conflict = false; + for (Intent excluded : sourceIntent.getExcludedIntents()) { + if (combinedTargetIntents.contains(excluded)) { + conflict = true; + break; + } + } + if (!conflict) { + targetIntents.add(sourceIntent); + } + } + + // inherit policy sets in the source list that do not conflict with policy sets or intents + // in the target list + for (PolicySet sourcePolicySet : sourcePolicySets) { + boolean conflict = false; + List<Intent> providedIntents = findAndExpandProfileIntents(sourcePolicySet.getProvidedIntents()); + checkConflict: for (Intent intent : providedIntents) { + for (Intent excluded : intent.getExcludedIntents()) { + if (combinedTargetIntents.contains(excluded)) { + conflict = true; + break checkConflict; + } + } + } + if (!conflict) + targetPolicySets.add(sourcePolicySet); + } + + } + + public static void checkForMutuallyExclusiveIntents(List<Intent> intents, + List<PolicySet> policySets, + ExtensionType intentAttachPointType, + String id) throws PolicyValidationException { + // gather all intents (keeping track of where they come from) + Map<Intent, PolicySet> combinedIntents = new HashMap<Intent, PolicySet>(); + for (PolicySet policySet : policySets) { + for (Intent providedIntent : findAndExpandProfileIntents(policySet.getProvidedIntents())) { + combinedIntents.put(providedIntent, policySet); + } + } + for (Intent intent : intents) { + combinedIntents.put(intent, null); + } + + // check for conflicts + for (Intent intent : combinedIntents.keySet()) { + for (Intent excluded : intent.getExcludedIntents()) { + if (combinedIntents.keySet().contains(excluded)) { + String sIntent1, sIntent2; + if (combinedIntents.get(intent) == null) + sIntent1 = intent.getName().toString(); + else + sIntent1 = + intent.getName().toString() + " in policy set " + + combinedIntents.get(intent).getName().toString(); + if (combinedIntents.get(excluded) == null) + sIntent2 = excluded.getName().toString(); + else + sIntent2 = + excluded.getName().toString() + " in policy set " + + combinedIntents.get(excluded).getName().toString(); + throw new PolicyValidationException(intentAttachPointType.getType() + " for " + + id + + " uses mutually-exclusive intents " + + sIntent1 + + " and " + + sIntent2); + } + } + } + } + + public static void expandProfileIntents(List<Intent> intents) { + List<Intent> expandedIntents = null; + if (intents.size() > 0) { + expandedIntents = findAndExpandProfileIntents(intents); + intents.clear(); + intents.addAll(expandedIntents); + } + } + + public static List<Intent> findAndExpandProfileIntents(List<Intent> intents) { + List<Intent> expandedIntents = new ArrayList<Intent>(); + for (Intent intent : intents) { + if (!intent.getRequiredIntents().isEmpty()) { + List<Intent> requiredIntents = intent.getRequiredIntents(); + expandedIntents.addAll(findAndExpandProfileIntents(requiredIntents)); + } else { + expandedIntents.add(intent); + } + } + return expandedIntents; + } + + private static byte[] addApplicablePolicySets(Document doc, Collection<PolicySet> policySets) + throws XPathExpressionException, TransformerConfigurationException, TransformerException { + + for (PolicySet policySet : policySets) { + if (policySet.getAppliesTo() != null) { + addApplicablePolicySets(policySet, doc); + } + } + + StringWriter sw = new StringWriter(); + final Source domSource = new DOMSource(doc); + final Result finalResult = new StreamResult(sw); + final Transformer transformer = TransformerFactory.newInstance().newTransformer(); + // transformer.setOutputProperty("omit-xml-declaration", "yes"); + // Allow priviledged access to let transformers read property files. Requires + // PropertyPermission in security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { + public Object run() throws TransformerException { + transformer.transform(domSource, finalResult); + return null; + } + }); + } catch (PrivilegedActionException e) { + throw (TransformerException)e.getException(); + } + + return sw.toString().getBytes(); + } + + private static void addApplicablePolicySets(PolicySet policySet, Document doc) throws XPathExpressionException { + XPathExpression expression = policySet.getAppliesToXPathExpression(); + NodeList result = (NodeList)expression.evaluate(doc, XPathConstants.NODESET); + + if (result != null) { + for (int counter = 0; counter < result.getLength(); ++counter) { + Node aResultNode = result.item(counter); + + String applicablePolicySets = null; + + String policySetPrefix = declareNamespace((Element)aResultNode, policySet.getName().getNamespaceURI()); + String appPolicyAttrPrefix = declareNamespace((Element)aResultNode, APPLICABLE_POLICYSET_ATTR_NS); + if (aResultNode.getAttributes().getNamedItemNS(APPLICABLE_POLICYSET_ATTR_NS, APPLICABLE_POLICYSET_ATTR) != null) { + applicablePolicySets = + aResultNode.getAttributes().getNamedItemNS(APPLICABLE_POLICYSET_ATTR_NS, + APPLICABLE_POLICYSET_ATTR).getNodeValue(); + } + + if (applicablePolicySets != null && applicablePolicySets.length() > 0) { + applicablePolicySets = + applicablePolicySets + " " + policySetPrefix + ":" + policySet.getName().getLocalPart(); + } else { + applicablePolicySets = policySetPrefix + ":" + policySet.getName().getLocalPart(); + } + + ((Element)aResultNode).setAttributeNS(APPLICABLE_POLICYSET_ATTR_NS, appPolicyAttrPrefix + ":" + + APPLICABLE_POLICYSET_ATTR, applicablePolicySets); + } + } + } + + public static byte[] addApplicablePolicySets(InputStream is, + Collection<PolicySet> domainPolicySets, + DocumentBuilderFactory documentBuilderFactory) throws Exception { + documentBuilderFactory.setNamespaceAware(true); + DocumentBuilder db = documentBuilderFactory.newDocumentBuilder(); + Document doc = db.parse(is); + is.close(); + return addApplicablePolicySets(doc, domainPolicySets); + } + + private static class DOMNamespaceContext implements NamespaceContext { + private Node node; + + /** + * @param node + */ + public DOMNamespaceContext(Node node) { + super(); + this.node = node; + } + + public String getNamespaceURI(String prefix) { + return node.lookupNamespaceURI(prefix); + } + + public String getPrefix(String namespaceURI) { + return node.lookupPrefix(namespaceURI); + } + + public Iterator<?> getPrefixes(String namespaceURI) { + return null; + } + + } + + private static String declareNamespace(Element element, String ns) { + if (ns == null) { + ns = ""; + } + Node node = element; + String prefix = ""; + boolean declared = false; + while (node != null && node.getNodeType() == Node.ELEMENT_NODE) { + if (node.lookupPrefix(ns) != null) { + prefix = node.lookupPrefix(ns); + declared = true; + break; + } else { + /*NamedNodeMap attrs = node.getAttributes(); + if (attrs == null) { + break; + } + Node attr = attrs.getNamedItem(qname); + if (attr != null) { + declared = ns.equals(attr.getNodeValue()); + break; + }*/ + node = node.getParentNode(); + } + } + if (!declared) { + // Find an available prefix + for (int i = 1;; i++) { + prefix = POLICYSET_PREFIX + i; + if (element.lookupNamespaceURI(prefix) == null) { + break; + } + } + String qname = "xmlns:" + prefix; + org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname); + attr.setValue(ns); + element.setAttributeNodeNS(attr); + } + return prefix; + } + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java new file mode 100644 index 0000000000..3ed4eac5a2 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java @@ -0,0 +1,38 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy.util; + +/** + * Exception to be throw for invalid policy intents / policysets + * + * @version $Rev$ $Date$ + */ +public class PolicyValidationException extends Exception { + private static final long serialVersionUID = 506979037642587755L; + + public PolicyValidationException(String message) { + super(message); + } + + public PolicyValidationException(Throwable e) { + super(e); + } + +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java new file mode 100644 index 0000000000..616eab5737 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java @@ -0,0 +1,98 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.policy.util; + +import java.util.List; + +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; + +/** + * @version $Rev$ $Date$ + */ +public class PolicyValidationUtils { + + public static boolean isConstrained(ExtensionType constrained, ExtensionType attachPointType) { + return (attachPointType != null + && (attachPointType.equals(constrained)) || (attachPointType.getBaseType().equals(constrained))); + } + + public static void validateIntents(PolicySubject attachPoint, ExtensionType attachPointType) + throws PolicyValidationException { + boolean found = false; + if (attachPointType != null) { + // validate intents specified against the parent (binding / + // implementation) + found = false; + for (Intent intent : attachPoint.getRequiredIntents()) { + if (!intent.isUnresolved()) { + for (ExtensionType constrained : intent.getConstrainedTypes()) { + if (isConstrained(constrained, attachPointType)) { + found = true; + break; + } + } + + if (!found) { + throw new PolicyValidationException("Policy Intent '" + intent.getName() + + "' does not constrain extension type " + + attachPointType.getType()); + } + } else { + throw new PolicyValidationException("Policy Intent '" + intent.getName() + + "' is not defined in this domain "); + } + } + } + } + + public static void validatePolicySets(PolicySubject subject) throws PolicyValidationException { + // validatePolicySets(subject, subject.getType(), subject.getAttachedPolicySets()); + } + + public static void validatePolicySets(PolicySubject subject, ExtensionType attachPointType) + throws PolicyValidationException { + validatePolicySets(subject, attachPointType, subject.getPolicySets()); + } + + public static void validatePolicySets(PolicySubject subject, + ExtensionType attachPointType, + List<PolicySet> applicablePolicySets) throws PolicyValidationException { + // Since the applicablePolicySets in a subject will already + // have the list of policysets that might ever be applicable to this attachPoint, + // just check if the defined policysets feature in the list of applicable + // policysets + for (PolicySet definedPolicySet : subject.getPolicySets()) { + if (!definedPolicySet.isUnresolved()) { + if (!applicablePolicySets.contains(definedPolicySet)) { + throw new PolicyValidationException("Policy Set '" + definedPolicySet.getName() + + "' does not apply to extension type " + + attachPointType.getType()); + } + } else { + throw new PolicyValidationException("Policy Set '" + definedPolicySet.getName() + + "' is not defined in this domain "); + + } + } + } +} diff --git a/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.DefinitionsFactory b/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.DefinitionsFactory new file mode 100644 index 0000000000..521d94f518 --- /dev/null +++ b/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.DefinitionsFactory @@ -0,0 +1,17 @@ +# 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.
+org.apache.tuscany.sca.definitions.DefaultDefinitionsFactory
\ No newline at end of file diff --git a/java/sca/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper b/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper index 821c58bde1..821c58bde1 100644 --- a/java/sca/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper +++ b/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper diff --git a/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory b/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory new file mode 100644 index 0000000000..846b3b24a4 --- /dev/null +++ b/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory @@ -0,0 +1,18 @@ +# 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. + +org.apache.tuscany.sca.policy.DefaultPolicyFactory
\ No newline at end of file diff --git a/java/sca/modules/assembly/src/main/resources/definitions-validation-messages.properties b/java/sca/modules/assembly/src/main/resources/definitions-validation-messages.properties new file mode 100644 index 0000000000..4cf9c01da5 --- /dev/null +++ b/java/sca/modules/assembly/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 diff --git a/java/sca/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java index acdaae799e..acdaae799e 100644 --- a/java/sca/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java +++ b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java diff --git a/java/sca/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java index d1faa5cf2b..d1faa5cf2b 100644 --- a/java/sca/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java +++ b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java diff --git a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java new file mode 100644 index 0000000000..2775c4ac71 --- /dev/null +++ b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java @@ -0,0 +1,55 @@ +/* + * 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. + */ +package org.apache.tuscany.sca.policy; + +import static org.junit.Assert.assertEquals; + +import javax.xml.namespace.QName; + +import org.junit.Before; +import org.junit.Test; + +/** + * Test building of policy model instances using the policy factory. + * + * @version $Rev$ $Date$ + */ +public class PolicyFactoryTestCase { + + PolicyFactory factory; + + @Before + public void setUp() throws Exception { + factory = new DefaultPolicyFactory(); + } + + @Test + public void testCreateIntent() { + Intent intent = factory.createIntent(); + intent.setName(new QName("http://test", "reliability")); + assertEquals(intent.getName(), new QName("http://test", "reliability")); + } + + @Test + public void testCreatePolicySet() { + PolicySet policySet = factory.createPolicySet(); + policySet.setName(new QName("http://test", "reliability")); + assertEquals(policySet.getName(), new QName("http://test", "reliability")); + } +} |