001: /*_############################################################################
002: _##
003: _## SNMP4J-AgentX - DefaultAgentXSharedMOTable.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## This program is free software; you can redistribute it and/or modify
008: _## it under the terms of the GNU General Public License version 2 as
009: _## published by the Free Software Foundation.
010: _##
011: _## This program is distributed in the hope that it will be useful,
012: _## but WITHOUT ANY WARRANTY; without even the implied warranty of
013: _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: _## GNU General Public License for more details.
015: _##
016: _## You should have received a copy of the GNU General Public License
017: _## along with this program; if not, write to the Free Software
018: _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
019: _## MA 02110-1301 USA
020: _##
021: _##########################################################################*/
022:
023: package org.snmp4j.agent.agentx.subagent;
024:
025: import org.snmp4j.agent.mo.DefaultMOTable;
026: import org.snmp4j.agent.mo.MOColumn;
027: import org.snmp4j.agent.mo.MOTableIndex;
028: import org.snmp4j.smi.OID;
029: import org.snmp4j.agent.mo.MOTableModel;
030: import org.snmp4j.agent.mo.MOMutableTableModel;
031: import org.snmp4j.agent.mo.MOTableRow;
032: import org.snmp4j.agent.mo.MOTableRowEvent;
033:
034: /**
035: * The <code>DefaultAgentXSharedMOTable</code> class is a default implementation
036: * for a shared table. It supports dynamic (while AgentX session is up) row
037: * creation and deletion.
038: *
039: * @author Frank Fock
040: * @version 1.0
041: */
042: public class DefaultAgentXSharedMOTable extends DefaultMOTable
043: implements AgentXSharedMutableMOTable {
044: private AgentXSharedMOTableSupport sharedTableSupport;
045: private byte overrideIndexAllocationMode = 0;
046: private byte overridePriority = 0;
047:
048: public DefaultAgentXSharedMOTable(OID oid, MOTableIndex indexDef,
049: MOColumn[] columns) {
050: super (oid, indexDef, columns);
051: }
052:
053: public DefaultAgentXSharedMOTable(OID oid, MOTableIndex indexDef,
054: MOColumn[] columns, MOTableModel model) {
055: super (oid, indexDef, columns, model);
056: }
057:
058: public AgentXSharedMOTableSupport getAgentXSharedMOTableSupport() {
059: return sharedTableSupport;
060: }
061:
062: public void setAgentXSharedMOTableSupport(
063: AgentXSharedMOTableSupport sharedTableSupport) {
064: if (this .sharedTableSupport != null) {
065: removeMOTableRowListener(this .sharedTableSupport);
066: }
067: this .sharedTableSupport = new AgentXSharedMOTableSupport(
068: sharedTableSupport.getAgentX(), sharedTableSupport
069: .getSession(), sharedTableSupport.getContext(),
070: (overridePriority == 0) ? sharedTableSupport
071: .getPriority() : overridePriority,
072: (overrideIndexAllocationMode == 0) ? sharedTableSupport
073: .getIndexMode() : overrideIndexAllocationMode);
074: addMOTableRowListener(this .sharedTableSupport);
075: }
076:
077: public byte getOverrideIndexAllocationMode() {
078: return overrideIndexAllocationMode;
079: }
080:
081: public byte getOverridePriority() {
082: return overridePriority;
083: }
084:
085: /**
086: * Sets the index allocation mode that overrides the allocation mode
087: * inherited from the shared table support for index allocation operations
088: * for this shared table.
089: *
090: * @param overrideIndexAllocationMode
091: * an index allocation mode as defined by
092: * {@link AgentXSharedMOTableSupport} or zero to use the default priority.
093: */
094: public void setOverrideIndexAllocationMode(
095: byte overrideIndexAllocationMode) {
096: this .overrideIndexAllocationMode = overrideIndexAllocationMode;
097: }
098:
099: /**
100: * Sets the registration priority that overrides the priority inherited from
101: * the shared table support object (if not equal zero).
102: * @param overridePriority
103: * a value between 1 and 255 (-1 respectively - its a byte) or zero which
104: * indicates that the default priority should be used.
105: */
106: public void setOverridePriority(byte overridePriority) {
107: this .overridePriority = overridePriority;
108: }
109:
110: public boolean changeRowIndex(OID oldIndex, OID newIndex) {
111: if (model instanceof MOMutableTableModel) {
112: MOMutableTableModel mutableModel = (MOMutableTableModel) model;
113: MOTableRow r = mutableModel.removeRow(oldIndex);
114: if (r == null) {
115: return false;
116: }
117: r.getIndex().setValue(newIndex.getValue());
118: if (mutableModel.addRow(r) == null) {
119: r.getIndex().setValue(oldIndex.getValue());
120: mutableModel.addRow(r);
121: return false;
122: }
123: fireRowChanged(new MOTableRowEvent(this , this , r,
124: MOTableRowEvent.UPDATED, false));
125: return true;
126: }
127: return false;
128: }
129:
130: }
|