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.core.entity;
017:
018: import java.lang.reflect.Method;
019: import java.util.Vector;
020: import java.util.List;
021:
022: import org.apache.openejb.ProxyInfo;
023: import org.apache.openejb.InterfaceType;
024: import org.apache.openejb.OpenEJBException;
025: import org.apache.openejb.DeploymentInfo;
026: import org.apache.openejb.core.ivm.EjbHomeProxyHandler;
027: import org.apache.openejb.core.ivm.EjbObjectProxyHandler;
028: import org.apache.openejb.util.proxy.ProxyManager;
029:
030: public class EntityEjbHomeHandler extends EjbHomeProxyHandler {
031:
032: public EntityEjbHomeHandler(DeploymentInfo deploymentInfo,
033: InterfaceType interfaceType, List<Class> interfaces) {
034: super (deploymentInfo, interfaceType, interfaces);
035: }
036:
037: public Object createProxy(Object primaryKey) {
038: Object proxy = super .createProxy(primaryKey);
039: EjbObjectProxyHandler handler = (EjbObjectProxyHandler) ProxyManager
040: .getInvocationHandler(proxy);
041:
042: /*
043: * Register the handle with the BaseEjbProxyHandler.liveHandleRegistry
044: * If the bean is removed by its home or by an identical proxy, then the
045: * this proxy will be automatically invalidated because its properly registered
046: * with the liveHandleRegistry.
047: */
048: registerHandler(handler.getRegistryId(), handler);
049:
050: return proxy;
051:
052: }
053:
054: protected Object findX(Class interfce, Method method,
055: Object[] args, Object proxy) throws Throwable {
056: Object retValue;
057: try {
058: retValue = container.invoke(deploymentID, interfce, method,
059: args, null);
060: } catch (OpenEJBException e) {
061: logger.debug(
062: "entityEjbHomeHandler.containerInvocationFailure",
063: e, e.getMessage());
064: throw e;
065: }
066:
067: if (retValue instanceof java.util.Collection) {
068: Object[] proxyInfos = ((java.util.Collection) retValue)
069: .toArray();
070: Vector proxies = new Vector();
071: for (int i = 0; i < proxyInfos.length; i++) {
072: ProxyInfo proxyInfo = (ProxyInfo) proxyInfos[i];
073: proxies.addElement(createProxy(proxyInfo
074: .getPrimaryKey()));
075: }
076: return proxies;
077: } else if (retValue instanceof org.apache.openejb.util.ArrayEnumeration) {
078: org.apache.openejb.util.ArrayEnumeration enumeration = (org.apache.openejb.util.ArrayEnumeration) retValue;
079: for (int i = enumeration.size() - 1; i >= 0; --i) {
080: ProxyInfo proxyInfo = ((ProxyInfo) enumeration.get(i));
081: enumeration.set(i, createProxy(proxyInfo
082: .getPrimaryKey()));
083: }
084: return enumeration;
085: } else if (retValue instanceof java.util.Enumeration) {
086: java.util.Enumeration enumeration = (java.util.Enumeration) retValue;
087:
088: java.util.List proxies = new java.util.ArrayList();
089: while (enumeration.hasMoreElements()) {
090: ProxyInfo proxyInfo = ((ProxyInfo) enumeration
091: .nextElement());
092: proxies.add(createProxy(proxyInfo.getPrimaryKey()));
093: }
094: return new org.apache.openejb.util.ArrayEnumeration(proxies);
095: } else {
096: org.apache.openejb.ProxyInfo proxyInfo = (org.apache.openejb.ProxyInfo) retValue;
097:
098: return createProxy(proxyInfo.getPrimaryKey());
099: }
100:
101: }
102:
103: protected Object removeByPrimaryKey(Class interfce, Method method,
104: Object[] args, Object proxy) throws Throwable {
105: Object primKey = args[0];
106: container.invoke(deploymentID, interfce, method, args, primKey);
107:
108: /*
109: * This operation takes care of invalidating all the EjbObjectProxyHanders associated with
110: * the same RegistryId. See this.createProxy().
111: */
112: invalidateAllHandlers(EntityEjbObjectHandler.getRegistryId(
113: container, deploymentID, primKey));
114: return null;
115: }
116:
117: protected EjbObjectProxyHandler newEjbObjectHandler(
118: DeploymentInfo deploymentInfo, Object pk,
119: InterfaceType interfaceType, List<Class> interfaces) {
120: return new EntityEjbObjectHandler(getDeploymentInfo(), pk,
121: interfaceType, interfaces);
122: }
123:
124: }
|