Package javax.naming.spi

Examples of javax.naming.spi.ObjectFactory


                }
                */
                return beanObj;
            }
           
            ObjectFactory factory = null;
            RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
            if (factoryRefAddr != null) {
                // Using the specified factory
                String factoryClassName =
                    factoryRefAddr.getContent().toString();
                // Loading factory
                ClassLoader tcl =
                    Thread.currentThread().getContextClassLoader();
                Class factoryClass = null;
                if (tcl != null) {
                    try {
                        factoryClass = tcl.loadClass(factoryClassName);
                    } catch(ClassNotFoundException e) {
                    }
                } else {
                    try {
                        factoryClass = Class.forName(factoryClassName);
                    } catch(ClassNotFoundException e) {
                    }
                }
                if (factoryClass != null) {
                    try {
                        factory = (ObjectFactory) factoryClass.newInstance();
                    } catch(Throwable t) {
                    }
                }
            }

            // Note: No defaults here
            if (factory != null) {
                return factory.getObjectInstance
                    (obj, name, nameCtx, environment);
            } else {
                throw new NamingException
                    ("Cannot create resource instance");
            }
View Full Code Here


            int index = jndiName.indexOf(":");
            if ( index > 0){                
                 String scheme = jndiName.substring(0, index);
                 ServiceReference[] sr = bundleContext.getServiceReferences(ObjectFactory.class.getName(), "(osgi.jndi.url.scheme=" + scheme +")");
                if (sr != null) {
                    ObjectFactory objectFactory = (ObjectFactory) bundleContext.getService(sr[0]);
                    // Get context
                    this.context = (Context) objectFactory.getObjectInstance(null, null, null, null);
                    Name parsedName = context.getNameParser("").parse(jndiName);

                    // create intermediate contexts
                    for (int i = 1; i < parsedName.size(); i++) {
                        Name contextName = parsedName.getPrefix(i);
View Full Code Here

        ServiceReference[] sr;
        try {
            sr = bundleContext.getServiceReferences(ObjectFactory.class.getName(), "(osgi.jndi.url.scheme="+ nameInNamespace.substring(0, nameInNamespace.indexOf(":")) + ")");
       
            if (sr != null) {
                ObjectFactory objectFactory = (ObjectFactory) bundleContext.getService(sr[0]);
                context = (Context) objectFactory.getObjectInstance(null, null,    null, null);
                for (AbstractName abstractName : set) {
                      try {
                        if (kernel.isRunning(abstractName)) {
                            addBinding(abstractName);                           
                          }
View Full Code Here

    }

    private Object getObjectInstance(final Object object, final Name name, final Hashtable<?, ?> environment) throws NamingException {
        try {
            final ObjectFactoryBuilder factoryBuilder = ObjectFactoryBuilder.INSTANCE;
            final ObjectFactory objectFactory = factoryBuilder.createObjectFactory(object, environment);
            return objectFactory.getObjectInstance(object, name, this, environment);
        } catch(NamingException e) {
            throw e;
        } catch(Throwable t) {
            throw namingException("Could not dereference object", t);
        }
View Full Code Here

        if(factoriesProp != null) {
            final String[] classes = factoriesProp.split(":");
            for(String className : classes) {
                try {
                    final Class<?> factoryClass = classLoader.loadClass(className);
                    final ObjectFactory objectFactory = ObjectFactory.class.cast(factoryClass.newInstance());
                    final Object result = objectFactory.getObjectInstance(ref, name, nameCtx, environment);
                    if(result != null) {
                        return result;
                    }
                } catch(Throwable ignored) {
                }
View Full Code Here

    }

    private ObjectFactory factoryFromReference(final Reference reference, final ClassLoader classLoader, final Hashtable<?, ?> environment) throws Exception {
        try {
            final Class<?> factoryClass = classLoader.loadClass(reference.getFactoryClassName());
            ObjectFactory factory = ObjectFactory.class.cast(factoryClass.newInstance());
            if (factory instanceof ServiceAwareObjectFactory) {
                ((ServiceAwareObjectFactory) factory).injectServiceRegistry(serviceRegistry);
            }
            return factory;
        } catch (Throwable t) {
View Full Code Here

                   is(source.getDirectoryForDefaultWorkspace()));
        refAttributes.remove(SVNRepositorySource.PREDEFINED_WORKSPACE_NAMES);
        assertThat(refAttributes.isEmpty(), is(true));

        // Recreate the object, use a newly constructed source ...
        ObjectFactory factory = new SVNRepositorySource();
        Name name = mock(Name.class);
        Context context = mock(Context.class);
        Hashtable<?, ?> env = new Hashtable<Object, Object>();
        SVNRepositorySource recoveredSource = (SVNRepositorySource)factory.getObjectInstance(ref, name, context, env);
        assertThat(recoveredSource, is(notNullValue()));

        assertThat(recoveredSource.getName(), is(source.getName()));
        assertThat(recoveredSource.getRepositoryRootURL(), is(source.getRepositoryRootURL()));
        assertThat(recoveredSource.getUsername(), is(source.getUsername()));
View Full Code Here

     * @throws IllegalArgumentException if the requested scheme/factory combination is not registered.
     */
    public static synchronized void removeUrlContextFactory(final String scheme, ObjectFactory factory) {
        Map<String, ObjectFactory> factories = new HashMap<String, ObjectFactory>(urlContextFactories);

        ObjectFactory f = factories.get(scheme);
        if (f == factory) {
            factories.remove(scheme);
            urlContextFactories = Collections.unmodifiableMap(factories);
            return;
        } else {
View Full Code Here

            if (!parsedName.remaining().isEmpty()) {
                final String firstPart = parsedName.remaining().get(0);
                int index = firstPart.indexOf(':');
                if (index != -1) {
                    final String scheme = firstPart.substring(0, index);
                    ObjectFactory factory = urlContextFactories.get(scheme);
                    if (factory != null) {
                        try {
                            return ((Context) factory.getObjectInstance(null, name, this, getEnvironment())).lookup(name);
                        }catch(NamingException e) {
                            throw e;
                        } catch (Exception e) {
                            NamingException n = new NamingException(e.getMessage());
                            n.initCause(e);
View Full Code Here

    }

    private Object getObjectInstance(final Object object, final Name name, final Hashtable<?, ?> environment) throws NamingException {
        try {
            final ObjectFactoryBuilder factoryBuilder = ObjectFactoryBuilder.INSTANCE;
            final ObjectFactory objectFactory = factoryBuilder.createObjectFactory(object, environment);
            return objectFactory.getObjectInstance(object, name, this, environment);
        } catch(NamingException e) {
            throw e;
        } catch(Throwable t) {
            throw MESSAGES.cannotDeferenceObject(t);
        }
View Full Code Here

TOP

Related Classes of javax.naming.spi.ObjectFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.