当前位置: 首页>>代码示例>>Java>>正文


Java Referenceable类代码示例

本文整理汇总了Java中javax.naming.Referenceable的典型用法代码示例。如果您正苦于以下问题:Java Referenceable类的具体用法?Java Referenceable怎么用?Java Referenceable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Referenceable类属于javax.naming包,在下文中一共展示了Referenceable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getObjectInterfaces

import javax.naming.Referenceable; //导入依赖的package包/类
private static Class<?>[] getObjectInterfaces(Class<?> objectClass, List<Class<?>> interfaces) {
	// Rq: object.getClass().getInterfaces() ne suffit pas pour Connection dans Tomcat
	// car la connection est une instance de PoolGuardConnectionWrapper
	// et connection.getClass().getInterfaces() est vide dans ce cas
	final List<Class<?>> myInterfaces;
	if (interfaces == null) {
		myInterfaces = new ArrayList<Class<?>>(Arrays.asList(objectClass.getInterfaces()));
		Class<?> classe = objectClass.getSuperclass();
		while (classe != null) {
			final Class<?>[] classInterfaces = classe.getInterfaces();
			if (classInterfaces.length > 0) {
				final List<Class<?>> superInterfaces = Arrays.asList(classInterfaces);
				// removeAll d'abord car il ne faut pas de doublon dans la liste
				myInterfaces.removeAll(superInterfaces);
				myInterfaces.addAll(superInterfaces);
			}
			classe = classe.getSuperclass();
		}
		// on ignore l'interface javax.naming.Referenceable car sinon le rebind sous jetty appelle
		// referenceable.getReference() et devient inutile
		myInterfaces.remove(Referenceable.class);
	} else {
		myInterfaces = interfaces;
	}
	return myInterfaces.toArray(new Class<?>[myInterfaces.size()]);
}
 
开发者ID:javamelody,项目名称:javamelody,代码行数:27,代码来源:JdbcWrapperHelper.java

示例2: getStateToBind

import javax.naming.Referenceable; //导入依赖的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

示例3: assertGetObjectResult

import javax.naming.Referenceable; //导入依赖的package包/类
/**
 * @param r
 * @param object
 * @param object2
 * @param env
 * @param a
 * @return
 */
private void assertGetObjectResult(Object o, Name n, Context c,
        Hashtable<String, String> h, Attributes a) throws NamingException {
    Object obj = null;
    try {
        obj = DirectoryManager.getObjectInstance(o, n, c, h, a);
    } catch (Exception e) {
        
        fail();
    }

    Hashtable<?, ?> t = (Hashtable<?, ?>) obj;
    if (o instanceof Referenceable) {
        assertSame(t.get("o"), ((Referenceable) o).getReference());
    } else {
        assertSame(t.get("o"), o);
    }
    assertSame(t.get("n"), n);
    assertSame(t.get("c"), c);
    assertSame(t.get("h"), h);
    assertSame(t.get("a"), a);

}
 
开发者ID:shannah,项目名称:cn1,代码行数:31,代码来源:DirectoryManagerTest.java

示例4: getStateToBind

import javax.naming.Referenceable; //导入依赖的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:freeVM,项目名称:freeVM,代码行数:41,代码来源:RegistryContext.java

示例5: getObjectInstance

import javax.naming.Referenceable; //导入依赖的package包/类
@Override
public Object getObjectInstance(Object obj, Name jndiNameObject, Context nameCtx, Hashtable<?,?> environment) throws Exception {
    Reference ref = (Reference) obj;
    if (log.isDebugEnabled()) { log.debug("referencing resource with reference of type " + ref.getClass()); }

    RefAddr refAddr = ref.get("uniqueName");
    if (refAddr == null)
        throw new NamingException("no 'uniqueName' RefAddr found");
    Object content = refAddr.getContent();
    if (!(content instanceof String))
        throw new NamingException("'uniqueName' RefAddr content is not of type java.lang.String");
    String uniqueName = (String) content;

    if (log.isDebugEnabled()) { log.debug("getting registered resource with uniqueName '" + uniqueName + "'"); }
    Referenceable resource = ResourceRegistrar.get(uniqueName);
    if (resource == null)
        throw new NamingException("no resource registered with uniqueName '" + uniqueName + "', available resources: " + ResourceRegistrar.getResourcesUniqueNames());

    return resource;
}
 
