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.server.ejbd;
017:
018: import org.apache.openejb.client.EJBHomeProxyHandle;
019: import org.apache.openejb.client.EJBHomeHandler;
020: import org.apache.openejb.client.EJBMetaDataImpl;
021: import org.apache.openejb.client.EJBObjectProxyHandle;
022: import org.apache.openejb.client.EJBObjectHandler;
023: import org.apache.openejb.InterfaceType;
024: import org.apache.openejb.DeploymentInfo;
025: import org.apache.openejb.util.LogCategory;
026: import org.apache.openejb.util.Logger;
027: import org.apache.openejb.core.ivm.EjbHomeProxyHandler;
028: import org.apache.openejb.core.ivm.EjbObjectProxyHandler;
029: import org.apache.openejb.loader.SystemInstance;
030: import org.apache.openejb.spi.ContainerSystem;
031:
032: import java.util.ArrayList;
033:
034: /**
035: * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 $
036: */
037: public class ServerSideResolver implements EJBHomeProxyHandle.Resolver,
038: EJBObjectProxyHandle.Resolver {
039:
040: private static Logger logger = Logger.getInstance(
041: LogCategory.OPENEJB_SERVER_REMOTE,
042: "org.apache.openejb.server.util.resources");
043:
044: public Object resolve(EJBHomeHandler handler) {
045: try {
046: EJBMetaDataImpl ejb = handler.getEjb();
047:
048: InterfaceType interfaceType = (ejb
049: .getRemoteInterfaceClass() == null) ? InterfaceType.BUSINESS_REMOTE_HOME
050: : InterfaceType.EJB_HOME;
051:
052: ArrayList<Class> interfaces = new ArrayList<Class>();
053: if (interfaceType.isBusiness()) {
054: interfaces.addAll(ejb.getBusinessClasses());
055: } else {
056: interfaces.add(ejb.getRemoteInterfaceClass());
057: }
058:
059: ContainerSystem containerSystem = SystemInstance.get()
060: .getComponent(ContainerSystem.class);
061: DeploymentInfo deploymentInfo = containerSystem
062: .getDeploymentInfo(ejb.getDeploymentID());
063:
064: return EjbHomeProxyHandler.createHomeProxy(deploymentInfo,
065: interfaceType, interfaces);
066: } catch (Exception e) {
067: logger.error(
068: "ServerSideResolver.resolve() failed, falling back to ClientSideResolver: "
069: + e.getClass().getName() + ": "
070: + e.getMessage(), e);
071: return new EJBHomeProxyHandle.ClientSideResovler()
072: .resolve(handler);
073: }
074: }
075:
076: public Object resolve(EJBObjectHandler handler) {
077: try {
078: EJBMetaDataImpl ejb = handler.getEjb();
079:
080: InterfaceType interfaceType = (ejb
081: .getRemoteInterfaceClass() == null) ? InterfaceType.BUSINESS_REMOTE_HOME
082: : InterfaceType.EJB_HOME;
083:
084: ArrayList<Class> interfaces = new ArrayList<Class>();
085: if (interfaceType.isBusiness()) {
086: interfaces.addAll(ejb.getBusinessClasses());
087: } else {
088: interfaces.add(ejb.getRemoteInterfaceClass());
089: }
090:
091: ContainerSystem containerSystem = SystemInstance.get()
092: .getComponent(ContainerSystem.class);
093: DeploymentInfo deploymentInfo = containerSystem
094: .getDeploymentInfo(ejb.getDeploymentID());
095:
096: return EjbObjectProxyHandler.createProxy(deploymentInfo,
097: handler.getPrimaryKey(), interfaceType, interfaces);
098: } catch (Exception e) {
099: logger.error(
100: "ServerSideResolver.resolve() failed, falling back to ClientSideResolver: "
101: + e.getClass().getName() + ": "
102: + e.getMessage(), e);
103: return new EJBObjectProxyHandle.ClientSideResovler()
104: .resolve(handler);
105: }
106: }
107: }
|