View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.testclient1;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.concurrent.ConcurrentHashMap;
22  import java.util.concurrent.atomic.AtomicInteger;
23  
24  import org.apache.cxf.message.Message;
25  import org.apache.cxf.phase.PhaseInterceptorChain;
26  import org.kuali.rice.ksb.messaging.remotedservices.BaseballCard;
27  import org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService;
28  import org.kuali.rice.ksb.messaging.remotedservices.ServiceCallInformationHolder;
29  
30  import javax.annotation.Resource;
31  import javax.ws.rs.core.Context;
32  import javax.ws.rs.core.HttpHeaders;
33  import javax.xml.ws.WebServiceContext;
34  
35  /**
36   * Implementation for {@link BaseballCardCollectionService}
37   * 
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   *
40   */
41  public class BaseballCardCollectionServiceImpl implements BaseballCardCollectionService {
42      // annotations on impl not supported by RESTServiceExporter/RestServiceDefinition
43      // @Context HttpHeaders headers;
44  
45      private Map<Integer, BaseballCard> cards = new ConcurrentHashMap<Integer, BaseballCard>();
46      private AtomicInteger nextId = new AtomicInteger(1);
47      
48      /**
49       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#add(org.kuali.rice.ksb.messaging.remotedservices.BaseballCard)
50       */
51      public Integer add(BaseballCard card) {
52          Integer result = null;
53          if (card != null) {
54              int id = nextId.addAndGet(1);
55              cards.put(id, card);
56              result = id;
57          }
58          return result;
59      }
60  
61      /**
62       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#delete(java.lang.Integer)
63       */
64      public void delete(Integer id) {
65          cards.remove(id);
66      }
67  
68      /**
69       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#get(java.lang.Integer)
70       */
71      public BaseballCard get(Integer id) {
72          return cards.get(id);
73      }
74  
75      /**
76       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#get(java.lang.String)
77       */
78      public List<BaseballCard> get(String playerName) {
79          List<BaseballCard> results = new ArrayList<BaseballCard>();
80          for (BaseballCard card : cards.values()) {
81              if (playerName.equals(card.getPlayerName())) results.add(card);
82          }
83          return results;
84      }
85  
86      /**
87       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#getAll()
88       */
89      public List<BaseballCard> getAll() {
90          // excuse me while we exploit this service to test service call version headers
91          // annotations on impl not supported by RESTServiceExporter/RestServiceDefinition
92          //ServiceCallInformationHolder.stuff.put("capturedHeaders", headers.getRequestHeaders());
93          ServiceCallInformationHolder.stuff.put("capturedHeaders", PhaseInterceptorChain.getCurrentMessage().get(Message.PROTOCOL_HEADERS));
94          return new ArrayList<BaseballCard>(cards.values());
95      }
96  
97      /**
98       * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#update(java.lang.Integer, org.kuali.rice.ksb.messaging.remotedservices.BaseballCard)
99       */
100     public void update(Integer id, BaseballCard card) {
101         cards.put(id, card);
102     }
103     
104     /**
105      * This method lacks JAX-RS annotations in the {@link BaseballCardCollectionService} interface
106      * 
107      * @see org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService#unannotatedMethod()
108      */
109     public void unannotatedMethod() {
110         // do nothing
111     }
112 
113 }