diff options
Diffstat (limited to 'sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider')
5 files changed, 320 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__ImplementationPolicyProvider.java b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__ImplementationPolicyProvider.java new file mode 100644 index 0000000000..129f0add6c --- /dev/null +++ b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__ImplementationPolicyProvider.java @@ -0,0 +1,63 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * 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 ${package}.${policyName}.provider; + +import java.util.List; + +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +import ${package}.util.PolicyHelper; +import ${package}.${policyName}.${policyName}Policy; + +/** + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}ImplementationPolicyProvider extends BasePolicyProvider<${policyName}Policy> { + private RuntimeComponent component; + + public ${policyName}ImplementationPolicyProvider(RuntimeComponent component) { + super(${policyName}Policy.class, component.getImplementation()); + this.component = component; + } + + /** + * @see ${groupId}.provider.PolicyProvider${symbol_pound}createInterceptor(${groupId}.interfacedef.Operation) + */ + @Override + public PhasedInterceptor createInterceptor(Operation operation) { + List<PolicySet> policySets = PolicyHelper.findPolicySets(component, ${policyName}Policy.POLICY_QNAME); + + + return policySets.isEmpty() ? null : new ${policyName}PolicyInterceptor(getContext(), operation, getPhase()); + } + + public String getPhase() { + return Phase.IMPLEMENTATION_POLICY; + } + +} diff --git a/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__PolicyInterceptor.java b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__PolicyInterceptor.java new file mode 100644 index 0000000000..164d59be90 --- /dev/null +++ b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__PolicyInterceptor.java @@ -0,0 +1,71 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * 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 ${package}.${policyName}.provider; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.1/impl/java}${policyName}Policy + * + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}PolicyInterceptor implements PhasedInterceptor { + private Invoker next; + private Operation operation; + private String context; + private String phase; + + public ${policyName}PolicyInterceptor(String context, Operation operation, String phase) { + super(); + this.operation = operation; + this.context = context; + this.phase = phase; + } + + @Override + public Message invoke(Message msg) { + // DO SOMETHING HERE + System.out.println("Inside policy interceptor invoke method"); + + return getNext().invoke(msg); + } + + @Override + public Invoker getNext() { + return next; + } + + @Override + public void setNext(Invoker next) { + this.next = next; + } + + @Override + public String getPhase() { + return phase; + } + +} diff --git a/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__PolicyProviderFactory.java b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__PolicyProviderFactory.java new file mode 100644 index 0000000000..44c962bc2c --- /dev/null +++ b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__PolicyProviderFactory.java @@ -0,0 +1,77 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * 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 ${package}.${policyName}.provider; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +import ${package}.${policyName}.${policyName}Policy; + +/** + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}PolicyProviderFactory implements PolicyProviderFactory<${policyName}Policy> { + private ExtensionPointRegistry registry; + + public ${policyName}PolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see ${groupId}.provider.PolicyProviderFactory${symbol_pound}createImplementationPolicyProvider(${groupId}.runtime.RuntimeComponent, ${groupId}.assembly.Implementation) + */ + @Override + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) { + return new ${policyName}ImplementationPolicyProvider(component); + } + + /** + * @see ${groupId}.provider.PolicyProviderFactory${symbol_pound}createReferencePolicyProvider(${groupId}.runtime.RuntimeComponent, ${groupId}.runtime.RuntimeComponentReference, ${groupId}.assembly.Binding) + */ + @Override + public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) { + return new ${policyName}ReferencePolicyProvider(endpointReference); + } + + /** + * @see ${groupId}.provider.PolicyProviderFactory${symbol_pound}createServicePolicyProvider(${groupId}.runtime.RuntimeComponent, ${groupId}.runtime.RuntimeComponentService, ${groupId}.assembly.Binding) + */ + @Override + public PolicyProvider createServicePolicyProvider(Endpoint endpoint) { + return new ${policyName}ServicePolicyProvider(endpoint); + } + + /** + * @see ${groupId}.provider.ProviderFactory${symbol_pound}getModelType() + */ + @Override + public Class<${policyName}Policy> getModelType() { + return ${policyName}Policy.class; + } + +} diff --git a/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__ReferencePolicyProvider.java b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__ReferencePolicyProvider.java new file mode 100644 index 0000000000..70ea13de2f --- /dev/null +++ b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__ReferencePolicyProvider.java @@ -0,0 +1,54 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * 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 ${package}.${policyName}.provider; + +import java.util.List; + +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +import ${package}.util.PolicyHelper; +import ${package}.${policyName}.${policyName}Policy; +/** + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}ReferencePolicyProvider extends BasePolicyProvider<${policyName}Policy> { + private EndpointReference endpointReference; + + public ${policyName}ReferencePolicyProvider(EndpointReference endpointReference) { + super(${policyName}Policy.class, endpointReference); + this.endpointReference = endpointReference; + } + + @Override + public PhasedInterceptor createInterceptor(Operation operation) { + List<PolicySet> policySets = PolicyHelper.findPolicySets(endpointReference, ${policyName}Policy.POLICY_QNAME); + + return (policySets.isEmpty()) ? null : new ${policyName}PolicyInterceptor(getContext(), operation, Phase.REFERENCE_POLICY); + } + +} diff --git a/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__ServicePolicyProvider.java b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__ServicePolicyProvider.java new file mode 100644 index 0000000000..cb23eb6dad --- /dev/null +++ b/sca-java-2.x/branches/2.0/maven/archetypes/policy/src/main/resources/archetype-resources/src/main/java/__policyName__/provider/__policyName__ServicePolicyProvider.java @@ -0,0 +1,55 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * 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 ${package}.${policyName}.provider; + +import java.util.List; + +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.provider.BasePolicyProvider; + +import ${package}.util.PolicyHelper; +import ${package}.${policyName}.${policyName}Policy; + +/** + * @version ${symbol_dollar}Rev${symbol_dollar} ${symbol_dollar}Date${symbol_dollar} + */ +public class ${policyName}ServicePolicyProvider extends BasePolicyProvider<${policyName}Policy> { + private Endpoint endpoint; + + public ${policyName}ServicePolicyProvider(Endpoint endpoint) { + super(${policyName}Policy.class, endpoint); + this.endpoint = endpoint; + } + + @Override + public PhasedInterceptor createInterceptor(Operation operation) { + List<PolicySet> policySets = PolicyHelper.findPolicySets(endpoint, ${policyName}Policy.POLICY_QNAME); + + return policySets.isEmpty() ? null : new ${policyName}PolicyInterceptor(getContext(), operation, Phase.SERVICE_POLICY); + } + +} |