开发者ID:bitronix,项目名称:btm,代码行数:21,代码来源:ResourceObjectFactory.java

示例6: serializeDataSources

import javax.naming.Referenceable; //导入依赖的package包/类
/**
 * Serialize and write data sources to file.
 * 
 * @param versionString Derby version string (i.e. 10.3.2.1)
 * @param buildNumber Derby build number (svn)
 * @param dataSourceClasses list of data source class names
 * @return The number of data sources serialized and written to file.
 * 
 * @throws ClassNotFoundException required class is not on the classpath
 * @throws InstantiationException if instantiating data source class fails
 * @throws IllegalAccessException if instantiating data source class fails
 * @throws IOException if writing to file fails
 * @throws NamingException if creating a naming reference for the data
 *      source fails
 */
private static int serializeDataSources(String versionString,
                                        String buildNumber,
                                        String[] dataSourceClasses)
        throws ClassNotFoundException, InstantiationException,
               IllegalAccessException, IOException, NamingException {
    String modifiedVersionString = versionString.replaceAll("\\.", "_");
    int dsCount = 0;
    for (String dsClassName : dataSourceClasses) {
        Class dsClass;
        // Try to load the class.
        try {
            dsClass = Class.forName(dsClassName);
        } catch (ClassNotFoundException cnfe) {
            // Print error message, but keep going.
            System.out.println("\tcouldn't load " + dsClassName);
            continue;
        }
        // Create new instance.
        DataSource ds = (DataSource)dsClass.newInstance();
        // Generate file name.
        File serialized = new File(dsClass.getSimpleName() + "-" +
                modifiedVersionString + ".ser");
        System.out.println("\twriting " + serialized.getName());
        OutputStream os = new FileOutputStream(serialized);
        ObjectOutputStream oos = new ObjectOutputStream(os);
        // Wrote version string, build number, the data source object and finally
        // a {@link javax.naming.Reference} for the data source.
        oos.writeUTF(versionString);
        oos.writeUTF(buildNumber);
        oos.writeObject(ds);
        Reference dsRef = ((Referenceable)ds).getReference(); 
        oos.writeObject(dsRef);
        oos.flush();
        oos.close();
        dsCount++;
    }
    return dsCount;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:54,代码来源:SerializeDataSources.java

示例7: assertDataSourceReferenceEmpty

import javax.naming.Referenceable; //导入依赖的package包/类
/**
 * Make sure it is possible to create a new data source using
 * <code>Referencable</code>, that the new instance has the correct
 * default values set for the bean properties and finally that the
 * data source can be serialized/deserialized.
 *
 * @param dsDesc data source descriptor
 * @param className data source class name
 * @throws Exception on a wide variety of error conditions...
 */
private void assertDataSourceReferenceEmpty(DataSourceDescriptor dsDesc,
                                            String className)
        throws Exception {
    println("Testing recreated empty data source.");
    // Create an empty data source.
    Object ds = Class.forName(className).newInstance();
    Referenceable refDs = (Referenceable)ds;
    Reference dsAsReference = refDs.getReference();
    String factoryClassName = dsAsReference.getFactoryClassName();
    ObjectFactory factory =
        (ObjectFactory)Class.forName(factoryClassName).newInstance();
    Object recreatedDs =
        factory.getObjectInstance(dsAsReference, null, null, null);
    // Empty, recreated data source should not be the same as the one we
    // created earlier on.
    assertNotNull("Recreated datasource is <null>", recreatedDs);
    assertNotSame(recreatedDs, ds);
    compareDataSources(dsDesc, ds, recreatedDs, true);

    // Serialize and recreate data source with default values.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(ds);
    oos.flush();
    oos.close();
    ByteArrayInputStream bais =
            new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);
    recreatedDs = ois.readObject();
    compareDataSources(dsDesc, ds, recreatedDs, true);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:42,代码来源:DataSourceReferenceTest.java

示例8: testReferenceable

import javax.naming.Referenceable; //导入依赖的package包/类
@SuppressWarnings("cast")
@Test
public void testReferenceable() throws Exception {
   ProxyAssertSupport.assertTrue(cf instanceof Referenceable);

   ProxyAssertSupport.assertTrue(queue1 instanceof Referenceable);

   ProxyAssertSupport.assertTrue(ActiveMQServerTestCase.topic1 instanceof Referenceable);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:10,代码来源:ReferenceableTest.java

示例9: encodeObject

import javax.naming.Referenceable; //导入依赖的package包/类
/**
 * Encode an Object : If the object is a referenceable bind this reference
 * @param o the object to encode
 * @return a <code>Remote Object</code> if o is a ressource o if else
 */
private Object encodeObject(Object o) throws NamingException {
    try {
        if ((!(o instanceof Remote)) && (o instanceof Referenceable)) {
            return ((Referenceable) o).getReference();
        } else if ((!(o instanceof Remote)) && (o instanceof Reference)) {
            return (Reference) o;
        } else {
            return o;
        }
    } catch (Exception e) {
        throw new NamingException("" + e);
    }
}
 
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:19,代码来源:left_LmiInitialContext_1.5.java

示例10: wrapObject

import javax.naming.Referenceable; //导入依赖的package包/类
/**
 * Wrap an Object : If the object is a reference wrap it into a Reference
 * Wrapper Object here the good way is to contact the carol configuration to
 * get the portable remote object
 * @param o the object to encode
 * @param name of the object
 * @param replace if the object need to be replaced
 * @return a <code>Remote JNDIRemoteReference Object</code> if o is a
 *         resource o if else
 * @throws NamingException if object cannot be wrapped
 */
protected Object wrapObject(Object o, Name name, boolean replace) throws NamingException {
        try {
            // Add wrapper for the two first cases. Then it will use PortableRemoteObject instead of UnicastRemoteObject
            // and when fixing JRMP exported objects port, it use JRMPProdelegate which is OK.
            if ((!(o instanceof Remote)) && (o instanceof Referenceable)) {
                return new UnicastJNDIReferenceWrapper(((Referenceable) o).getReference(), getObjectPort());
            } else if ((!(o instanceof Remote)) && (o instanceof Reference)) {
                return new UnicastJNDIReferenceWrapper((Reference) o, getObjectPort());
            } else if ((!(o instanceof Remote)) && (!(o instanceof Referenceable)) && (!(o instanceof Reference))
                    && (o instanceof Serializable)) {
                // Only Serializable (not implementing Remote or Referenceable or
                // Reference)
                JNDIResourceWrapper irw = new JNDIResourceWrapper((Serializable) o);
                PortableRemoteObjectDelegate proDelegate = ConfigurationRepository.getCurrentConfiguration().getProtocol().getPortableRemoteObject();
                proDelegate.exportObject(irw);

                Remote oldObj = (Remote) addToExported(name, irw);
                if (oldObj != null) {
                    if (replace) {
                        proDelegate.unexportObject(oldObj);
                    } else {
                        proDelegate.unexportObject(irw);
                        addToExported(name, oldObj);
                        throw new NamingException("Object '" + o + "' with name '" + name + "' is already bind");
                    }
                }
                return irw;
            } else {
                return o;
            }
        } catch (Exception e) {
            throw NamingExceptionHelper.create("Cannot wrap object '" + o + "' with name '" + name + "' : "
                    + e.getMessage(), e);
        }
}
 
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:47,代码来源:right_CmiContext_1.3.java

示例11: serializeDataSources

import javax.naming.Referenceable; //导入依赖的package包/类
/**
 * Serialize and write data sources to file.
 * 
 * @param versionString Derby version string (i.e. 10.3.2.1)
 * @param buildNumber Derby build number (svn)
 * @param dataSourceClasses list of data source class names
 * @return The number of data sources serialized and written to file.
 * 
 * @throws ClassNotFoundException required class is not on the classpath
 * @throws InstantiationException if instantiating data source class fails
 * @throws IllegalAccessException if instantiating data source class fails
 * @throws IOException if writing to file fails
 * @throws NamingException if creating a naming reference for the data
 *      source fails
 */
private static int serializeDataSources(String versionString,
                                        String buildNumber,
                                        String[] dataSourceClasses)
        throws ClassNotFoundException, InstantiationException,
               IllegalAccessException, IOException, NamingException {
    String modifiedVersionString = versionString.replaceAll("\\.", "F");
    int dsCount = 0;
    for (String dsClassName : dataSourceClasses) {
        Class dsClass;
        // Try to load the class.
        try {
            dsClass = Class.forName(dsClassName);
        } catch (ClassNotFoundException cnfe) {
            // Print error message, but keep going.
            System.out.println("\tcouldn't load " + dsClassName);
            continue;
        }
        // Create new instance.
        DataSource ds = (DataSource)dsClass.newInstance();
        // Generate file name.
        File serialized = new File(dsClass.getSimpleName() + "-" +
                modifiedVersionString + ".ser");
        System.out.println("\twriting " + serialized.getName());
        OutputStream os = new FileOutputStream(serialized);
        ObjectOutputStream oos = new ObjectOutputStream(os);
        // Wrote version string, build number, the data source object and finally
        // a {@link javax.naming.Reference} for the data source.
        oos.writeUTF(versionString);
        oos.writeUTF(buildNumber);
        oos.writeObject(ds);
        Reference dsRef = ((Referenceable)ds).getReference(); 
        oos.writeObject(dsRef);
        oos.flush();
        oos.close();
        dsCount++;
    }
    return dsCount;
}
 
开发者ID:splicemachine,项目名称:spliceengine,代码行数:54,代码来源:SerializeDataSources.java

示例12: bind

import javax.naming.Referenceable; //导入依赖的package包/类
/**
 * Binds a name to an object. All intermediate contexts and the target 
 * context (that named by all but terminal atomic component of the name) 
 * must already exist.
 * 
 * @param name the name to bind; may not be empty
 * @param obj the object to bind; possibly null
 * @param rebind if true, then perform a rebind (ie, overwrite)
 * @exception NameAlreadyBoundException if name is already bound
 * @exception javax.naming.directory.InvalidAttributesException if object
 * did not supply all mandatory attributes
 * @exception NamingException if a naming exception is encountered
 */
protected void bind(Name name, Object obj, boolean rebind)
    throws NamingException {
    
    if (!checkWritable()) {
        return;
    }
    
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));
    
    NamingEntry entry = bindings.get(name.get(0));
    
    if (name.size() > 1) {
        if (entry == null) {
            throw new NameNotFoundException(sm.getString(
                    "namingContext.nameNotBound", name, name.get(0)));
        }
        if (entry.type == NamingEntry.CONTEXT) {
            if (rebind) {
                ((Context) entry.value).rebind(name.getSuffix(1), obj);
            } else {
                ((Context) entry.value).bind(name.getSuffix(1), obj);
            }
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        if ((!rebind) && (entry != null)) {
            throw new NameAlreadyBoundException
                (sm.getString("namingContext.alreadyBound", name.get(0)));
        } else {
            // Getting the type of the object and wrapping it within a new
            // NamingEntry
            Object toBind = 
                NamingManager.getStateToBind(obj, name, this, env);
            if (toBind instanceof Context) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.CONTEXT);
            } else if (toBind instanceof LinkRef) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.LINK_REF);
            } else if (toBind instanceof Reference) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.REFERENCE);
            } else if (toBind instanceof Referenceable) {
                toBind = ((Referenceable) toBind).getReference();
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.REFERENCE);
            } else {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.ENTRY);
            }
            bindings.put(name.get(0), entry);
        }
    }
    
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:75,代码来源:NamingContext.java

