diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:45 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:45 +0000 |
commit | 6a3ca6736c808c1647854e405ef379b609f276db (patch) | |
tree | 67670193d3511b227100419589d0f2ec0bb02cc0 /sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main | |
parent | 9f395ebf3ec27f89c8dc63137bc99c8d6b0cff6d (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835126 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main')
18 files changed, 940 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/AddService.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..5f90ec7245 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/AddService.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Requires; +import org.osoa.sca.annotations.Service; + +/** + * The Add service interface + */ +@Remotable +@Service +//@Requires(PolicyQNames.TEST_INTENT_FIVE) +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/AddServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..7ca8fb04b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Add service + */ +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/CalculatorClient.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..9abc488523 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,69 @@ +/* + * 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 calculator; + +import javax.security.auth.login.Configuration; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +public class CalculatorClient { + public static void main(String[] args) throws Exception { + try { + Configuration secConf = Configuration.getConfiguration(); + } catch ( java.lang.SecurityException e ) { + if ( e.getMessage().equals("Unable to locate a login configuration") ) { + System.setProperty("java.security.auth.login.config", "target/classes/CalculatorJass.config"); + } else { + throw e; + } + } + + SCADomain scaDomain = SCADomain.newInstance("Calculator.composite"); + + CalculatorService calculatorService = + scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // Calculate + System.out.println("Calling CalculatorServiceComponent configured with 'logging' " + + "policy for subtract and divide operations..."); + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + calculatorService = + scaDomain.getService(CalculatorService.class, "AnotherCalculatorServiceComponent"); + + // Calculate + System.out.println("Calling CalculatorServiceComponent configured with 'logging' " + + "for all operations in the implementation..."); + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + scaDomain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/CalculatorService.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..b5d3cce0ff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/CalculatorService.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 calculator; + +import org.osoa.sca.annotations.Requires; +import org.osoa.sca.annotations.Service; + + +/** + * The Calculator service interface. + */ + +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..28ce0ec78a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,76 @@ +/* + * 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 calculator; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Requires; + + +/** + * An implementation of the Calculator service. + */ +@Requires(PolicyQNames.TEST_INTENT_ONE) +public class CalculatorServiceImpl implements CalculatorService, PolicyQNames { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + //@Requires({TEST_INTENT_TWO, TEST_INTENT_THREE}) + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + @Requires(TEST_INTENT_TWO) + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + @Requires(PolicyQNames.QUALIFIED_TEST_INTENT_ONE) + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + //@Requires(QUALIFIED_TEST_INTENT_FOUR) + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/DivideService.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..f72b05cece --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/DivideService.java @@ -0,0 +1,33 @@ +/* + * 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 calculator; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +/** + * The divide service interface + */ +@Remotable +@Service +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/DivideServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..1323edf55a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/DivideServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Divide service. + */ +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/MultiplyService.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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 calculator; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/MultiplyServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..91b803bc9e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Multiply service. + */ +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/PolicyQNames.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/PolicyQNames.java new file mode 100644 index 0000000000..3e1bc45842 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/PolicyQNames.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 calculator; + +/** + * @version $Rev$ $Date$ + */ +public interface PolicyQNames { + public static final String QUALIFIER = "."; + + public static final String POLICY_ITEST_PREFIX="{http://itest/policy}"; + public static final String TEST_INTENT_ONE = POLICY_ITEST_PREFIX + "TestIntent_1"; + public static final String TEST_INTENT_TWO = POLICY_ITEST_PREFIX + "TestIntent_2"; + public static final String TEST_INTENT_THREE = POLICY_ITEST_PREFIX + "TestIntent_3"; + public static final String TEST_INTENT_FOUR = POLICY_ITEST_PREFIX + "TestIntent_4"; + public static final String TEST_INTENT_FIVE = POLICY_ITEST_PREFIX + "TestIntent_5"; + + public static final String QUALIFIER_ONE = "Qualifier_1"; + + public static final String QUALIFIED_TEST_INTENT_FOUR = + TEST_INTENT_FOUR + QUALIFIER + QUALIFIER_ONE; + + public static final String QUALIFIED_TEST_INTENT_ONE = + TEST_INTENT_ONE + QUALIFIER + QUALIFIER_ONE; + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/SubtractService.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * 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 calculator; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/SubtractServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..58cc4a3547 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the subtract service. + */ +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/policy/TestImplPolicyHandler.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/policy/TestImplPolicyHandler.java new file mode 100644 index 0000000000..4b04a4d0b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/policy/TestImplPolicyHandler.java @@ -0,0 +1,84 @@ +/* + * 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 calculator.policy; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.junit.Assert; + +/** + * @version $Rev$ $Date$ + */ +public class TestImplPolicyHandler implements PolicyHandler { + private PolicySet applicablePolicySet = null; + + public void afterInvoke(Object... arg0) { + } + + public void beforeInvoke(Object... context) { + for ( Object contextObj : context) { + if ( contextObj instanceof Operation ) { + Operation op = (Operation)contextObj; + //System.out.println(" *TestImplPolicyHandler* " + op.getName() + " ** " + applicablePolicySet); + if ( op.getName().equals("add") ) { + boolean match = applicablePolicySet.getName().getLocalPart().equals("TestPolicySet_1_implementation") || + applicablePolicySet.getName().getLocalPart().equals("TestPolicySet_2_implementation") || + applicablePolicySet.getName().getLocalPart().equals("TestPolicySet_1_Qualified_implementation") || + applicablePolicySet.getName().getLocalPart().equals("TestPolicySet_3_implementation") ; + Assert.assertTrue(match); + } else if ( op.getName().equals("subtract") ) { + boolean match = applicablePolicySet.getName().getLocalPart().equals("TestPolicySet_1_Qualified_implementation") || + applicablePolicySet.getName().getLocalPart().equals("TestPolicySet_1_implementation"); + Assert.assertTrue(match); + } else if ( op.getName().equals("divide")) { + Assert.assertEquals(applicablePolicySet.getName().getLocalPart(), + "TestPolicySet_1_implementation"); + } else if ( op.getName().equals("multiply") ) { + boolean match = applicablePolicySet.getName().getLocalPart().equals("TestPolicySet_5_implementation") || + applicablePolicySet.getName().getLocalPart().equals("TestPolicySet_1_implementation"); + Assert.assertTrue(match); + } + else { + Assert.fail(); + } + //System.out.println(" *TestImplPolicyHandler* " + op.getName() + " ** " + applicablePolicySet); + } else if ( contextObj instanceof Message ) { + Message msg = (Message)contextObj; + System.out.println(" *TestImplPolicyHandler* " + msg.getOperation().getName() + " ** " + applicablePolicySet); + } + } + } + + public void cleanUp(Object... arg0) { + } + + public PolicySet getApplicablePolicySet() { + return applicablePolicySet; + } + + public void setApplicablePolicySet(PolicySet arg0) { + this.applicablePolicySet = arg0; + } + + public void setUp(Object... arg0) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/policy/TestRefPolicyHandler.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/policy/TestRefPolicyHandler.java new file mode 100644 index 0000000000..35cef96287 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/policy/TestRefPolicyHandler.java @@ -0,0 +1,62 @@ +/* + * 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 calculator.policy; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.junit.Assert; + +/** + * @version $Rev$ $Date$ + */ +public class TestRefPolicyHandler implements PolicyHandler { + private PolicySet applicablePolicySet = null; + + public void afterInvoke(Object... arg0) { + } + + public void beforeInvoke(Object... context) { + for ( Object contextObj : context) { + if ( contextObj instanceof Operation ) { + Operation op = (Operation)contextObj; + System.out.println(" *TestReflPolicyHandler* " + op.getName() + " ** " + applicablePolicySet); + } else if ( contextObj instanceof Message ) { + Message msg = (Message)contextObj; + System.out.println(" *TestRefPolicyHandler* " + msg.getOperation().getName() + " ** " + applicablePolicySet); + } + } + } + + public void cleanUp(Object... arg0) { + } + + public PolicySet getApplicablePolicySet() { + return applicablePolicySet; + } + + public void setApplicablePolicySet(PolicySet arg0) { + this.applicablePolicySet = arg0; + } + + public void setUp(Object... arg0) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/policy/TestSvcPolicyHandler.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/policy/TestSvcPolicyHandler.java new file mode 100644 index 0000000000..3269d77876 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/java/calculator/policy/TestSvcPolicyHandler.java @@ -0,0 +1,62 @@ +/* + * 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 calculator.policy; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.util.PolicyHandler; +import org.junit.Assert; + +/** + * @version $Rev$ $Date$ + */ +public class TestSvcPolicyHandler implements PolicyHandler { + private PolicySet applicablePolicySet = null; + + public void afterInvoke(Object... arg0) { + } + + public void beforeInvoke(Object... context) { + for ( Object contextObj : context) { + if ( contextObj instanceof Operation ) { + Operation op = (Operation)contextObj; + System.out.println(" *TestSvcPolicyHandler* " + op.getName() + " ** " + applicablePolicySet); + } else if ( contextObj instanceof Message ) { + Message msg = (Message)contextObj; + System.out.println(" *TestSvcPolicyHandler* " + msg.getOperation().getName() + " ** " + applicablePolicySet); + } + } + } + + public void cleanUp(Object... arg0) { + } + + public PolicySet getApplicablePolicySet() { + return applicablePolicySet; + } + + public void setApplicablePolicySet(PolicySet arg0) { + this.applicablePolicySet = arg0; + } + + public void setUp(Object... arg0) { + } +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/resources/Calculator.composite b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..1ade981ca7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/resources/Calculator.composite @@ -0,0 +1,66 @@ +<?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 + * 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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://itest/policy" xmlns:sample="http://itest/policy" name="Calculator" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" + xmlns:ip="http://itest/policy"> + + <component name="CalculatorServiceComponent"> + <implementation.java class="calculator.CalculatorServiceImpl"></implementation.java> + <!-- reference name="addService" target="AddServiceComponent" /--> + <reference name="addService"> + <interface.java interface="calculator.AddService" /> + <binding.ws uri="http://localhost:8085/AddServiceComponent" /> + </reference> + <reference name="subtractService" target="SubtractServiceComponent" /> + <reference name="multiplyService" target="MultiplyServiceComponent" /> + <reference name="divideService" target="DivideServiceComponent" /> + </component> + + <component name="AddServiceComponent"> + <implementation.java class="calculator.AddServiceImpl" requires="ip:TestIntent_3" /> + <service name="AddService"> + <interface.java interface="calculator.AddService" /> + <binding.ws uri="http://localhost:8085/AddServiceComponent" /> + <binding.sca/> + </service> + </component> + + <component name="SubtractServiceComponent"> + <implementation.java class="calculator.SubtractServiceImpl" /> + </component> + + <component name="MultiplyServiceComponent"> + <implementation.java class="calculator.MultiplyServiceImpl" /> + </component> + + <component name="DivideServiceComponent"> + <implementation.java class="calculator.DivideServiceImpl" /> + </component> + + <component name="AnotherCalculatorServiceComponent"> + <implementation.java class="calculator.CalculatorServiceImpl" /> + <reference name="addService" target="AddServiceComponent" /> + <reference name="subtractService" target="SubtractServiceComponent" /> + <reference name="multiplyService" target="MultiplyServiceComponent" /> + <reference name="divideService" target="DivideServiceComponent" /> + </component> + +</composite> diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler new file mode 100644 index 0000000000..d9f144b3ff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler @@ -0,0 +1,28 @@ +# 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.
+#
+# PolicyHandlerClasses to interpret specific PolicyModels against specific QoS infrastructures
+# handler classname;qname=<policy intent addressed>;model=<policy model class>
+calculator.policy.TestImplPolicyHandler;intent=http://itest/policy#TestIntent_1,model=org.apache.neethi.Policy,appliesTo=sca:implementation.java
+calculator.policy.TestRefPolicyHandler;intent=http://itest/policy#TestIntent_1,model=org.apache.neethi.Policy,appliesTo=sca:reference
+calculator.policy.TestSvcPolicyHandler;intent=http://itest/policy#TestIntent_1,model=org.apache.neethi.Policy,appliesTo=sca:service
+calculator.policy.TestImplPolicyHandler;intent=http://itest/policy#TestIntent_1.Qualifier_1,model=org.apache.neethi.Policy,appliesTo=sca:implementation.java
+calculator.policy.TestImplPolicyHandler;intent=http://itest/policy#TestIntent_2,model=org.apache.neethi.Policy,appliesTo=sca:implementation.java
+calculator.policy.TestRefPolicyHandler;intent=http://itest/policy#TestIntent_2,model=org.apache.neethi.Policy,appliesTo=sca:reference
+calculator.policy.TestSvcPolicyHandler;intent=http://itest/policy#TestIntent_2,model=org.apache.neethi.Policy,appliesTo=sca:service
+calculator.policy.TestImplPolicyHandler;intent=http://itest/policy#TestIntent_3,model=org.apache.neethi.Policy,appliesTo=sca:implementation.java
+calculator.policy.TestImplPolicyHandler;intent=http://itest/policy#TestIntent_5,model=org.apache.neethi.Policy,appliesTo=sca:implementation.java
\ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/resources/definitions.xml b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/resources/definitions.xml new file mode 100644 index 0000000000..54aa8ec480 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/policy/src/main/resources/definitions.xml @@ -0,0 +1,147 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + * 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. +--> +<definitions xmlns="http://www.osoa.org/xmlns/sca/1.0" targetNamespace="http://itest/policy" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" + xmlns:calc="http://calculator" + xmlns:ip="http://itest/policy" > + + <!-- Policy Intents --> + <sca:intent name="TestIntent_1" constrains="sca:implementation.java sca:binding.ws"> + <description>Test Intent One</description> + </sca:intent> + + <sca:intent name="TestIntent_2" constrains="sca:implementation.java sca:binding.ws"> + <description>Test Intent Two</description> + </sca:intent> + + <sca:intent name="TestIntent_3" constrains="sca:implementation.java sca:binding.ws"> + <description>Test Intent Three</description> + </sca:intent> + + <sca:intent name="TestIntent_4" constrains="sca:implementation.java sca:binding.ws"> + <description>Test Intent Four</description> + </sca:intent> + + <sca:intent name="TestIntent_5" constrains="sca:implementation.java sca:binding.ws"> + <description>Test Intent Five</description> + </sca:intent> + + <sca:intent name="TestIntent_1.Qualifier_1" /> + + + + <!-- PolicySets --> + <sca:policySet name="TestPolicySet_1_implementation" provides="ip:TestIntent_1" + appliesTo="sca:implementation.java" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <intentMap provides="ip:TestIntent_1" default="Qualifier_1"> + <qualifier name="Qualifier_1"> + <wsp:Policy /> + </qualifier> + </intentMap> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_1_Qualified_implementation" provides="ip:TestIntent_1.Qualifier_1" + appliesTo="sca:implementation.java" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_1_reference" provides="ip:TestIntent_1" appliesTo="sca:reference" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_1_service" provides="ip:TestIntent_1" appliesTo="sca:service" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + + <sca:policySet name="TestPolicySet_2_implementation" provides="ip:TestIntent_2" + appliesTo="sca:implementation.java" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_2_reference" provides="ip:TestIntent_2" appliesTo="sca:reference" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_2_service" provides="ip:TestIntent_2" appliesTo="sca:service" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + + <sca:policySet name="TestPolicySet_3_implementation" provides="ip:TestIntent_3" + appliesTo="sca:implementation.java" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_3_reference" provides="ip:TestIntent_3" appliesTo="sca:reference" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_3_service" provides="ip:TestIntent_3" appliesTo="sca:service" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_4_implementation" provides="ip:TestIntent_4" + appliesTo="sca:implementation.java" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_4_service" provides="ip:TestIntent_4" appliesTo="sca:service" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_4_reference" provides="ip:TestIntent_4" appliesTo="sca:reference" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_5_implementation" provides="" appliesTo="sca:implementation.java" + tuscany:alwaysAppliesTo="sca:component[@name='MultiplyServiceComponent']" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_5_service" provides="ip:TestIntent_5" appliesTo="sca:service" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_5_reference" provides="ip:TestIntent_5" appliesTo="sca:reference" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy /> + </sca:policySet> + + <sca:policySet name="TestPolicySet_4_qualified_1_implementation" provides="ip:TestIntent_4" + appliesTo="sca:implementation.java" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <intentMap provides="ip:TestIntent_4" default="Qualifier_1"> + <qualifier name="Qualifier_1"> + <wsp:Policy /> + </qualifier> + </intentMap> + </sca:policySet> +</definitions>
\ No newline at end of file |