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;
}
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());
}
}
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());
}
}
Aggregations