From 6a3ca6736c808c1647854e405ef379b609f276db Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:07:45 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835126 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/supplychain/OSGiBundleImpl.java | 163 +++++++++++++++++++++ .../main/java/supplychain/customer/Customer.java | 39 +++++ .../customer/JavaCustomerComponentImpl.java | 88 +++++++++++ .../customer/OSGiCustomerComponentImpl.java | 106 ++++++++++++++ .../customer/OSGiCustomerFactoryImpl.java | 65 ++++++++ .../supplychain/customer/OSGiCustomerImpl.java | 92 ++++++++++++ .../OSGiCustomerWithQueryComponentImpl.java | 100 +++++++++++++ .../customer/OSGiCustomerWithQueryImpl.java | 82 +++++++++++ .../OSGiStatelessCustomerComponentImpl.java | 30 ++++ .../customer/OSGiStatelessCustomerImpl.java | 35 +++++ .../customer/OSGiVersionedCustomerImpl.java | 98 +++++++++++++ .../retailer/JavaRetailerComponentImpl.java | 67 +++++++++ .../retailer/OSGiRetailerComponentImpl.java | 64 ++++++++ .../supplychain/retailer/OSGiRetailerImpl.java | 58 ++++++++ .../retailer/OSGiRetailerServiceImpl.java | 45 ++++++ .../OSGiRetailerWithQueryComponentImpl.java | 78 ++++++++++ .../retailer/OSGiRetailerWithQueryImpl.java | 64 ++++++++ .../retailer/OSGiVersionedRetailerImpl.java | 75 ++++++++++ .../retailer/OSGiVersionedRetailerServiceImpl.java | 47 ++++++ .../main/java/supplychain/retailer/Retailer.java | 28 ++++ .../java/supplychain/retailer/RetailerQuery.java | 28 ++++ .../shipper/JavaShipperComponentImpl.java | 58 ++++++++ .../shipper/OSGiShipperComponentImpl.java | 62 ++++++++ .../shipper/OSGiShipperFactoryImpl.java | 78 ++++++++++ .../java/supplychain/shipper/OSGiShipperImpl.java | 57 +++++++ .../shipper/OSGiShipperServiceImpl.java | 43 ++++++ .../shipper/OSGiStatelessShipperComponentImpl.java | 30 ++++ .../shipper/OSGiStatelessShipperServiceImpl.java | 35 +++++ .../shipper/OSGiVersionedShipperImpl.java | 78 ++++++++++ .../shipper/OSGiVersionedShipperServiceImpl.java | 46 ++++++ .../src/main/java/supplychain/shipper/Shipper.java | 28 ++++ .../warehouse/JavaWarehouseComponentImpl.java | 48 ++++++ .../JavaWarehouseWithQueryComponentImpl.java | 52 +++++++ .../warehouse/OSGiWarehouseComponentImpl.java | 57 +++++++ .../supplychain/warehouse/OSGiWarehouseImpl.java | 68 +++++++++ .../warehouse/OSGiWarehouseServiceImpl.java | 62 ++++++++ .../main/java/supplychain/warehouse/Warehouse.java | 28 ++++ .../java/supplychain/warehouse/WarehouseQuery.java | 28 ++++ 38 files changed, 2310 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/OSGiBundleImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/Customer.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/JavaCustomerComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerWithQueryComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerWithQueryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiStatelessCustomerComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiStatelessCustomerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiVersionedCustomerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/Retailer.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/RetailerQuery.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/Shipper.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/JavaWarehouseComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/JavaWarehouseWithQueryComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/Warehouse.java create mode 100644 sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/WarehouseQuery.java (limited to 'sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain') diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/OSGiBundleImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/OSGiBundleImpl.java new file mode 100644 index 0000000000..25d7bcf2ff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/OSGiBundleImpl.java @@ -0,0 +1,163 @@ +/* + * 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 supplychain; + + + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Hashtable; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; + + +/** + * This class implements the Customer service component. + */ +public class OSGiBundleImpl implements ServiceListener, BundleActivator { + + + String name; + + String[] references; + Class[] referenceClasses; + Field[] referenceFields; + String[] referenceFilters; + + Class myClass; + ArrayList serviceNames = new ArrayList(); + ArrayList serviceObjs = new ArrayList(); + ArrayList> serviceProperties = new ArrayList>(); + + + private BundleContext bundleContext; + + public OSGiBundleImpl() {} + + public OSGiBundleImpl(String[] references, String[] filters) { + + myClass = this.getClass(); + this.name = this.getClass().getSimpleName(); + this.references = references == null?new String[0] : references; + + + try { + referenceClasses = new Class[references.length]; + referenceFields = new Field[references.length]; + referenceFilters = new String[references.length]; + for (int i = 0; i < references.length; i++) { + referenceFields[i] = this.getClass().getDeclaredField(references[i]); + referenceFields[i].setAccessible(true); + referenceClasses[i] = referenceFields[i].getType(); + + if (filters != null && filters.length > i) + referenceFilters[i] = filters[i]; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + public void start(BundleContext bc) { + + System.out.println("Started bundle " + name); + + this.bundleContext = bc; + + boolean useSingleRegisterService = serviceNames.size() > 1; + for (int i = 1; i < serviceNames.size(); i++) { + if (serviceObjs.get(i) != serviceObjs.get(0) || + serviceProperties.get(i) != serviceProperties.get(0)) { + useSingleRegisterService = false; + break; + } + } + if (useSingleRegisterService) { + bundleContext.registerService(serviceNames.toArray(new String[serviceNames.size()]), + serviceObjs.get(0), serviceProperties.get(0)); + } + else { + for (int i = 0; i < serviceNames.size(); i++) { + bundleContext.registerService(serviceNames.get(i), serviceObjs.get(i), serviceProperties.get(i)); + } + } + + started(bc); + + for (int i = 0; i < references.length; i++) { + + try { + if (referenceFields[i].get(this) != null) + continue; + + ServiceReference[] refs = bundleContext.getServiceReferences(referenceClasses[i].getName(), referenceFilters[i]); + if (refs != null && refs.length > 0) { + Object obj = bundleContext.getService(refs[0]); + referenceFields[i].set(this, referenceClasses[i].cast(obj)); + } else { + String filter = "(objectclass=" + referenceClasses[i].getName() + ")"; + this.bundleContext.addServiceListener(this, filter); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + public void stop(BundleContext bc) { + System.out.println("Stop bundle " + name); + + } + + protected void started(BundleContext bc) { + + } + + public void serviceChanged(ServiceEvent event) { + try { + if (event.getType() == ServiceEvent.REGISTERED) { + + ServiceReference ref = event.getServiceReference(); + Object obj = bundleContext.getService(ref); + for (int i = 0; i < references.length; i++) { + if (referenceClasses[i].isAssignableFrom(obj.getClass())) { + referenceFields[i].set(this, referenceClasses[i].cast(obj)); + } + } + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + + + public void registerService(Object serviceObject, String serviceName, Hashtable props) { + serviceObjs.add(serviceObject); + serviceNames.add(serviceName); + serviceProperties.add(props == null? new Hashtable() : props); + } +} + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/Customer.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/Customer.java new file mode 100644 index 0000000000..2762bc62be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/Customer.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 supplychain.customer; + +import org.osoa.sca.annotations.OneWay; + +/** + * This is the business interface of the Customer service component. + */ +public interface Customer { + + public void purchaseBooks(); + + public void purchaseGames(); + + public void purchaseGoods(); + + @OneWay + public void notifyShipment(String order); + + public boolean hasOutstandingOrders(); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/JavaCustomerComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/JavaCustomerComponentImpl.java new file mode 100644 index 0000000000..80346311b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/JavaCustomerComponentImpl.java @@ -0,0 +1,88 @@ +/* + * 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 supplychain.customer; + +import java.util.ArrayList; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import supplychain.retailer.Retailer; + +/** + * This class implements the Customer service component. + */ +@Service(Customer.class) +@Scope("COMPOSITE") +public class JavaCustomerComponentImpl implements Customer { + + private Retailer retailer1; + + private Retailer retailer2; + + private Retailer retailer3; + + private static ArrayList outstandingOrders = new ArrayList(); + + @Reference + public void setRetailer1(Retailer retailer1) { + this.retailer1 = retailer1; + } + + @Reference + public void setRetailer2(Retailer retailer2) { + this.retailer2 = retailer2; + } + + @Reference + public void setRetailer3(Retailer retailer3) { + this.retailer3 = retailer3; + } + + public void purchaseBooks() { + System.out.println("JavaCustomerComponentImpl.purchaseBooks"); + outstandingOrders.add("Order, submitted (amazon.com), fulfilled, shipped (ParcelForce)"); + retailer1.submitOrder("Order"); + } + + public void purchaseGames() { + System.out.println("JavaCustomerComponentImpl.purchaseGames"); + outstandingOrders.add("Order, submitted (play.com), fulfilled, shipped (ParcelForce)"); + + retailer2.submitOrder("Order"); + } + + public void purchaseGoods() { + retailer3.submitOrder("Order"); + } + + public void notifyShipment(String order) { + outstandingOrders.remove(order); + System.out.print("Work thread " + Thread.currentThread() + " - "); + System.out.println(order); + } + + public boolean hasOutstandingOrders() { + return outstandingOrders.size() != 0; + } + + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerComponentImpl.java new file mode 100644 index 0000000000..a879505610 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerComponentImpl.java @@ -0,0 +1,106 @@ +/* + * 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 supplychain.customer; + + +import java.util.ArrayList; + +import org.osgi.service.component.ComponentContext; + + +import supplychain.retailer.Retailer; + +/** + * This class implements the Customer service component. + */ +public class OSGiCustomerComponentImpl implements Customer { + + + private Retailer retailer1; + private Retailer retailer2; + private Retailer retailer3; + + private static ArrayList outstandingOrders = new ArrayList(); + + public OSGiCustomerComponentImpl() { + System.out.println("Created OSGiCustomerComponentImpl " + this); + } + + protected void setRetailer1(Retailer retailer1) { + this.retailer1 = retailer1; + } + + protected void unsetRetailer1(Retailer retailer1) { + // this.retailer1 = null; + } + + + protected void setRetailer2(Retailer retailer2) { + this.retailer2 = retailer2; + } + + protected void unsetRetailer2(Retailer retailer2) { + // this.retailer2 = null; + } + + protected void setRetailer3(Retailer retailer3) { + this.retailer3 = retailer3; + } + + protected void unsetRetailer3(Retailer retailer3) { + // this.retailer3 = null; + } + + + public void purchaseBooks() { + System.out.println("OSGiCustomerComponentImpl.purchaseBooks, retailer1 is " + retailer1); + outstandingOrders.add("Order, submitted (amazon.com), fulfilled, shipped (ParcelForce)"); + retailer1.submitOrder("Order"); + } + + public void purchaseGames() { + System.out.println("OSGiCustomerComponentImpl.purchaseGames, retailer2 is " + retailer2); + outstandingOrders.add("Order, submitted (play.com), fulfilled, shipped (ParcelForce)"); + + retailer2.submitOrder("Order"); + } + + public void purchaseGoods() { + System.out.println("OSGiCustomerComponentImpl.purchaseGames, retailer3 is " + retailer3); + retailer3.submitOrder("Order"); + } + + public void notifyShipment(String order) { + outstandingOrders.remove(order); + System.out.print("Work thread " + Thread.currentThread() + " - "); + System.out.println(order); + } + + protected void activate(ComponentContext context){ + System.out.println("Activated OSGiCustomerComponentImpl bundle "); + } + + protected void deactivate(ComponentContext context){ + System.out.println("Deactivated OSGiCustomerComponentImpl bundle "); + } + + public boolean hasOutstandingOrders() { + return outstandingOrders.size() != 0; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerFactoryImpl.java new file mode 100644 index 0000000000..c8cb522cf4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerFactoryImpl.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 supplychain.customer; + + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceFactory; +import org.osgi.framework.ServiceRegistration; + +/** + * This class implements the Customer service component. + */ +public class OSGiCustomerFactoryImpl implements BundleActivator, ServiceFactory { + + private BundleContext bundleContext; + + public OSGiCustomerFactoryImpl() { + } + + + public void start(BundleContext bc) { + + this.bundleContext = bc; + bc.registerService(Customer.class.getName(), this, null); + } + + + + + public void stop(BundleContext context) throws Exception { + + } + + + public Object getService(Bundle bundle, ServiceRegistration registration) { + + OSGiCustomerImpl customer = new OSGiCustomerImpl(false); + customer.start(bundleContext); + return customer; + + } + + public void ungetService(Bundle bundle, ServiceRegistration registration, Object obj) { + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerImpl.java new file mode 100644 index 0000000000..546971860e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerImpl.java @@ -0,0 +1,92 @@ +/* + * 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 supplychain.customer; + + +import java.util.ArrayList; + +import org.osoa.sca.annotations.AllowsPassByReference; + +import supplychain.OSGiBundleImpl; +import supplychain.retailer.Retailer; + +/** + * This class implements the Customer service component. + */ +@AllowsPassByReference +public class OSGiCustomerImpl extends OSGiBundleImpl implements Customer { + + private ArrayList outstandingOrders = new ArrayList(); + + private Retailer retailer1; + private Retailer retailer2; + private Retailer retailer3; + + public OSGiCustomerImpl() { + super( new String[]{"retailer1", "retailer2", "retailer3"}, + new String[]{"(retailerName=amazon.com)", + "(retailerName=play.com)", + "(retailerName=ebay.com)" + }); + registerService(this, "supplychain.customer.Customer", null); + + } + + public OSGiCustomerImpl(boolean ignore) { // Used only to test service factories + super( new String[]{"retailer1", "retailer2", "retailer3"}, + new String[]{"(retailerName=amazon.com)", + "(retailerName=play.com)", + "(retailerName=ebay.com)" + }); + + } + + public void purchaseBooks() { + System.out.println("OSGiCustomerImpl.purchaseBooks, retailer is " + retailer1); + outstandingOrders.add("Order, submitted (amazon.com), fulfilled, shipped (ParcelForce)"); + + retailer1.submitOrder("Order"); + + } + + public void purchaseGames() { + System.out.println("OSGiCustomerImpl.purchaseGames, retailer is " + retailer2); + outstandingOrders.add("Order, submitted (play.com), fulfilled, shipped (ParcelForce)"); + + retailer2.submitOrder("Order"); + + } + + public void purchaseGoods() { + retailer3.submitOrder("Order"); + } + + public void notifyShipment(String order) { + + outstandingOrders.remove(order); + + System.out.print("Work thread " + Thread.currentThread() + " - "); + System.out.println(order); + } + + public boolean hasOutstandingOrders() { + return outstandingOrders.size() != 0; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerWithQueryComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerWithQueryComponentImpl.java new file mode 100644 index 0000000000..593e55f3f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerWithQueryComponentImpl.java @@ -0,0 +1,100 @@ +/* + * 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 supplychain.customer; + + +import java.util.ArrayList; + +import org.osgi.service.component.ComponentContext; + + +import supplychain.retailer.Retailer; +import supplychain.retailer.RetailerQuery; + +/** + * This class implements the Customer service component. + */ +public class OSGiCustomerWithQueryComponentImpl implements Customer { + + + private Retailer retailer; + private RetailerQuery retailerQuery; + + private static ArrayList outstandingOrders = new ArrayList(); + + public OSGiCustomerWithQueryComponentImpl() { + System.out.println("Created OSGiCustomerWithQueryComponentImpl " + this); + } + + protected void setRetailer(Retailer retailer) { + this.retailer = retailer; + } + + protected void unsetRetailer(Retailer retailer) { + // this.retailer = null; + } + + + protected void setRetailerQuery(RetailerQuery retailerQuery) { + this.retailerQuery = retailerQuery; + } + + protected void unsetRetailerQuery(RetailerQuery retailerQuery) { + // this.retailerQuery = null; + } + + public void purchaseBooks() { + System.out.println("OSGiCustomerWithQueryComponentImpl.purchaseBooks"); + outstandingOrders.add("Order, submitted (amazon.com), fulfilled, shipped (RoyalMail)"); + + if (retailerQuery.isAvailable("Order")) + retailer.submitOrder("Order"); + } + + public void purchaseGames() { + System.out.println("OSGiCustomerWithQueryComponentImpl.purchaseGames"); + outstandingOrders.add("Order, submitted (amazon.com), fulfilled, shipped (RoyalMail)"); + + if (retailerQuery.isAvailable("Order")) + retailer.submitOrder("Order"); + } + + public void purchaseGoods() { + if (retailerQuery.isAvailable("Order")) + retailer.submitOrder("Order"); + } + + public void notifyShipment(String order) { + outstandingOrders.remove(order); + System.out.print("Work thread " + Thread.currentThread() + " - "); + System.out.println(order); + } + + protected void activate(ComponentContext context){ + System.out.println("Activated OSGiCustomerWithQueryComponentImpl bundle "); + } + + protected void deactivate(ComponentContext context){ + System.out.println("Deactivated OSGiCustomerWithQueryComponentImpl bundle "); + } + + public boolean hasOutstandingOrders() { + return outstandingOrders.size() != 0; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerWithQueryImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerWithQueryImpl.java new file mode 100644 index 0000000000..18483817ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiCustomerWithQueryImpl.java @@ -0,0 +1,82 @@ +/* + * 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 supplychain.customer; + + +import java.util.ArrayList; + +import supplychain.OSGiBundleImpl; +import supplychain.retailer.Retailer; +import supplychain.retailer.RetailerQuery; + +/** + * This class implements the Customer service component. + */ +public class OSGiCustomerWithQueryImpl extends OSGiBundleImpl implements Customer { + + private static ArrayList outstandingOrders = new ArrayList(); + + private Retailer retailer; + private RetailerQuery retailerQuery; + + public OSGiCustomerWithQueryImpl() { + super( new String[]{"retailer", "retailerQuery"}, + new String[]{"(component.service.name=RetailerComponent/Retailer)", + "(component.service.name=RetailerComponent/RetailerQuery)" + }); + registerService(this, "supplychain.customer.Customer", null); + + } + + public void purchaseBooks() { + System.out.println("OSGiCustomerWithQueryImpl.purchaseBooks"); + outstandingOrders.add("Order, submitted (amazon.com), fulfilled, shipped (RoyalMail)"); + + if (retailerQuery.isAvailable("Order")) + retailer.submitOrder("Order"); + + } + + public void purchaseGames() { + System.out.println("OSGiCustomerWithQueryImpl.purchaseGames"); + outstandingOrders.add("Order, submitted (amazon.com), fulfilled, shipped (RoyalMail)"); + + if (retailerQuery.isAvailable("Order")) + retailer.submitOrder("Order"); + + } + + public void purchaseGoods() { + if (retailerQuery.isAvailable("Order")) + retailer.submitOrder("Order"); + } + + public void notifyShipment(String order) { + + outstandingOrders.remove(order); + + System.out.print("Work thread " + Thread.currentThread() + " - "); + System.out.println(order); + } + + public boolean hasOutstandingOrders() { + return outstandingOrders.size() != 0; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiStatelessCustomerComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiStatelessCustomerComponentImpl.java new file mode 100644 index 0000000000..5ba42780f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiStatelessCustomerComponentImpl.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 supplychain.customer; + +import org.osoa.sca.annotations.Scope; + + +/** + * This class implements the Customer service component. + */ +@Scope("STATELESS") +public class OSGiStatelessCustomerComponentImpl extends OSGiCustomerComponentImpl { + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiStatelessCustomerImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiStatelessCustomerImpl.java new file mode 100644 index 0000000000..bc569d0ac0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiStatelessCustomerImpl.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 supplychain.customer; + + +import org.osoa.sca.annotations.Scope; + + +/** + * This class implements the Customer service component. + */ +@Scope("STATELESS") +public class OSGiStatelessCustomerImpl extends OSGiCustomerImpl { + + public OSGiStatelessCustomerImpl(boolean ignore) { + super(ignore); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiVersionedCustomerImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiVersionedCustomerImpl.java new file mode 100644 index 0000000000..599ab51a50 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/customer/OSGiVersionedCustomerImpl.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 supplychain.customer; + + +import java.util.ArrayList; +import java.util.Hashtable; + +import org.osgi.framework.BundleContext; + +import supplychain.OSGiBundleImpl; +import supplychain.retailer.Retailer; + +/** + * This class implements the Customer service component. + */ +public class OSGiVersionedCustomerImpl extends OSGiBundleImpl implements Customer { + + private static ArrayList outstandingOrders = new ArrayList(); + + private Retailer retailer1; + private Retailer retailer2; + private Retailer retailer3; + private int version; + + public OSGiVersionedCustomerImpl() { + super( new String[]{"retailer1", "retailer2", "retailer3"}, + new String[]{"(retailerName=amazon.com)", + "(retailerName=play.com)", + "(retailerName=ebay.com)" + }); + + } + + protected void started(BundleContext bc) { + + String jarFile = bc.getBundle().getLocation(); + if (jarFile.endsWith("1.jar")) version = 1; + else if (jarFile.endsWith("2.jar")) version = 2; + else version = 3; + + Hashtable props1 = new Hashtable(); + props1.put("component.name", "CustomerComponent" + version); + bc.registerService("supplychain.customer.Customer", this, props1); + + } + + public void purchaseBooks() { + System.out.println("OSGiVersionedCustomerImpl.purchaseBooks , retailer is " + retailer1); + outstandingOrders.add("Order, submitted (amazon.com v" + version + + "), fulfilled, shipped (ParcelForce)"); + + retailer1.submitOrder("Order"); + + } + + public void purchaseGames() { + System.out.println("OSGiCustomerImpl.purchaseGames"); + outstandingOrders.add("Order, submitted (play.com v" + version + + "), fulfilled, shipped (ParcelForce)"); + + retailer2.submitOrder("Order"); + + } + + public void purchaseGoods() { + retailer3.submitOrder("Order"); + } + + public void notifyShipment(String order) { + + outstandingOrders.remove(order); + + System.out.print("Work thread " + Thread.currentThread() + " - "); + System.out.println(order); + } + + public boolean hasOutstandingOrders() { + return outstandingOrders.size() != 0; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java new file mode 100644 index 0000000000..df52c6c760 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java @@ -0,0 +1,67 @@ +/* + * 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 supplychain.retailer; + + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import supplychain.warehouse.Warehouse; + +/** + * This class implements the Customer service component. + */ +@Service(Retailer.class) +@Scope("COMPOSITE") +public class JavaRetailerComponentImpl implements Retailer { + + private Warehouse warehouse; + + private String retailerName; + + public JavaRetailerComponentImpl() { + System.out.println("Created RetailerComponentImpl"); + } + + @Reference + public void setWarehouse(Warehouse warehouse) { + System.out.println("retailer setWarehouse " + warehouse); + + this.warehouse = warehouse; + } + + @Property + public void setRetailerName(String retailerName) { + this.retailerName = retailerName; + } + + + public void submitOrder(String order) { + + System.out.println("JavaRetailerComponentImpl.submitOrder " + warehouse); + warehouse.fulfillOrder(order + ", submitted (" + retailerName + ")"); + + } + + + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerComponentImpl.java new file mode 100644 index 0000000000..aca5943552 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerComponentImpl.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 supplychain.retailer; + +import org.osgi.service.component.ComponentContext; + +import supplychain.warehouse.Warehouse; + +/** + * This class implements the Customer service component. + */ +public class OSGiRetailerComponentImpl implements Retailer { + + private Warehouse warehouse; + private String retailerName; + + + protected void setWarehouse(Warehouse warehouse) { + this.warehouse = warehouse; + } + + protected void unsetWarehouse(Warehouse warehouse) { + // this.warehouse = null; + } + + public void submitOrder(String order) { + + System.out.println("OSGiRetailerComponentImpl.submitOrder , warehouse is " + warehouse); + warehouse.fulfillOrder(order + ", submitted (" + retailerName + ")"); + + } + + protected void activate(ComponentContext context){ + System.out.println("Activated OSGiRetailerComponentImpl bundle "); + + Object prop = context.getProperties().get("retailerName"); + if (prop instanceof String[]) + retailerName = ((String [])prop)[0]; + + + } + + protected void deactivate(ComponentContext context){ + System.out.println("Deactivated OSGiRetailerComponentImpl bundle "); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerImpl.java new file mode 100644 index 0000000000..e71c624f49 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerImpl.java @@ -0,0 +1,58 @@ +/* + * 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 supplychain.retailer; + + +import java.util.Hashtable; + +import supplychain.OSGiBundleImpl; +import supplychain.warehouse.Warehouse; + +/** + * This class implements the Retailer service component. + */ +public class OSGiRetailerImpl extends OSGiBundleImpl { + + protected Warehouse warehouse; + + public OSGiRetailerImpl() { + + super(new String[]{"warehouse"}, + new String[]{"(component.service.name=WarehouseComponent1/Warehouse)"}); + + Hashtable props1 = new Hashtable(); + props1.put("retailerName", "amazon.com"); + registerService(new OSGiRetailerServiceImpl(this, "amazon.com"), + "supplychain.retailer.Retailer", props1); + + Hashtable props2 = new Hashtable(); + props2.put("retailerName", "play.com"); + registerService( + new OSGiRetailerServiceImpl(this, "play.com"), + "supplychain.retailer.Retailer", props2); + + Hashtable props3 = new Hashtable(); + props3.put("retailerName", "ebay.com"); + registerService( + new OSGiRetailerServiceImpl(this, "ebay.com"), + "supplychain.retailer.Retailer", props3); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerServiceImpl.java new file mode 100644 index 0000000000..a036ecfc76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerServiceImpl.java @@ -0,0 +1,45 @@ +/* + * 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 supplychain.retailer; + + +/** + * This class implements the Retailer service. + */ +public class OSGiRetailerServiceImpl implements Retailer { + + private OSGiRetailerImpl retailerImpl; + + private String retailerName; + + OSGiRetailerServiceImpl(OSGiRetailerImpl retailerImpl, String retailerName) { + this.retailerImpl = retailerImpl; + this.retailerName = retailerName; + + } + + public void submitOrder(String order) { + + System.out.println("Retailer.submitOrder, warehouse is " + retailerImpl.warehouse); + retailerImpl.warehouse.fulfillOrder(order + ", submitted (" + + retailerName + ")"); + + } + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryComponentImpl.java new file mode 100644 index 0000000000..db877bb366 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryComponentImpl.java @@ -0,0 +1,78 @@ +/* + * 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 supplychain.retailer; + +import org.osgi.service.component.ComponentContext; + +import supplychain.warehouse.Warehouse; +import supplychain.warehouse.WarehouseQuery; + +/** + * This class implements the Customer service component. + */ +public class OSGiRetailerWithQueryComponentImpl implements Retailer, RetailerQuery { + + private Warehouse warehouse; + private WarehouseQuery warehouseQuery; + private String retailerName; + + + protected void setWarehouse(Warehouse warehouse) { + this.warehouse = warehouse; + } + + protected void unsetWarehouse(Warehouse warehouse) { + // this.warehouse = null; + } + + protected void setWarehouseQuery(WarehouseQuery warehouseQuery) { + this.warehouseQuery = warehouseQuery; + } + + protected void unsetWarehouseQuery(WarehouseQuery warehouse) { + // this.warehouseQuery = null; + } + + public void submitOrder(String order) { + + System.out.println("OSGiRetailerComponentImpl.submitOrder , warehouse is " + warehouse); + warehouse.fulfillOrder(order + ", submitted (" + retailerName + ")"); + + } + + public boolean isAvailable(String order) { + return warehouseQuery.isAvailable(order); + } + + protected void activate(ComponentContext context){ + System.out.println("Activated OSGiRetailerComponentImpl bundle "); + + Object prop = context.getProperties().get("retailerName"); + if (prop instanceof String[]) + retailerName = ((String [])prop)[0]; + + + } + + protected void deactivate(ComponentContext context){ + System.out.println("Deactivated OSGiRetailerComponentImpl bundle "); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryImpl.java new file mode 100644 index 0000000000..ee1f575e70 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryImpl.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 supplychain.retailer; + + +import java.util.Hashtable; + +import supplychain.OSGiBundleImpl; +import supplychain.warehouse.Warehouse; +import supplychain.warehouse.WarehouseQuery; + +/** + * This class implements the Retailer service component with query. + */ +public class OSGiRetailerWithQueryImpl extends OSGiBundleImpl implements Retailer, RetailerQuery { + + private Warehouse warehouse; + private WarehouseQuery warehouseQuery; + + public OSGiRetailerWithQueryImpl() { + + super(new String[]{"warehouse", "warehouseQuery"}, null); + + Hashtable props1 = new Hashtable(); + props1.put("retailerName", "amazon.com"); + registerService(this, + "supplychain.retailer.Retailer", props1); + + registerService(this, + "supplychain.retailer.RetailerQuery", props1); + + } + + public void submitOrder(String order) { + + System.out.println("Retailer.submitOrder, warehouse is " + warehouse); + warehouse.fulfillOrder(order + ", submitted (" + + "amazon.com" + ")"); + + } + + public boolean isAvailable(String order) { + return warehouseQuery.isAvailable(order); + } + + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerImpl.java new file mode 100644 index 0000000000..09e60ca626 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerImpl.java @@ -0,0 +1,75 @@ +/* + * 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 supplychain.retailer; + + +import java.util.Hashtable; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; + +import supplychain.OSGiBundleImpl; +import supplychain.warehouse.Warehouse; + +/** + * This class implements the Retailer service component. + */ +public class OSGiVersionedRetailerImpl extends OSGiBundleImpl { + + protected Warehouse warehouse; + + private int version; + + public OSGiVersionedRetailerImpl() { + + super(new String[]{"warehouse"}, null); + + + } + + protected void started(BundleContext bc) { + String jarFile = bc.getBundle().getLocation(); + if (jarFile.endsWith("1.jar")) version = 1; + else if (jarFile.endsWith("2.jar")) version = 2; + else version = 3; + + Hashtable props1 = new Hashtable(); + props1.put("retailerName", "amazon.com"); + bc.registerService("supplychain.retailer.Retailer", + new OSGiVersionedRetailerServiceImpl(this, "amazon.com", version), + props1); + + Hashtable props2 = new Hashtable(); + props2.put("retailerName", "play.com"); + bc.registerService( + "supplychain.retailer.Retailer", + new OSGiVersionedRetailerServiceImpl(this, "play.com", version), + props2); + + try { + ServiceReference[] refs = bc.getServiceReferences(Warehouse.class.getName(), + "(component.service.name=WarehouseComponent" + version + "/Warehouse)"); + if (refs != null && refs.length > 0) { + warehouse = (Warehouse) bc.getService(refs[0]); + } + } catch (InvalidSyntaxException e) { + } + } +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerServiceImpl.java new file mode 100644 index 0000000000..7dd70889c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerServiceImpl.java @@ -0,0 +1,47 @@ +/* + * 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 supplychain.retailer; + + +/** + * This class implements the Retailer service. + */ +public class OSGiVersionedRetailerServiceImpl implements Retailer { + + private OSGiVersionedRetailerImpl retailerImpl; + + private String retailerName; + + private int version; + + OSGiVersionedRetailerServiceImpl(OSGiVersionedRetailerImpl retailerImpl, String retailerName, int version) { + this.retailerImpl = retailerImpl; + this.retailerName = retailerName; + this.version = version; + } + + public void submitOrder(String order) { + + System.out.println("Retailer.submitOrder, warehouse is " + retailerImpl.warehouse); + retailerImpl.warehouse.fulfillOrder(order + ", submitted (" + + retailerName + " v" + version + ")"); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/Retailer.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/Retailer.java new file mode 100644 index 0000000000..1e87d59af1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/Retailer.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 supplychain.retailer; + +/** + * This is the business interface of the Retailer service component. + */ +public interface Retailer { + + public void submitOrder(String order); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/RetailerQuery.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/RetailerQuery.java new file mode 100644 index 0000000000..354f40a064 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/retailer/RetailerQuery.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 supplychain.retailer; + +/** + * This is the business interface of the RetailerQuery service. + */ +public interface RetailerQuery { + + public boolean isAvailable(String order); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java new file mode 100644 index 0000000000..d0cf43a960 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java @@ -0,0 +1,58 @@ +/* + * 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 supplychain.shipper; + + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import supplychain.customer.Customer; + +/** + * This class implements the Shipper service component. + */ +@Service(Shipper.class) +@Scope("COMPOSITE") +public class JavaShipperComponentImpl implements Shipper { + + private Customer customer; + + private String shipperName; + + @Reference + public void setCustomer(Customer customer) { + this.customer = customer; + } + + @Property + public void setShipperName(String shipperName) { + this.shipperName = shipperName; + } + + + + public void processShipment(String order) { + System.out.println("JavaShipperComponentImpl.processShipment"); + customer.notifyShipment(order + ", shipped (" + shipperName + ")"); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperComponentImpl.java new file mode 100644 index 0000000000..ff40a7ae36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperComponentImpl.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 supplychain.shipper; + + +import org.osgi.service.component.ComponentContext; + +import supplychain.customer.Customer; + +/** + * This class implements the Shipper service component. + */ +public class OSGiShipperComponentImpl implements Shipper { + + private Customer customer; + private String shipperName; + + protected void setCustomer(Customer customer) { + this.customer = customer; + } + + protected void unsetCustomer(Customer customer) { + // this.customer = null; + } + + public void processShipment(String order) { + System.out.println("OSGiShipperComponentImpl.processShipment, customer is " + customer); + customer.notifyShipment(order + ", shipped (" + shipperName + ")"); + } + + + protected void activate(ComponentContext context){ + System.out.println("Activated OSGiShipperComponentImpl bundle "); + + Object prop = context.getProperties().get("shipperName"); + if (prop instanceof String[]) + shipperName = ((String [])prop)[0]; + + } + + protected void deactivate(ComponentContext context){ + System.out.println("Deactivated OSGiShipperComponentImpl bundle "); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperFactoryImpl.java new file mode 100644 index 0000000000..ef989d6fcf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperFactoryImpl.java @@ -0,0 +1,78 @@ +/* + * 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 supplychain.shipper; + + +import java.util.Hashtable; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceFactory; +import org.osgi.framework.ServiceRegistration; + + +/** + * This class implements the Shipper service component. + */ +public class OSGiShipperFactoryImpl implements BundleActivator, ServiceFactory { + + private BundleContext bundleContext; + + public OSGiShipperFactoryImpl() { + + } + + + public void start(BundleContext bc) { + + this.bundleContext = bc; + + Hashtable props1 = new Hashtable(); + props1.put("shipperName", "RoyalMail"); + bc.registerService(Shipper.class.getName(), this, props1); + + Hashtable props2 = new Hashtable(); + props2.put("shipperName", "ParcelForce"); + bc.registerService(Shipper.class.getName(), this, props2); + } + + + + + public void stop(BundleContext context) throws Exception { + + } + + + public Object getService(Bundle bundle, ServiceRegistration reg) { + OSGiShipperImpl shipper = new OSGiShipperImpl(false); + shipper.start(bundleContext); + OSGiStatelessShipperServiceImpl shipperService = new OSGiStatelessShipperServiceImpl(shipper, + (String)reg.getReference().getProperty("shipperName")); + return shipperService; + } + + public void ungetService(Bundle arg0, ServiceRegistration arg1, Object arg2) { + + } + + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperImpl.java new file mode 100644 index 0000000000..effae8c246 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperImpl.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 supplychain.shipper; + + +import java.util.Hashtable; + +import supplychain.OSGiBundleImpl; +import supplychain.customer.Customer; + +/** + * This class implements the Shipper service component. + */ +public class OSGiShipperImpl extends OSGiBundleImpl { + + protected Customer customer; + + + public OSGiShipperImpl() { + + super(new String[]{"customer"}, null); + + Hashtable props1 = new Hashtable(); + props1.put("shipperName", "RoyalMail"); + registerService(new OSGiShipperServiceImpl(this, "RoyalMail"), + "supplychain.shipper.Shipper", props1); + + Hashtable props2 = new Hashtable(); + props2.put("shipperName", "ParcelForce"); + registerService( + new OSGiShipperServiceImpl(this, "ParcelForce"), + "supplychain.shipper.Shipper", props2); + } + + // Used only by service factories + public OSGiShipperImpl(boolean ignore) { + + super(new String[]{"customer"}, null); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperServiceImpl.java new file mode 100644 index 0000000000..4effadf208 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperServiceImpl.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 supplychain.shipper; + + +/** + * This class implements the Shipper service. + */ +public class OSGiShipperServiceImpl implements Shipper { + + private OSGiShipperImpl shipperImpl; + + private String shipperName; + + OSGiShipperServiceImpl(OSGiShipperImpl shipperImpl, String shipperName) { + this.shipperImpl = shipperImpl; + this.shipperName = shipperName; + } + + public void processShipment(String order) { + + System.out.println("Shipper.submitOrder, warehouse is " + shipperImpl.customer); + shipperImpl.customer.notifyShipment(order + ", shipped (" + shipperName + ")"); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperComponentImpl.java new file mode 100644 index 0000000000..13bce67bb4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperComponentImpl.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 supplychain.shipper; + +import org.osoa.sca.annotations.Scope; + + +/** + * This class implements the Shipper service component. + */ +@Scope("STATELESS") +public class OSGiStatelessShipperComponentImpl extends OSGiShipperComponentImpl { + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperServiceImpl.java new file mode 100644 index 0000000000..071a131f40 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperServiceImpl.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 supplychain.shipper; + +import org.osoa.sca.annotations.Scope; + + +/** + * This class implements the Shipper service. + */ +@Scope("STATELESS") +public class OSGiStatelessShipperServiceImpl extends OSGiShipperServiceImpl { + + public OSGiStatelessShipperServiceImpl(OSGiShipperImpl shipperImpl, String shipperName) { + super(shipperImpl, shipperName); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperImpl.java new file mode 100644 index 0000000000..6ebd1f2894 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperImpl.java @@ -0,0 +1,78 @@ +/* + * 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 supplychain.shipper; + + +import java.util.Hashtable; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; + +import supplychain.OSGiBundleImpl; +import supplychain.customer.Customer; + +/** + * This class implements the Shipper service component. + */ +public class OSGiVersionedShipperImpl extends OSGiBundleImpl { + + protected Customer customer; + + private int version; + + + public OSGiVersionedShipperImpl() { + + super(new String[]{"customer"}, null); + } + + protected void started(BundleContext bc) { + + String jarFile = bc.getBundle().getLocation(); + if (jarFile.endsWith("1.jar")) version = 1; + else if (jarFile.endsWith("2.jar")) version = 2; + + + Hashtable props1 = new Hashtable(); + props1.put("shipperName", "RoyalMail"); + props1.put("component.service.name", "ShipperComponent"+version+"/ShipperService1"); + bc.registerService("supplychain.shipper.Shipper", + new OSGiVersionedShipperServiceImpl(this, "RoyalMail", version), + props1); + + Hashtable props2 = new Hashtable(); + props2.put("shipperName", "ParcelForce"); + props2.put("component.service.name", "ShipperComponent"+version+"/ShipperService2"); + bc.registerService("supplychain.shipper.Shipper", + new OSGiVersionedShipperServiceImpl(this, "ParcelForce", version), + props2); + + try { + ServiceReference[] refs = bc.getServiceReferences(Customer.class.getName(), + "(component.service.name=CustomerComponent" + version + "/CustomerService)"); + if (refs != null && refs.length > 0) { + customer = (Customer) bc.getService(refs[0]); + } + } catch (InvalidSyntaxException e) { + } + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperServiceImpl.java new file mode 100644 index 0000000000..b66961b1c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperServiceImpl.java @@ -0,0 +1,46 @@ +/* + * 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 supplychain.shipper; + + +/** + * This class implements the Shipper service. + */ +public class OSGiVersionedShipperServiceImpl implements Shipper { + + private OSGiVersionedShipperImpl shipperImpl; + + private String shipperName; + + private int version; + + OSGiVersionedShipperServiceImpl(OSGiVersionedShipperImpl shipperImpl, String shipperName, int version) { + this.shipperImpl = shipperImpl; + this.shipperName = shipperName; + this.version = version; + } + + public void processShipment(String order) { + + System.out.println("Shipper.processShipment, version " + version + " customer is " + shipperImpl.customer); + shipperImpl.customer.notifyShipment(order + ", shipped (" + shipperName + ")"); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/Shipper.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/Shipper.java new file mode 100644 index 0000000000..2514928c10 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/shipper/Shipper.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 supplychain.shipper; + +/** + * This is the business interface of the Shipper service component. + */ +public interface Shipper { + + public void processShipment(String order); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/JavaWarehouseComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/JavaWarehouseComponentImpl.java new file mode 100644 index 0000000000..9edf3567e5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/JavaWarehouseComponentImpl.java @@ -0,0 +1,48 @@ +/* + * 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 supplychain.warehouse; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import supplychain.shipper.Shipper; + +/** + * This class implements the Warehouse service component. + */ +@Service(Warehouse.class) +@Scope("STATELESS") +public class JavaWarehouseComponentImpl implements Warehouse { + + private Shipper shipper; + + @Reference + public void setShipper(Shipper shipper) { + this.shipper = shipper; + } + + public void fulfillOrder(String order) { + System.out.println("JavaWarehouseComponentImpl.fulfillOrder : shipper is " + shipper); + + shipper.processShipment(order + ", fulfilled"); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/JavaWarehouseWithQueryComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/JavaWarehouseWithQueryComponentImpl.java new file mode 100644 index 0000000000..659f16be7f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/JavaWarehouseWithQueryComponentImpl.java @@ -0,0 +1,52 @@ +/* + * 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 supplychain.warehouse; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import supplychain.shipper.Shipper; + +/** + * This class implements the Warehouse service component. + */ +@Service(interfaces={Warehouse.class, WarehouseQuery.class}) +@Scope("COMPOSITE") +public class JavaWarehouseWithQueryComponentImpl implements Warehouse, WarehouseQuery { + + private Shipper shipper; + + @Reference + public void setShipper(Shipper shipper) { + this.shipper = shipper; + } + + public void fulfillOrder(String order) { + System.out.println("JavaWarehouseComponentImpl.fulfillOrder : shipper is " + shipper); + + shipper.processShipment(order + ", fulfilled"); + } + + public boolean isAvailable(String order) { + return true; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseComponentImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseComponentImpl.java new file mode 100644 index 0000000000..7c9e102fd2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseComponentImpl.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 supplychain.warehouse; + + +import org.osgi.service.component.ComponentContext; + +import supplychain.shipper.Shipper; + +/** + * This class implements the Warehouse service component. + */ + +public class OSGiWarehouseComponentImpl implements Warehouse { + + private Shipper shipper; + + protected void setShipper(Shipper shipper) { + this.shipper = shipper; + } + + protected void unsetShipper(Shipper shipper) { + // this.shipper = null; + } + + public void fulfillOrder(String order) { + System.out.println("OSGiWarehouseComponentImpl.fulfillOrder : shipper is " + shipper); + + shipper.processShipment(order + ", fulfilled"); + + } + + protected void activate(ComponentContext context){ + System.out.println("Activated OSGiWarehouseComponentImpl "); + } + + protected void deactivate(ComponentContext context){ + System.out.println("Deactivated OSGiWarehouseComponentImpl "); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseImpl.java new file mode 100644 index 0000000000..bb04ff42e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseImpl.java @@ -0,0 +1,68 @@ +/* + * 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 supplychain.warehouse; + + +import java.util.Hashtable; + +import org.osgi.framework.BundleContext; + +import supplychain.OSGiBundleImpl; +import supplychain.shipper.Shipper; + +/** + * This class implements the Warehouse service component. + */ + +public class OSGiWarehouseImpl extends OSGiBundleImpl implements Warehouse { + + protected Shipper shipper; + private OSGiWarehouseServiceImpl warehouseService1; + private OSGiWarehouseServiceImpl warehouseService2; + + public OSGiWarehouseImpl() { + super(new String[]{"shipper"}, null); + + Hashtable props1 = new Hashtable(); + props1.put("component.name", "WarehouseComponent1"); + warehouseService1 = new OSGiWarehouseServiceImpl(this, 2); + registerService(warehouseService1, + "supplychain.warehouse.Warehouse", props1); + + Hashtable props2 = new Hashtable(); + props2.put("component.name", "WarehouseComponent2"); + warehouseService2 = new OSGiWarehouseServiceImpl(this, 1); + registerService(warehouseService2, + "supplychain.warehouse.Warehouse", props2); + } + + protected void started(BundleContext bc) { + warehouseService1.started(bc); + warehouseService2.started(bc); + } + + public void fulfillOrder(String order) { + System.out.println("OSGiWarehouseImpl.fulfillOrder : shipper is " + shipper); + + shipper.processShipment(order + ", fulfilled"); + + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseServiceImpl.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseServiceImpl.java new file mode 100644 index 0000000000..3317816557 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/OSGiWarehouseServiceImpl.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 supplychain.warehouse; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; + +import supplychain.shipper.Shipper; + + +/** + * This class implements the Warehouse service. + */ +public class OSGiWarehouseServiceImpl implements Warehouse { + + private OSGiWarehouseImpl warehouseImpl; + private Shipper shipper; + private int shipperNum; + + + OSGiWarehouseServiceImpl(OSGiWarehouseImpl warehouseImpl, int shipperNum) { + this.warehouseImpl = warehouseImpl; + this.shipperNum = shipperNum; + } + + + protected void started(BundleContext bc) { + try { + ServiceReference[] refs = bc.getServiceReferences(Shipper.class.getName(), + "(component.service.name=ShipperComponent" + shipperNum + "/Shipper)"); + if (refs != null && refs.length > 0) { + shipper = (Shipper) bc.getService(refs[0]); + } + } catch (InvalidSyntaxException e) { + } + } + + public void fulfillOrder(String order) { + System.out.println("OSGiWarehouseImpl.fulfillOrder : shipper is " + warehouseImpl.shipper); + + shipper.processShipment(order + ", fulfilled"); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/Warehouse.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/Warehouse.java new file mode 100644 index 0000000000..6f1f6b8730 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/Warehouse.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 supplychain.warehouse; + +/** + * This is the business interface of the Warehouse service component. + */ +public interface Warehouse { + + public void fulfillOrder(String order); + +} diff --git a/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/WarehouseQuery.java b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/WarehouseQuery.java new file mode 100644 index 0000000000..6d1ad76796 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.2.1/itest/osgi-implementation/src/main/java/supplychain/warehouse/WarehouseQuery.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 supplychain.warehouse; + +/** + * This is the business interface of the RetailerQuery service. + */ +public interface WarehouseQuery { + + public boolean isAvailable(String order); + +} -- cgit v1.2.3