KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > ProxyForwardRequest


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - ProxyForwardRequest.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21
22 package org.snmp4j.agent;
23
24 import org.snmp4j.*;
25 import org.snmp4j.smi.*;
26 import org.snmp4j.agent.mo.snmp.SnmpProxyMIB;
27 import org.snmp4j.agent.security.VACM;
28 import org.snmp4j.agent.request.SnmpRequest;
29 import org.snmp4j.agent.mo.snmp.CoexistenceInfo;
30
31 /**
32  * To (proxy) forward a request or notification to a target, the
33  * original command responder event, the context engine ID, and context
34  * are required information. A response PDU is returned which has to
35  * be send to request originator for confirmed class PDUs.
36  *
37  * @author Frank Fock
38  * @version 1.8.3
39  */

40 public class ProxyForwardRequest {
41
42   private CommandResponderEvent commandEvent;
43   private PDU responsePDU;
44   private CoexistenceInfo coexistenceInfo;
45   private int proxyType;
46
47   public ProxyForwardRequest(CommandResponderEvent commandEvent,
48                              CoexistenceInfo coexistenceInfo) {
49     this.commandEvent = commandEvent;
50     this.coexistenceInfo = coexistenceInfo;
51     setProxyType();
52   }
53
54   public CommandResponderEvent getCommandEvent() {
55     return commandEvent;
56   }
57
58   public void setResponsePDU(PDU responsePDU) {
59     this.responsePDU = responsePDU;
60   }
61
62   public PDU getResponsePDU() {
63     return responsePDU;
64   }
65
66   public OctetString getContextEngineID() {
67     return coexistenceInfo.getContextEngineID();
68   }
69
70   public OctetString getContext() {
71     return coexistenceInfo.getContextName();
72   }
73
74   public OctetString getSecurityName() {
75     return coexistenceInfo.getSecurityName();
76   }
77
78   public CoexistenceInfo getCoexistenceInfo() {
79     return coexistenceInfo;
80   }
81
82   public int getProxyType() {
83     return proxyType;
84   }
85
86   private void setProxyType() {
87     int viewType =
88         SnmpRequest.getViewType(commandEvent.getPDU().getType());
89     switch (viewType) {
90       case VACM.VIEW_WRITE: {
91         proxyType = SnmpProxyMIB.SnmpProxyTypeEnum.write;
92         break;
93       }
94       case VACM.VIEW_NOTIFY: {
95         if (commandEvent.getPDU().getType() == PDU.INFORM) {
96           proxyType = SnmpProxyMIB.SnmpProxyTypeEnum.inform;
97         }
98         else {
99           proxyType = SnmpProxyMIB.SnmpProxyTypeEnum.trap;
100         }
101         break;
102       }
103       default: {
104         proxyType = SnmpProxyMIB.SnmpProxyTypeEnum.read;
105       }
106     }
107   }
108
109   public String JavaDoc toString() {
110     return ProxyForwardRequest.class.getName()+
111         "[coexistenceInfo="+coexistenceInfo+
112         ",proxyType="+proxyType+
113         ",commandEvent="+commandEvent+"]";
114   }
115
116 }
117
Popular Tags