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 java.util.HashMap;
19  import java.util.Map;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.jdiagnose.remote.provider.SystemHolder;
25  import org.jdiagnose.remote.provider.SystemProvider;
26  import org.jdiagnose.remote.system.RemoteAgent;
27  import org.jdiagnose.remote.system.RemoteAgentAtHost;
28  import org.jdiagnose.remote.system.RemoteHost;
29  import org.jdiagnose.remote.system.RemoteSystem;
30  import org.springframework.web.servlet.ModelAndView;
31  import org.springframework.web.servlet.mvc.ParameterizableViewController;
32  
33  /***
34   * @author jmccrindle
35   */
36  public class RemoteSystemController extends ParameterizableViewController {
37  
38      private SystemProvider provider = null;
39      
40      /* (non-Javadoc)
41       * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
42       */
43      protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
44          
45          String host = request.getParameter("host");
46          String agent = request.getParameter("agent");
47          String diagnostic = request.getParameter("diagnostic");
48          String systemParam = request.getParameter("system");
49  
50          SystemHolder holder = provider.getHolder(systemParam);
51          RemoteSystem remoteSystem = holder.getRemoteSystem();
52  
53          Map model = new HashMap();
54          RemoteHost remoteHost = host != null ? remoteSystem.getHost(host) : null;
55          RemoteAgent remoteAgent = agent != null ? remoteSystem.getAgent(agent) : null;
56  
57          if(host != null) {
58              model.put("host", remoteHost);
59          }
60  
61          if(agent != null) {
62              model.put("agent", remoteAgent);
63          }
64          
65          if(host != null && agent != null && remoteHost != null) {
66              RemoteAgentAtHost remoteAgentAtHost = remoteHost.getAgent(agent);
67              model.put("agentAtHost", remoteAgentAtHost);
68              if(diagnostic != null && remoteAgentAtHost != null) {
69                  model.put("diagnostic", remoteAgentAtHost.getDiagnostic(diagnostic));
70              }
71          }
72  
73          model.put("systemHolder", holder);
74          model.put("system", remoteSystem);
75          return new ModelAndView(getViewName(), model);
76      }
77  
78      public void setProvider(SystemProvider provider) {
79          this.provider = provider;
80      }
81  
82  }