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


Java NamingManager.getStateToBind方法代碼示例

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


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

示例1: bind

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Override
public void bind(Name name, Object obj) throws NamingException {
	if (name.isEmpty()) {
		throw new InvalidNameException("Cannot bind empty name");
	}

	Name nm = getMyComponents(name);
	String atom = nm.get(0);
	Object inter = iBindings.get(atom);

	if (nm.size() == 1) {
		if (inter != null)
			throw new NameAlreadyBoundException("Use rebind to override");

		obj = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, iEnv);

		iBindings.put(atom, obj);
	} else {
		if (!(inter instanceof Context))
			throw new NotContextException(atom + " does not name a context");

		((Context) inter).bind(nm.getSuffix(1), obj);
	}
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:25,代碼來源:LocalContext.java

示例2: rebind

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Override
public void rebind(Name name, Object obj) throws NamingException {
	if (name.isEmpty())
		throw new InvalidNameException("Cannot bind empty name");

	Name nm = getMyComponents(name);
	String atom = nm.get(0);

	if (nm.size() == 1) {
		obj = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, iEnv);

		iBindings.put(atom, obj);
	} else {
		Object inter = iBindings.get(atom);
		
		if (!(inter instanceof Context))
			throw new NotContextException(atom + " does not name a context");

		((Context) inter).rebind(nm.getSuffix(1), obj);
	}
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:22,代碼來源:LocalContext.java

示例3: encodeObject

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Encodes an object prior to binding it in the registry.  First,
 * NamingManager.getStateToBind() is invoked.  If the resulting
 * object is Remote, it is returned.  If it is a Reference or
 * Referenceable, the reference is wrapped in a Remote object.
 * Otherwise, an exception is thrown.
 *
 * @param name      The object's name relative to this context.
 */
