Search in sources :

Example 1 with ObjectFactoryBuilder

use of javax.naming.spi.ObjectFactoryBuilder in project aries by apache.

the class DirObjectFactoryHelper method getObjectInstanceUsingObjectFactoryBuilders.

private Object getObjectInstanceUsingObjectFactoryBuilders(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment, Attributes attrs) throws Exception {
    ObjectFactory factory = null;
    ServiceReference[] refs = Utils.getReferencesPrivileged(callerContext, ObjectFactoryBuilder.class);
    if (refs != null) {
        Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
        for (ServiceReference ref : refs) {
            ObjectFactoryBuilder builder = (ObjectFactoryBuilder) Utils.getServicePrivileged(callerContext, ref);
            try {
                factory = builder.createObjectFactory(obj, environment);
            } catch (NamingException e) {
            // TODO: log it
            } finally {
                callerContext.ungetService(ref);
            }
            if (factory != null) {
                break;
            }
        }
    }
    Object result = null;
    if (factory != null) {
        if (factory instanceof DirObjectFactory) {
            result = ((DirObjectFactory) factory).getObjectInstance(obj, name, nameCtx, environment, attrs);
        } else {
            result = factory.getObjectInstance(obj, name, nameCtx, environment);
        }
    }
    return (result == null) ? obj : result;
}
Also used : DirObjectFactory(javax.naming.spi.DirObjectFactory) ObjectFactory(javax.naming.spi.ObjectFactory) ObjectFactoryBuilder(javax.naming.spi.ObjectFactoryBuilder) NamingException(javax.naming.NamingException) DirObjectFactory(javax.naming.spi.DirObjectFactory) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with ObjectFactoryBuilder

use of javax.naming.spi.ObjectFactoryBuilder in project aries by apache.

the class ObjectFactoryHelper method getObjectInstanceUsingObjectFactoryBuilders.

private Object getObjectInstanceUsingObjectFactoryBuilders(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment, Attributes attrs) throws Exception {
    ObjectFactory factory = null;
    for (ObjectFactoryBuilder ofb : Activator.getServices(callerContext, ObjectFactoryBuilder.class)) {
        try {
            factory = ofb.createObjectFactory(obj, environment);
        } catch (NamingException e) {
        // TODO: log it
        }
        if (factory != null) {
            break;
        }
    }
    Object result = null;
    if (factory != null) {
        result = getObjectFromFactory(obj, name, nameCtx, environment, attrs, factory);
    }
    return (result == null) ? obj : result;
}
Also used : DirObjectFactory(javax.naming.spi.DirObjectFactory) ObjectFactory(javax.naming.spi.ObjectFactory) ObjectFactoryBuilder(javax.naming.spi.ObjectFactoryBuilder)

Example 3 with ObjectFactoryBuilder

use of javax.naming.spi.ObjectFactoryBuilder in project aries by apache.

the class ObjectFactoryHelper method getObjectInstanceUsingObjectFactoryBuilders.

private Object getObjectInstanceUsingObjectFactoryBuilders(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    ObjectFactory factory = null;
    ServiceReference[] refs = Utils.getReferencesPrivileged(callerContext, ObjectFactoryBuilder.class);
    if (refs != null) {
        Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
        for (ServiceReference ref : refs) {
            ObjectFactoryBuilder builder = (ObjectFactoryBuilder) Utils.getServicePrivileged(callerContext, ref);
            try {
                factory = builder.createObjectFactory(obj, environment);
            } catch (NamingException e) {
            // TODO: log it
            } finally {
                callerContext.ungetService(ref);
            }
            if (factory != null) {
                break;
            }
        }
    }
    Object result = null;
    if (factory != null) {
        result = factory.getObjectInstance(obj, name, nameCtx, environment);
    }
    return (result == null) ? obj : result;
}
Also used : DirObjectFactory(javax.naming.spi.DirObjectFactory) ObjectFactory(javax.naming.spi.ObjectFactory) ObjectFactoryBuilder(javax.naming.spi.ObjectFactoryBuilder) NamingException(javax.naming.NamingException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

DirObjectFactory (javax.naming.spi.DirObjectFactory)3 ObjectFactory (javax.naming.spi.ObjectFactory)3 ObjectFactoryBuilder (javax.naming.spi.ObjectFactoryBuilder)3 NamingException (javax.naming.NamingException)2 ServiceReference (org.osgi.framework.ServiceReference)2