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.geronimo.corba.proxy;
017:
018: import java.net.URI;
019: import javax.naming.NameNotFoundException;
020:
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023: import org.apache.geronimo.gbean.AbstractName;
024: import org.apache.geronimo.gbean.AbstractNameQuery;
025: import org.apache.geronimo.kernel.GBeanNotFoundException;
026: import org.apache.geronimo.kernel.Kernel;
027: import org.apache.geronimo.kernel.repository.Artifact;
028: import org.apache.geronimo.naming.reference.ConfigurationAwareReference;
029:
030: /**
031: * @version $Revision: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
032: */
033: public final class CORBAProxyReference extends
034: ConfigurationAwareReference {
035:
036: private final static Log log = LogFactory
037: .getLog(CORBAProxyReference.class);
038:
039: private final URI nsCorbaloc;
040: private final String objectName;
041: private final String home;
042:
043: public CORBAProxyReference(Artifact[] configId,
044: AbstractNameQuery abstractNameQuery, URI nsCorbaloc,
045: String objectName, String home) {
046: super (configId, abstractNameQuery);
047: this .nsCorbaloc = nsCorbaloc;
048: this .objectName = objectName;
049: this .home = home;
050: if (log.isDebugEnabled()) {
051: log.debug("<init> " + nsCorbaloc.toString() + ", "
052: + objectName + ", " + abstractNameQuery + ", "
053: + home);
054: }
055: }
056:
057: public String getClassName() {
058: return home;
059: }
060:
061: public Object getContent() throws NameNotFoundException {
062:
063: if (log.isDebugEnabled()) {
064: log.debug("Obtaining home from " + nsCorbaloc.toString()
065: + ", " + objectName + ", " + abstractNameQueries
066: + ", " + home);
067: }
068: AbstractName containerName;
069: try {
070: containerName = resolveTargetName();
071: } catch (GBeanNotFoundException e) {
072: throw (NameNotFoundException) new NameNotFoundException(
073: "Could not resolve gbean from name query: "
074: + abstractNameQueries).initCause(e);
075: }
076: Kernel kernel = getKernel();
077: Object proxy;
078: try {
079: //TODO configid objectname might well be wrong kind of thing.
080: proxy = kernel.invoke(containerName, "getHome",
081: new Object[] { nsCorbaloc, objectName },
082: new String[] { URI.class.getName(),
083: String.class.getName() });
084: } catch (Exception e) {
085: log.error("Could not get proxy from " + containerName, e);
086: throw (IllegalStateException) new IllegalStateException(
087: "Could not get proxy").initCause(e);
088: }
089: if (proxy == null) {
090: log.error("Proxy not returned from " + containerName);
091: throw new IllegalStateException(
092: "Proxy not returned. Target " + containerName
093: + " not started");
094: }
095: if (!org.omg.CORBA.Object.class.isAssignableFrom(proxy
096: .getClass())) {
097: log
098: .error("Proxy not an instance of expected class org.omg.CORBA.Object from "
099: + containerName);
100: throw new ClassCastException(
101: "Proxy not an instance of expected class org.omg.CORBA.Object");
102: }
103: return proxy;
104: }
105: }
|