use of java.lang.reflect.InvocationHandler in project Payara by payara.
the class WriteableView method removeNestedElements.
boolean removeNestedElements(Object object) {
InvocationHandler h = Proxy.getInvocationHandler(object);
if (!(h instanceof WriteableView)) {
// h instanceof ConfigView
ConfigBean bean = (ConfigBean) ((ConfigView) h).getMasterView();
h = bean.getWriteableView();
if (h == null) {
ConfigBeanProxy writable;
try {
writable = currentTx.enroll((ConfigBeanProxy) object);
} catch (TransactionFailure e) {
// something is seriously wrong
throw new RuntimeException(e);
}
h = Proxy.getInvocationHandler(writable);
} else {
// so oldValue was already processed
return false;
}
}
WriteableView writableView = (WriteableView) h;
synchronized (writableView) {
writableView.isDeleted = true;
}
boolean removed = false;
for (Property property : writableView.bean.model.elements.values()) {
if (property.isCollection()) {
Object nested = writableView.getter(property, parameterizedType);
ProtectedList list = (ProtectedList) nested;
if (list.size() > 0) {
list.clear();
removed = true;
}
} else if (!property.isLeaf()) {
// Element
Object oldValue = writableView.getter(property, ConfigBeanProxy.class);
if (oldValue != null) {
writableView.setter(property, null, Dom.class);
removed = true;
removeNestedElements(oldValue);
}
}
}
return removed;
}
use of java.lang.reflect.InvocationHandler in project Payara by payara.
the class ProfiledConnectionWrapper40 method getProxyObject.
// TODO refactor this method and move to a higher level
private <T> T getProxyObject(final Object actualObject, Class<T>[] ifaces) throws Exception {
T result;
InvocationHandler ih = new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
SQLTraceRecord record = new SQLTraceRecord();
record.setMethodName(method.getName());
record.setParams(args);
record.setClassName(actualObject.getClass().getName());
record.setThreadName(Thread.currentThread().getName());
record.setThreadID(Thread.currentThread().getId());
record.setTimeStamp(System.currentTimeMillis());
try {
long startTime = System.currentTimeMillis();
Object methodResult = method.invoke(actualObject, args);
record.setExecutionTime(System.currentTimeMillis() - startTime);
return methodResult;
} catch (InvocationTargetException ex) {
Throwable cause = ex.getCause();
if (cause != null) {
throw cause;
} else {
throw ex;
}
} finally {
sqlTraceDelegator.sqlTrace(record);
}
}
};
result = (T) Proxy.newProxyInstance(actualObject.getClass().getClassLoader(), ifaces, ih);
return result;
}
use of java.lang.reflect.InvocationHandler in project Payara by payara.
the class ImplementorCacheDelegateImpl method createImplementor.
private Implementor createImplementor(RuntimeEndpointInfo targetEndpoint) throws Exception {
Tie tie = (Tie) targetEndpoint.getTieClass().newInstance();
Class seiClass = targetEndpoint.getRemoteInterface();
Class implClass = targetEndpoint.getImplementationClass();
Remote servant = null;
if (seiClass.isAssignableFrom(implClass)) {
// if servlet endpoint impl is a subtype of SEI, use an
// instance as the servant.
servant = (Remote) implClass.newInstance();
} else {
// Create a dynamic proxy that implements SEI (and optionally
// ServiceLifecycle) and delegates to an instance of the
// endpoint impl.
Object implInstance = implClass.newInstance();
InvocationHandler handler = new ServletImplInvocationHandler(implInstance);
boolean implementsLifecycle = ServiceLifecycle.class.isAssignableFrom(implClass);
Class[] proxyInterfaces = implementsLifecycle ? new Class[] { seiClass, ServiceLifecycle.class } : new Class[] { seiClass };
servant = (Remote) Proxy.newProxyInstance(implClass.getClassLoader(), proxyInterfaces, handler);
}
tie.setTarget(servant);
Implementor implementor = rpcFactory_.createImplementor(servletContext_, tie);
implementor.init();
return implementor;
}
use of java.lang.reflect.InvocationHandler in project Payara by payara.
the class PayaraClusteredCDIEventImpl method getQualifiers.
@Override
public Set<Annotation> getQualifiers() {
if (qualifiers == null) {
try {
qualifiers = qualifiersPayload.getValue();
} catch (IOException | ClassNotFoundException ex) {
Logger.getLogger(PayaraClusteredCDIEventImpl.class.getName()).log(Level.INFO, "Unable to deserialize qualifiers received on the event ignoring...", ex);
}
}
if (qualifiers != null) {
Set<Annotation> result = new HashSet<>(qualifiers.size());
for (InvocationHandler qualifier : qualifiers) {
// ok we have the invocation handlers that have been serialized
// we now need to create a Proxy for each
// First find the type
Method[] methods = Annotation.class.getMethods();
Class<?> annotationClazz = null;
for (Method method : methods) {
if (method.getName().equals("annotationType")) {
try {
annotationClazz = (Class<?>) qualifier.invoke(null, method, new Object[0]);
// then create a proxy for the annotation type from the serialized Invocation Handler
result.add((Annotation) Proxy.newProxyInstance(Utility.getClassLoader(), new Class[] { annotationClazz }, qualifier));
} catch (Throwable ex) {
Logger.getLogger(PayaraClusteredCDIEventImpl.class.getName()).log(Level.INFO, "Problem determining the qualifier type of an Event ignoring", ex);
}
}
}
}
return result;
} else {
return Collections.EMPTY_SET;
}
}
use of java.lang.reflect.InvocationHandler in project Payara by payara.
the class CommandRunnerTest method simpleDomain.
private static Domain simpleDomain() {
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
throw new UnsupportedOperationException("Feature-free dummy implementation for injection only");
}
};
Domain d = (Domain) Proxy.newProxyInstance(Domain.class.getClassLoader(), new Class[] { Domain.class }, handler);
return d;
}
Aggregations