001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.iiop.orb;
031:
032: import com.caucho.vfs.*;
033: import com.caucho.iiop.*;
034: import com.caucho.iiop.any.*;
035:
036: import org.omg.CORBA.*;
037:
038: import java.applet.Applet;
039: import java.lang.reflect.Proxy;
040: import java.util.Properties;
041: import java.util.logging.Logger;
042: import javax.rmi.PortableRemoteObject;
043: import java.io.IOException;
044:
045: public class ORBImpl extends org.omg.CORBA.ORB {
046: public static final Logger log = Logger.getLogger(ORBImpl.class
047: .getName());
048:
049: private String _host;
050: private int _port;
051:
052: private Path _path;
053:
054: private IiopSocketPool _socketPool;
055:
056: private TypeCodeFactory _typeCodeFactory = new TypeCodeFactory();
057: private final StubDelegateImpl _stubDelegate;
058:
059: public ORBImpl() {
060: _stubDelegate = new StubDelegateImpl(this );
061:
062: System.setProperty("javax.rmi.CORBA.PortableRemoteObjectClass",
063: "com.caucho.iiop.orb.PortableRemoteObjectDelegateImpl");
064: }
065:
066: public String getHost() {
067: return _host;
068: }
069:
070: public void setHost(String host) {
071: _host = host;
072: }
073:
074: public int getPort() {
075: return _port;
076: }
077:
078: public void setPort(int port) {
079: _port = port;
080: }
081:
082: StubDelegateImpl getStubDelegate() {
083: return _stubDelegate;
084: }
085:
086: WriteStream openWriter() {
087: ReadWritePair pair = openReadWrite();
088:
089: return pair.getWriteStream();
090: }
091:
092: ReadWritePair openReadWrite() {
093: try {
094: if (_socketPool == null && _host != null) {
095: _socketPool = new IiopSocketPool(_host, _port);
096: }
097:
098: return _socketPool.open();
099: } catch (IOException e) {
100: throw new RuntimeException(e);
101: }
102: }
103:
104: IiopSocketPool getSocketPool() {
105: if (_socketPool == null && _host != null) {
106: _socketPool = new IiopSocketPool(_host, _port);
107: }
108:
109: return _socketPool;
110: }
111:
112: public TypeCode create_alias_tc(String id, String name,
113: TypeCode original) {
114: throw new UnsupportedOperationException();
115: }
116:
117: public Any create_any() {
118: return new AnyImpl(_typeCodeFactory);
119: }
120:
121: public AbstractTypeCode createTypeCode(Class type) {
122: return _typeCodeFactory.createTypeCode(type);
123: }
124:
125: public TypeCode create_array_tc(int length, TypeCode element_type) {
126: throw new UnsupportedOperationException();
127: }
128:
129: @Override
130: public TypeCode create_abstract_interface_tc(String id, String name) {
131: return new AbstractInterfaceTypeCode(id, name);
132: }
133:
134: public ContextList create_context_list() {
135: throw new UnsupportedOperationException();
136: }
137:
138: public TypeCode create_enum_tc(String id, String name,
139: String[] members) {
140: throw new UnsupportedOperationException();
141: }
142:
143: public Environment create_environment() {
144: throw new UnsupportedOperationException();
145: }
146:
147: public ExceptionList create_exception_list() {
148: throw new UnsupportedOperationException();
149: }
150:
151: public TypeCode create_exception_tc(String id, String name,
152: StructMember[] members) {
153: throw new UnsupportedOperationException();
154: }
155:
156: public TypeCode create_interface_tc(String id, String name) {
157: throw new UnsupportedOperationException();
158: }
159:
160: public NVList create_list(int count) {
161: throw new UnsupportedOperationException();
162: }
163:
164: public NamedValue create_named_value(String s, Any any, int flags) {
165: throw new UnsupportedOperationException();
166: }
167:
168: public TypeCode create_native_tc(String id, String name) {
169: throw new UnsupportedOperationException();
170: }
171:
172: public org.omg.CORBA.portable.OutputStream create_output_stream() {
173: throw new UnsupportedOperationException();
174: }
175:
176: @Deprecated
177: public TypeCode create_recursive_sequence_tc(int bound, int offset) {
178: throw new UnsupportedOperationException();
179: }
180:
181: public TypeCode create_sequence_tc(int bound, TypeCode element_type) {
182: throw new UnsupportedOperationException();
183: }
184:
185: public TypeCode create_string_tc(int bound) {
186: throw new UnsupportedOperationException();
187: }
188:
189: public TypeCode create_struct_tc(String id, String name,
190: StructMember[] members) {
191: throw new UnsupportedOperationException();
192: }
193:
194: public TypeCode create_union_tc(String id, String name,
195: TypeCode discriminator_type, UnionMember[] members) {
196: throw new UnsupportedOperationException();
197: }
198:
199: public TypeCode create_wstring_tc(int bound) {
200: throw new UnsupportedOperationException();
201: }
202:
203: public Context get_default_context() {
204: throw new UnsupportedOperationException();
205: }
206:
207: public Request get_next_response() {
208: throw new UnsupportedOperationException();
209: }
210:
211: public TypeCode get_primitive_tc(org.omg.CORBA.TCKind tcKind) {
212: throw new UnsupportedOperationException();
213: }
214:
215: public String[] list_initial_services() {
216: return new String[0];
217: }
218:
219: @Override
220: public String object_to_string(org.omg.CORBA.Object obj) {
221: throw new UnsupportedOperationException();
222: }
223:
224: public boolean poll_next_response() {
225: throw new UnsupportedOperationException();
226: }
227:
228: public org.omg.CORBA.Object resolve_initial_references(
229: String object_name) {
230: try {
231: Thread thread = Thread.currentThread();
232: ClassLoader loader = thread.getContextClassLoader();
233:
234: Iiop10Writer writer = new Iiop10Writer();
235:
236: ReadWritePair pair = openReadWrite();
237:
238: MessageWriter out = new StreamMessageWriter(pair
239: .getWriteStream());
240:
241: IiopReader in = new IiopReader(pair.getReadStream());
242: in.setOrb(this );
243:
244: writer.init(out, new IiopReader(pair.getReadStream()));
245:
246: byte[] oid = new byte[] { 'I', 'N', 'I', 'T' };
247:
248: writer.startRequest(oid, 0, oid.length, "get", 1, null);
249:
250: writer.writeString(object_name);
251:
252: in = writer._call();
253: in.setOrb(this );
254:
255: org.omg.CORBA.Object value = in.read_Object();
256:
257: in.close();
258:
259: return value;
260: } catch (Exception e) {
261: throw new RuntimeException(e);
262: }
263: }
264:
265: public void send_multiple_requests_deferred(Request[] req) {
266: throw new UnsupportedOperationException();
267: }
268:
269: public void send_multiple_requests_oneway(Request[] req) {
270: throw new UnsupportedOperationException();
271: }
272:
273: public void set_parameters(Applet app, Properties props) {
274: throw new UnsupportedOperationException();
275: }
276:
277: public void set_parameters(String[] args, Properties props) {
278: if (props != null) {
279: java.lang.Object port = props
280: .get("org.omg.CORBA.ORBInitialPort");
281: java.lang.Object host = props
282: .get("org.omg.CORBA.ORBInitialHost");
283:
284: if (host != null)
285: _host = String.valueOf(host);
286:
287: if (port == null) {
288: } else if (port instanceof Number)
289: _port = ((Number) port).intValue();
290: else
291: _port = Integer.parseInt(String.valueOf(port));
292:
293: _path = Vfs.lookup("tcp://" + _host + ":" + port);
294: }
295: }
296:
297: public org.omg.CORBA.Object string_to_object(String str) {
298: throw new UnsupportedOperationException();
299: }
300:
301: public String toString() {
302: if (_host != null)
303: return "ORBImpl[" + _host + ", " + _port + "]";
304: else
305: return "ORBImpl[]";
306: }
307: }
|