KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - DefaultMOMutableRow2PC.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.request.*;
25 import org.snmp4j.smi.*;
26 import org.snmp4j.agent.mo.DefaultMOTable.ChangeSet;
27
28 public class DefaultMOMutableRow2PC extends DefaultMOTableRow
29     implements MOMutableRow2PC {
30
31   private MOTableRow baseRow;
32   private Object JavaDoc userObject;
33
34   public DefaultMOMutableRow2PC(OID index, Variable[] values) {
35     super(index, values);
36   }
37
38   public void cleanup(SubRequest subRequest, int column) {
39     subRequest.completed();
40   }
41
42   public void commit(SubRequest subRequest, MOTableRow changeSet, int column) {
43     subRequest.setUndoValue(values[column]);
44     setValue(column,
45              (Variable) subRequest.getVariableBinding().getVariable().clone());
46     subRequest.completed();
47   }
48
49   public MOTableRow getBaseRow() {
50     return baseRow;
51   }
52
53   public OID getIndex() {
54     return index;
55   }
56
57   public Object JavaDoc getUserObject() {
58     return userObject;
59   }
60
61   public Variable getValue(int column) {
62     return values[column];
63   }
64
65   public void setBaseRow(MOTableRow baseRow) {
66     this.baseRow = baseRow;
67   }
68
69   public void setUserObject(Object JavaDoc userObject) {
70     this.userObject = userObject;
71   }
72
73   public void setValue(int column, Variable value) {
74     values[column] = value;
75   }
76
77   public int size() {
78     return values.length;
79   }
80
81   public void undo(SubRequest subRequest, int column) {
82     if (subRequest.getUndoValue() instanceof Variable) {
83       setValue(column, (Variable) subRequest.getUndoValue());
84     }
85     subRequest.completed();
86   }
87
88   /**
89    * Returns the value of the specified column that would result if the
90    * specified changes would have been applied to the row.
91    * @param column
92    * the column to return
93    * @param changes
94    * a <code>MOTableRow</code> instance representing the changes to apply
95    * to this row. Values that are not changed must be returned as
96    * <code>null</code> values.
97    * @return
98    * the resulting <code>Variable</code>.
99    */

100   public Variable getResultingValue(int column, MOTableRow changes) {
101     Variable retval = changes.getValue(column);
102     if (retval == null) {
103       retval = getValue(column);
104     }
105     return retval;
106   }
107
108   public void commitRow(SubRequest subRequest, MOTableRow changeSet) {
109     // overwrite this to perform actions when a row has been committed.
110
}
111
112   public void prepare(SubRequest subRequest, MOTableRow changeSet, int column) {
113   }
114
115   public void cleanupRow(SubRequest request, ChangeSet changeSet) {
116   }
117
118   public void undoRow(SubRequest request, ChangeSet changeSet) {
119   }
120
121   public void prepareRow(SubRequest subRequest, MOTableRow changeSet) {
122   }
123
124   public String JavaDoc toString() {
125     return "DefaultMOMutableRow2PC["+toStringMembers();
126   }
127
128 }
129
Popular Tags