Search in sources :

Example 1 with ArrayEnumeration

use of org.apache.openejb.util.ArrayEnumeration in project tomee by apache.

the class EntityContainer method findMethod.

protected Object findMethod(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();
    callContext.setCurrentOperation(Operation.FIND);
    final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
    Object returnValue = invoke(type, callMethod, runMethod, args, callContext);
    /*
        * Find operations return either a single primary key or a collection of primary keys.
        * The primary keys are converted to ProxyInfo objects.
        */
    if (returnValue instanceof Collection) {
        final Iterator keys = ((Collection) returnValue).iterator();
        final Vector<ProxyInfo> proxies = new Vector<ProxyInfo>();
        while (keys.hasNext()) {
            final Object primaryKey = keys.next();
            proxies.addElement(new ProxyInfo(beanContext, primaryKey));
        }
        returnValue = proxies;
    } else if (returnValue instanceof Enumeration) {
        final Enumeration keys = (Enumeration) returnValue;
        final Vector<ProxyInfo> proxies = new Vector<ProxyInfo>();
        while (keys.hasMoreElements()) {
            final Object primaryKey = keys.nextElement();
            proxies.addElement(new ProxyInfo(beanContext, primaryKey));
        }
        returnValue = new ArrayEnumeration(proxies);
    } else {
        returnValue = new ProxyInfo(beanContext, returnValue);
    }
    return returnValue;
}
Also used : BeanContext(org.apache.openejb.BeanContext) ProxyInfo(org.apache.openejb.ProxyInfo) Enumeration(java.util.Enumeration) ArrayEnumeration(org.apache.openejb.util.ArrayEnumeration) Iterator(java.util.Iterator) Collection(java.util.Collection) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) Method(java.lang.reflect.Method) Vector(java.util.Vector) ArrayEnumeration(org.apache.openejb.util.ArrayEnumeration)

Example 2 with ArrayEnumeration

use of org.apache.openejb.util.ArrayEnumeration in project tomee by apache.

the class SecurityServiceImplTest method plusInPath.

@Test
public void plusInPath() throws Exception {
    final AtomicReference<String> path = new AtomicReference<>();
    final ClassLoader jaasLoader = new URLClassLoader(new URL[0]) {

        @Override
        public Enumeration<URL> getResources(final String name) throws IOException {
            return new ArrayEnumeration(asList(new URL("file:/tmp/jaas/folder+with+plus/login.config")));
        }
    };
    Thread.currentThread().setContextClassLoader(jaasLoader);
    try {
        final Method mtd = SecurityServiceImpl.class.getDeclaredMethod("installJaas");
        mtd.setAccessible(true);
        mtd.invoke(null);
        final String config = System.getProperty("java.security.auth.login.config");
        assertEquals("file:/tmp/jaas/folder+with+plus/login.config", config);
    } finally {
        Thread.currentThread().setContextClassLoader(jaasLoader.getParent());
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) AtomicReference(java.util.concurrent.atomic.AtomicReference) Method(java.lang.reflect.Method) ArrayEnumeration(org.apache.openejb.util.ArrayEnumeration) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ArrayEnumeration

use of org.apache.openejb.util.ArrayEnumeration in project tomee by apache.

the class EntityEjbHomeHandler method findX.

protected Object findX(final Class interfce, final Method method, final Object[] args, final Object proxy) throws Throwable {
    final Object retValue;
    try {
        retValue = container.invoke(deploymentID, interfaceType, interfce, method, args, null);
    } catch (final OpenEJBException e) {
        logger.debug("entityEjbHomeHandler.containerInvocationFailure", e, e.getMessage());
        throw e;
    }
    if (retValue instanceof Collection) {
        final Object[] proxyInfos = ((Collection) retValue).toArray();
        final Vector proxies = new Vector();
        for (int i = 0; i < proxyInfos.length; i++) {
            final ProxyInfo proxyInfo = (ProxyInfo) proxyInfos[i];
            proxies.addElement(createProxy(proxyInfo.getPrimaryKey(), getMainInterface()));
        }
        return proxies;
    } else if (retValue instanceof ArrayEnumeration) {
        final ArrayEnumeration enumeration = (ArrayEnumeration) retValue;
        for (int i = enumeration.size() - 1; i >= 0; --i) {
            final ProxyInfo proxyInfo = (ProxyInfo) enumeration.get(i);
            enumeration.set(i, createProxy(proxyInfo.getPrimaryKey(), getMainInterface()));
        }
        return enumeration;
    } else if (retValue instanceof Enumeration) {
        final Enumeration enumeration = (Enumeration) retValue;
        final List proxies = new ArrayList();
        while (enumeration.hasMoreElements()) {
            final ProxyInfo proxyInfo = (ProxyInfo) enumeration.nextElement();
            proxies.add(createProxy(proxyInfo.getPrimaryKey(), getMainInterface()));
        }
        return new ArrayEnumeration(proxies);
    } else {
        final ProxyInfo proxyInfo = (ProxyInfo) retValue;
        return createProxy(proxyInfo.getPrimaryKey(), getMainInterface());
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ProxyInfo(org.apache.openejb.ProxyInfo) Enumeration(java.util.Enumeration) ArrayEnumeration(org.apache.openejb.util.ArrayEnumeration) ArrayList(java.util.ArrayList) Collection(java.util.Collection) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) ArrayList(java.util.ArrayList) List(java.util.List) Vector(java.util.Vector) ArrayEnumeration(org.apache.openejb.util.ArrayEnumeration)

Aggregations

ArrayEnumeration (org.apache.openejb.util.ArrayEnumeration)3 Method (java.lang.reflect.Method)2 Collection (java.util.Collection)2 Enumeration (java.util.Enumeration)2 Vector (java.util.Vector)2 EJBLocalObject (javax.ejb.EJBLocalObject)2 EJBObject (javax.ejb.EJBObject)2 ProxyInfo (org.apache.openejb.ProxyInfo)2 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BeanContext (org.apache.openejb.BeanContext)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 Test (org.junit.Test)1