示例13: bind

import javax.naming.Referenceable; //导入依赖的package包/类
/**
 * Binds a name to an object. All intermediate contexts and the target 
 * context (that named by all but terminal atomic component of the name) 
 * must already exist.
 * 
 * @param name the name to bind; may not be empty
 * @param obj the object to bind; possibly null
 * @param rebind if true, then perform a rebind (ie, overwrite)
 * @exception NameAlreadyBoundException if name is already bound
 * @exception InvalidAttributesException if object did not supply all 
 * mandatory attributes
 * @exception NamingException if a naming exception is encountered
 */
protected void bind(Name name, Object obj, boolean rebind)
    throws NamingException {
    
    checkWritable();
    
    while ((!name.isEmpty()) && (name.get(0).length() == 0))
        name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException
            (sm.getString("namingContext.invalidName"));
    
    NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
    
    if (name.size() > 1) {
        if (entry == null) {
            throw new NameNotFoundException
                (sm.getString("namingContext.nameNotBound", name.get(0)));
        }
        if (entry.type == NamingEntry.CONTEXT) {
            if (rebind) {
                ((Context) entry.value).rebind(name.getSuffix(1), obj);
            } else {
                ((Context) entry.value).bind(name.getSuffix(1), obj);
            }
        } else {
            throw new NamingException
                (sm.getString("namingContext.contextExpected"));
        }
    } else {
        if ((!rebind) && (entry != null)) {
            throw new NameAlreadyBoundException
                (sm.getString("namingContext.alreadyBound", name.get(0)));
        } else {
            // Getting the type of the object and wrapping it within a new
            // NamingEntry
            Object toBind = 
                NamingManager.getStateToBind(obj, name, this, env);
            if (toBind instanceof Context) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.CONTEXT);
            } else if (toBind instanceof LinkRef) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.LINK_REF);
            } else if (toBind instanceof Reference) {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.REFERENCE);
            } else if (toBind instanceof Referenceable) {
                toBind = ((Referenceable) toBind).getReference();
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.REFERENCE);
            } else {
                entry = new NamingEntry(name.get(0), toBind, 
                                        NamingEntry.ENTRY);
            }
            bindings.put(name.get(0), entry);
        }
    }
    
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:73,代码来源:NamingContext.java