private Remote encodeObject(Object obj, Name name)
        throws NamingException, RemoteException
{
    obj = NamingManager.getStateToBind(obj, name, this, environment);

    if (obj instanceof Remote) {
        return (Remote)obj;
    }
    if (obj instanceof Reference) {
        return (new ReferenceWrapper((Reference)obj));
    }
    if (obj instanceof Referenceable) {
        return (new ReferenceWrapper(((Referenceable)obj).getReference()));
    }
    throw (new IllegalArgumentException(
            "RegistryContext: " +
            "object to bind must be Remote, Reference, or Referenceable"));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:RegistryContext.java

示例4: getStateToBind

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
/**
 * Prepares object for binding. It calls
 * {@link NamingManager#getStateToBind(Object, Name, Context, Hashtable)}
 * and makes the resulting object {@link Remote} by wrapping it into
 * {@link RemoteReferenceWrapper}.
 * 
 * @param name
 *            Object name.
 * 
 * @param obj
 *            Object to prepare for binding.
 * 
 * @return Object ready for binding.
 * 
 * @throws NamingException
 *             If some naming error occurs.
 * 
 * @throws RemoteException
 *             If remote exception occurs.
 */
protected Remote getStateToBind(String name, Object obj)
        throws NamingException, RemoteException {
    obj = NamingManager.getStateToBind(obj, new CompositeName().add(name),
            this, environment);

    if (obj instanceof Remote) {
        return (Remote) obj;
    }

    if (obj instanceof Reference) {
        return new RemoteReferenceWrapper((Reference) obj);
    }

    if (obj instanceof Referenceable) {
        return new RemoteReferenceWrapper(((Referenceable) obj)
                .getReference());
    }
    // jndi.82=Cannot bind to RMI Registry object that is neither Remote nor
    // Reference nor Referenceable
    throw new IllegalArgumentException(Messages.getString("jndi.82")); //$NON-NLS-1$
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:42,代碼來源:RegistryContext.java

示例5: testGetStateToBind_null_null_null_hash

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetStateToBind_null_null_null_hash() {
	log.setMethod("testGetStateToBind_null_null_null_hash()");
	Object o = null;
	Name n = null;
	Context c = null;
	Hashtable<String, String> h = new Hashtable<String, String>();
	h
			.put(Context.STATE_FACTORIES,
					"org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");

	try {
		Hashtable<?, ?> r = (Hashtable<?, ?>) NamingManager.getStateToBind(o, n, c, h);
		assertEquals(r.get("o"), o);
		assertEquals(r.get("n"), n);
		assertEquals(r.get("c"), c);
		assertEquals(r.get("h"), h);
	} catch (Throwable e) {
		log.log(e);
		fail();
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:22,代碼來源:NamingManagerTest.java

示例6: testGetStateToBind_null_name_ctx_hash

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetStateToBind_null_name_ctx_hash() {
	log.setMethod("testGetStateToBind_null_name_ctx_hash()");
	Object o = null;
	Name n = new CompositeName();
	Context c = new MockDirContext(new Hashtable<Object, Object>());
	// lead to state factory
	Hashtable<String, String> h = new Hashtable<String, String>();
	h
			.put(Context.STATE_FACTORIES,
					"org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");

	try {
		Hashtable<?, ?> r = (Hashtable<?, ?>) NamingManager.getStateToBind(o, n, c, h);
		assertEquals(r.get("o"), o);
		assertEquals(r.get("n"), n);
		assertEquals(r.get("c"), c);
		assertEquals(r.get("h"), h);
	} catch (Throwable e) {
		log.log(e);
		fail();
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:23,代碼來源:NamingManagerTest.java

示例7: testGetStateToBind_obj_name_ctx_hash

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetStateToBind_obj_name_ctx_hash() {
	log.setMethod("testGetStateToBind_obj_name_ctx_hash()");
	Object o = "object";
	Name n = new CompositeName();
	Context c = new MockDirContext(new Hashtable<Object, Object>());
	// lead to state factory
	Hashtable<String, String> h = new Hashtable<String, String>();
	h
			.put(Context.STATE_FACTORIES,
					"org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");

	try {
		Hashtable<?, ?> r = (Hashtable<?, ?>) NamingManager.getStateToBind(o, n, c, h);
		assertEquals(r.get("o"), o);
		assertEquals(r.get("n"), n);
		assertEquals(r.get("c"), c);
		assertEquals(r.get("h"), h);
	} catch (Throwable e) {
		log.log(e);
		fail();
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:23,代碼來源:NamingManagerTest.java

示例8: testGetStateToBind_f1BadClassName_Success

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetStateToBind_f1BadClassName_Success() {
	log.setMethod("testGetStateToBind_f1BadClassName_Success()");
	Object o = "object";
	Name n = new CompositeName();
	Context c = new MockContext(new Hashtable<String, Object>()); // no state factory
	Hashtable<Object, Object> h = new Hashtable<Object, Object>();
	h.put(Context.STATE_FACTORIES,"bad.class.Name:org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");

       try {
		Hashtable<?, ?> r = (Hashtable<?, ?>) NamingManager.getStateToBind(o, n, c, h);
		assertEquals(r.get("o"), o);
		assertEquals(r.get("n"), n);
		assertEquals(r.get("c"), c);
		assertEquals(r.get("h"), h);
	} catch (Throwable e) {
		log.log(e);
		fail();
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:20,代碼來源:NamingManagerTest.java

示例9: testGetStateToBind_f1ReturnNull_Success

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
   public void testGetStateToBind_f1ReturnNull_Success() {
	log.setMethod("testGetStateToBind_f1ReturnNull_Success()");
	Object o = "object";
	Name n = new CompositeName();
	Context c = new MockContext(new Hashtable<String, Object>()); // no state factory
	Hashtable<Object, Object> h = new Hashtable<Object, Object>();
	h
			.put(
					Context.STATE_FACTORIES,
					"org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory"
							+ ":"
							+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicSuccessMockStateFactory");
	indicateReturnNull(h);

	try {
		Hashtable<Object, Object> r = (Hashtable<Object, Object>) NamingManager.getStateToBind(o, n, c, h);
		assertEquals(r.get("o"), o);
		assertEquals(r.get("n"), n);
		assertEquals(r.get("c"), c);
		assertEquals(r.get("h"), h);
	} catch (Throwable e) {
		log.log(e);
		fail();
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:27,代碼來源:NamingManagerTest.java

示例10: testGetStateToBind_f1Success_f2Success

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetStateToBind_f1Success_f2Success() {
	log.setMethod("testGetStateToBind_f1Success_f2Success()");
	Object o = "object";
	Name n = new CompositeName();
	Context c = new MockDirContext(new Hashtable<Object, Object>());
	// lead to state factory
	Hashtable<Object, Object> h = new Hashtable<Object, Object>();
	h
			.put(Context.STATE_FACTORIES,
					"org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicSuccessMockStateFactory");
	indicateRuntimeException(h);

	try {
           Hashtable<?, ?> r = (Hashtable<?, ?>) NamingManager.getStateToBind(o, n, c, h);
		assertEquals(r.get("o"), o);
		assertEquals(r.get("n"), n);
		assertEquals(r.get("c"), c);
		assertEquals(r.get("h"), h);
	} catch (Throwable e) {
		log.log(e);
		fail();
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:24,代碼來源:NamingManagerTest.java

示例11: testGetStateToBind_f1ReturnNull

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetStateToBind_f1ReturnNull() {
	log.setMethod("testGetStateToBind_f1ReturnNull()");
	Object o = "object";
	Name n = new CompositeName();
	Context c = new MockContext(new Hashtable<String, Object>()); // no state factory
	Hashtable<Object, Object> h = new Hashtable<Object, Object>();
	h
			.put(Context.STATE_FACTORIES,
					"org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
	indicateReturnNull(h);

	try {
		Object result = NamingManager.getStateToBind(o, n, c, h);
		assertEquals(o, result);
	} catch (Throwable e) {
		log.log(e);
		fail();
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:20,代碼來源:NamingManagerTest.java

示例12: testGetStateToBind_f1BadClassName

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetStateToBind_f1BadClassName() {
	log.setMethod("testGetStateToBind_f1BadClassName()");
	Object o = "object";
	Name n = new CompositeName();
	Context c = new MockContext(new Hashtable<String, Object>()); // no state factory
	Hashtable<String, String> h = new Hashtable<String, String>();
	h.put(Context.STATE_FACTORIES, "bad.class.Name");

	try {
		Object result = NamingManager.getStateToBind(o, n, c, h);
		assertEquals(o, result);
	} catch (Throwable e) {
		log.log(e);
		fail();
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:17,代碼來源:NamingManagerTest.java

示例13: bind

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Override
public void bind(final Name name, final Object obj) throws NamingException {
	final Name bindName = validateName(name);
	// If null, it means we don't know how to handle this -> throw to the
	// parent
	if (bindName == null) {
		parent.bind(name, obj);
	}
	// If empty name, complain - we should have a child name here
	if (bindName.isEmpty()) {
		throw new InvalidNameException("Cannot rebind an empty name");
	}

	// Extract components that belong to this namespace
	final Name nm = bindName; // getMyComponents(name);
	final String atom = nm.get(0);
	final Object inter = bindings.get(atom);

	if (nm.size() == 1) {
		// Atomic name: Find object in internal data structure
		if (inter != null) {
			throw new NameAlreadyBoundException("Use rebind to override");
		}

		// Call getStateToBind for using any state factories
		final Object result = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, environnement);

		// Add object to internal data structure
		bindings.put(atom, result);
	} else {
		// Intermediate name: Consume name in this context and continue
		if (!(inter instanceof Context)) {
			throw new NotContextException(atom + " does not name a context");
		}
		((Context) inter).bind(nm.getSuffix(1), obj);
	}
}
 
開發者ID:geronimo-iia,項目名稱:winstone,代碼行數:38,代碼來源:NamingContext.java

示例14: rebind

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
@Override
public void rebind(final Name name, final Object obj) throws NamingException {
	final Name bindName = validateName(name);
	// If null, it means we don't know how to handle this -> throw to the
	// parent
	if (bindName == null) {
		parent.bind(name, obj);
	}
	// If empty name, complain - we should have a child name here
	if (bindName.isEmpty()) {
		throw new InvalidNameException("Cannot rebind an empty name");
	}

	// Extract components that belong to this namespace
	final Name nm = bindName; // getMyComponents(name);
	final String atom = nm.get(0);

	if (nm.size() == 1) {
		// Atomic name

		// Call getStateToBind for using any state factories
		final Object result = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, environnement);

		// Add object to internal data structure
		bindings.put(atom, result);
	} else {
		// Intermediate name: Consume name in this context and continue
		final Object inter = bindings.get(atom);
		if (!(inter instanceof Context)) {
			throw new NotContextException(atom + " does not name a context");
		}
		((Context) inter).rebind(nm.getSuffix(1), obj);
	}
}
 
開發者ID:geronimo-iia,項目名稱:winstone,代碼行數:35,代碼來源:NamingContext.java

示例15: testGetStateToBind_null_null_null_null

import javax.naming.spi.NamingManager; //導入方法依賴的package包/類
public void testGetStateToBind_null_null_null_null() {
	log.setMethod("testGetStateToBind_null_null_null_null()");
	Object o = null;
	Name n = null;
	Context c = null;
	Hashtable<?, ?> h = null;

	try {
		Object r = NamingManager.getStateToBind(o, n, c, h);
		assertNull(r);
	} catch (NamingException e) {
		fail("should throw NullPointerException");
	}
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:15,代碼來源:NamingManagerTest.java


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