001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
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 and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb.core.command;
025:
026: import java.io.*;
027:
028: import org.myoodb.core.*;
029:
030: public final class InvokeMethodCommand extends AbstractCommand {
031: private Identifier m_identifier;
032: private String m_signature;
033: private String m_methodName;
034: private int m_methodIndex;
035: private Object[] m_arguments;
036: private int m_accessLevel;
037:
038: public InvokeMethodCommand() {
039: }
040:
041: public InvokeMethodCommand(Identifier identifier, int methodIndex,
042: Object[] arguments, int accessLevel) {
043: m_identifier = identifier;
044: m_methodIndex = methodIndex;
045: m_arguments = arguments;
046: m_accessLevel = accessLevel;
047: m_tunnelIdentifier = -1;
048: }
049:
050: public InvokeMethodCommand(Identifier identifier,
051: String methodName, String signature, Object[] arguments,
052: int accessLevel) {
053: m_identifier = identifier;
054: m_signature = signature;
055: m_methodIndex = -1;
056: m_methodName = methodName;
057: m_arguments = arguments;
058: m_accessLevel = accessLevel;
059: m_tunnelIdentifier = -1;
060: }
061:
062: public Identifier getIdentifier() {
063: return m_identifier;
064: }
065:
066: public String getSignature() {
067: return m_signature;
068: }
069:
070: public void setArguments(Object[] arguments) {
071: m_arguments = arguments;
072: }
073:
074: public Object[] getArguments() {
075: return m_arguments;
076: }
077:
078: public String getMethodName() {
079: return m_methodName;
080: }
081:
082: public int getMethodIndex() {
083: return m_methodIndex;
084: }
085:
086: public int getAccessLevel() {
087: return m_accessLevel;
088: }
089:
090: public void process(AbstractTransaction tx) throws Exception {
091: if (m_methodIndex != -1) {
092: m_result = tx.invokeMethod(m_identifier, m_methodIndex,
093: (Object[]) m_arguments, m_accessLevel);
094: } else {
095: m_result = tx.invokeMethod(m_identifier, m_methodName,
096: m_signature, (Object[]) m_arguments, m_accessLevel);
097: }
098: }
099:
100: public void writeExternal(ObjectOutput out) throws IOException {
101: super .writeExternal(out);
102:
103: if (m_tunnelIdentifier == -1) {
104: out.writeObject(m_identifier);
105: out.writeInt(m_methodIndex);
106: if (m_methodIndex == -1) {
107: out.writeUTF(m_methodName);
108: out.writeUTF(m_signature);
109: }
110:
111: out.writeObject(m_arguments);
112: out.writeInt(m_accessLevel);
113: }
114: }
115:
116: public void readExternal(ObjectInput in) throws IOException,
117: ClassNotFoundException {
118: super .readExternal(in);
119:
120: if (m_tunnelIdentifier == -1) {
121: m_identifier = (Identifier) in.readObject();
122: m_methodIndex = in.readInt();
123: if (m_methodIndex == -1) {
124: m_methodName = in.readUTF();
125: m_signature = in.readUTF();
126: }
127:
128: m_arguments = (Object[]) in.readObject();
129: m_accessLevel = in.readInt();
130: }
131: }
132: }
|