diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-22 14:34:30 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-22 14:34:30 +0000 |
commit | d2a69e96416b2d8380743e443cebc03c87c6bf3c (patch) | |
tree | e2388bbcfe4162566129e7ea6b115127ca2d96f6 /sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer | |
parent | dbc0816ae90e3d07f8d039fa491be5e432e8f9d3 (diff) |
Add some exception handling to the customer registry
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@757191 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
3 files changed, 72 insertions, 5 deletions
diff --git a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerNotFoundException.java b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerNotFoundException.java new file mode 100644 index 0000000000..ebfb104650 --- /dev/null +++ b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerNotFoundException.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 scatours.customer; + + +public class CustomerNotFoundException extends Exception { + private static final long serialVersionUID = -129752837478357452L; + + /** + * + */ + public CustomerNotFoundException() { + + } + + /** + * @param message + */ + public CustomerNotFoundException(String message) { + super(message); + + } + + /** + * @param cause + */ + public CustomerNotFoundException(Throwable cause) { + super(cause); + + } + + /** + * @param message + * @param cause + */ + public CustomerNotFoundException(String message, Throwable cause) { + super(message, cause); + + } + +} diff --git a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistry.java b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistry.java index 0a23f6a81a..c7c9f11a6c 100644 --- a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistry.java +++ b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistry.java @@ -31,7 +31,7 @@ public interface CustomerRegistry { boolean updateCustomer(Customer customer); - Customer getCustomer(String id); + Customer getCustomer(String id) throws CustomerNotFoundException; Collection<Customer> getAllCustomers(); diff --git a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistryImpl.java b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistryImpl.java index 8a55e43fc5..615f0ef1b9 100644 --- a/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistryImpl.java +++ b/sandbox/travelsample/shared-contributions/payment-java-contribution/src/main/java/scatours/customer/CustomerRegistryImpl.java @@ -85,15 +85,24 @@ public class CustomerRegistryImpl implements CustomerRegistry { return customers.values(); } - public Customer getCustomer(String id) { - return customers.get(id); + public Customer getCustomer(String id) throws CustomerNotFoundException { + Customer customer = customers.get(id); + + if (customer == null){ + throw new CustomerNotFoundException("Customer " + id + " not found"); + } + + return customer; } public boolean updateCustomer(Customer customer) { - Customer current = getCustomer(customer.getId()); - if (current == null) { + Customer current = null; + try { + current = getCustomer(customer.getId()); + } catch (Exception ex) { return false; } + current.setEmail(customer.getEmail()); current.setName(customer.getName()); current.setCreditCard(customer.getCreditCard()); |