summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl')
-rw-r--r--sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CarPartnerImpl.java36
-rw-r--r--sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CarVendorImpl.java34
-rw-r--r--sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CurrencyConverterImpl.java45
-rw-r--r--sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CustomerImpl.java47
-rw-r--r--sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/FlightPartnerImpl.java31
-rw-r--r--sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/HotelPartnerImpl.java31
-rw-r--r--sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/TripBookingImpl.java73
7 files changed, 297 insertions, 0 deletions
diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CarPartnerImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CarPartnerImpl.java
new file mode 100644
index 0000000000..687fc49230
--- /dev/null
+++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/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/usingsca/src/main/java/com/tuscanyscatours/using/impl/CarVendorImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CarVendorImpl.java
new file mode 100644
index 0000000000..f8644bab2c
--- /dev/null
+++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CarVendorImpl.java
@@ -0,0 +1,34 @@
+/*
+ * 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 {
+
+ protected int minAge; // implicitly defines an SCA property
+
+ 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/usingsca/src/main/java/com/tuscanyscatours/using/impl/CurrencyConverterImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CurrencyConverterImpl.java
new file mode 100644
index 0000000000..3749221aa9
--- /dev/null
+++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CurrencyConverterImpl.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 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), 2, 0);
+ }
+
+ private BigDecimal getRate(String currency) {
+ int rate = 0;
+ for (int i = 0; i < currency.length(); i++) {
+ rate += currency.codePointAt(i);
+ }
+ return new BigDecimal(rate).divide(new BigDecimal(100));
+ }
+}
diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CustomerImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CustomerImpl.java
new file mode 100644
index 0000000000..84ca6c7593
--- /dev/null
+++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/CustomerImpl.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 com.tuscanyscatours.using.impl;
+
+import org.osoa.sca.annotations.Property;
+import com.tuscanyscatours.Address;
+import com.tuscanyscatours.BillingAddress;
+import com.tuscanyscatours.CustomerInfo;
+
+public class CustomerImpl implements CustomerInfo {
+
+ @Property
+ protected BillingAddress billingAddress;
+
+ @Property
+ protected Address deliveryAddress;
+
+ public String getBillingAddress() {
+ return billingAddress.getStreet() + ", " +
+ billingAddress.getCity() + ", " +
+ billingAddress.getState() + " " +
+ billingAddress.getZip();
+ }
+
+ public String getDeliveryAddress() {
+ return deliveryAddress.getStreet() + ", " +
+ deliveryAddress.getCity() + ", " +
+ deliveryAddress.getState() + " " +
+ deliveryAddress.getZip();
+ }
+}
diff --git a/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/FlightPartnerImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/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/usingsca/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/usingsca/src/main/java/com/tuscanyscatours/using/impl/HotelPartnerImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/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/usingsca/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/usingsca/src/main/java/com/tuscanyscatours/using/impl/TripBookingImpl.java b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/TripBookingImpl.java
new file mode 100644
index 0000000000..9d81a0d4ed
--- /dev/null
+++ b/sca-java-1.x/trunk/tutorials/travelsample/contributions/usingsca/src/main/java/com/tuscanyscatours/using/impl/TripBookingImpl.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 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 {
+
+ public 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) {
+ /* In a real implementation this method would look up the trip code
+ in the travel catalog to get details of the car, flight and hotel
+ bookings needed. Instead these details are hard-wired here for
+ test purposes. */
+ Date startDate = new Date(); //TEMP - need to fix
+ /*
+ try {
+ startDate = DateFormat.getInstance().parse("7 Jul, 2012");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ */
+
+ if (people > 0) {
+ cars.bookCar(startDate, 7, "B");
+ flights.bookFlight("AA123", startDate, people, "Y");
+ hotels.bookHotel("DBH", startDate, 7, "SUP");
+
+ return "HW3546";
+
+ } else {
+ return "NONE";
+ }
+ }
+}