01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1999-2004 Gerald Brose
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Library General Public License for more details.
15: *
16: * You should have received a copy of the GNU Library General Public
17: * License along with this library; if not, write to the Free
18: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19: *
20: */
21:
22: package org.jacorb.notification.container;
23:
24: import java.lang.reflect.Method;
25:
26: import org.jacorb.util.ObjectUtil;
27: import org.picocontainer.PicoContainer;
28: import org.picocontainer.PicoInitializationException;
29: import org.picocontainer.PicoIntrospectionException;
30: import org.picocontainer.PicoVerificationException;
31: import org.picocontainer.defaults.AbstractComponentAdapter;
32: import org.picocontainer.defaults.AssignabilityRegistrationException;
33:
34: /**
35: * @author Alphonse Bendt
36: * @version $Id: CORBAObjectComponentAdapter.java,v 1.3 2005/08/21 13:11:30 alphonse.bendt Exp $
37: */
38: public class CORBAObjectComponentAdapter extends
39: AbstractComponentAdapter {
40: private static final long serialVersionUID = 1L;
41:
42: private final org.omg.CORBA.Object delegate_;
43:
44: /**
45: * Component Adapter to specify a reference to a CORBA Object.
46: *
47: * @param service CORBA Interface the delegate offers
48: * @param delegate CORBA object that offers the service
49: */
50: public CORBAObjectComponentAdapter(Class service,
51: org.omg.CORBA.Object delegate) {
52: super (service, service);
53:
54: final String _interfaceName = service.getName();
55: final String _helperClassName = _interfaceName + "Helper";
56: boolean _notAssignable = false;
57:
58: try {
59: final Class _helperClass;
60: if (service.getClassLoader() != null) {
61: _helperClass = service.getClassLoader().loadClass(
62: _helperClassName);
63: } else {
64: _helperClass = ObjectUtil
65: .classForName(_helperClassName);
66: }
67:
68: Method _idMethod = _helperClass.getMethod("id",
69: new Class[0]);
70: String _id = (String) _idMethod.invoke(null, null);
71:
72: if (!delegate._is_a(_id)) {
73: _notAssignable = true;
74: }
75: } catch (Exception e) {
76: _notAssignable = true;
77: }
78:
79: if (_notAssignable) {
80: throw new AssignabilityRegistrationException(service,
81: delegate.getClass());
82: }
83:
84: delegate_ = delegate;
85: }
86:
87: public Object getComponentInstance(PicoContainer container)
88: throws PicoInitializationException,
89: PicoIntrospectionException {
90: return delegate_;
91: }
92:
93: public void verify(PicoContainer container)
94: throws PicoVerificationException {
95: // no op
96: }
97: }
|