orbremotecontext.java

来自「OpenJMS是一个开源的Java Message Service API 1.」· Java 代码 · 共 628 行 · 第 1/2 页

JAVA
628
字号
     *     * @param name the name of the object to look up     * @return	the object bound to <tt>name</tt>, not following the     * terminal link (if any)     * @throws	NamingException if a naming exception is encountered     */    public Object lookupLink(String name) throws NamingException {        return wrap(_context.lookupLink(name));    }    /**     * Retrieves the parser associated with the named context.     *     * @param name the name of the context from which to get the parser     * @return	a name parser that can parse compound names into their atomic     * components     * @throws	NamingException if a naming exception is encountered     */    public NameParser getNameParser(Name name) throws NamingException {        return _context.getNameParser(name);    }    /**     * Retrieves the parser associated with the named context.     *     * @param name the name of the context from which to get the parser     * @return	a name parser that can parse compound names into their atomic     * components     * @throws	NamingException if a naming exception is encountered     */    public NameParser getNameParser(String name) throws NamingException {        return _context.getNameParser(name);    }    /**     * Composes the name of this context with a name relative to     * this context.     *     * @param name   a name relative to this context     * @param prefix the name of this context relative to one of its ancestors     * @return	the composition of <code>prefix</code> and <code>name</code>     * @throws	NamingException if a naming exception is encountered     */    public Name composeName(Name name, Name prefix) throws NamingException {        return _context.composeName(name, prefix);    }    /**     * Composes the name of this context with a name relative to     * this context.     *     * @param name   a name relative to this context     * @param prefix the name of this context relative to one of its ancestors     * @return	the composition of <code>prefix</code> and <code>name</code>     * @throws	NamingException if a naming exception is encountered     */    public String composeName(String name, String prefix)            throws NamingException {        return _context.composeName(name, prefix);    }    /**     * Adds a new environment property to the environment of this     * context.  If the property already exists, its value is overwritten.     *     * @param propName the name of the environment property to add; may not be null     * @param propVal  the value of the property to add; may not be null     * @return	the previous value of the property, or null if the property was     * not in the environment before     * @throws	NamingException if a naming exception is encountered     */    public Object addToEnvironment(String propName, Object propVal)            throws NamingException {        return _context.addToEnvironment(propName, propVal);    }    /**     * Removes an environment property from the environment of this     * context.  See class description for more details on environment     * properties.     *     * @param propName the name of the environment property to remove; may not be null     * @return	the previous value of the property, or null if the property was     * not in the environment     * @throws	NamingException if a naming exception is encountered     */    public Object removeFromEnvironment(String propName)            throws NamingException {        return _context.removeFromEnvironment(propName);    }    /**     * Retrieves the environment in effect for this context.     *     * @return	the environment of this context; never null     * @throws	NamingException if a naming exception is encountered     */    public Hashtable getEnvironment() throws NamingException {        return _context.getEnvironment();    }    /**     * Closes this context.     *     * @throws	NamingException if a naming exception is encountered     */    public void close() throws NamingException {        if (_context != null) {            if (dereference() <= 0) {                Object provider = getEnvironment().get(                        RemoteContext.NAMING_PROVIDER);                if (provider instanceof Proxy) {                    ((Proxy) provider).disposeProxy();                }            }            _context.close();            _context = null;        }    }    /**     * Retrieves the full name of this context within its own namespace.     *     * @return	this context's name in its own namespace; never null     * @throws	NamingException if a naming exception is encountered     */    public String getNameInNamespace() throws NamingException {        return _context.getNameInNamespace();    }    /**     * Called by the garbage collector on an object when garbage collection     * determines that there are no more references to the object.     *     * @throws Throwable the <code>Exception</code> raised by this method     */    protected void finalize() throws Throwable {        close();    }    /**     * Wrap the supplied object in an <code>ORBRemoteContext</code> iff it     * is an instance of <code>RemoteContext</code>, otherwise returns the     * object unchanged.     *     * @param object the object to wrap     * @return the supplied object in an <code>ORBRemoteContext</code> iff it     * is an instance of <code>RemoteContext</code>, otherwise returns the     * object unchanged.     * @throws NamingException if a naming exception is encountered     */    private Object wrap(Object object) throws NamingException {        if (object instanceof RemoteContext) {            return new ORBRemoteContext((RemoteContext) object);        }        return object;    }    /**     * Increment the reference count of the provider. This is the number     * of <code>Context</code> instances that refer to it.     *     * @throws NamingException for any naming error     */    private void reference() throws NamingException {        Ref ref = (Ref) _context.getEnvironment().get(REFERENCE_KEY);        if (ref == null) {            ref = new Ref();            _context.addToEnvironment(REFERENCE_KEY, ref);        }        ref.inc();    }    /**     * Dereference the reference count of the provider.     *     * @return the number of references     * @throws NamingException for any naming error     */    private int dereference() throws NamingException {        Ref ref = (Ref) _context.getEnvironment().get(REFERENCE_KEY);        return (ref != null) ? ref.dec() : 0;    }    /**     * Helper to wrap any <code>RemoteContext</code> instances returned     * by a <code>NamingEnumeration</code> in <code>ORBRemoteContext</code>     * instances.     */    private static class ORBNamingEnumeration implements NamingEnumeration {        /**         * The enumeration.         */        private final NamingEnumeration _iterator;        /**         * Construct a new <code>ORBNamingEnumeration</code>.         *         * @param iterator the enumeration to delegate to         */        private ORBNamingEnumeration(NamingEnumeration iterator) {            _iterator = iterator;        }        /**         * Retrieves the next element in the enumeration.         *         * @return the next element in the enumeration.         * @throws NamingException for any naming error         * @throws java.util.NoSuchElementException If attempting to get the next element when none is available.         */        public Object next() throws NamingException {            return wrap(_iterator.next());        }        /**         * Determines whether there are any more elements in the enumeration.         *         * @throws NamingException for any naming error.         * @return		true if there is more in the enumeration; false otherwise.         */        public boolean hasMore() throws NamingException {            return _iterator.hasMore();        }        /**         * Closes this enumeration.         *         * @throws NamingException for any naming error         */        public void close() throws NamingException {            _iterator.close();        }        /**         * Tests if this enumeration contains more elements.         *         * @return <code>true</code> if and only if this enumeration object         *         contains at least one more element to provide;         *         <code>false</code> otherwise.         */        public boolean hasMoreElements() {            return _iterator.hasMoreElements();        }        /**         * Returns the next element of this enumeration if this enumeration         * object has at least one more element to provide.         *         * @return the next element of this enumeration.         * @throws java.util.NoSuchElementException if no more elements exist.         */        public Object nextElement() {            try {                return wrap(_iterator.nextElement());            } catch (NamingException exception) {                throw new NoSuchElementException(exception.getMessage());            }        }        /**         * Wraps any <code>Context</code> instances in <code>ORBRemoteContext</code>.         *         * @param obj the object         * @return obj         * @throws NamingException for any naming error         */        private Object wrap(Object obj) throws NamingException {            if (obj instanceof Binding) {                Binding binding = (Binding) obj;                Object bound = binding.getObject();                if (bound instanceof RemoteContext) {                    binding.setObject(                            new ORBRemoteContext((RemoteContext) bound));                }            }            return obj;        }    }    /**     * Helper to maintain a reference count.     */    private static class Ref {        /**         * The reference count.         */        private int _count;        /**         * Increment the reference count.         *         * @return the reference count         */        public synchronized int inc() {            return ++_count;        }        /**         * Decrement the reference count.         *         * @return the reference count         */        public synchronized int dec() {            return --_count;        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?