View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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.jdiagnose.library.web.spring;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpSession;
20  
21  import org.jdiagnose.remote.provider.SystemHolder;
22  import org.jdiagnose.remote.provider.SystemProvider;
23  import org.jdiagnose.remote.system.RemoteSystem;
24  
25  /***
26   * @author jmccrindle
27   */
28  public class DefaultProviderHelper implements ProviderHelper {
29      
30      private SystemProvider provider = null;
31      private String sessionProviderIdKey = SystemProvider.class.getName() + ".sessionProviderIdKey";
32  
33      /* (non-Javadoc)
34       * @see org.jdiagnose.library.web.spring.ProviderHelper#getRemoteSystem(javax.servlet.http.HttpServletRequest)
35       */
36      public RemoteSystem getRemoteSystem(HttpServletRequest request) {
37          return getHolder(request).getRemoteSystem();
38      }
39  
40      public void setProvider(SystemProvider provider) {
41          this.provider = provider;
42      }
43  
44      public void setSessionProviderIdKey(String sessionProviderIdKey) {
45          this.sessionProviderIdKey = sessionProviderIdKey;
46      }
47  
48      /* (non-Javadoc)
49       * @see org.jdiagnose.library.web.spring.ProviderHelper#getSystemHolder(javax.servlet.http.HttpServletRequest)
50       */
51      public SystemHolder getHolder(HttpServletRequest request) {
52          HttpSession session = request.getSession(true);
53          String providerId = (String) session.getAttribute(sessionProviderIdKey);
54          SystemHolder holder = provider.getHolder(providerId);
55          return holder;
56      }
57      
58      public void setHolder(HttpServletRequest request, String holderId) {
59          HttpSession session = request.getSession(true);
60          session.setAttribute(sessionProviderIdKey, holderId);
61      }
62  }