diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-26 22:10:11 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-26 22:10:11 +0000 |
commit | e320d6586edc59f6518776b307413ba94588a3b1 (patch) | |
tree | 3bd56918add6c7ced8efd8f55feb9de70f5bf2a0 /sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java | |
parent | a03fb0ee873ee7dc199381a0fad10ea707198f4e (diff) |
Store scenario using JAX-RS from Apache Wink
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@903450 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java')
5 files changed, 209 insertions, 0 deletions
diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Catalog.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Catalog.java new file mode 100644 index 0000000000..635c34c316 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Catalog.java @@ -0,0 +1,40 @@ +/* + * 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 services; + +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Produces(MediaType.APPLICATION_JSON) +public interface Catalog { + @GET + @Produces(MediaType.APPLICATION_JSON) + List<Item> get(); + + @GET + @Path("{id}") + @Produces(MediaType.APPLICATION_JSON) + Item get(@PathParam("id") String id); +} diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverter.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverter.java new file mode 100644 index 0000000000..ed0e99f27a --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverter.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 services; + +public interface CurrencyConverter { + + public double getConversion(String fromCurrenycCode, String toCurrencyCode, double amount); + + public String getCurrencySymbol(String currencyCode); +} diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverterImpl.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverterImpl.java new file mode 100644 index 0000000000..1498f0f643 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/CurrencyConverterImpl.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 services; + +public class CurrencyConverterImpl implements CurrencyConverter { + + public double getConversion(String fromCurrencyCode, String toCurrencyCode, double amount) { + if (toCurrencyCode.equals("USD")) + return amount; + else if (toCurrencyCode.equals("EUR")) + return ((double)Math.round(amount * 0.7256 * 100)) /100; + return 0; + } + + public String getCurrencySymbol(String currencyCode) { + if (currencyCode.equals("USD")) + return "$"; + else if (currencyCode.equals("EUR")) + return "E"; //"€"; + return "?"; + } +} diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/FruitsCatalogImpl.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/FruitsCatalogImpl.java new file mode 100644 index 0000000000..1287edf149 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/FruitsCatalogImpl.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 services; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.Path; + +@Path("catalog") +public class FruitsCatalogImpl implements Catalog { + public String currencyCode = "USD"; + + public CurrencyConverter currencyConverter = new CurrencyConverterImpl(); + + private List<Item> catalog = new ArrayList<Item>(); + + public FruitsCatalogImpl() { + init(); + } + + public void init() { + String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode); + catalog.add(new Item("Apple", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99))); + catalog.add(new Item("Orange", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55))); + catalog.add(new Item("Pear", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55))); + } + + public List<Item> get() { + return catalog; + } + + public Item get(String id) { + throw new UnsupportedOperationException("Not yet implemented."); + } +} diff --git a/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Item.java b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Item.java new file mode 100644 index 0000000000..fe32cfc828 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/store-jaxrs/src/main/java/services/Item.java @@ -0,0 +1,50 @@ +/* + * 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 services; + +public class Item { + private String name; + private String price; + + public Item() { + } + + public Item(String name, String price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + +} |