diff options
Diffstat (limited to 'sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper')
10 files changed, 515 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java new file mode 100644 index 0000000000..d0cf43a960 --- /dev/null +++ b/sca-java-1.x/tags/1.2/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/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperComponentImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperComponentImpl.java new file mode 100644 index 0000000000..ff40a7ae36 --- /dev/null +++ b/sca-java-1.x/tags/1.2/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/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperFactoryImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperFactoryImpl.java new file mode 100644 index 0000000000..ef989d6fcf --- /dev/null +++ b/sca-java-1.x/tags/1.2/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<String, Object> props1 = new Hashtable<String, Object>(); + props1.put("shipperName", "RoyalMail"); + bc.registerService(Shipper.class.getName(), this, props1); + + Hashtable<String, Object> props2 = new Hashtable<String, Object>(); + 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/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperImpl.java new file mode 100644 index 0000000000..effae8c246 --- /dev/null +++ b/sca-java-1.x/tags/1.2/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<String, Object> props1 = new Hashtable<String, Object>(); + props1.put("shipperName", "RoyalMail"); + registerService(new OSGiShipperServiceImpl(this, "RoyalMail"), + "supplychain.shipper.Shipper", props1); + + Hashtable<String, Object> props2 = new Hashtable<String, Object>(); + 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/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperServiceImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiShipperServiceImpl.java new file mode 100644 index 0000000000..4effadf208 --- /dev/null +++ b/sca-java-1.x/tags/1.2/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/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperComponentImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperComponentImpl.java new file mode 100644 index 0000000000..13bce67bb4 --- /dev/null +++ b/sca-java-1.x/tags/1.2/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/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperServiceImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiStatelessShipperServiceImpl.java new file mode 100644 index 0000000000..071a131f40 --- /dev/null +++ b/sca-java-1.x/tags/1.2/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/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperImpl.java new file mode 100644 index 0000000000..6ebd1f2894 --- /dev/null +++ b/sca-java-1.x/tags/1.2/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<String, Object> props1 = new Hashtable<String, Object>(); + props1.put("shipperName", "RoyalMail"); + props1.put("component.service.name", "ShipperComponent"+version+"/ShipperService1"); + bc.registerService("supplychain.shipper.Shipper", + new OSGiVersionedShipperServiceImpl(this, "RoyalMail", version), + props1); + + Hashtable<String, Object> props2 = new Hashtable<String, Object>(); + 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/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperServiceImpl.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/OSGiVersionedShipperServiceImpl.java new file mode 100644 index 0000000000..b66961b1c2 --- /dev/null +++ b/sca-java-1.x/tags/1.2/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/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/Shipper.java b/sca-java-1.x/tags/1.2/itest/osgi-implementation/src/main/java/supplychain/shipper/Shipper.java new file mode 100644 index 0000000000..2514928c10 --- /dev/null +++ b/sca-java-1.x/tags/1.2/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); + +} |