001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.customer.book;
019:
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.Map;
023:
024: import javax.jws.WebService;
025:
026: @WebService(endpointInterface="org.apache.cxf.customer.book.BookService")
027: public class BookServiceImpl implements BookService {
028: long currentId = 1;
029: Map books = new HashMap();
030:
031: @SuppressWarnings("unchecked")
032: public BookServiceImpl() {
033: Book book = createBook();
034: System.out.println("Enregistre Book de id " + book.getId());
035: books.put(book.getId(), book);
036: }
037:
038: @SuppressWarnings("unchecked")
039: public Books getBooks() {
040: for (Iterator iter = books.entrySet().iterator(); iter
041: .hasNext();) {
042: Map.Entry me = (Map.Entry) iter.next();
043: System.out.println("getBooks -> " + me.getKey() + " : "
044: + me.getValue());
045: }
046: Books b = new Books();
047: b.setBooks((Book[]) books.values().toArray(
048: new Book[books.size()]));
049: return b;
050: }
051:
052: public Book getBook(GetBook getBook) throws BookNotFoundFault {
053: for (Iterator iter = books.entrySet().iterator(); iter
054: .hasNext();) {
055: Map.Entry me = (Map.Entry) iter.next();
056: System.out.println("getBook -> " + me.getKey() + " : "
057: + ((Book) me.getValue()).getName() + ", "
058: + ((Book) me.getValue()).getId());
059: }
060: System.out.println("Book de id " + getBook.getId());
061: Book b = (Book) books.get(((Long) getBook.getId()).longValue());
062:
063: if (b == null) {
064: BookNotFoundDetails details = new BookNotFoundDetails();
065: details.setId(getBook.getId());
066: throw new BookNotFoundFault(details);
067: }
068: return b;
069: }
070:
071: public Book getAnotherBook(GetAnotherBook getAnotherBook)
072: throws BookNotFoundFault {
073: for (Iterator iter = books.entrySet().iterator(); iter
074: .hasNext();) {
075: Map.Entry me = (Map.Entry) iter.next();
076: System.out.println("getBook -> " + me.getKey() + " : "
077: + ((Book) me.getValue()).getName() + ", "
078: + ((Book) me.getValue()).getId());
079: }
080: System.out.println("Book de id " + getAnotherBook.getId());
081: Book b = (Book) books.get(((Long) getAnotherBook.getId())
082: .longValue());
083:
084: if (b == null) {
085: BookNotFoundDetails details = new BookNotFoundDetails();
086: details.setId(getAnotherBook.getId());
087: throw new BookNotFoundFault(details);
088: }
089: return b;
090: }
091:
092: @SuppressWarnings("unchecked")
093: public void updateBook(Book b) {
094: books.put(b.getId(), b);
095: for (Iterator iter = books.entrySet().iterator(); iter
096: .hasNext();) {
097: Map.Entry me = (Map.Entry) iter.next();
098: System.out.println("updateBook -> " + me.getKey() + " : "
099: + me.getValue());
100: }
101: }
102:
103: @SuppressWarnings("unchecked")
104: public long addBook(Book b) {
105: long id = ++currentId;
106: System.out.println("addBook : " + b.getName());
107: b.setId(id);
108: books.put(id, b);
109: for (Iterator iter = books.entrySet().iterator(); iter
110: .hasNext();) {
111: Map.Entry me = (Map.Entry) iter.next();
112: System.out.println("addBook -> " + me.getKey() + " : "
113: + ((Book) me.getValue()).getName() + ", "
114: + ((Book) me.getValue()).getId());
115: }
116:
117: return b.getId();
118: }
119:
120: public void deleteBook(long id) {
121: books.remove(id);
122: for (Iterator iter = books.entrySet().iterator(); iter
123: .hasNext();) {
124: Map.Entry me = (Map.Entry) iter.next();
125: System.out.println("deleteBook -> " + me.getKey() + " : "
126: + me.getValue());
127: }
128: }
129:
130: final Book createBook() {
131: Book b = new Book();
132: b.setName("CXF in Action");
133: b.setId(123);
134: return b;
135: }
136: }
|