From f31b8fa6a3b9d9d356212670296c60beb468c8e5 Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 16 Mar 2010 17:57:42 +0000 Subject: Copy travelsample from 1.x to 2.x git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@923906 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/InteractionConversationClientImpl.java | 73 ++++++++++++++++++++ .../client/impl/InteractionLocalClientImpl.java | 53 +++++++++++++++ .../impl/InteractionOneWayCallbackClientImpl.java | 78 ++++++++++++++++++++++ .../client/impl/InteractionRemoteClientImpl.java | 64 ++++++++++++++++++ .../impl/InteractionRequestResponseClientImpl.java | 39 +++++++++++ .../main/resources/META-INF/sca-contribution.xml | 30 +++++++++ .../src/main/resources/client.composite | 77 +++++++++++++++++++++ 7 files changed, 414 insertions(+) create mode 100644 sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionConversationClientImpl.java create mode 100644 sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionLocalClientImpl.java create mode 100644 sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionOneWayCallbackClientImpl.java create mode 100644 sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionRemoteClientImpl.java create mode 100644 sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionRequestResponseClientImpl.java create mode 100644 sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/resources/client.composite (limited to 'sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main') diff --git a/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionConversationClientImpl.java b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionConversationClientImpl.java new file mode 100644 index 0000000000..290e6e6aee --- /dev/null +++ b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionConversationClientImpl.java @@ -0,0 +1,73 @@ +/* + * 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 scatours.client.impl; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import com.tuscanyscatours.common.TripItem; +import com.tuscanyscatours.shoppingcart.CartStore; + +@Scope("COMPOSITE") +@Service(Runnable.class) +public class InteractionConversationClientImpl implements Runnable { + + @Reference + protected CartStore cartStoreConversation; + + public void run() { + System.out.println("\nCalling cart store using the conversational interaction pattern"); + + // add some trip items to the cart store + TripItem tripItem = getTestTripItem(); + cartStoreConversation.addTrip(tripItem); + + tripItem.setDescription("2nd trip item"); + cartStoreConversation.addTrip(tripItem); + + tripItem.setDescription("3rd trip item"); + cartStoreConversation.addTrip(tripItem); + + System.out.println("Trip items now in cart"); + TripItem[] tripItems = cartStoreConversation.getTrips(); + for (TripItem item : tripItems) { + System.out.println("Item - " + item.getDescription()); + } + + System.out.println("Reset the cart"); + cartStoreConversation.reset(); + + System.out.println("Trip items now in cart"); + tripItems = cartStoreConversation.getTrips(); + for (TripItem item : tripItems) { + System.out.println("Item - " + item.getDescription()); + } + } + + private TripItem getTestTripItem() { + TripItem tripItem = new TripItem(); + tripItem.setLocation("FLR"); + tripItem.setFromDate("06/12/09 00:00"); + tripItem.setToDate("13/12/09 00:00"); + tripItem.setDescription("1st trip item"); + return tripItem; + } +} diff --git a/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionLocalClientImpl.java b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionLocalClientImpl.java new file mode 100644 index 0000000000..ca3cb2874a --- /dev/null +++ b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionLocalClientImpl.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package scatours.client.impl; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +import com.tuscanyscatours.calendar.Calendar; +import com.tuscanyscatours.common.TripLeg; + +@Service(Runnable.class) +public class InteractionLocalClientImpl implements Runnable { + + @Reference + protected Calendar calendarLocal; + + public void run() { + System.out.println("\nCalling calendar component over a local binding"); + TripLeg tripLeg = getTestTripLeg(); + String toDate = calendarLocal.getEndDate(tripLeg.getFromDate(), 10); + tripLeg.setToDate(toDate); + System.out.println("Calculated trip end date - " + toDate); + ; + } + + private TripLeg getTestTripLeg() { + TripLeg tripLeg = new TripLeg(); + tripLeg.setFromLocation("LGW"); + tripLeg.setToLocation("FLR"); + tripLeg.setFromDate("06/12/09 00:00"); + tripLeg.setToDate("13/12/09 00:00"); + tripLeg.setNoOfPeople("1"); + tripLeg.setId("TRIP27"); + return tripLeg; + } +} diff --git a/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionOneWayCallbackClientImpl.java b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionOneWayCallbackClientImpl.java new file mode 100644 index 0000000000..9689ce8e0c --- /dev/null +++ b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionOneWayCallbackClientImpl.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 scatours.client.impl; + +import java.util.concurrent.CountDownLatch; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import com.tuscanyscatours.common.Search; +import com.tuscanyscatours.common.SearchCallback; +import com.tuscanyscatours.common.TripItem; +import com.tuscanyscatours.common.TripLeg; + +@Scope("COMPOSITE") +@Service(Runnable.class) +public class InteractionOneWayCallbackClientImpl implements Runnable, SearchCallback { + + @Reference + protected Search hotelSearchOneWayCallback; + + CountDownLatch resultsReceivedCountdown; + + public void run() { + System.out.println("\nCalling hotel component using both one way and callback interation patterns"); + resultsReceivedCountdown = new CountDownLatch(1); + TripLeg tripLeg = getTestTripLeg(); + hotelSearchOneWayCallback.searchAsynch(tripLeg); + + // start other searched here while the hotel search progresses + + // wait for responses to come back + try { + resultsReceivedCountdown.await(); + } catch (InterruptedException ex) { + } + } + + public void searchResults(TripItem[] items) { + for (TripItem tripItem : items) { + System.out.println("Found hotel - " + tripItem.getName()); + } + resultsReceivedCountdown.countDown(); + } + + public void setPercentComplete(String searchComponent, int percentComplete) { + // Not used in this sample + } + + private TripLeg getTestTripLeg() { + TripLeg tripLeg = new TripLeg(); + tripLeg.setFromLocation("LGW"); + tripLeg.setToLocation("FLR"); + tripLeg.setFromDate("06/12/09 00:00"); + tripLeg.setToDate("13/12/09 00:00"); + tripLeg.setNoOfPeople("1"); + tripLeg.setId("TRIP27"); + return tripLeg; + } +} diff --git a/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionRemoteClientImpl.java b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionRemoteClientImpl.java new file mode 100644 index 0000000000..1fd9d9cbe8 --- /dev/null +++ b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionRemoteClientImpl.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 scatours.client.impl; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +import com.tuscanyscatours.common.Search; +import com.tuscanyscatours.common.SearchCallback; +import com.tuscanyscatours.common.TripItem; +import com.tuscanyscatours.common.TripLeg; + +@Service(Runnable.class) +public class InteractionRemoteClientImpl implements Runnable, SearchCallback { + + @Reference + protected Search hotelSearchRemote; + + public void run() { + System.out.println("\nCalling hotel component over a remote binding"); + TripLeg tripLeg = getTestTripLeg(); + TripItem[] tripItems = hotelSearchRemote.searchSynch(tripLeg); + for (TripItem tripItem : tripItems) { + System.out.println("Found hotel - " + tripItem.getName()); + } + } + + public void searchResults(TripItem[] items) { + // we are calling the hotel component synchronously here + // so the callback interface is not used + } + + public void setPercentComplete(String searchComponent, int percentComplete) { + // Not used in this sample + } + + private TripLeg getTestTripLeg() { + TripLeg tripLeg = new TripLeg(); + tripLeg.setFromLocation("LGW"); + tripLeg.setToLocation("FLR"); + tripLeg.setFromDate("06/12/09 00:00"); + tripLeg.setToDate("13/12/09 00:00"); + tripLeg.setNoOfPeople("1"); + tripLeg.setId("TRIP27"); + return tripLeg; + } +} diff --git a/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionRequestResponseClientImpl.java b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionRequestResponseClientImpl.java new file mode 100644 index 0000000000..d1438434ae --- /dev/null +++ b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/java/scatours/client/impl/InteractionRequestResponseClientImpl.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 scatours.client.impl; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +import com.tuscanyscatours.currencyconverter.CurrencyConverter; + +@Service(Runnable.class) +public class InteractionRequestResponseClientImpl implements Runnable { + + @Reference + protected CurrencyConverter currencyConverterRequestResponse; + + public void run() { + System.out.println("\nCalling currency converter component using request response interation pattern"); + double exchangeRate = currencyConverterRequestResponse.getExchangeRate("GBP", "USD"); + System.out.println("GBP to USD exchange rate is " + exchangeRate); + } + +} diff --git a/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/resources/META-INF/sca-contribution.xml b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..283a1588df --- /dev/null +++ b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/resources/client.composite b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/resources/client.composite new file mode 100644 index 0000000000..1c8552974b --- /dev/null +++ b/sca-java-2.x/trunk/tutorials/travelsample/contributions/interaction-client/src/main/resources/client.composite @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3