use of com.caucho.hessian.io.AbstractSerializerFactory in project cayenne by apache.
the class HessianConfig method loadFactory.
static AbstractSerializerFactory loadFactory(String factoryName, EntityResolver resolver) throws Exception {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class factoryClass = Class.forName(factoryName, true, loader);
if (!AbstractSerializerFactory.class.isAssignableFrom(factoryClass)) {
throw new IllegalArgumentException(factoryClass + " is not a AbstractSerializerFactory");
}
Constructor c = factoryClass.getDeclaredConstructor();
if (!Util.isAccessible(c)) {
c.setAccessible(true);
}
AbstractSerializerFactory object = (AbstractSerializerFactory) c.newInstance();
if (resolver != null) {
try {
Method setter = factoryClass.getDeclaredMethod("setEntityResolver", EntityResolver.class);
if (!Util.isAccessible(setter)) {
setter.setAccessible(true);
}
setter.invoke(object, resolver);
} catch (Exception e) {
// ignore injection exception
}
}
return object;
}
use of com.caucho.hessian.io.AbstractSerializerFactory in project cayenne by apache.
the class CayenneSerializerFactory method getDeserializer.
@Override
public Deserializer getDeserializer(Class cl) throws HessianProtocolException {
for (int i = 0; _factories != null && i < _factories.size(); i++) {
AbstractSerializerFactory factory;
factory = (AbstractSerializerFactory) _factories.get(i);
Deserializer deserializer = factory.getDeserializer(cl);
if (deserializer != null) {
return deserializer;
}
}
return super.getDeserializer(cl);
}
use of com.caucho.hessian.io.AbstractSerializerFactory in project cayenne by apache.
the class HessianConfigTest method testLoadFactoryInjection.
@Test
public void testLoadFactoryInjection() throws Exception {
EntityResolver resolver = new EntityResolver();
AbstractSerializerFactory factory = HessianConfig.loadFactory(MockAbstractSerializerFactory.class.getName(), resolver);
assertTrue(factory instanceof MockAbstractSerializerFactory);
assertSame(resolver, ((MockAbstractSerializerFactory) factory).getEntityResolver());
}
use of com.caucho.hessian.io.AbstractSerializerFactory in project cayenne by apache.
the class HessianConfigTest method testLoadFactoryNoInjection.
@Test
public void testLoadFactoryNoInjection() throws Exception {
AbstractSerializerFactory factory = HessianConfig.loadFactory(MockAbstractSerializerFactory.class.getName(), null);
assertTrue(factory instanceof MockAbstractSerializerFactory);
assertNull(((MockAbstractSerializerFactory) factory).getEntityResolver());
}
Aggregations