001: /*_############################################################################
002: _##
003: _## SNMP4J-Agent - DefaultMOMutableRow2PC.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.request.*;
024: import org.snmp4j.smi.*;
025: import org.snmp4j.agent.mo.DefaultMOTable.ChangeSet;
026:
027: public class DefaultMOMutableRow2PC extends DefaultMOTableRow implements
028: MOMutableRow2PC {
029:
030: private MOTableRow baseRow;
031: private Object userObject;
032:
033: public DefaultMOMutableRow2PC(OID index, Variable[] values) {
034: super (index, values);
035: }
036:
037: public void cleanup(SubRequest subRequest, int column) {
038: subRequest.completed();
039: }
040:
041: public void commit(SubRequest subRequest, MOTableRow changeSet,
042: int column) {
043: subRequest.setUndoValue(values[column]);
044: setValue(column, (Variable) subRequest.getVariableBinding()
045: .getVariable().clone());
046: subRequest.completed();
047: }
048:
049: public MOTableRow getBaseRow() {
050: return baseRow;
051: }
052:
053: public OID getIndex() {
054: return index;
055: }
056:
057: public Object getUserObject() {
058: return userObject;
059: }
060:
061: public Variable getValue(int column) {
062: return values[column];
063: }
064:
065: public void setBaseRow(MOTableRow baseRow) {
066: this .baseRow = baseRow;
067: }
068:
069: public void setUserObject(Object userObject) {
070: this .userObject = userObject;
071: }
072:
073: public void setValue(int column, Variable value) {
074: values[column] = value;
075: }
076:
077: public int size() {
078: return values.length;
079: }
080:
081: public void undo(SubRequest subRequest, int column) {
082: if (subRequest.getUndoValue() instanceof Variable) {
083: setValue(column, (Variable) subRequest.getUndoValue());
084: }
085: subRequest.completed();
086: }
087:
088: /**
089: * Returns the value of the specified column that would result if the
090: * specified changes would have been applied to the row.
091: * @param column
092: * the column to return
093: * @param changes
094: * a <code>MOTableRow</code> instance representing the changes to apply
095: * to this row. Values that are not changed must be returned as
096: * <code>null</code> values.
097: * @return
098: * the resulting <code>Variable</code>.
099: */
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,
113: int column) {
114: }
115:
116: public void cleanupRow(SubRequest request, ChangeSet changeSet) {
117: }
118:
119: public void undoRow(SubRequest request, ChangeSet changeSet) {
120: }
121:
122: public void prepareRow(SubRequest subRequest, MOTableRow changeSet) {
123: }
124:
125: public String toString() {
126: return "DefaultMOMutableRow2PC[" + toStringMembers();
127: }
128:
129: }
|