001: /*
002: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: /*
021: * This file contains fragments from Apache Axis class.
022: *
023: * Copyright 2001-2004 The Apache Software Foundation.
024: *
025: * Licensed under the Apache License, Version 2.0 (the "License");
026: * you may not use this file except in compliance with the License.
027: * You may obtain a copy of the License at
028: *
029: * http://www.apache.org/licenses/LICENSE-2.0
030: *
031: * Unless required by applicable law or agreed to in writing, software
032: * distributed under the License is distributed on an "AS IS" BASIS,
033: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
034: * See the License for the specific language governing permissions and
035: * limitations under the License.
036: */
037:
038: package com.nabhinc.ws.service.adapter;
039:
040: import java.lang.reflect.InvocationTargetException;
041: import java.lang.reflect.Method;
042: import java.util.Properties;
043:
044: import org.omg.CORBA.ORB;
045: import org.omg.CORBA.ORBPackage.InvalidName;
046: import org.omg.CosNaming.NameComponent;
047: import org.omg.CosNaming.NamingContext;
048: import org.omg.CosNaming.NamingContextHelper;
049: import org.omg.CosNaming.NamingContextPackage.CannotProceed;
050: import org.omg.CosNaming.NamingContextPackage.NotFound;
051:
052: import com.nabhinc.ws.core.WebServiceException;
053: import com.nabhinc.ws.service.core.JavaDelegateWebService;
054:
055: /**
056: * A Web service implementation that delegates operation
057: * execution to the corresponding method on a CORBA proxy.
058: * <p/>
059: * Service Properties (* indicates required properties):<br/>
060: * <ul>
061: * <li>scope - "service", "session", "request". The
062: * default is "service".</li>
063: * <li>attributeName - Specifies name of the session/appliaction attribute
064: * used for caching the implementation object. Applicable only when
065: * the scope is "session" or "application". </li>
066: * <li>orbInitialHost - Host name or IP address of ORB host. Default is localhost.</li>
067: * <li>orbInitialPort - ORB port number. Default is 900.</li>
068: * <li>nameID* - Name of the CORBA object. </li>
069: * <li>nameKind* - Kind of the CORBA object. </li>
070: * <li>helperClass* - Name of the helper class used in narrowing the proxy object. </li>
071: * <li>interfaceClass* - CORBA interface class name </li>
072: * </ul>
073: * <p/>
074: * In addition you can specify properties to be set on the delegate
075: * Java bean object. These properties will depend on the particular
076: * Java bean class you are using and cannot be enumerated here.
077: *
078: * @author Padmanabh Dabke
079: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
080: */
081: public class CORBAAdapter extends JavaDelegateWebService {
082:
083: private static final Class[] CORBA_OBJECT_CLASS = new Class[] { org.omg.CORBA.Object.class };
084:
085: private String orbInitialHost = "localhost";
086: private String orbInitialPort = "900";
087: private String nameID = null;
088: private String nameKind = null;
089: private String helperClassName = null;
090: private String interfaceClassName = null;
091:
092: public String getHelperClass() {
093: return helperClassName;
094: }
095:
096: public void setHelperClass(String helperClass) {
097: this .helperClassName = helperClass;
098: }
099:
100: public String getNameID() {
101: return nameID;
102: }
103:
104: public void setNameID(String nameID) {
105: this .nameID = nameID;
106: }
107:
108: public String getNameKind() {
109: return nameKind;
110: }
111:
112: public void setNameKind(String nameKind) {
113: this .nameKind = nameKind;
114: }
115:
116: public String getOrbInitialHost() {
117: return orbInitialHost;
118: }
119:
120: public void setOrbInitialHost(String orbInitialHost) {
121: this .orbInitialHost = orbInitialHost;
122: }
123:
124: public String getOrbInitialPort() {
125: return orbInitialPort;
126: }
127:
128: public void setOrbInitialPort(String orbInitialPort) {
129: this .orbInitialPort = orbInitialPort;
130: }
131:
132: public String getInterfaceClass() {
133: return interfaceClassName;
134: }
135:
136: public void setInterfaceClass(String cl) {
137: interfaceClassName = cl;
138: }
139:
140: protected void checkProperties() throws WebServiceException {
141: super .checkProperties();
142: if (nameID == null)
143: throw new WebServiceException("Missing name ID.");
144: if (nameKind == null)
145: throw new WebServiceException("Missing name kind.");
146: if (helperClassName == null)
147: throw new WebServiceException("Missing helper class name.");
148: }
149:
150: public Object createDelegateInstance() throws WebServiceException {
151:
152: // Initialize ORB
153: Properties orbProps = new Properties();
154: orbProps.put("org.omg.CORBA.ORBInitialHost", orbInitialHost);
155: orbProps.put("org.omg.CORBA.ORBInitialPort", orbInitialPort);
156: ORB orb = ORB.init(new String[0], orbProps);
157:
158: try {
159: // Find the object
160: NamingContext root = NamingContextHelper.narrow(orb
161: .resolve_initial_references("NameService"));
162: NameComponent nc = new NameComponent(nameID, nameKind);
163: NameComponent[] ncs = { nc };
164: org.omg.CORBA.Object corbaObject = root.resolve(ncs);
165:
166: Class helperClass = Class.forName(helperClassName);
167:
168: // Narrow the object reference
169: Method narrowMethod = helperClass.getMethod("narrow",
170: CORBA_OBJECT_CLASS);
171: Object targetObject = narrowMethod.invoke(null,
172: new Object[] { corbaObject });
173:
174: return targetObject;
175: } catch (ClassNotFoundException e) {
176: throw new WebServiceException("Invalid helper class name.",
177: e);
178: } catch (InvalidName e) {
179: throw new WebServiceException(
180: "Failed to resolve initial reference to naming service.",
181: e);
182: } catch (NotFound e) {
183: throw new WebServiceException("CORBA object not found.", e);
184: } catch (CannotProceed e) {
185: throw new WebServiceException(
186: "Failed to resolve CORBA object.", e);
187: } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
188: throw new WebServiceException(
189: "Failed to lookup CORBA object.", e);
190: } catch (SecurityException e) {
191: throw new WebServiceException(
192: "Security exception in finding narrow method.", e);
193: } catch (NoSuchMethodException e) {
194: throw new WebServiceException(
195: "Failed to find narrow method on helper class.", e);
196: } catch (IllegalArgumentException e) {
197: throw new WebServiceException(
198: "Failed to narrow target object.", e);
199: } catch (IllegalAccessException e) {
200: throw new WebServiceException(
201: "Failed to narrow target object.", e);
202: } catch (InvocationTargetException e) {
203: throw new WebServiceException(
204: "Failed to narrow target object.", e);
205: }
206: }
207:
208: }
|