KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > CommunityTarget


1 /*_############################################################################
2   _##
3   _## SNMP4J - CommunityTarget.java
4   _##
5   _## Copyright 2003-2007 Frank Fock and Jochen Katz (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
23
24
25 package org.snmp4j;
26
27 import org.snmp4j.smi.OctetString;
28 import org.snmp4j.smi.Address;
29 import org.snmp4j.mp.SnmpConstants;
30
31 /**
32  * A <code>CommunityTarget</code> represents SNMP target properties for
33  * community based message processing models (SNMPv1 and SNMPv2c).
34  * @author Frank Fock
35  * @version 1.1
36  */

37 public class CommunityTarget extends AbstractTarget {
38
39   static final long serialVersionUID = 147443821594052003L;
40
41   private org.snmp4j.smi.OctetString community = new OctetString();
42
43   /**
44    * Default constructor.
45    */

46   public CommunityTarget() {
47     setVersion(SnmpConstants.version1);
48   }
49
50   /**
51    * Creates a fully specified communtity target.
52    * @param address
53    * the transport <code>Address</code> of the target.
54    * @param community
55    * the community to be used for the target.
56    */

57   public CommunityTarget(Address address, OctetString community) {
58     super(address);
59     setVersion(SnmpConstants.version1);
60     setCommunity(community);
61   }
62
63   /**
64    * Gets the community octet string.
65    * @return
66    * an <code>OctetString</code> instance, never <code>null</code>.
67    */

68   public OctetString getCommunity() {
69     return community;
70   }
71
72   /**
73    * Sets the community octet sting.
74    * @param community
75    * an <code>OctetString</code> instance which must not be
76    * <code>null</code>.
77    */

78   public void setCommunity(OctetString community) {
79     if (community == null) {
80       throw new IllegalArgumentException JavaDoc("Community must not be null");
81     }
82     this.community = community;
83   }
84
85   public String JavaDoc toString() {
86     return "CommunityTarget["+toStringAbstractTarget()+
87         ", community="+community+"]";
88   }
89
90 }
91
Popular Tags