diff options
Diffstat (limited to 'sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java')
9 files changed, 440 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java new file mode 100644 index 0000000000..ef2565b750 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Client.java @@ -0,0 +1,29 @@ +/* + * 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.itest.bindingsca; + +/** + * + */ +public interface Client { + String getName(String id); + + String create(String name); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java new file mode 100644 index 0000000000..96a0f2dadd --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/ClientImpl.java @@ -0,0 +1,53 @@ +/* + * 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.itest.bindingsca; + +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Service; + +/** + * + */ +@Service(Client.class) +public class ClientImpl implements Client { + @Reference + protected Local local; + + @Reference + protected Remote remote; + + public String getName(String id) { + Customer customer = null; + try { + customer = remote.getCustomer(id); + } catch (CustomerNotFoundException e) { + return null; + } + customer.dump("Client.getName()"); + return local.getName(customer); + } + + public String create(String name) { + String id = remote.generateId(); + Customer customer = remote.createCustomer(id, name); + customer.dump("Client.create()"); + return remote.getId(customer); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.java b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.java new file mode 100644 index 0000000000..f2b7b1e41d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Customer.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.itest.bindingsca; + +/** + * + */ +public class Customer { + private String id; + private String name; + + public Customer() { + } + + /** + * @param id + * @param name + */ + public Customer(String id, String name) { + super(); + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Customer [id=" + id + ", name=" + name + "]"; + } + + public void dump(String prefix) { + System.out.print(prefix); + System.out.print(": "); + System.out.print(toString()); + System.out.println(" @" + System.identityHashCode(this)); + System.out.println(getClass().getClassLoader()); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/CustomerNotFoundException.java b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/CustomerNotFoundException.java new file mode 100644 index 0000000000..a6e80c9eca --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/CustomerNotFoundException.java @@ -0,0 +1,64 @@ +/* + * 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.itest.bindingsca; + +/** + * + */ +public class CustomerNotFoundException extends Exception { + private String customerId; + + /** + * + */ + public CustomerNotFoundException() { + } + + /** + * @param message + */ + public CustomerNotFoundException(String message) { + super(message); + } + + /** + * @param cause + */ + public CustomerNotFoundException(Throwable cause) { + super(cause); + } + + /** + * @param message + * @param cause + */ + public CustomerNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public String getCustomerId() { + return customerId; + } + + public void setCustomerId(String customerId) { + this.customerId = customerId; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.java b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.java new file mode 100644 index 0000000000..0fe30c9d53 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Local.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.itest.bindingsca; + +/** + * + */ +public interface Local { + String getName(Customer customer); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.java b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.java new file mode 100644 index 0000000000..8783808334 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/LocalServiceImpl.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.itest.bindingsca; + +import org.oasisopen.sca.annotation.Service; + +/** + * + */ +@Service(Local.class) +public class LocalServiceImpl implements Local { + + public String getName(Customer customer) { + if (customer == null) { + return null; + } + customer.dump("Local.getName()"); + return customer.getName(); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java new file mode 100644 index 0000000000..050d35007b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/Remote.java @@ -0,0 +1,36 @@ +/* + * 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.itest.bindingsca; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * + */ +@Remotable +public interface Remote { + String generateId(); + + String getId(Customer customer); + + Customer getCustomer(String id) throws CustomerNotFoundException; + + Customer createCustomer(String id, String name); +} diff --git a/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.java b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.java new file mode 100644 index 0000000000..6c432a500a --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/RemoteServiceImpl.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.itest.bindingsca; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.oasisopen.sca.annotation.AllowsPassByReference; +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.Service; + +/** + * + */ +@Service(Remote.class) +@Scope("COMPOSITE") +public class RemoteServiceImpl implements Remote { + private Map<String, Customer> customers = new HashMap<String, Customer>(); + + public String generateId() { + return UUID.randomUUID().toString(); + } + + @AllowsPassByReference + public String getId(Customer customer) { + customer.dump("Remote.getId()"); + return customer.getId(); + } + + public Customer getCustomer(String id) throws CustomerNotFoundException { + Customer customer = customers.get(id); + if (customer == null) { + CustomerNotFoundException ex = new CustomerNotFoundException("Customer not found"); + ex.setCustomerId(id); + throw ex; + } + customer.dump("Remote.getCustomer()"); + return customer; + } + + public Customer createCustomer(String id, String name) { + Customer customer = new Customer(id, name); + customer.dump("Remote.createCustomer()"); + customers.put(id, customer); + return customer; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/SCAClientImpl.java b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/SCAClientImpl.java new file mode 100644 index 0000000000..3573eea978 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta3/testing/itest/nodes/binding-sca-tribes/src/main/java/org/apache/tuscany/sca/itest/bindingsca/SCAClientImpl.java @@ -0,0 +1,57 @@ +/* + * 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.itest.bindingsca; + +import java.net.URI; + +import org.oasisopen.sca.client.SCAClientFactory; + +/** + * + */ +public class SCAClientImpl implements Client { + private Local local; + private Remote remote; + + public SCAClientImpl(String domainURI) throws Exception { + SCAClientFactory factory = SCAClientFactory.newInstance(URI.create(domainURI)); + local = factory.getService(Local.class, "LocalComponent/Local"); + remote = factory.getService(Remote.class, "RemoteComponent/Remote"); + } + + public String getName(String id) { + Customer customer = null; + try { + customer = remote.getCustomer(id); + } catch (CustomerNotFoundException e) { + return null; + } + customer.dump("Client.getName()"); + return local.getName(customer); + } + + public String create(String name) { + String id = remote.generateId(); + Customer customer = remote.createCustomer(id, name); + customer.dump("Client.create()"); + return remote.getId(customer); + } + +} |