KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > core > command > InvokeMethodCommand


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
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 and GNU Library
9
// General Public License as published by the Free Software Foundation;
10
// either version 2, or (at your option) any later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License and GNU Library General Public License
16
// for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// and GNU Library General Public License along with this program; if
20
// not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21
// MA 02139, USA.
22
//
23
///////////////////////////////////////////////////////////////////////////////
24
package org.myoodb.core.command;
25
26 import java.io.*;
27
28 import org.myoodb.*;
29 import org.myoodb.core.*;
30
31 public final class InvokeMethodCommand extends AbstractCommand implements Externalizable
32 {
33     private String JavaDoc m_sig;
34     private Object JavaDoc m_args;
35     private MyOodbProxy m_object;
36     private String JavaDoc m_methodName;
37     private int m_methodIndex;
38     private int m_accessLevel;
39     private Object JavaDoc m_tunnelIdentifier;
40
41     public InvokeMethodCommand()
42     {
43     }
44
45     public InvokeMethodCommand(MyOodbProxy object, int methodIndex, Object JavaDoc[] args, int accessLevel)
46     {
47         m_args = args;
48         m_object = object;
49         m_methodIndex = methodIndex;
50         m_accessLevel = accessLevel;
51     }
52
53     public InvokeMethodCommand(MyOodbProxy object, String JavaDoc methodName, String JavaDoc sig, Object JavaDoc[] args, int accessLevel)
54     {
55         m_sig = sig;
56         m_args = args;
57         m_object = object;
58         m_methodIndex = -1;
59         m_methodName = methodName;
60         m_accessLevel = accessLevel;
61     }
62
63     public void setArguments(Object JavaDoc[] args)
64     {
65         m_args = args;
66     }
67
68     public Object JavaDoc[] getArguments()
69     {
70         return (m_args instanceof Object JavaDoc[]) ? (Object JavaDoc[]) m_args : null;
71     }
72
73     public void setTunnelPassThroughFlag(boolean flag)
74     {
75         m_args = new Boolean JavaDoc(flag);
76     }
77
78     public boolean getTunnelPassThroughFlag()
79     {
80         return (m_args instanceof Boolean JavaDoc) ? (Boolean JavaDoc) m_args : false;
81     }
82
83     public void setTunnelIdentifier(Object JavaDoc identifier)
84     {
85         m_tunnelIdentifier = identifier;
86     }
87
88     public Object JavaDoc getTunnelIdentifier()
89     {
90         return m_tunnelIdentifier;
91     }
92
93     public void process(AbstractTransaction tx) throws Exception JavaDoc
94     {
95         if (m_methodIndex > -1)
96         {
97             m_result = tx.invokeMethod(m_object.getDatabaseHandle(), m_methodIndex, (Object JavaDoc[]) m_args, m_accessLevel);
98         }
99         else
100         {
101             m_result = tx.invokeMethod(m_object.getDatabaseHandle(), m_methodName, m_sig, (Object JavaDoc[]) m_args, m_accessLevel);
102         }
103
104         m_result = Converter.LocalToProxy(m_result);
105     }
106
107     public void writeExternal(ObjectOutput out) throws IOException
108     {
109         out.writeObject(m_object);
110         out.writeInt(m_methodIndex);
111         if (m_methodIndex == -1)
112         {
113             out.writeObject(m_methodName);
114             out.writeObject(m_sig);
115         }
116
117         out.writeInt(m_accessLevel);
118         out.writeObject(m_args);
119         out.writeObject(m_tunnelIdentifier);
120     }
121
122     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException JavaDoc
123     {
124         m_object = (MyOodbProxy) in.readObject();
125         m_methodIndex = in.readInt();
126         if (m_methodIndex == -1)
127         {
128             m_methodName = (String JavaDoc) in.readObject();
129             m_sig = (String JavaDoc) in.readObject();
130         }
131
132         m_accessLevel = in.readInt();
133         m_args = in.readObject();
134         m_tunnelIdentifier = in.readObject();
135     }
136 }
137
Popular Tags