示例14: bind

import javax.naming.Referenceable; //导入依赖的package包/类
/**
    * Binds a name to an object. All intermediate contexts and the target 
    * context (that named by all but terminal atomic component of the name) 
    * must already exist.
    * 
    * @param name the name to bind; may not be empty
    * @param object the object to bind; possibly null
    * @param rebind if true, then perform a rebind (ie, overwrite)
    * @exception NameAlreadyBoundException if name is already bound
    * @exception InvalidAttributesException if object did not supply all 
    * mandatory attributes
    * @exception NamingException if a naming exception is encountered
    */
   protected void bind(Name name, Object obj, boolean rebind)
       throws NamingException {
       
       checkWritable();
       
while ((!name.isEmpty()) && (name.get(0).length() == 0))
    name = name.getSuffix(1);
       if (name.isEmpty())
           throw new NamingException
               (sm.getString("namingContext.invalidName"));
       
       NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
       
       if (name.size() > 1) {
           if (entry == null) {
               throw new NameNotFoundException
                   (sm.getString("namingContext.nameNotBound", name.get(0)));
           }
           if (entry.type == NamingEntry.CONTEXT) {
               if (rebind) {
                   ((Context) entry.value).rebind(name.getSuffix(1), obj);
               } else {
                   ((Context) entry.value).bind(name.getSuffix(1), obj);
               }
           } else {
               throw new NamingException
                   (sm.getString("namingContext.contextExpected"));
           }
       } else {
           if ((!rebind) && (entry != null)) {
               throw new NamingException
                   (sm.getString("namingContext.alreadyBound", name.get(0)));
           } else {
               // Getting the type of the object and wrapping it within a new
               // NamingEntry
               Object toBind = 
                   NamingManager.getStateToBind(obj, name, this, env);
               if (toBind instanceof Context) {
                   entry = new NamingEntry(name.get(0), toBind, 
                                           NamingEntry.CONTEXT);
               } else if (toBind instanceof LinkRef) {
                   entry = new NamingEntry(name.get(0), toBind, 
                                           NamingEntry.LINK_REF);
               } else if (toBind instanceof Reference) {
                   entry = new NamingEntry(name.get(0), toBind, 
                                           NamingEntry.REFERENCE);
               } else if (toBind instanceof Referenceable) {
                   toBind = ((Referenceable) toBind).getReference();
                   entry = new NamingEntry(name.get(0), toBind, 
                                           NamingEntry.REFERENCE);
               } else {
                   entry = new NamingEntry(name.get(0), toBind, 
                                           NamingEntry.ENTRY);
               }
               bindings.put(name.get(0), entry);
           }
       }
       
   }
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:73,代码来源:NamingContext.java

