Search in sources :

Example 1 with AbstractSerializerFactory

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;
}
Also used : AbstractSerializerFactory(com.caucho.hessian.io.AbstractSerializerFactory) Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 2 with AbstractSerializerFactory

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);
}
Also used : AbstractSerializerFactory(com.caucho.hessian.io.AbstractSerializerFactory) Deserializer(com.caucho.hessian.io.Deserializer)

Example 3 with AbstractSerializerFactory

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());
}
Also used : AbstractSerializerFactory(com.caucho.hessian.io.AbstractSerializerFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 4 with AbstractSerializerFactory

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());
}
Also used : AbstractSerializerFactory(com.caucho.hessian.io.AbstractSerializerFactory) Test(org.junit.Test)

Aggregations

AbstractSerializerFactory (com.caucho.hessian.io.AbstractSerializerFactory)4 Test (org.junit.Test)2 Deserializer (com.caucho.hessian.io.Deserializer)1 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 EntityResolver (org.apache.cayenne.map.EntityResolver)1