001: /*_############################################################################
002: _##
003: _## SNMP4J-Agent - MOColumn.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j.agent.mo;
022:
023: import org.snmp4j.agent.*;
024: import org.snmp4j.smi.*;
025: import org.snmp4j.agent.request.SubRequest;
026: import org.snmp4j.mp.SnmpConstants;
027:
028: /**
029: * The <code>MOColumn</code> class represents columnar SMI objects. It
030: * represents all instances of a table's column not only a single instance
031: * (cell).
032: * <p>
033: * Objects represented by <code>MOColumn</code> cannot be modified via SNMP,
034: * thus <code>MOColumn</code> supports read-only maximum access only.
035: *
036: * @see MOMutableColumn
037: * @author Frank Fock
038: * @version 1.0
039: */
040: public class MOColumn implements Comparable {
041:
042: private int columnID;
043: private int syntax;
044: private MOAccess access;
045: private MOTable table;
046:
047: public MOColumn(int columnID, int syntax) {
048: this .columnID = columnID;
049: this .syntax = syntax;
050: this .access = MOAccessImpl.ACCESS_READ_ONLY;
051: }
052:
053: public MOColumn(int columnID, int syntax, MOAccess access) {
054: this .columnID = columnID;
055: this .syntax = syntax;
056: if (access == null) {
057: throw new NullPointerException("Access must be specified");
058: }
059: this .access = access;
060: }
061:
062: public void setColumnID(int columnID) {
063: this .columnID = columnID;
064: }
065:
066: public void setSyntax(int syntax) {
067: this .syntax = syntax;
068: }
069:
070: public void setAccess(MOAccess access) {
071: this .access = access;
072: }
073:
074: /**
075: * Sets the table instance this columnar object is contained in. This method
076: * should be called by {@link MOTable} instance to register the table with
077: * the column.
078: * @param table
079: * the <code>MOTable</code> instance where this column is contained in.
080: */
081: public void setTable(MOTable table) {
082: this .table = table;
083: }
084:
085: public int getColumnID() {
086: return columnID;
087: }
088:
089: public int getSyntax() {
090: return syntax;
091: }
092:
093: public MOAccess getAccess() {
094: return access;
095: }
096:
097: public MOTable getTable() {
098: return table;
099: }
100:
101: public Variable getValue(MOTableRow row, int column) {
102: return row.getValue(column);
103: }
104:
105: /**
106: * Tests if the supplied row is volatile or persistent. If volatile then
107: * the row will not be saved when the table is saved to persistent storage.
108: *
109: * @param row
110: * a row of the table where this column is part of.
111: * @param column
112: * the column index of this column in <code>row</code>.
113: * @return
114: * <code>true</code> if <code>row</code> should not be
115: */
116: public boolean isVolatile(MOTableRow row, int column) {
117: return false;
118: }
119:
120: /**
121: * Compares this managed object column by its ID with another column.
122: * @param column
123: * another <code>MOColumn</code>.
124: * @return int
125: * a negative integer, zero, or a positive integer as this column ID
126: * is less than, equal to, or greater than the specified object's column
127: * ID.
128: */
129: public int compareTo(Object column) {
130: return columnID - ((MOColumn) column).getColumnID();
131: }
132:
133: public String toString() {
134: return this .getClass().getName() + "[columnID=" + getColumnID()
135: + ",syntax=" + getSyntax() + "]";
136: }
137:
138: public void get(SubRequest subRequest, MOTableRow row, int column) {
139: if (getAccess().isAccessibleForRead()) {
140: Variable value = getValue(row, column);
141: if (value != null) {
142: subRequest.getVariableBinding().setVariable(
143: (Variable) value.clone());
144: } else {
145: subRequest.getVariableBinding().setVariable(
146: Null.noSuchInstance);
147: }
148: subRequest.completed();
149: } else {
150: subRequest.getStatus().setErrorStatus(
151: SnmpConstants.SNMP_ERROR_NO_ACCESS);
152: }
153: }
154:
155: }
|