Package javax.naming.spi

Examples of javax.naming.spi.ObjectFactory


                                    Hashtable environment)
        throws Exception {
       
        if (obj instanceof ResourceEnvRef) {
            Reference ref = (Reference) obj;
            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


                }
                */
                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

                    if (! (rof instanceof ObjectFactory)) {
                        throw new Exception(rof + " must implement ObjectFactory");
                    }

                    ObjectFactory of = (ObjectFactory)rof;
                    Reference newref = new Reference(repositoryConfigClassName,
                        configFactoryClassName, null);

                    // carry over all arguments except our own
                    for (Enumeration en = ref.getAll(); en.hasMoreElements(); ){
                        RefAddr ra = (RefAddr)en.nextElement();
                        String type = ra.getType();
                        if (! RCF.equals(type) && ! RCC.equals(type)) {
                            newref.add(ra);
                        }
                    }

                    Object config = of.getObjectInstance(newref, name, nameCtx, environment);
                    if (! (config instanceof RepositoryConfig)) {
                        throw new Exception(config + " must implement RepositoryConfig");
                    }
                    return RepositoryImpl.create((RepositoryConfig)config);
                }
View Full Code Here

  {
    ServiceReference ref = bc.getServiceReference(ObjectFactory.class.getName());
   
    assertNotNull("The aries url context object factory was not registered", ref);
   
    ObjectFactory factory = (ObjectFactory) bc.getService(ref);
   
    assertNotNull("The aries url context object factory was null", factory);
  }
View Full Code Here

  @Test
  public void testURLReferenceWithMatchingHandler() throws Exception
  {
    String testObject = "Test object";
    ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
    Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);

    Properties props = new Properties();
    props.setProperty("osgi.jndi.urlScheme", "wibble");
View Full Code Here

  @Test
  public void testReferenceWithNoClassName() throws Exception
  {
    String testObject = "Test object";
    ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
    Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);

    bc.registerService(ObjectFactory.class.getName(), factory, null);

    Reference ref = new Reference(null);
View Full Code Here

  @Test
  public void testSpecifiedFactoryWithMatchingFactory() throws Exception
  {
    String testObject = "Test object";
    ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
    Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);

    Reference ref = new Reference("dummy.class.name", factory.getClass().getName(), "");

    bc.registerService(new String[] {ObjectFactory.class.getName(), factory.getClass().getName()},
                       factory, null);

    Object obj = NamingManager.getObjectInstance(ref, null, null, env);
   
    assertEquals("The naming manager should have returned the test object", testObject, obj);
View Full Code Here

  @Test
  public void testSpecifiedFactoryWithRegisteredButNotMatchingFactory() throws Exception
  {
    String testObject = "Test object";
    ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
    Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), testObject);

    Reference ref = new Reference("dummy.class.name", "dummy.factory.class.name", "");

    bc.registerService(new String[] {ObjectFactory.class.getName(), factory.getClass().getName()},
                       factory, null);

    Object obj = NamingManager.getObjectInstance(ref, null, null, env);

    assertSame("The naming manager should have returned the reference object", ref, obj);
View Full Code Here

      URL u = new URL( fClassLocation );
      cl = new URLClassLoader( new URL[] { u }, ClassLoader.getSystemClassLoader() );
        }
   
    Class fClass = Class.forName( fClassName, true, cl );
    ObjectFactory of = (ObjectFactory) fClass.newInstance();
    return of.getObjectInstance( ref, name, nameCtx, env );
      }
  catch ( Exception e )
      {
    if (Debug.DEBUG)
        {
View Full Code Here

      //
      // For some reason, this comes back as a Reference
      // instance under CruiseControl !?
      //
      Reference objAsRef = (Reference) obj;
      ObjectFactory factory = (ObjectFactory) Class.forName(
          objAsRef.getFactoryClassName()).newInstance();
      boundDs = (DataSource) factory.getObjectInstance(objAsRef,
          datasourceName, this.ctx, new Hashtable<Object, Object>());
    }

    assertTrue("Datasource not bound", boundDs != null);
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.