當前位置: 首頁>>代碼示例>>Java>>正文


Java NamingManager.hasInitialContextFactoryBuilder方法代碼示例

本文整理匯總了Java中javax.naming.spi.NamingManager.hasInitialContextFactoryBuilder方法的典型用法代碼示例。如果您正苦於以下問題:Java NamingManager.hasInitialContextFactoryBuilder方法的具體用法?Java NamingManager.hasInitialContextFactoryBuilder怎麽用?Java NamingManager.hasInitialContextFactoryBuilder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.naming.spi.NamingManager的用法示例。


在下文中一共展示了NamingManager.hasInitialContextFactoryBuilder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setup

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {

    // container.enableInterfaceMocking(true);
    if (!NamingManager.hasInitialContextFactoryBuilder()) {
        NamingManager
                .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder());
    }
    InitialContext initialContext = new InitialContext();
    Properties properties = new Properties();
    properties.put("mail.smtp.from", "[email protected]");
    mailMock = Session.getInstance(properties);
    initialContext.bind("java:openejb/Resource/" + DEFAULT_MAIL_RESOURCE, mailMock);
    configurationService = mock(APPConfigurationServiceBean.class);
    commService = spy(new APPCommunicationServiceBean());
    commService.configService = configurationService;
    doNothing().when(commService).transportMail(
            Matchers.any(MimeMessage.class));
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:APPCommunicationServiceBeanTest.java

示例2: activate

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Register the context builder by registering it with the JNDI NamingManager.
 * Note that once this has been done, {@code new InitialContext()} will always
 * return a context from this factory. Use the {@code emptyActivatedContextBuilder()}
 * static method to get an empty context (for example, in test methods).
 * @throws IllegalStateException if there's already a naming context builder
 * registered with the JNDI NamingManager
 */
