KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > MOColumn


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - MOColumn.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;
23
24 import org.snmp4j.agent.*;
25 import org.snmp4j.smi.*;
26 import org.snmp4j.agent.request.SubRequest;
27 import org.snmp4j.mp.SnmpConstants;
28
29 /**
30  * The <code>MOColumn</code> class represents columnar SMI objects. It
31  * represents all instances of a table's column not only a single instance
32  * (cell).
33  * <p>
34  * Objects represented by <code>MOColumn</code> cannot be modified via SNMP,
35  * thus <code>MOColumn</code> supports read-only maximum access only.
36  *
37  * @see MOMutableColumn
38  * @author Frank Fock
39  * @version 1.0
40  */

41 public class MOColumn implements Comparable JavaDoc {
42
43   private int columnID;
44   private int syntax;
45   private MOAccess access;
46   private MOTable table;
47
48   public MOColumn(int columnID, int syntax) {
49     this.columnID = columnID;
50     this.syntax = syntax;
51     this.access = MOAccessImpl.ACCESS_READ_ONLY;
52   }
53
54   public MOColumn(int columnID, int syntax, MOAccess access) {
55     this.columnID = columnID;
56     this.syntax = syntax;
57     if (access == null) {
58       throw new NullPointerException JavaDoc("Access must be specified");
59     }
60     this.access = access;
61   }
62
63   public void setColumnID(int columnID) {
64     this.columnID = columnID;
65   }
66
67   public void setSyntax(int syntax) {
68     this.syntax = syntax;
69   }
70
71   public void setAccess(MOAccess access) {
72     this.access = access;
73   }
74
75   /**
76    * Sets the table instance this columnar object is contained in. This method
77    * should be called by {@link MOTable} instance to register the table with
78    * the column.
79    * @param table
80    * the <code>MOTable</code> instance where this column is contained in.
81    */

82   public void setTable(MOTable table) {
83     this.table = table;
84   }
85
86   public int getColumnID() {
87     return columnID;
88   }
89
90   public int getSyntax() {
91     return syntax;
92   }
93
94   public MOAccess getAccess() {
95     return access;
96   }
97
98   public MOTable getTable() {
99     return table;
100   }
101
102   public Variable getValue(MOTableRow row, int column) {
103     return row.getValue(column);
104   }
105
106   /**
107    * Tests if the supplied row is volatile or persistent. If volatile then
108    * the row will not be saved when the table is saved to persistent storage.
109    *
110    * @param row
111    * a row of the table where this column is part of.
112    * @param column
113    * the column index of this column in <code>row</code>.
114    * @return
115    * <code>true</code> if <code>row</code> should not be
116    */

117   public boolean isVolatile(MOTableRow row, int column) {
118     return false;
119   }
120
121   /**
122    * Compares this managed object column by its ID with another column.
123    * @param column
124    * another <code>MOColumn</code>.
125    * @return int
126    * a negative integer, zero, or a positive integer as this column ID
127    * is less than, equal to, or greater than the specified object's column
128    * ID.
129    */

130   public int compareTo(Object JavaDoc column) {
131     return columnID - ((MOColumn)column).getColumnID();
132   }
133
134   public String JavaDoc toString() {
135     return this.getClass().getName()+"[columnID="+getColumnID()+",syntax="+
136         getSyntax()+"]";
137   }
138
139   public void get(SubRequest subRequest, MOTableRow row, int column) {
140     if (getAccess().isAccessibleForRead()) {
141       Variable value = getValue(row, column);
142       if (value != null) {
143         subRequest.getVariableBinding().setVariable((Variable) value.clone());
144       }
145       else {
146         subRequest.getVariableBinding().setVariable(Null.noSuchInstance);
147       }
148       subRequest.completed();
149     }
150     else {
151       subRequest.getStatus().setErrorStatus(SnmpConstants.SNMP_ERROR_NO_ACCESS);
152     }
153   }
154
155 }
156
Popular Tags