Examples of InitialContextFactory


Examples of javax.naming.spi.InitialContextFactory

        });
               
                if (references != null) {
                    Context initialContext = null;
                    for (ServiceReference reference : references) {
                        InitialContextFactory factory = (InitialContextFactory) Utils.getServicePrivileged(context, reference);
                        try {
                            initialContext = factory.getInitialContext(environment);
                            if (initialContext != null) {
                              provider = new SingleContextProvider(context, reference, initialContext);
                              break;
                          }
                        } finally {
                            if (provider == null) context.ungetService(reference);
                        }
                    }
                }
            }
        } else {
            ServiceReference ref = ServiceTrackerCustomizers.ICF_CACHE.find(contextFactoryClass);
           
            if (ref != null) {
              Context initialContext = null;
              InitialContextFactory factory = (InitialContextFactory) Utils.getServicePrivileged(context, ref);
              if (factory != null) {
                try {
                    initialContext = factory.getInitialContext(environment);
                    provider = new SingleContextProvider(context, ref, initialContext);
                } finally {
                    if (provider == null) context.ungetService(ref);
                }
              }
View Full Code Here

Examples of javax.naming.spi.InitialContextFactory

        return Activator.getInitialContextFactoryBuilderServices();
      }         
    });
         
        if (refs != null) {
            InitialContextFactory factory = null;
            for (ServiceReference ref : refs) {                   
                InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) Utils.getServicePrivileged(context, ref);
                try {
                  factory = builder.createInitialContextFactory(environment);
                } catch (NamingException ne) {
                  // TODO: log
                  // ignore this, if the builder fails we want to move onto the next one
                }
               
                if (factory != null) {
                  try {
                    provider = new SingleContextProvider(context, ref, factory.getInitialContext(environment));
                  } finally {
                    if (provider == null) context.ungetService(ref); // we didn't get something back, so this was no good.
                  }
                  break;
                } else {
View Full Code Here

Examples of javax.naming.spi.InitialContextFactory

   */
  public static Context createContext(Hashtable<?,?> env)
    throws NamingException
  {
   
    InitialContextFactory icf = null;
    ServiceReference ref = null;

    String icfFactory = (String) env.get(Context.INITIAL_CONTEXT_FACTORY);
   
    boolean icfFactorySet = true;

    if (icfFactory == null) {
      icfFactory = InitialContextFactory.class.getName();
      icfFactorySet = false;
    }
   
    try {
      ServiceReference[] refs = context.getAllServiceReferences(icfFactory, null);
      if (refs != null) {
        ref = refs[0];
        icf = (InitialContextFactory) context.getService(ref);
      }
    } catch (InvalidSyntaxException e) {
      // TODO nls enable this.
      NamingException e4 = new NamingException("Argh this should never happen :)");
      e4.initCause(e);
     
      throw e4;
    }

    if (icf == null) {
      try {
        ServiceReference[] refs = context.getAllServiceReferences(InitialContextFactoryBuilder.class.getName(), null);

        if (refs != null) {
          for (ServiceReference icfbRef : refs) {
            InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) context.getService(icfbRef);

            icf = builder.createInitialContextFactory(env);
           
            context.ungetService(icfbRef);
            if (icf != null) {
              break;
            }
          }
        }
      } catch (InvalidSyntaxException e) {
        // TODO nls enable this.
        NamingException e4 = new NamingException("Argh this should never happen :)");
        e4.initCause(e);   
        throw e4;
      }
    }

    if (icf == null && icfFactorySet) {
      try {
        Class<?> clazz = Class.forName(icfFactory, true, null);
        icf = (InitialContextFactory) clazz.newInstance();
      } catch (ClassNotFoundException e11) {
        // TODO nls enable this.
        NamingException e = new NamingException("Argh this should never happen :)");
        e.initCause(e11);   
        throw e;
      } catch (InstantiationException e2) {
        // TODO nls enable this.
        NamingException e4 = new NamingException("Argh this should never happen :)");
        e4.initCause(e2);   
        throw e4;
      } catch (IllegalAccessException e1) {
        // TODO nls enable this.
        NamingException e4 = new NamingException("Argh this should never happen :)");
        e4.initCause(e1);   
        throw e4;
      }
    }

    if (icf == null) {

      // TODO nls enable this.
      NamingException e3 = new NoInitialContextException("We could not find an InitialContextFactory to use");
     
      throw e3;
    }

    Context ctx = icf.getInitialContext(env);

    if (ref != null) context.ungetService(ref);

    if (ctx == null) {
      // TODO nls enable this
View Full Code Here

Examples of javax.naming.spi.InitialContextFactory

 
 
  private static Context createIcfContext(Hashtable<?,?> env) throws NamingException
  {
    String icfFactory = (String) env.get(Context.INITIAL_CONTEXT_FACTORY);
    InitialContextFactory icf = null;

    if (icfFactory != null) {
      try {
        Class<?> clazz = Class.forName(icfFactory, true, Thread.currentThread()
            .getContextClassLoader());
        icf = (InitialContextFactory) clazz.newInstance();

      } catch (ClassNotFoundException e11) {
        NamingException e4 = new NamingException("Argh this should never happen :)");
        e4.initCause(e11);
        throw e4;
      } catch (InstantiationException e2) {
        NamingException e4 = new NamingException("Argh this should never happen :)");
        e4.initCause(e2);
        throw e4;
      } catch (IllegalAccessException e1) {
        NamingException e4 = new NamingException("Argh this should never happen :)");
        e4.initCause(e1);
        throw e4;
      }
    }
    Context ctx = null;

    if (icf != null) {
      ctx = icf.getInitialContext(env);
    }   
   
    return ctx;
  }
View Full Code Here

Examples of javax.naming.spi.InitialContextFactory

     * @return
     * @throws NamingException
     */
    public Context createContext (Hashtable<?,?> env) throws NamingException {

        InitialContextFactory icf = null;
        ServiceReference ref = null;

        String icfFactory = (String) env.get(Context.INITIAL_CONTEXT_FACTORY);

        boolean icfFactorySet = true;

        if (icfFactory == null) {
            icfFactory = InitialContextFactory.class.getName();
            icfFactorySet = false;
        }

        try {
            ServiceReference[] refs = context.getAllServiceReferences(icfFactory, null);
            if (refs != null) {
                ref = refs[0];
                icf = (InitialContextFactory) context.getService(ref);
            }
        } catch (InvalidSyntaxException e) {
            NamingException e4 = new NamingException("Argh this should never happen :)");
            e4.initCause(e);

            throw e4;
        }

        if (icf == null) {
            try {
                ServiceReference[] refs = context.getAllServiceReferences(InitialContextFactoryBuilder.class.getName(), null);

                if (refs != null) {
                    for (ServiceReference icfbRef : refs) {
                        InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) context.getService(icfbRef);

                        icf = builder.createInitialContextFactory(env);

                        context.ungetService(icfbRef);
                        if (icf != null) {
                            break;
                        }
                    }
                }
            } catch (InvalidSyntaxException e) {
                NamingException e4 = new NamingException("Argh this should never happen :)");
                e4.initCause(e);
                throw e4;
            }
        }

        if (icf == null && icfFactorySet) {
            try {
                Class<?> clazz = Class.forName(icfFactory, true, Thread.currentThread().getContextClassLoader());
                icf = (InitialContextFactory) clazz.newInstance();
            } catch (ClassNotFoundException e11) {
                NamingException e = new NamingException("Argh this should never happen :)");
                e.initCause(e11);
                throw e;
            } catch (InstantiationException e2) {
                NamingException e4 = new NamingException("Argh this should never happen :)");
                e4.initCause(e2);
                throw e4;
            } catch (IllegalAccessException e1) {
                NamingException e4 = new NamingException("Argh this should never happen :)");
                e4.initCause(e1);
                throw e4;
            }
        }

        if (icf == null) {
            NamingException e3 = new NoInitialContextException("We could not find an InitialContextFactory to use");

            throw e3;
        }

        Context ctx = icf.getInitialContext(env);

        if (ref != null) context.ungetService(ref);

        if (ctx == null) {
          NamingException e = new NamingException("The ICF returned a null context");
View Full Code Here

Examples of javax.naming.spi.InitialContextFactory

    {

        Context context = mock(Context.class);
        when(context.lookup(NAME)).thenReturn(RESOLVED_NAME);

        InitialContextFactory jndiContextFactory = mock(InitialContextFactory.class);
        when(jndiContextFactory.getInitialContext(any(Hashtable.class))).thenReturn(context);

        CachedJndiNameResolver jndiNameResolver = new CachedJndiNameResolver();
        jndiNameResolver.setContextFactory(jndiContextFactory);
        jndiNameResolver.setJndiInitialFactory("initialFactory");
        jndiNameResolver.initialise();
View Full Code Here

Examples of javax.naming.spi.InitialContextFactory

        super.setUp();

        environment.put("useEmbeddedBroker", "true");
        environment.put("brokerURL", "vm://localhost");

        InitialContextFactory factory = new ActiveMQInitialContextFactory();
        context = factory.getInitialContext(environment);
        assertTrue("No context created", context != null);
    }
View Full Code Here

Examples of javax.naming.spi.InitialContextFactory

    protected void setUp() throws Exception {
        super.setUp();

        configureEnvironment();

        InitialContextFactory factory = new ActiveMQInitialContextFactory();
        context = factory.getInitialContext(environment);
        assertTrue("No context created", context != null);
    }
View Full Code Here

Examples of javax.naming.spi.InitialContextFactory

         * @see javax.naming.spi.InitialContextFactoryBuilder#createInitialContextFactory(java.util.Hashtable)
         */
        @Override
        public InitialContextFactory createInitialContextFactory(final Hashtable<?, ?> environment)
                throws NamingException {
            return new InitialContextFactory() {
                @Override
                public Context getInitialContext(final Hashtable<?, ?> environment) throws NamingException {
                    return new StubContext(environment);
                }
            };
View Full Code Here

Examples of javax.naming.spi.InitialContextFactory

    protected void setUp() throws Exception
    {
        super.setUp();

        InitialContextFactory factory = new PropertiesFileInitialContextFactory();

        Hashtable<String, String> env = new Hashtable<String, String>();

        // Create Client 1
        _clientConnection = getConnection();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.