KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > snmp > CoexistenceInfo


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - CoexistenceInfo.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.mo.snmp;
23
24 import org.snmp4j.smi.*;
25
26 /**
27  * A coexistence information object has attributes needed to map messages
28  * between different versions of the SNMP protocol. A good portion of those
29  * attributes are from the SNMP-COMMUNITY-MIB.
30  *
31  * @author Frank Fock
32  * @version 1.0
33  */

34 public class CoexistenceInfo implements Comparable JavaDoc {
35
36   private OctetString securityName;
37   private OctetString contextEngineID;
38   private OctetString contextName;
39   private OctetString transportTag;
40   private int maxMessageSize = Integer.MAX_VALUE;
41
42   /**
43    * Creates an context info object based on a security name, context engine ID,
44    * and context name. The transport tag is not defined (= <code>null</code>).
45    *
46    * @param securityName
47    * a security name.
48    * @param contextEngineID
49    * a context engine ID.
50    * @param contextName
51    * a context name
52    */

53   public CoexistenceInfo(OctetString securityName,
54                          OctetString contextEngineID,
55                          OctetString contextName) {
56     this.securityName = securityName;
57     this.contextEngineID = contextEngineID;
58     this.contextName = contextName;
59   }
60
61   /**
62    * Creates an context info object based on a security name, context engine ID,
63    * context name, and transport tag.
64    *
65    * @param securityName
66    * a security name.
67    * @param contextEngineID
68    * a context engine ID.
69    * @param contextName
70    * a context name
71    * @param transportTag
72    * a tag identifying the transport within the SNMP-TARGET-MIB that is
73    * associated with the SNMP message on behalf of which this coexistence
74    * information is created.
75    */

76   public CoexistenceInfo(OctetString securityName,
77                          OctetString contextEngineID,
78                          OctetString contextName,
79                          OctetString transportTag) {
80     this(securityName, contextEngineID, contextName);
81     this.transportTag = transportTag;
82   }
83
84   public void setTransportTag(OctetString transportTag) {
85     this.transportTag = transportTag;
86   }
87
88   public void setMaxMessageSize(int maxMessageSize) {
89     this.maxMessageSize = maxMessageSize;
90   }
91
92   public OctetString getSecurityName() {
93     return securityName;
94   }
95
96   public OctetString getContextEngineID() {
97     return contextEngineID;
98   }
99
100   public OctetString getContextName() {
101     return contextName;
102   }
103
104   public OctetString getTransportTag() {
105     return transportTag;
106   }
107
108   public int getMaxMessageSize() {
109     return maxMessageSize;
110   }
111
112   public String JavaDoc toString() {
113     return "CoexistenceInfo[securityName="+getSecurityName()+
114         ",contextEngineID="+getContextEngineID()+
115         ",contextName="+getContextName()+
116         ",transportTag="+getTransportTag()+"]";
117   }
118
119   public boolean equals(Object JavaDoc o) {
120     if (o instanceof CoexistenceInfo) {
121       return (compareTo(o) == 0);
122     }
123     return false;
124   }
125
126   public int hashCode() {
127     return securityName.hashCode();
128   }
129
130   /**
131    * Compares this object with the specified object for order.
132    *
133    * @param o the Object to be compared.
134    * @return a negative integer, zero, or a positive integer as this object is
135    * less than, equal to, or greater than the specified object.
136    */

137   public int compareTo(Object JavaDoc o) {
138     CoexistenceInfo other = (CoexistenceInfo)o;
139     int c = other.getSecurityName().compareTo(getSecurityName());
140     if (c == 0) {
141       c = other.getContextEngineID().compareTo(getContextEngineID());
142     }
143     if (c == 0) {
144       c = other.getContextName().compareTo(getContextName());
145     }
146     return c;
147   }
148 }
149
Popular Tags