001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.client;
017:
018: import java.io.IOException;
019: import java.io.ObjectInput;
020: import java.io.ObjectOutput;
021:
022: public class JNDIResponse implements ClusterableResponse {
023:
024: private transient int responseCode = -1;
025: private transient Object result;
026: private transient ServerMetaData server;
027:
028: public JNDIResponse() {
029: }
030:
031: public JNDIResponse(int code, Object obj) {
032: responseCode = code;
033: result = obj;
034: }
035:
036: public int getResponseCode() {
037: return responseCode;
038: }
039:
040: public Object getResult() {
041: return result;
042: }
043:
044: public void setResponseCode(int responseCode) {
045: this .responseCode = responseCode;
046: }
047:
048: public void setResult(Object result) {
049: this .result = result;
050: }
051:
052: public void setServer(ServerMetaData server) {
053: this .server = server;
054: }
055:
056: public ServerMetaData getServer() {
057: return server;
058: }
059:
060: public void readExternal(ObjectInput in) throws IOException,
061: ClassNotFoundException {
062: byte version = in.readByte(); // future use
063:
064: boolean readServer = in.readBoolean();
065: if (readServer) {
066: server = new ServerMetaData();
067: server.readExternal(in);
068: }
069:
070: responseCode = in.readByte();
071:
072: switch (responseCode) {
073: case ResponseCodes.JNDI_BUSINESS_OBJECT:
074: case ResponseCodes.JNDI_OK:
075: case ResponseCodes.JNDI_NAMING_EXCEPTION:
076: case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
077: case ResponseCodes.JNDI_ERROR:
078: case ResponseCodes.JNDI_RESOURCE:
079: result = in.readObject();
080: break;
081: case ResponseCodes.JNDI_CONTEXT:
082: case ResponseCodes.JNDI_NOT_FOUND:
083: break;
084: case ResponseCodes.JNDI_EJBHOME:
085: EJBMetaDataImpl m = new EJBMetaDataImpl();
086: m.readExternal(in);
087: result = m;
088: break;
089: case ResponseCodes.JNDI_DATA_SOURCE:
090: DataSourceMetaData ds = new DataSourceMetaData();
091: ds.readExternal(in);
092: result = ds;
093: break;
094: case ResponseCodes.JNDI_INJECTIONS:
095: InjectionMetaData imd = new InjectionMetaData();
096: imd.readExternal(in);
097: result = imd;
098: break;
099: case ResponseCodes.JNDI_WEBSERVICE:
100: WsMetaData ws = (WsMetaData) in.readObject();
101: result = ws;
102: break;
103: case ResponseCodes.JNDI_ENUMERATION:
104: NameClassPairEnumeration ncpe = new NameClassPairEnumeration();
105: ncpe.readExternal(in);
106: result = ncpe;
107: break;
108: }
109: }
110:
111: public void writeExternal(ObjectOutput out) throws IOException {
112: // write out the version of the serialized data for future use
113: out.writeByte(1);
114:
115: if (null != server) {
116: out.writeBoolean(true);
117: server.writeExternal(out);
118: } else {
119: out.writeBoolean(false);
120: }
121:
122: out.writeByte((byte) responseCode);
123:
124: switch (responseCode) {
125: case ResponseCodes.JNDI_BUSINESS_OBJECT:
126: case ResponseCodes.JNDI_OK:
127: case ResponseCodes.JNDI_NAMING_EXCEPTION:
128: case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
129: case ResponseCodes.JNDI_ERROR:
130: case ResponseCodes.JNDI_RESOURCE:
131: out.writeObject(result);
132: break;
133: case ResponseCodes.JNDI_CONTEXT:
134: case ResponseCodes.JNDI_NOT_FOUND:
135: break;
136: case ResponseCodes.JNDI_EJBHOME:
137: EJBMetaDataImpl m = (EJBMetaDataImpl) result;
138: m.writeExternal(out);
139: break;
140: case ResponseCodes.JNDI_DATA_SOURCE:
141: DataSourceMetaData ds = (DataSourceMetaData) result;
142: ds.writeExternal(out);
143: break;
144: case ResponseCodes.JNDI_INJECTIONS:
145: InjectionMetaData imd = (InjectionMetaData) result;
146: imd.writeExternal(out);
147: break;
148: case ResponseCodes.JNDI_WEBSERVICE:
149: WsMetaData ws = (WsMetaData) result;
150: out.writeObject(ws);
151: break;
152: case ResponseCodes.JNDI_ENUMERATION:
153: NameClassPairEnumeration ncpe = (NameClassPairEnumeration) result;
154: ncpe.writeExternal(out);
155: break;
156: }
157: }
158:
159: public String toString() {
160: StringBuilder sb = new StringBuilder(100);
161:
162: switch (responseCode) {
163: case ResponseCodes.JNDI_BUSINESS_OBJECT:
164: sb.append("JNDI_BUSINESS_OBJECT:");
165: break;
166: case ResponseCodes.JNDI_OK:
167: sb.append("JNDI_OK:");
168: break;
169: case ResponseCodes.JNDI_NAMING_EXCEPTION:
170: sb.append("JNDI_NAMING_EXCEPTION:");
171: break;
172: case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
173: sb.append("JNDI_RUNTIME_EXCEPTION:");
174: break;
175: case ResponseCodes.JNDI_ERROR:
176: sb.append("JNDI_ERROR:");
177: break;
178: case ResponseCodes.JNDI_RESOURCE:
179: sb.append("JNDI_RESOURCE:");
180: break;
181: case ResponseCodes.JNDI_CONTEXT:
182: sb.append("JNDI_CONTEXT:");
183: break;
184: case ResponseCodes.JNDI_NOT_FOUND:
185: sb.append("JNDI_NOT_FOUND:");
186: break;
187: case ResponseCodes.JNDI_EJBHOME:
188: sb.append("JNDI_EJBHOME:");
189: break;
190: case ResponseCodes.JNDI_DATA_SOURCE:
191: sb.append("JNDI_DATA_SOURCE:");
192: break;
193: case ResponseCodes.JNDI_INJECTIONS:
194: sb.append("JNDI_INJECTIONS:");
195: break;
196: }
197: sb.append(this.getResult());
198: return sb.toString();
199: }
200:
201: }
|