public void activate() throws IllegalStateException, NamingException {
	logger.info("Activating simple JNDI environment");
	synchronized (initializationLock) {
		if (!initialized) {
			if (NamingManager.hasInitialContextFactoryBuilder()) {
				throw new IllegalStateException(
						"Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " +
						"Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " +
						"with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.");
			}
			NamingManager.setInitialContextFactoryBuilder(this);
			initialized = true;
		}
	}
	activated = this;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:SimpleNamingContextBuilder.java

示例3: activate

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Register the context builder by registering it with the JNDI NamingManager.
 * Note that once this has been done, {@code new InitialContext()} will always
 * return a context from this factory. Use the {@code emptyActivatedContextBuilder()}
 * static method to get an empty context (for example, in test methods).
 * @throws IllegalStateException if there's already a naming context builder
 * registered with the JNDI NamingManager
 */
public void activate() throws IllegalStateException, NamingException {
  logger.info("Activating simple JNDI environment");
  synchronized (initializationLock) {
    if (!initialized) {
      if (NamingManager.hasInitialContextFactoryBuilder()) {
        throw new IllegalStateException(
            "Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " +
                "Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " +
                "with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.");
      }
      NamingManager.setInitialContextFactoryBuilder(this);
      initialized = true;
    }
  }
  activated = this;
}
 
開發者ID:tzolov,項目名稱:springboot-gemfire-jpa-atomikos,代碼行數:25,代碼來源:SimpleNamingContextBuilder.java

示例4: getNativeURLOrDefaultInitCtx

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
protected Context getNativeURLOrDefaultInitCtx(Name name) throws NamingException {
   if (NamingManager.hasInitialContextFactoryBuilder()) {
      return defaultNativeContext;
   }
   if (name.size() > 0) {
      String first = name.get(0);
      String scheme = getURLScheme(first);
      if (scheme != null) {
         Context ctx = NamingManager.getURLContext(scheme, nativeEnv);
         if (ctx != null) {
            return ctx;
         }
      }
   }
   return defaultNativeContext;
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:17,代碼來源:CibetRemoteContext.java

示例5: getURLOrDefaultInitCtx

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Obtains the context for resolving the given name. If the first component of
 * the name is the URL string, this method tries to find the corressponding
 * URL naming context. If it is not an URL string, or the URL context is not
 * found, the default initial context is returned.
 *
 * @param name the name, for that it is required to obtain the context.
 * @return the context for resolving the name.
 * @throws NamingException
 */
protected Context getURLOrDefaultInitCtx(String name) throws NamingException
{
  String scheme = null;

  if (NamingManager.hasInitialContextFactoryBuilder())
    return getDefaultInitCtx();
  int colon = name.indexOf(':');
  int slash = name.indexOf('/');
  if (colon > 0 && (slash == - 1 || colon < slash))
    scheme = name.substring(0, colon);
  if (scheme != null)
    {
      Context context = NamingManager.getURLContext(scheme, myProps);
      if (context != null)
        return context;
    }

  return getDefaultInitCtx();
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:30,代碼來源:InitialContext.java

示例6: setup

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {

    // container.enableInterfaceMocking(true);
    if (!NamingManager.hasInitialContextFactoryBuilder()) {
        NamingManager
                .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder());
    }
    InitialContext initialContext = new InitialContext();
    Properties properties = new Properties();
    properties.put("mail.from", "[email protected]");
    mailMock = Session.getInstance(properties);
    initialContext.bind("mail/BSSMail", mailMock);
    configurationService = mock(APPConfigurationServiceBean.class);
    commService = spy(new APPCommunicationServiceBean());
    commService.configService = configurationService;
    doNothing().when(commService).transportMail(
            Matchers.any(MimeMessage.class));
}
 
開發者ID:servicecatalog,項目名稱:development,代碼行數:20,代碼來源:APPCommunicationServiceBeanTest.java

示例7: getURLOrDefaultInitCtx

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Obtains the context for resolving the given name. If the first component of
 * the name is the URL string, this method tries to find the corressponding
 * URL naming context. If it is not an URL string, or the URL context is not
 * found, the default initial context is returned.
 * 
 * @param name the name, for that it is required to obtain the context.
 * @return the context for resolving the name.
 * @throws NamingException
 */
protected Context getURLOrDefaultInitCtx(String name) throws NamingException
{
  String scheme = null;

  if (NamingManager.hasInitialContextFactoryBuilder())
    return getDefaultInitCtx();
  int colon = name.indexOf(':');
  int slash = name.indexOf('/');
  if (colon > 0 && (slash == - 1 || colon < slash))
    scheme = name.substring(0, colon);
  if (scheme != null)
    {
      Context context = NamingManager.getURLContext(scheme, myProps);
      if (context != null)
        return context;
    }

  return getDefaultInitCtx();
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:30,代碼來源:InitialContext.java

示例8: testHandleTimer_doHandleControllerProvisioning_bug11449

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Test
public void testHandleTimer_doHandleControllerProvisioning_bug11449()
        throws Exception {
    // given
    ServiceInstance instance = new ServiceInstance();
    instance.setInstanceId("123");
    instance.setSubscriptionId("subscriptionId");
    instance.setControllerId("ess.vmware");
    instance.setProvisioningStatus(ProvisioningStatus.WAITING_FOR_SYSTEM_CREATION);
    InstanceStatus status = new InstanceStatus();
    status.setIsReady(false);

    when(
            controller.getInstanceStatus(anyString(),
                    any(ProvisioningSettings.class))).thenReturn(status);
    doNothing().when(besDAOMock).notifyOnProvisioningStatusUpdate(
            any(ServiceInstance.class), anyListOf(LocalizedText.class));
    if (!NamingManager.hasInitialContextFactoryBuilder()) {
        NamingManager
                .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder());
    }
    InitialContext context = new InitialContext();
    context.bind(APPlatformController.JNDI_PREFIX + "ess.vmware",
            controller);

    // when
    timerService.doHandleControllerProvisioning(instance);

    // then
    verify(em, times(1)).refresh(any(ServiceInstance.class));
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:32,代碼來源:APPTimerServiceBeanTest.java

示例9: getURLOrDefaultInitCtx

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Returns a non-null context for the specified name of string
 * representation.
 * <p>
 * If an initial context factory builder has been defined, then the
 * specified name parameter is ignored and the result of <code>
 * getDefaultInitCtx</code>
 * is returned. Otherwise, if the name is not a URL string, then it returns
 * the result of invoking <code>getDefaultInitCtx
 * </code>. Otherwise, it
 * attempts to return a URL context
 * {@link javax.naming.spi.NamingManager#getURLContext(String, Hashtable)},
 * but if unsuccessful, returns the result of invoking <code>
 * getDefaultInitCtx</code>.
 * </p>
 * 
 * @param name
 *            a name used in a naming operation which may not be null
 * @return a context which may be a URL context
 * @throws NamingException
 *             If failed to get the desired context.
 */
protected Context getURLOrDefaultInitCtx(String name)
        throws NamingException {

    /*
     * If an initial context factory builder has been defined, then the
     * specified name parameter is ignored and the result of
     * getDefaultInitCtx() is returned.
     */
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }

    if (null == name) {
        // jndi.00=name must not be null
        throw new NullPointerException(Messages.getString("jndi.00")); //$NON-NLS-1$
    }

    // If the name has components
    String scheme = UrlParser.getScheme(name);
    Context ctx = null;
    if (null != scheme) {
        synchronized (contextCache) {
            if (contextCache.containsKey(scheme)) {
                return contextCache.get(scheme);
            }

            // So the first component is a valid URL
            ctx = NamingManager.getURLContext(scheme, myProps);
            if (null == ctx) {
                ctx = getDefaultInitCtx();
            }
            contextCache.put(scheme, ctx);
        }
        return ctx;
    }
    return getDefaultInitCtx();
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:60,代碼來源:InitialContext.java

示例10: testFactoryBuilder

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testFactoryBuilder() throws IllegalStateException,
		SecurityException, NamingException {
	// log.setMethod("testFactoryBuilder");

	if (!NamingManager.hasInitialContextFactoryBuilder()) {
		InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
				.getInstance();
		NamingManager
				.setInitialContextFactoryBuilder(contextFactoryBuilder);
	}

	Hashtable<Object, Object> env = new Hashtable<Object, Object>();
	env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");

	MyInitialContext context = new MyInitialContext(env);
	// log.log(context.getEnvironment().toString());
	// log.log("DefaultContext:" +
	// context.getDefaultContext().getClass().getName());
	//
	Context urlContext = NamingManager.getURLContext("http", env);
	assertEquals("http", urlContext.getEnvironment().get("url.schema"));

	String name = "http://www.apache.org";
	String obj = "String object";
	context.bind(name, obj);

	assertNull(InvokeRecord.getLatestUrlSchema());
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:29,代碼來源:NamingManagerExploreTest.java

示例11: testFactoryBuilder_name

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testFactoryBuilder_name() throws IllegalStateException,
		SecurityException, NamingException {
	// log.setMethod("testFactoryBuilder_name");

	if (!NamingManager.hasInitialContextFactoryBuilder()) {
		InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
				.getInstance();
		NamingManager
				.setInitialContextFactoryBuilder(contextFactoryBuilder);
	}

	Hashtable<Object, Object> env = new Hashtable<Object, Object>();
	env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");

	MyInitialContext context = new MyInitialContext(env);
	// log.log(context.getEnvironment().toString());
	// log.log("DefaultContext:" +
	// context.getDefaultContext().getClass().getName());
	//
	Context urlContext = NamingManager.getURLContext("http", env);
	assertEquals("http", urlContext.getEnvironment().get("url.schema"));

	Name name = new CompositeName("http://www.apache.org");
	String obj = "Name object";
	context.bind(name, obj);

	assertNull(InvokeRecord.getLatestUrlSchema());
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:29,代碼來源:NamingManagerExploreTest.java

示例12: getURLOrDefaultInitCtx

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Returns a non-null context for the specified name of string
 * representation.
 * <p>
 * If an initial context factory builder has been defined, then the
 * specified name parameter is ignored and the result of <code>
 * getDefaultInitCtx</code>
 * is returned. Otherwise, if the name is not a URL string, then it returns
 * the result of invoking <code>getDefaultInitCtx
 * </code>. Otherwise, it
 * attempts to return a URL context
 * {@link NamingManager#getURLContext(String, Hashtable)},
 * but if unsuccessful, returns the result of invoking <code>
 * getDefaultInitCtx</code>.
 * </p>
 * 
 * @param name
 *            a name used in a naming operation which may not be null
 * @return a context which may be a URL context
 * @throws NamingException
 *             If failed to get the desired context.
 */
protected Context getURLOrDefaultInitCtx(String name)
        throws NamingException {

    /*
     * If an initial context factory builder has been defined, then the
     * specified name parameter is ignored and the result of
     * getDefaultInitCtx() is returned.
     */
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }

    if (null == name) {
        // jndi.00=name must not be null
        throw new NullPointerException(Messages.getString("jndi.00")); //$NON-NLS-1$
    }

    // If the name has components
    String scheme = UrlParser.getScheme(name);
    Context ctx = null;
    if (null != scheme) {
        synchronized (contextCache) {
            if (contextCache.containsKey(scheme)) {
                return contextCache.get(scheme);
            }

            // So the first component is a valid URL
            ctx = NamingManager.getURLContext(scheme, myProps);
            if (null == ctx) {
                ctx = getDefaultInitCtx();
            }
            contextCache.put(scheme, ctx);
        }
        return ctx;
    }
    return getDefaultInitCtx();
}
 
開發者ID:nextopio,項目名稱:nextop-client,代碼行數:60,代碼來源:InitialContext.java

示例13: getURLOrDefaultInitCtx

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Retrieves a context for resolving <code>name</code>.
 * If the first component of <code>name</code> name is a URL string,
 * then attempt to find a URL context for it. If none is found, or if
 * the first component of <code>name</code> is not a URL string,
 * then return <code>getDefaultInitCtx()</code>.
 *<p>
 * When creating a subclass of InitialContext, use this method as
 * follows.
 * Define a new method that uses this method to get an initial
 * context of the desired subclass.
 * <blockquote><pre>
 * protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
 * throws NamingException {
 *  Context answer = getURLOrDefaultInitCtx(name);
 *  if (!(answer instanceof XXXContext)) {
 *    if (answer == null) {
 *      throw new NoInitialContextException();
 *    } else {
 *      throw new NotContextException("Not an XXXContext");
 *    }
 *  }
 *  return (XXXContext)answer;
 * }
 * </pre></blockquote>
 * When providing implementations for the new methods in the subclass,
 * use this newly defined method to get the initial context.
 * <blockquote><pre>
 * public Object XXXMethod1(Name name, ...) {
 *  throws NamingException {
 *    return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
 * }
 * </pre></blockquote>
 *
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 *
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    if (name.size() > 0) {
        String first = name.get(0);
        String scheme = getURLScheme(first);
        if (scheme != null) {
            Context ctx = NamingManager.getURLContext(scheme, myProps);
            if (ctx != null) {
                return ctx;
            }
        }
    }
    return getDefaultInitCtx();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:60,代碼來源:InitialContext.java

示例14: getURLOrDefaultInitCtx

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Retrieves a context for resolving <code>name</code>.
 * If the first component of <code>name</code> name is a URL string,
 * then attempt to find a URL context for it. If none is found, or if
 * the first component of <code>name</code> is not a URL string,
 * then return <code>getDefaultInitCtx()</code>.
 *<p>
 * When creating a subclass of InitialContext, use this method as
 * follows.
 * Define a new method that uses this method to get an initial
 * context of the desired subclass.
 * <p><blockquote><pre>
 * protected XXXContext getURLOrDefaultInitXXXCtx(Name name)
 * throws NamingException {
 *  Context answer = getURLOrDefaultInitCtx(name);
 *  if (!(answer instanceof XXXContext)) {
 *    if (answer == null) {
 *      throw new NoInitialContextException();
 *    } else {
 *      throw new NotContextException("Not an XXXContext");
 *    }
 *  }
 *  return (XXXContext)answer;
 * }
 * </pre></blockquote>
 * When providing implementations for the new methods in the subclass,
 * use this newly defined method to get the initial context.
 * <p><blockquote><pre>
 * public Object XXXMethod1(Name name, ...) {
 *  throws NamingException {
 *    return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...);
 * }
 * </pre></blockquote>
 *
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cached
 *         initial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 *
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name)
    throws NamingException {
    if (NamingManager.hasInitialContextFactoryBuilder()) {
        return getDefaultInitCtx();
    }
    if (name.size() > 0) {
        String first = name.get(0);
        String scheme = getURLScheme(first);
        if (scheme != null) {
            Context ctx = NamingManager.getURLContext(scheme, myProps);
            if (ctx != null) {
                return ctx;
            }
        }
    }
    return getDefaultInitCtx();
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:60,代碼來源:InitialContext.java

示例15: enableJndiMock

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Tries to register a mocked <code>NamingContextFactoryBuilder</code> to
 * enable basic JNDI functionality in the test code.
 * 
 * @throws NamingException
 * @see {@link TestNamingContext}
 */
protected static void enableJndiMock() throws NamingException {
    if (!NamingManager.hasInitialContextFactoryBuilder()) {
        NamingManager
                .setInitialContextFactoryBuilder(new TestNamingContextFactoryBuilder(PERSISTENCE));
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:14,代碼來源:BaseAdmUmTest.java


注:本文中的javax.naming.spi.NamingManager.hasInitialContextFactoryBuilder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。