示例15: bind

import javax.naming.Referenceable; //导入依赖的package包/类
/**
 * Binds a name to an object. All intermediate contexts and the target
 * context (that named by all but terminal atomic component of the name)
 * must already exist.
 * 
 * @param name
 *            the name to bind; may not be empty
 * @param obj
 *            the object to bind; possibly null
 * @param rebind
 *            if true, then perform a rebind (ie, overwrite)
 * @exception NameAlreadyBoundException
 *                if name is already bound
 * @exception javax.naming.directory.InvalidAttributesException
 *                if object did not supply all mandatory attributes
 * @exception NamingException
 *                if a naming exception is encountered
 */
protected void bind(Name name, Object obj, boolean rebind) throws NamingException {

	if (!checkWritable()) {
		return;
	}

	while ((!name.isEmpty()) && (name.get(0).length() == 0))
		name = name.getSuffix(1);
	if (name.isEmpty())
		throw new NamingException(sm.getString("namingContext.invalidName"));

	NamingEntry entry = bindings.get(name.get(0));

	if (name.size() > 1) {
		if (entry == null) {
			throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0)));
		}
		if (entry.type == NamingEntry.CONTEXT) {
			if (rebind) {
				((Context) entry.value).rebind(name.getSuffix(1), obj);
			} else {
				((Context) entry.value).bind(name.getSuffix(1), obj);
			}
		} else {
			throw new NamingException(sm.getString("namingContext.contextExpected"));
		}
	} else {
		if ((!rebind) && (entry != null)) {
			throw new NameAlreadyBoundException(sm.getString("namingContext.alreadyBound", name.get(0)));
		} else {
			// Getting the type of the object and wrapping it within a new
			// NamingEntry
			Object toBind = NamingManager.getStateToBind(obj, name, this, env);
			if (toBind instanceof Context) {
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.CONTEXT);
			} else if (toBind instanceof LinkRef) {
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.LINK_REF);
			} else if (toBind instanceof Reference) {
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE);
			} else if (toBind instanceof Referenceable) {
				toBind = ((Referenceable) toBind).getReference();
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE);
			} else {
				entry = new NamingEntry(name.get(0), toBind, NamingEntry.ENTRY);
			}
			bindings.put(name.get(0), entry);
		}
	}

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:69,代码来源:NamingContext.java


注:本文中的javax.naming.Referenceable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。