From f954cf1a6fc059e30a63ffcef953d6e40a0fd917 Mon Sep 17 00:00:00 2001 From: nash Date: Mon, 22 Mar 2010 08:03:53 +0000 Subject: Add new contribution "using" with examples for using SCA components git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@925991 13f79535-47bb-0310-9956-ffa450edef68 --- .../travelsample/contributions/using/build.xml | 22 ++++++++ .../travelsample/contributions/using/pom.xml | 56 ++++++++++++++++++++ .../java/com/tuscanyscatours/AirportCodes.java | 10 ++++ .../main/java/com/tuscanyscatours/Bookings.java | 26 +++++++++ .../src/main/java/com/tuscanyscatours/Cars.java | 27 ++++++++++ .../com/tuscanyscatours/CurrencyConverter.java | 8 +++ .../src/main/java/com/tuscanyscatours/Flights.java | 27 ++++++++++ .../src/main/java/com/tuscanyscatours/Hotels.java | 27 ++++++++++ .../tuscanyscatours/using/impl/CarPartnerImpl.java | 36 +++++++++++++ .../tuscanyscatours/using/impl/CarVendorImpl.java | 32 ++++++++++++ .../using/impl/CurrencyConverterImpl.java | 34 ++++++++++++ .../using/impl/FlightPartnerImpl.java | 31 +++++++++++ .../using/impl/HotelPartnerImpl.java | 31 +++++++++++ .../using/impl/TripBookingImpl.java | 61 ++++++++++++++++++++++ 14 files changed, 428 insertions(+) create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/build.xml create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/pom.xml create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/AirportCodes.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Bookings.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Cars.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/CurrencyConverter.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Flights.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Hotels.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CarPartnerImpl.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CarVendorImpl.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CurrencyConverterImpl.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/FlightPartnerImpl.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/HotelPartnerImpl.java create mode 100644 sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/TripBookingImpl.java (limited to 'sca-java-1.x/trunk/tutorials') diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/build.xml b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/build.xml new file mode 100644 index 0000000000..51983cf967 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/build.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/pom.xml b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/pom.xml new file mode 100644 index 0000000000..f2c7343eb7 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + scatours + 1.0-SNAPSHOT + ../../pom.xml + 1.0-SNAPSHOT + scatours-contribution-using + Apache Tuscany SCA Tours Using Components Contribution + + + + org.apache.tuscany.sca + tuscany-sca-api + ${tuscany.version} + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + ${tuscany.version} + runtime + + + + junit + junit + 4.5 + test + + + + + ${artifactId} + + diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/AirportCodes.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/AirportCodes.java new file mode 100644 index 0000000000..54826a4254 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/AirportCodes.java @@ -0,0 +1,10 @@ +package com.tuscanyscatours; + +public class AirportCodes { + public String getAirport(String code) { + if ("AAA".equals(code)) return "Anaa"; + else if ("AAB".equals(code)) return "Arrabury"; + // other airport codes and cities would follow here + else return null; + } +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Bookings.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Bookings.java new file mode 100644 index 0000000000..9d54d46bb6 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Bookings.java @@ -0,0 +1,26 @@ +/* + * 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 com.tuscanyscatours; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Bookings { + String newBooking(String trip, int people); +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Cars.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Cars.java new file mode 100644 index 0000000000..f58fa33c8d --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Cars.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.tuscanyscatours; + +import java.util.Date; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Cars { + String bookCar(Date pickup, int days, String carClass); +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/CurrencyConverter.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/CurrencyConverter.java new file mode 100644 index 0000000000..88db57a35f --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/CurrencyConverter.java @@ -0,0 +1,8 @@ +package com.tuscanyscatours; +import java.math.BigDecimal; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface CurrencyConverter { + BigDecimal convert(BigDecimal amount); +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Flights.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Flights.java new file mode 100644 index 0000000000..873b0afc0c --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Flights.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.tuscanyscatours; + +import java.util.Date; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Flights { + String bookFlight(String flightNumber, Date date, int seats, String flightClass); +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Hotels.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Hotels.java new file mode 100644 index 0000000000..85944ad1b6 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/Hotels.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.tuscanyscatours; + +import java.util.Date; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Hotels { + String bookHotel(String hotelCode, Date date, int days, String roomType); +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CarPartnerImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CarPartnerImpl.java new file mode 100644 index 0000000000..3482090405 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CarPartnerImpl.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.tuscanyscatours.using.impl; + +import java.util.Date; +import org.osoa.sca.annotations.Reference; +import com.tuscanyscatours.Cars; + +public class CarPartnerImpl implements Cars { + + @Reference + protected Cars[] cars; + + @Reference(required=false) + protected Cars[] luxuryCars; + + public String bookCar(Date pickup, int days, String carClass) { + return cars[0].bookCar(pickup, days, carClass); + } +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CarVendorImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CarVendorImpl.java new file mode 100644 index 0000000000..7b440467d2 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CarVendorImpl.java @@ -0,0 +1,32 @@ +/* + * 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 com.tuscanyscatours.using.impl; + +import java.util.Date; +import com.tuscanyscatours.Cars; + +public class CarVendorImpl implements Cars { + + public String bookCar(Date pickup, int days, String carClass) { + System.out.println("Booking confirmed for pickup date " + pickup + + " duration " + days + " days in a " + carClass + + " class car"); + return "CV234"; + } +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CurrencyConverterImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CurrencyConverterImpl.java new file mode 100644 index 0000000000..55ed3e7c55 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/CurrencyConverterImpl.java @@ -0,0 +1,34 @@ +package com.tuscanyscatours.using.impl; +import java.math.BigDecimal; +import org.osoa.sca.annotations.Property; +import com.tuscanyscatours.CurrencyConverter; + +public class CurrencyConverterImpl implements CurrencyConverter { + + @Property + protected String fromCurrency; + + @Property + protected String toCurrency; + + public BigDecimal convert(BigDecimal amount) { + return amount.multiply(getRate(toCurrency)) + .divide(getRate(fromCurrency)); + } + + private BigDecimal getRate(String currency) { + lastRate = lastRate.add(increment); // test code + return lastRate; // test code A + } + + private BigDecimal lastRate; // test code + private BigDecimal increment; // test code + + CurrencyConverterImpl() { // test code + try { + lastRate = new BigDecimal("1.1"); + increment = new BigDecimal("0.2"); + } catch (Exception e) { + } + } +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/FlightPartnerImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/FlightPartnerImpl.java new file mode 100644 index 0000000000..c5d6747a6b --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/FlightPartnerImpl.java @@ -0,0 +1,31 @@ +/* + * 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 com.tuscanyscatours.using.impl; + +import java.util.Date; +import com.tuscanyscatours.Flights; + +public class FlightPartnerImpl implements Flights { + + public String bookFlight(String flightNumber, Date date, int seats, String flightClass) { + System.out.println("Booking confirmed for flight " + flightNumber + " on date " + + date + " with " + seats + " seats in " + flightClass + " class"); + return "FP345"; + } +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/HotelPartnerImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/HotelPartnerImpl.java new file mode 100644 index 0000000000..6cca73b0d0 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/HotelPartnerImpl.java @@ -0,0 +1,31 @@ +/* + * 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 com.tuscanyscatours.using.impl; + +import java.util.Date; +import com.tuscanyscatours.Hotels; + +public class HotelPartnerImpl implements Hotels { + + public String bookHotel(String hotelCode, Date date, int days, String roomType) { + System.out.println("Booking confirmed for hotel " + hotelCode + " arriving on " + + date + " for " + days + " days in a " + roomType + " room"); + return "HP456"; + } +} diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/TripBookingImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/TripBookingImpl.java new file mode 100644 index 0000000000..670d14b3d7 --- /dev/null +++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/using/src/main/java/com/tuscanyscatours/using/impl/TripBookingImpl.java @@ -0,0 +1,61 @@ +/* + * 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 com.tuscanyscatours.using.impl; + +import java.text.DateFormat; +import java.util.Date; +import org.osoa.sca.annotations.Reference; + +import com.tuscanyscatours.Bookings; +import com.tuscanyscatours.Cars; +import com.tuscanyscatours.Flights; +import com.tuscanyscatours.Hotels; + +public class TripBookingImpl implements Bookings { + + TripBookingImpl(@Reference(name="cars") Cars cars) { + this.cars = cars; + } + + protected Cars cars; + + @Reference + protected Flights flights; + + private Hotels hotels; + + @Reference + public void setHotels(Hotels hotels) { + this.hotels = hotels; + } + + public String newBooking(String trip, int people) { + Date startDate = null; + try { + startDate = DateFormat.getInstance().parse("07/07/2012"); + } catch (Exception e) { + } + + cars.bookCar(startDate, 7, "B"); + flights.bookFlight("AA123", startDate, people, "Y"); + hotels.bookHotel("DBH", startDate, 7, "SUP"); + + return "HW3546"; + } +} -- cgit v1.2.3