diff options
Diffstat (limited to 'branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer')
10 files changed, 554 insertions, 0 deletions
diff --git a/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java new file mode 100644 index 0000000000..df52c6c760 --- /dev/null +++ b/branches/sca-android/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/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerComponentImpl.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerComponentImpl.java new file mode 100644 index 0000000000..aca5943552 --- /dev/null +++ b/branches/sca-android/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/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerImpl.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerImpl.java new file mode 100644 index 0000000000..e71c624f49 --- /dev/null +++ b/branches/sca-android/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<String, Object> props1 = new Hashtable<String, Object>(); + props1.put("retailerName", "amazon.com"); + registerService(new OSGiRetailerServiceImpl(this, "amazon.com"), + "supplychain.retailer.Retailer", props1); + + Hashtable<String, Object> props2 = new Hashtable<String, Object>(); + props2.put("retailerName", "play.com"); + registerService( + new OSGiRetailerServiceImpl(this, "play.com"), + "supplychain.retailer.Retailer", props2); + + Hashtable<String, Object> props3 = new Hashtable<String, Object>(); + props3.put("retailerName", "ebay.com"); + registerService( + new OSGiRetailerServiceImpl(this, "ebay.com"), + "supplychain.retailer.Retailer", props3); + } + + +} diff --git a/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerServiceImpl.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerServiceImpl.java new file mode 100644 index 0000000000..a036ecfc76 --- /dev/null +++ b/branches/sca-android/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/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryComponentImpl.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryComponentImpl.java new file mode 100644 index 0000000000..db877bb366 --- /dev/null +++ b/branches/sca-android/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/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryImpl.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiRetailerWithQueryImpl.java new file mode 100644 index 0000000000..ee1f575e70 --- /dev/null +++ b/branches/sca-android/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<String, Object> props1 = new Hashtable<String, Object>(); + 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/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerImpl.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerImpl.java new file mode 100644 index 0000000000..09e60ca626 --- /dev/null +++ b/branches/sca-android/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<String, Object> props1 = new Hashtable<String, Object>(); + props1.put("retailerName", "amazon.com"); + bc.registerService("supplychain.retailer.Retailer", + new OSGiVersionedRetailerServiceImpl(this, "amazon.com", version), + props1); + + Hashtable<String, Object> props2 = new Hashtable<String, Object>(); + 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/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerServiceImpl.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/OSGiVersionedRetailerServiceImpl.java new file mode 100644 index 0000000000..7dd70889c7 --- /dev/null +++ b/branches/sca-android/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/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/Retailer.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/Retailer.java new file mode 100644 index 0000000000..1e87d59af1 --- /dev/null +++ b/branches/sca-android/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/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/RetailerQuery.java b/branches/sca-android/itest/osgi-implementation/src/main/java/supplychain/retailer/RetailerQuery.java new file mode 100644 index 0000000000..354f40a064 --- /dev/null +++ b/branches/sca-android/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); + +} |