001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package inout.wsiftypes;
059:
060: import inout.wsifservice.Inout;
061: import java.util.Date;
062: import java.util.Hashtable;
063: import java.util.Iterator;
064:
065: import util.AddressUtility;
066:
067: import addressbook.wsiftypes.Address;
068: import addressbook.wsiftypes.Phone;
069:
070: /**
071: * Inout service used by InoutTest for various miscelleanous tests.
072: * @author Mark Whitlock
073: */
074: public class InoutImpl implements Inout {
075: private Hashtable name2AddressTable = new Hashtable();
076:
077: public InoutImpl() {
078: addEntry("John B. Good", new Address(123, "Main Street",
079: "Anytown", "NY", 12345, new Phone(123, "456", "7890")));
080: addEntry("Bob Q. Public", new Address(456, "North Whatever",
081: "Notown", "ME", 12424, new Phone(987, "444", "5566")));
082: }
083:
084: public void addEntry(String name, Address address) {
085: if (name != null && address != null)
086: name2AddressTable.put(name, address);
087: }
088:
089: public void addEntry(String firstName, String lastName,
090: Address address) {
091: if (firstName != null && lastName != null && address != null)
092: name2AddressTable.put(firstName + " " + lastName, address);
093: }
094:
095: public Address getAddressFromName(String name)
096: throws IllegalArgumentException {
097: if (name == null)
098: return null;
099: return getAddressFromName(new Mutablestring(name));
100: }
101:
102: public Address getAddressFromName(Mutablestring name)
103: throws IllegalArgumentException {
104: if (name == null)
105: return null;
106:
107: String found = null;
108: int star = name.toString().indexOf("*");
109: if (star != -1) {
110: String trimmed = name.toString().substring(0, star);
111: Iterator it = name2AddressTable.keySet().iterator();
112: while (it.hasNext()) {
113: String key = (String) it.next();
114: if (key.startsWith(trimmed)) {
115: found = key;
116: break;
117: }
118: }
119:
120: if (found == null)
121: throw new IllegalArgumentException("Couldn't find "
122: + name + " trimmed=" + trimmed);
123: } else
124: found = name.toString();
125:
126: return (Address) name2AddressTable.get(found);
127: }
128:
129: public boolean getAddressFromName(Mutablestring name, Address addr)
130: throws IllegalArgumentException {
131: Address newAddr = getAddressFromName(name);
132: if (newAddr == null)
133: return false;
134: AddressUtility addrUtil = new AddressUtility(newAddr);
135: addrUtil.copy(addr);
136: return true;
137: }
138:
139: public int addNumbers(int[] nums) {
140: int result = 0;
141: for (int i = 0; i < nums.length; i++)
142: result += nums[i];
143: return result;
144: }
145:
146: public Date getDate() {
147: return new Date();
148: }
149:
150: public String whoami(String s) {
151: return new String("String");
152: }
153:
154: public String whoami(float f) {
155: return new String("float");
156: }
157:
158: public String whoami(int i) {
159: return new String("int");
160: }
161:
162: public String whoami(Address a) {
163: return new String("Address");
164: }
165: }
|