KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > agentx > subagent > DefaultAgentXSharedMOTable


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentX - DefaultAgentXSharedMOTable.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## This program is free software; you can redistribute it and/or modify
8   _## it under the terms of the GNU General Public License version 2 as
9   _## published by the Free Software Foundation.
10   _##
11   _## This program is distributed in the hope that it will be useful,
12   _## but WITHOUT ANY WARRANTY; without even the implied warranty of
13   _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   _## GNU General Public License for more details.
15   _##
16   _## You should have received a copy of the GNU General Public License
17   _## along with this program; if not, write to the Free Software
18   _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19   _## MA 02110-1301 USA
20   _##
21   _##########################################################################*/

22
23 package org.snmp4j.agent.agentx.subagent;
24
25 import org.snmp4j.agent.mo.DefaultMOTable;
26 import org.snmp4j.agent.mo.MOColumn;
27 import org.snmp4j.agent.mo.MOTableIndex;
28 import org.snmp4j.smi.OID;
29 import org.snmp4j.agent.mo.MOTableModel;
30 import org.snmp4j.agent.mo.MOMutableTableModel;
31 import org.snmp4j.agent.mo.MOTableRow;
32 import org.snmp4j.agent.mo.MOTableRowEvent;
33
34 /**
35  * The <code>DefaultAgentXSharedMOTable</code> class is a default implementation
36  * for a shared table. It supports dynamic (while AgentX session is up) row
37  * creation and deletion.
38  *
39  * @author Frank Fock
40  * @version 1.0
41  */

42 public class DefaultAgentXSharedMOTable
43     extends DefaultMOTable
44     implements AgentXSharedMutableMOTable
45 {
46   private AgentXSharedMOTableSupport sharedTableSupport;
47   private byte overrideIndexAllocationMode = 0;
48   private byte overridePriority = 0;
49
50   public DefaultAgentXSharedMOTable(OID oid, MOTableIndex indexDef,
51                                     MOColumn[] columns) {
52     super(oid, indexDef, columns);
53   }
54
55   public DefaultAgentXSharedMOTable(OID oid, MOTableIndex indexDef,
56                                     MOColumn[] columns, MOTableModel model) {
57     super(oid, indexDef, columns, model);
58   }
59
60   public AgentXSharedMOTableSupport getAgentXSharedMOTableSupport() {
61     return sharedTableSupport;
62   }
63
64   public void setAgentXSharedMOTableSupport(AgentXSharedMOTableSupport
65                                             sharedTableSupport) {
66     if (this.sharedTableSupport != null) {
67       removeMOTableRowListener(this.sharedTableSupport);
68     }
69     this.sharedTableSupport =
70         new AgentXSharedMOTableSupport(sharedTableSupport.getAgentX(),
71                                        sharedTableSupport.getSession(),
72                                        sharedTableSupport.getContext(),
73                                        (overridePriority == 0) ?
74                                        sharedTableSupport.getPriority() :
75                                        overridePriority,
76                                        (overrideIndexAllocationMode == 0) ?
77                                        sharedTableSupport.getIndexMode() :
78                                        overrideIndexAllocationMode);
79     addMOTableRowListener(this.sharedTableSupport);
80   }
81
82   public byte getOverrideIndexAllocationMode() {
83     return overrideIndexAllocationMode;
84   }
85
86   public byte getOverridePriority() {
87     return overridePriority;
88   }
89
90   /**
91    * Sets the index allocation mode that overrides the allocation mode
92    * inherited from the shared table support for index allocation operations
93    * for this shared table.
94    *
95    * @param overrideIndexAllocationMode
96    * an index allocation mode as defined by
97    * {@link AgentXSharedMOTableSupport} or zero to use the default priority.
98    */

99   public void setOverrideIndexAllocationMode(byte overrideIndexAllocationMode) {
100     this.overrideIndexAllocationMode = overrideIndexAllocationMode;
101   }
102
103   /**
104    * Sets the registration priority that overrides the priority inherited from
105    * the shared table support object (if not equal zero).
106    * @param overridePriority
107    * a value between 1 and 255 (-1 respectively - its a byte) or zero which
108    * indicates that the default priority should be used.
109    */

110   public void setOverridePriority(byte overridePriority) {
111     this.overridePriority = overridePriority;
112   }
113
114   public boolean changeRowIndex(OID oldIndex, OID newIndex) {
115     if (model instanceof MOMutableTableModel) {
116       MOMutableTableModel mutableModel = (MOMutableTableModel) model;
117       MOTableRow r = mutableModel.removeRow(oldIndex);
118       if (r == null) {
119         return false;
120       }
121       r.getIndex().setValue(newIndex.getValue());
122       if (mutableModel.addRow(r) == null) {
123         r.getIndex().setValue(oldIndex.getValue());
124         mutableModel.addRow(r);
125         return false;
126       }
127       fireRowChanged(new MOTableRowEvent(this, this, r,
128                                          MOTableRowEvent.UPDATED, false));
129       return true;
130     }
131     return false;
132   }
133
134 }
135
Popular Tags