use of javassist.util.proxy.ProxyObject in project jbosstools-hibernate by jbosstools.
the class Hbm2DDLExporterFacadeTest method setUp.
@Before
public void setUp() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setSuperclass(Hbm2DDLExporter.class);
Class<?> proxyClass = proxyFactory.createClass();
hbm2ddlExporter = (Hbm2DDLExporter) proxyClass.newInstance();
((ProxyObject) hbm2ddlExporter).setHandler(new MethodHandler() {
@Override
public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Throwable {
if (methodName == null) {
methodName = m.getName();
}
if (arguments == null) {
arguments = args;
}
return proceed.invoke(self, args);
}
});
hbm2DDLExporterFacade = new AbstractHbm2DDLExporterFacade(FACADE_FACTORY, hbm2ddlExporter) {
};
reset();
}
use of javassist.util.proxy.ProxyObject in project orientdb by orientechnologies.
the class OObjectProxyMethodHandler method detachAll.
/**
* Method that detaches all fields contained in the document to the given object
*
* @param self
* :- The object containing this handler instance
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws NoSuchMethodException
*/
public void detachAll(final Object self, final boolean nonProxiedInstance, final Map<Object, Object> alreadyDetached, final Map<Object, Object> lazyObjects) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
final Class<?> selfClass = self.getClass();
for (String fieldName : doc.fieldNames()) {
final Field field = OObjectEntitySerializer.getField(fieldName, selfClass);
if (field != null) {
Object value = getValue(self, fieldName, false, null, true);
if (value instanceof OObjectLazyMultivalueElement) {
((OObjectLazyMultivalueElement<?>) value).detachAll(nonProxiedInstance, alreadyDetached, lazyObjects);
if (nonProxiedInstance)
value = ((OObjectLazyMultivalueElement<?>) value).getNonOrientInstance();
} else if (value instanceof Proxy) {
OObjectProxyMethodHandler handler = (OObjectProxyMethodHandler) ((ProxyObject) value).getHandler();
if (nonProxiedInstance) {
value = OObjectEntitySerializer.getNonProxiedInstance(value);
}
if (OObjectEntitySerializer.isFetchLazyField(self.getClass(), fieldName)) {
// just make a placeholder with only the id, so it can be fetched later (but not by orient internally)
// do not use the already detached map for this, that might mix up lazy and non-lazy objects
Object lazyValue = lazyObjects.get(handler.doc.getIdentity());
if (lazyValue != null) {
value = lazyValue;
} else {
OObjectEntitySerializer.setIdField(field.getType(), value, handler.doc.getIdentity());
lazyObjects.put(handler.doc.getIdentity(), value);
}
} else {
Object detachedValue = alreadyDetached.get(handler.doc.getIdentity());
if (detachedValue != null) {
value = detachedValue;
} else {
ORID identity = handler.doc.getIdentity();
if (identity.isValid())
alreadyDetached.put(identity, value);
handler.detachAll(value, nonProxiedInstance, alreadyDetached, lazyObjects);
}
}
}
OObjectEntitySerializer.setFieldValue(field, self, value);
}
}
OObjectEntitySerializer.setIdField(selfClass, self, doc.getIdentity());
OObjectEntitySerializer.setVersionField(selfClass, self, doc.getVersion());
}
use of javassist.util.proxy.ProxyObject in project orientdb by orientechnologies.
the class OObjectLazyMap method convert.
/**
* Assure that the requested key is converted.
*/
private void convert(final String iKey) {
if (converted || !convertToRecord)
return;
if (super.containsKey(iKey))
return;
final ORecord record = (ORecord) underlying.get(iKey);
if (record == null)
return;
TYPE o = getDatabase().getUserObjectByRecord(record, null);
((OObjectProxyMethodHandler) (((ProxyObject) o)).getHandler()).setParentObject(sourceRecord);
super.put(iKey, o);
}
use of javassist.util.proxy.ProxyObject in project fastjson by alibaba.
the class ProxyTest method create.
public static <T> T create(Class<T> classs) throws Exception {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(classs);
Class clazz = factory.createClass();
MethodHandler handler = new MethodHandler() {
public Object invoke(Object self, Method overridden, Method forwarder, Object[] args) throws Throwable {
return forwarder.invoke(self, args);
}
};
Object instance = clazz.newInstance();
((ProxyObject) instance).setHandler(handler);
return (T) instance;
}
use of javassist.util.proxy.ProxyObject in project jbosstools-hibernate by jbosstools.
the class GenericExporterFacadeTest method setUp.
@Before
public void setUp() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setSuperclass(GenericExporter.class);
Class<?> proxyClass = proxyFactory.createClass();
genericExporter = (GenericExporter) proxyClass.newInstance();
((ProxyObject) genericExporter).setHandler(new MethodHandler() {
@Override
public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Throwable {
if (methodName == null) {
methodName = m.getName();
}
if (arguments == null) {
arguments = args;
}
return proceed.invoke(self, args);
}
});
genericExporterFacade = new AbstractGenericExporterFacade(FACADE_FACTORY, genericExporter) {
};
reset();
}
Aggregations