Package javax.naming.spi

Examples of javax.naming.spi.ObjectFactory


                                                               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;
    }
View Full Code Here


        throws NamingException {
     
        ServicePair<ObjectFactory> urlObjectFactory = getURLObjectFactory(context, urlScheme, env);
       
        if (urlObjectFactory != null) {
            ObjectFactory factory = urlObjectFactory.get();
           
            if (factory != null) {
                return new URLContextProvider(context, urlObjectFactory.getReference(), factory, env);
            }
        }
View Full Code Here

        if (refs != null) {
          for (final ServiceReference finderRef : refs) {
            URLObjectFactoryFinder finder = (URLObjectFactoryFinder) Utils.getServicePrivileged(ctx, finderRef);
               
            if (finder != null) {
              ObjectFactory f = finder.findFactory(urlScheme, environment);
             
              if (f != null) {
                result = new ServicePair<ObjectFactory>(ctx, finderRef, f);
                break;
              } else {
View Full Code Here

        public ClassLoader run() {
          return Thread.currentThread().getContextClassLoader();
        }
      });
      for (String cand : candidates) {
        ObjectFactory factory = null;
        try {
          @SuppressWarnings("unchecked")
          Class<ObjectFactory> clz = (Class<ObjectFactory>) cl.loadClass(cand);
          factory = clz.newInstance();
        } catch (Exception e) {
          logger.log(Level.FINE, "Exception instantiating factory: " + e);
          continue;
        }
        logger.log(Level.FINE, "cand=" + cand + " factory=" + factory);
        if (factory != null) {
          result = factory.getObjectInstance(obj, name, nameCtx, environment);
        }
        if (result != null && result != obj) break;
      }
    }
    return (result == null) ? obj : result;
View Full Code Here

        if (refs != null) {
            Arrays.sort(refs, Utils.SERVICE_REFERENCE_COMPARATOR);
           
            for (ServiceReference ref : refs) {
              if (canCallObjectFactory(obj, ref)) {
                ObjectFactory factory = (ObjectFactory) Utils.getServicePrivileged(callerContext, ref);

                try {
                    result = factory.getObjectInstance(obj, name, nameCtx, environment);
                } catch (NamingException ne) {
                  // Ignore this since we are doing last ditch finding, another OF might work.
                } finally {
                    callerContext.ungetService(ref);
                }
View Full Code Here

                String urlScheme = getUrlScheme( (String) address.getContent() );
               
                ServicePair<ObjectFactory> factoryService = ContextHelper.getURLObjectFactory(callerContext, urlScheme, environment);
               
                if (factoryService != null) {
                    ObjectFactory factory = factoryService.get();
                   
                    String value = (String) address.getContent();
                    try {
                        result = factory.getObjectInstance(value, name, nameCtx, environment);
                    } finally {
                        factoryService.unget();
                    }
                   
                    // if the result comes back and is not null and not the reference
View Full Code Here

                } catch (InvalidSyntaxException e) {
                    // should not happen
                    throw new RuntimeException(Utils.MESSAGES.getMessage("null.is.invalid.filter"), e);
                }

                ObjectFactory factory = null;
               
                if (serviceReference != null) {
                    factory = (ObjectFactory) ctx.getService(serviceReference);           
                }
               
View Full Code Here

                                                               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;
    }
View Full Code Here

  }

  @Test
  public void testLookupWithoutICFButWithURLLookup() throws NamingException
  {
    ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
    Context ctx = Skeleton.newMock(Context.class);
    Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class),
                                                 ctx);
    Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", String.class), "someText");
   
View Full Code Here

    Skeleton.getSkeleton(backCtx).assertCalled(new MethodCall(LdapContext.class, "extendedOperation", req));
  }
 
  @Test
  public void testURLLookup() throws Exception {
      ObjectFactory of = new ObjectFactory() {
          public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
              return dummyContext("result");
          }
      };
     
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.