01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.sample.addressbook;
20:
21: import org.apache.axis2.jaxws.TestLogger;
22:
23: import java.util.ArrayList;
24: import java.util.Iterator;
25:
26: import javax.jws.WebService;
27:
28: @WebService(endpointInterface="org.apache.axis2.jaxws.sample.addressbook.AddressBook")
29: public class AddressBookImpl implements AddressBook {
30:
31: private static ArrayList<AddressBookEntry> data;
32:
33: static {
34: data = new ArrayList<AddressBookEntry>();
35:
36: ObjectFactory factory = new ObjectFactory();
37: AddressBookEntry entry = factory.createAddressBookEntry();
38: entry.setFirstName("Joe");
39: entry.setLastName("Test");
40: entry.setStreet("1214 Test Ln.");
41: entry.setCity("Austin");
42: entry.setState("TX");
43: data.add(entry);
44:
45: entry = factory.createAddressBookEntry();
46: entry.setFirstName("Sue");
47: entry.setLastName("Testfield");
48: entry.setStreet("780 1st St.");
49: entry.setCity("New York");
50: entry.setState("NY");
51: data.add(entry);
52: }
53:
54: public boolean addEntry(AddressBookEntry entry) {
55: if (entry != null) {
56: TestLogger.logger.debug("New AddressBookEntry received");
57: TestLogger.logger
58: .debug(" [name] " + entry.getLastName()
59: + ", " + entry.getFirstName());
60: TestLogger.logger
61: .debug(" [phone] " + entry.getPhone());
62: TestLogger.logger.debug(" [street] "
63: + entry.getStreet());
64: TestLogger.logger.debug("[city, state] " + entry.getCity()
65: + ", " + entry.getState());
66: data.add(entry);
67: return true;
68: } else {
69: return false;
70: }
71: }
72:
73: public AddressBookEntry findEntryByName(String firstname,
74: String lastname) {
75: TestLogger.logger.debug("New request received.");
76: TestLogger.logger.debug("Looking for entry: [" + firstname
77: + "] [" + lastname + "]");
78: Iterator<AddressBookEntry> i = data.iterator();
79: while (i.hasNext()) {
80: AddressBookEntry entry = i.next();
81:
82: //If they have a firstname and it doesn't match, just go on
83: //to the next entry.
84: if (firstname != null) {
85: if (!firstname.equals(entry.getFirstName()))
86: continue;
87: }
88:
89: if (lastname != null) {
90: if (lastname.equals(entry.getLastName()))
91: return entry;
92: }
93: }
94:
95: return null;
96: }
97:
98: }
|