You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xbean-dev@geronimo.apache.org by Guillaume Nodet <gn...@gmail.com> on 2006/08/17 03:05:49 UTC
Re: svn commit: r432088 [1/2] - in /geronimo/xbean/branches/colossus: ./ xbean-naming/ xbean-naming/src/ xbean-naming/src/main/ xbean-naming/src/main/java/ xbean-naming/src/main/java/org/ xbean-naming/src/main/java/org/apache/ xbean-naming/src/main/j
Maybe we should also put the classloader stuff in its own module, as it
is really reusable and completely independant of the rest of xbean-server.
On 8/17/06, dain@apache.org <da...@apache.org> wrote:
> Author: dain
> Date: Wed Aug 16 17:50:03 2006
> New Revision: 432088
>
> URL: http://svn.apache.org/viewvc?rev=432088&view=rev
> Log:
> Global, unmodifiable and immutable JNDI contexts.
>
> Added:
> geronimo/xbean/branches/colossus/xbean-naming/
> geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt
> geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt
> geronimo/xbean/branches/colossus/xbean-naming/pom.xml
> geronimo/xbean/branches/colossus/xbean-naming/src/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractReadOnlyContext.java
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.java
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/global/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/global/GlobalContextManager.java
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/java/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java
> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/SimpleReference.java
> geronimo/xbean/branches/colossus/xbean-naming/src/test/
> geronimo/xbean/branches/colossus/xbean-naming/src/test-data/
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/AbstractContextTest.java
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableContextTest.java
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/UnmodifiableContextTest.java
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/global/
> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/global/GlobalContextManagerTest.java
> Modified:
> geronimo/xbean/branches/colossus/pom.xml
>
> Modified: geronimo/xbean/branches/colossus/pom.xml
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/pom.xml?rev=432088&r1=432087&r2=432088&view=diff
> ==============================================================================
> --- geronimo/xbean/branches/colossus/pom.xml (original)
> +++ geronimo/xbean/branches/colossus/pom.xml Wed Aug 16 17:50:03 2006
> @@ -179,6 +179,7 @@
> -->
> <module>xbean-colossus</module>
> <module>xbean-kernel</module>
> + <module>xbean-naming</module>
> <module>xbean-osgi</module>
> <module>xbean-reflect</module>
> <module>xbean-server</module>
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,203 @@
> +
> + Apache License
> + Version 2.0, January 2004
> + http://www.apache.org/licenses/
> +
> + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
> +
> + 1. Definitions.
> +
> + "License" shall mean the terms and conditions for use, reproduction,
> + and distribution as defined by Sections 1 through 9 of this document.
> +
> + "Licensor" shall mean the copyright owner or entity authorized by
> + the copyright owner that is granting the License.
> +
> + "Legal Entity" shall mean the union of the acting entity and all
> + other entities that control, are controlled by, or are under common
> + control with that entity. For the purposes of this definition,
> + "control" means (i) the power, direct or indirect, to cause the
> + direction or management of such entity, whether by contract or
> + otherwise, or (ii) ownership of fifty percent (50%) or more of the
> + outstanding shares, or (iii) beneficial ownership of such entity.
> +
> + "You" (or "Your") shall mean an individual or Legal Entity
> + exercising permissions granted by this License.
> +
> + "Source" form shall mean the preferred form for making modifications,
> + including but not limited to software source code, documentation
> + source, and configuration files.
> +
> + "Object" form shall mean any form resulting from mechanical
> + transformation or translation of a Source form, including but
> + not limited to compiled object code, generated documentation,
> + and conversions to other media types.
> +
> + "Work" shall mean the work of authorship, whether in Source or
> + Object form, made available under the License, as indicated by a
> + copyright notice that is included in or attached to the work
> + (an example is provided in the Appendix below).
> +
> + "Derivative Works" shall mean any work, whether in Source or Object
> + form, that is based on (or derived from) the Work and for which the
> + editorial revisions, annotations, elaborations, or other modifications
> + represent, as a whole, an original work of authorship. For the purposes
> + of this License, Derivative Works shall not include works that remain
> + separable from, or merely link (or bind by name) to the interfaces of,
> + the Work and Derivative Works thereof.
> +
> + "Contribution" shall mean any work of authorship, including
> + the original version of the Work and any modifications or additions
> + to that Work or Derivative Works thereof, that is intentionally
> + submitted to Licensor for inclusion in the Work by the copyright owner
> + or by an individual or Legal Entity authorized to submit on behalf of
> + the copyright owner. For the purposes of this definition, "submitted"
> + means any form of electronic, verbal, or written communication sent
> + to the Licensor or its representatives, including but not limited to
> + communication on electronic mailing lists, source code control systems,
> + and issue tracking systems that are managed by, or on behalf of, the
> + Licensor for the purpose of discussing and improving the Work, but
> + excluding communication that is conspicuously marked or otherwise
> + designated in writing by the copyright owner as "Not a Contribution."
> +
> + "Contributor" shall mean Licensor and any individual or Legal Entity
> + on behalf of whom a Contribution has been received by Licensor and
> + subsequently incorporated within the Work.
> +
> + 2. Grant of Copyright License. Subject to the terms and conditions of
> + this License, each Contributor hereby grants to You a perpetual,
> + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
> + copyright license to reproduce, prepare Derivative Works of,
> + publicly display, publicly perform, sublicense, and distribute the
> + Work and such Derivative Works in Source or Object form.
> +
> + 3. Grant of Patent License. Subject to the terms and conditions of
> + this License, each Contributor hereby grants to You a perpetual,
> + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
> + (except as stated in this section) patent license to make, have made,
> + use, offer to sell, sell, import, and otherwise transfer the Work,
> + where such license applies only to those patent claims licensable
> + by such Contributor that are necessarily infringed by their
> + Contribution(s) alone or by combination of their Contribution(s)
> + with the Work to which such Contribution(s) was submitted. If You
> + institute patent litigation against any entity (including a
> + cross-claim or counterclaim in a lawsuit) alleging that the Work
> + or a Contribution incorporated within the Work constitutes direct
> + or contributory patent infringement, then any patent licenses
> + granted to You under this License for that Work shall terminate
> + as of the date such litigation is filed.
> +
> + 4. Redistribution. You may reproduce and distribute copies of the
> + Work or Derivative Works thereof in any medium, with or without
> + modifications, and in Source or Object form, provided that You
> + meet the following conditions:
> +
> + (a) You must give any other recipients of the Work or
> + Derivative Works a copy of this License; and
> +
> + (b) You must cause any modified files to carry prominent notices
> + stating that You changed the files; and
> +
> + (c) You must retain, in the Source form of any Derivative Works
> + that You distribute, all copyright, patent, trademark, and
> + attribution notices from the Source form of the Work,
> + excluding those notices that do not pertain to any part of
> + the Derivative Works; and
> +
> + (d) If the Work includes a "NOTICE" text file as part of its
> + distribution, then any Derivative Works that You distribute must
> + include a readable copy of the attribution notices contained
> + within such NOTICE file, excluding those notices that do not
> + pertain to any part of the Derivative Works, in at least one
> + of the following places: within a NOTICE text file distributed
> + as part of the Derivative Works; within the Source form or
> + documentation, if provided along with the Derivative Works; or,
> + within a display generated by the Derivative Works, if and
> + wherever such third-party notices normally appear. The contents
> + of the NOTICE file are for informational purposes only and
> + do not modify the License. You may add Your own attribution
> + notices within Derivative Works that You distribute, alongside
> + or as an addendum to the NOTICE text from the Work, provided
> + that such additional attribution notices cannot be construed
> + as modifying the License.
> +
> + You may add Your own copyright statement to Your modifications and
> + may provide additional or different license terms and conditions
> + for use, reproduction, or distribution of Your modifications, or
> + for any such Derivative Works as a whole, provided Your use,
> + reproduction, and distribution of the Work otherwise complies with
> + the conditions stated in this License.
> +
> + 5. Submission of Contributions. Unless You explicitly state otherwise,
> + any Contribution intentionally submitted for inclusion in the Work
> + by You to the Licensor shall be under the terms and conditions of
> + this License, without any additional terms or conditions.
> + Notwithstanding the above, nothing herein shall supersede or modify
> + the terms of any separate license agreement you may have executed
> + with Licensor regarding such Contributions.
> +
> + 6. Trademarks. This License does not grant permission to use the trade
> + names, trademarks, service marks, or product names of the Licensor,
> + except as required for reasonable and customary use in describing the
> + origin of the Work and reproducing the content of the NOTICE file.
> +
> + 7. Disclaimer of Warranty. Unless required by applicable law or
> + agreed to in writing, Licensor provides the Work (and each
> + Contributor provides its Contributions) on an "AS IS" BASIS,
> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> + implied, including, without limitation, any warranties or conditions
> + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
> + PARTICULAR PURPOSE. You are solely responsible for determining the
> + appropriateness of using or redistributing the Work and assume any
> + risks associated with Your exercise of permissions under this License.
> +
> + 8. Limitation of Liability. In no event and under no legal theory,
> + whether in tort (including negligence), contract, or otherwise,
> + unless required by applicable law (such as deliberate and grossly
> + negligent acts) or agreed to in writing, shall any Contributor be
> + liable to You for damages, including any direct, indirect, special,
> + incidental, or consequential damages of any character arising as a
> + result of this License or out of the use or inability to use the
> + Work (including but not limited to damages for loss of goodwill,
> + work stoppage, computer failure or malfunction, or any and all
> + other commercial damages or losses), even if such Contributor
> + has been advised of the possibility of such damages.
> +
> + 9. Accepting Warranty or Additional Liability. While redistributing
> + the Work or Derivative Works thereof, You may choose to offer,
> + and charge a fee for, acceptance of support, warranty, indemnity,
> + or other liability obligations and/or rights consistent with this
> + License. However, in accepting such obligations, You may act only
> + on Your own behalf and on Your sole responsibility, not on behalf
> + of any other Contributor, and only if You agree to indemnify,
> + defend, and hold each Contributor harmless for any liability
> + incurred by, or claims asserted against, such Contributor by reason
> + of your accepting any such warranty or additional liability.
> +
> + END OF TERMS AND CONDITIONS
> +
> + APPENDIX: How to apply the Apache License to your work.
> +
> + To apply the Apache License to your work, attach the following
> + boilerplate notice, with the fields enclosed by brackets "[]"
> + replaced with your own identifying information. (Don't include
> + the brackets!) The text should be enclosed in the appropriate
> + comment syntax for the file format. We also recommend that a
> + file or class name and description of purpose be included on the
> + same "printed page" as the copyright notice for easier
> + identification within third-party archives.
> +
> + Copyright [yyyy] [name of copyright owner]
> +
> + Licensed under the Apache License, Version 2.0 (the "License");
> + you may not use this file except in compliance with the License.
> + You may obtain a copy of the License at
> +
> + http://www.apache.org/licenses/LICENSE-2.0
> +
> + Unless required by applicable law or agreed to in writing, software
> + distributed under the License is distributed on an "AS IS" BASIS,
> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + See the License for the specific language governing permissions and
> + limitations under the License.
> +
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,3 @@
> +This product includes software developed by
> +The Apache Software Foundation (http://www.apache.org/).
> +
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/pom.xml
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/pom.xml?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/pom.xml (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/pom.xml Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,40 @@
> +<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
> + <parent>
> + <artifactId>xbean</artifactId>
> + <groupId>org.apache.xbean</groupId>
> + <version>COL-SNAPSHOT</version>
> + </parent>
> + <modelVersion>4.0.0</modelVersion>
> + <artifactId>xbean-naming</artifactId>
> + <name>XBean :: Naming</name>
> + <version>COL-SNAPSHOT</version>
> + <build>
> + <plugins>
> + <plugin>
> + <artifactId>maven-compiler-plugin</artifactId>
> + <configuration>
> + <source>1.4</source>
> + <target>1.4</target>
> + </configuration>
> + </plugin>
> + <plugin>
> + <artifactId>maven-surefire-plugin</artifactId>
> + <configuration>
> + <excludes/>
> + </configuration>
> + </plugin>
> + </plugins>
> + </build>
> + <dependencies>
> + <dependency>
> + <groupId>backport-util-concurrent</groupId>
> + <artifactId>backport-util-concurrent</artifactId>
> + </dependency>
> + <dependency>
> + <groupId>org.apache.geronimo.modules</groupId>
> + <artifactId>geronimo-naming</artifactId>
> + <version>1.2-SNAPSHOT</version>
> + <optional>true</optional>
> + </dependency>
> + </dependencies>
> +</project>
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractReadOnlyContext.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractReadOnlyContext.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractReadOnlyContext.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractReadOnlyContext.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,560 @@
> +/**
> + *
> + * Copyright 2003-2004 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package org.apache.xbean.naming.context;
> +
> +import javax.naming.CompositeName;
> +import javax.naming.Context;
> +import javax.naming.InitialContext;
> +import javax.naming.Name;
> +import javax.naming.NameNotFoundException;
> +import javax.naming.NameParser;
> +import javax.naming.NamingEnumeration;
> +import javax.naming.NamingException;
> +import javax.naming.NotContextException;
> +import javax.naming.OperationNotSupportedException;
> +import javax.naming.InvalidNameException;
> +import javax.naming.LinkRef;
> +import java.io.Serializable;
> +import java.util.Hashtable;
> +import java.util.Map;
> +import java.util.Collections;
> +
> +/**
> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
> + */
> +public abstract class AbstractReadOnlyContext implements Context, ContextFactory, Serializable {
> + private static final long serialVersionUID = 3808693663629444493L;
> + private final String nameInNamespace;
> +
> + protected AbstractReadOnlyContext(String nameInNamespace) {
> + this.nameInNamespace = nameInNamespace;
> + }
> +
> + /**
> + * Gets the name of this context withing the global namespace. This method may return null
> + * if the location of the node in the global namespace is not known
> + * @return the name of this context within the global namespace or null if unknown.
> + */
> + public String getNameInNamespace() {
> + return nameInNamespace;
> + }
> +
> + /**
> + * Gets the name of a path withing the global namespace context.
> + */
> + protected String getNameInNamespace(String path) {
> + String nameInNamespace = getNameInNamespace();
> + if (nameInNamespace == null || nameInNamespace.length() == 0) {
> + return path;
> + } else {
> + return nameInNamespace + "/" + path;
> + }
> + }
> +
> +
> + /**
> + * Always returns a new (empty) Hashtable.
> + * @return a new (empty) Hashtable
> + */
> + public Hashtable getEnvironment() {
> + return new Hashtable();
> + }
> +
> + /**
> + * A parser that can turn Strings into javax.naming.Name objects.
> + * @return ContextUtil.NAME_PARSER
> + */
> + protected NameParser getNameParser() {
> + return ContextUtil.NAME_PARSER;
> + }
> +
> + //
> + // Lookup Binding
> + //
> +
> + /**
> + * Gets the object bound to the name. The name may contain slashes.
> + * @param name the name
> + * @return the object bound to the name, or null if not found
> + */
> + protected Object getDeepBinding(String name) {
> + return null;
> + }
> +
> + /**
> + * Gets the object bound to the name. The name will not contain slashes.
> + * @param name the name
> + * @return the object bound to the name, or null if not found
> + */
> + protected Object getBinding(String name) throws NamingException {
> + Map bindings = getBindings();
> + return bindings.get(name);
> + }
> +
> + /**
> + * Finds the specified entry. Normally there is no need to override this method; insted you should
> + * simply implement the getBindings(String) method.
> + *
> + * @param stringName the string version of the name; maybe null
> + * @param parsedName the parsed name; may be null
> + * @return the value bound to the name
> + * @throws NamingException if no value is bound to that name or if a problem occurs during the lookup
> + */
> + protected Object lookup(String stringName, Name parsedName) throws NamingException {
> + if (stringName == null && parsedName == null) {
> + throw new IllegalArgumentException("Both stringName and parsedName are null");
> + }
> + if (stringName == null) stringName = parsedName.toString();
> +
> + // try to look up the name directly (this is the fastest path)
> + Object directLookup = getDeepBinding(stringName);
> + if (directLookup != null) {
> + return ContextUtil.resolve(stringName, directLookup);
> + }
> +
> + // if the parsed name has no parts, they are asking for the current context
> + if (parsedName == null) parsedName = getNameParser().parse(stringName);
> + if (parsedName.size() == 0) {
> + return this;
> + }
> +
> +
> + // we didn't find an entry, pop the first element off the parsed name and attempt to
> + // get a context from the bindings and delegate to that context
> + Object localValue;
> + String firstNameElement = parsedName.get(0);
> + if (firstNameElement.length() == 0) {
> + // the element is null... this is normally caused by looking up with a trailing '/' character
> + localValue = this;
> + } else {
> + localValue = getBinding(firstNameElement);
> + }
> +
> + if (localValue != null) {
> +
> + // if the name only had one part, we've looked up everything
> + if (parsedName.size() == 1) {
> + localValue = ContextUtil.resolve(stringName, localValue);
> + return localValue;
> + }
> +
> + // if we have a link ref, follow it
> + if (localValue instanceof LinkRef) {
> + LinkRef linkRef = (LinkRef) localValue;
> + localValue = lookup(linkRef.getLinkName());
> + }
> +
> + // we have more to lookup so we better have a context object
> + if (!(localValue instanceof Context)) {
> + throw new NameNotFoundException(stringName);
> + }
> +
> + // delegate to the sub-context
> + return ((Context) localValue).lookup(parsedName.getSuffix(1));
> + }
> +
> + // if we didn't find an entry, it may be an absolute name
> + if (stringName.indexOf(':') > 0) {
> + Context ctx = new InitialContext();
> + return ctx.lookup(parsedName);
> + }
> + throw new NameNotFoundException(stringName);
> + }
> +
> + //
> + // List Bindings
> + //
> +
> + /**
> + * Gets a map of the bindings for the current node (i.e., no names with slashes).
> + * This method must not return null.
> + */
> + protected Map getBindings() throws NamingException {
> + throw new OperationNotSupportedException("This context is not listable");
> + }
> +
> + protected NamingEnumeration list() throws NamingException {
> + Map bindings = getBindings();
> + return new ContextUtil.ListEnumeration(bindings);
> + }
> +
> + protected NamingEnumeration listBindings() throws NamingException {
> + Map bindings = getBindings();
> + return new ContextUtil.ListBindingEnumeration(bindings);
> + }
> +
> + //
> + // Add Binding
> + //
> +
> + /**
> + * Add the binding to the context. The name will not contain a path but the value may
> + * be a nested context which should be indexed for indexing contexts.
> + * @param name name under which the value should be bound
> + * @param value the value to bind
> + * @throws NamingException if a problem occurs during the bind such as a value already being bound
> + */
> + protected void addBinding(String name, Object value) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + protected void addDeepBinding(String name, Object value) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> + if (value == null) throw new NullPointerException("value is null");
> +
> + Name compoundName = ContextUtil.parseName(name);
> + if (compoundName.isEmpty()) {
> + throw new InvalidNameException("Name is empty");
> + }
> +
> + AbstractReadOnlyContext currentContext = this;
> + for (int i = 0; i < compoundName.size(); i++) {
> + String part = compoundName.get(i);
> +
> + // empty path parts are not allowed
> + if (part.length() == 0) {
> + throw new InvalidNameException("Name part " + i + " is empty: " + name);
> + }
> +
> + // Is this the last element in the name?
> + if (i == compoundName.size() - 1) {
> + // we're at the end... bind the value into the parent context
> + currentContext.addBinding(part, value);
> +
> + // all done... this is redundant but makes the code more readable
> + break;
> + } else {
> + Map currentBindings = currentContext.getBindings();
> + Object currentValue = currentBindings.get(part);
> + if (currentValue == null) {
> + // the next step in the tree is not present, so create everything down
> + // and add it to the current bindings
> + Context context = currentContext.createContextTree(compoundName.getPrefix(i).toString(),
> + compoundName.getSuffix(i),
> + value);
> + currentContext.addBinding(part, context);
> +
> + // all done
> + break;
> + } else {
> + // the current value must be an abstract read only context
> + // todo this is a problem since a nested node could be an AbstractReadOnlyContext but not one of our contexts
> + if (!(currentValue instanceof AbstractReadOnlyContext)) {
> + throw new NotContextException("Expected an instance of AbstractReadOnlyContext to be bound at " +
> + part + " but found an instance of " + currentValue.getClass().getName());
> + }
> + currentContext = (AbstractReadOnlyContext) currentValue;
> + // now we recurse into the current context
> + }
> + }
> + }
> + }
> +
> + /**
> + * Creates a context tree which will be rooted at the specified path and contain a single entry located down
> + * a path specified by the name. All necessary intermediate contexts will be created using the createContext method.
> + * @param path the path to the context that will contains this context
> + * @param name the name under which the value should be bound
> + * @param value the vale
> + * @return a context with the value bound at the specified name
> + * @throws NamingException
> + */
> + protected Context createContextTree(String path, Name name, Object value) throws NamingException {
> + if (path == null) throw new NullPointerException("path is null");
> + if (name == null) throw new NullPointerException("name is null");
> + if (name.size() < 2) throw new InvalidNameException("name must have at least 2 parts " + name);
> +
> + if (!path.endsWith("/")) path += "/";
> +
> + for (int i = name.size() - 2; i >= 0; i--) {
> + String fullPath = path + name.getSuffix(i);
> + String key = name.get(i + 1);
> + value = createContext(fullPath, Collections.singletonMap(key, value));
> + }
> + return (AbstractReadOnlyContext) value;
> + }
> +
> + //
> + // Remove Binding
> + //
> +
> + /**
> + * Removes the binding from the context. The name will not contain a path and the value will not
> + * be a nested context although it may be a foreign context.
> + * @param name name under which the value should be bound
> + * @throws NamingException if a problem occurs during the bind such as a value already being bound
> + */
> + protected void removeBinding(String name) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + protected void removeDeepBinding(String name) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> +
> + Name compoundName = ContextUtil.parseName(name);
> + if (compoundName.isEmpty()) {
> + throw new InvalidNameException("Name is empty");
> + }
> +
> + // we serch the tree for a target context and name to remove
> + // this is normally the last context in the tree and the final name part, but
> + // it may be farther up the path if the intervening nodes are empty
> + AbstractReadOnlyContext targetContext = this;
> + String targetName = compoundName.get(0);
> +
> + AbstractReadOnlyContext currentContext = this;
> + for (int i = 0; i < compoundName.size(); i++) {
> + String part = compoundName.get(i);
> +
> + // empty path parts are not allowed
> + if (part.length() == 0) {
> + throw new InvalidNameException("Name part " + i + " is empty: " + name);
> + }
> +
> + Map currentBindings = currentContext.getBindings();
> +
> + // update targets
> + if (currentBindings.size() > 1) {
> + targetContext = currentContext;
> + targetName = part;
> + }
> +
> +
> + // Is this the last element in the name?
> + if (i == compoundName.size() - 1) {
> + // we're at the end... bind the value into the parent context
> + targetContext.removeBinding(targetName);
> +
> + // all done... this is redundant but makes the code more readable
> + break;
> + } else {
> + Object currentValue = currentBindings.get(part);
> + if (currentValue == null) {
> + // path not found we are done
> + break;
> + } else {
> + // the current value must be an abstract read only context
> + // todo this is a problem since a nested node could be an AbstractReadOnlyContext but not one of our contexts
> + if (!(currentValue instanceof AbstractReadOnlyContext)) {
> + throw new NotContextException("Expected an instance of AbstractReadOnlyContext to be bound at " +
> + part + " but found an instance of " + currentValue.getClass().getName());
> + }
> + currentContext = (AbstractReadOnlyContext) currentValue;
> + // now we recurse into the current context
> + }
> + }
> + }
> + }
> +
> + // ==================================================================================
> + // =================== Final Methods (see methods above) ============================
> + // ==================================================================================
> +
> + //
> + // Lookup methods
> + //
> +
> + public final Object lookup(String name) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> +
> + Object value = lookup(name, null);
> +
> + // if we got a link back we need to resolve it
> + if (value instanceof LinkRef) {
> + LinkRef linkRef = (LinkRef) value;
> + value = lookup(linkRef.getLinkName());
> + }
> + return value;
> + }
> +
> + public final Object lookup(Name name) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> +
> + Object value = lookup(null, name);
> +
> + // if we got a link back we need to resolve it
> + if (value instanceof LinkRef) {
> + LinkRef linkRef = (LinkRef) value;
> + value = lookup(linkRef.getLinkName());
> + }
> +
> + return value;
> + }
> +
> + public final Object lookupLink(String name) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> +
> + return lookup(name, null);
> + }
> +
> + public final Object lookupLink(Name name) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> +
> + return lookup(null, name);
> + }
> +
> + //
> + // List Operations
> + //
> +
> + public final NamingEnumeration list(String name) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> +
> + Object o = lookup(name);
> + if (o == this) {
> + return list();
> + } else if (o instanceof Context) {
> + return ((Context) o).list("");
> + } else {
> + throw new NotContextException();
> + }
> + }
> +
> + public final NamingEnumeration listBindings(String name) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> +
> + Object o = lookup(name);
> + if (o == this) {
> + return listBindings();
> + } else if (o instanceof Context) {
> + return ((Context) o).listBindings("");
> + } else {
> + throw new NotContextException();
> + }
> + }
> +
> + public final NamingEnumeration list(Name name) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> +
> + Object o = lookup(name);
> + if (o == this) {
> + return list();
> + } else if (o instanceof Context) {
> + return ((Context) o).list("");
> + } else {
> + throw new NotContextException();
> + }
> + }
> +
> + public final NamingEnumeration listBindings(Name name) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> +
> + Object o = lookup(name);
> + if (o == this) {
> + return listBindings();
> + } else if (o instanceof Context) {
> + return ((Context) o).listBindings("");
> + } else {
> + throw new NotContextException();
> + }
> + }
> +
> + //
> + // Name manipulation
> + //
> +
> + public final NameParser getNameParser(Name name) {
> + return getNameParser();
> + }
> +
> + public final NameParser getNameParser(String name) {
> + return getNameParser();
> + }
> +
> + public final Name composeName(Name name, Name prefix) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> + if (prefix == null) throw new NullPointerException("prefix is null");
> +
> + Name result = (Name) prefix.clone();
> + result.addAll(name);
> + return result;
> + }
> +
> + public final String composeName(String name, String prefix) throws NamingException {
> + if (name == null) throw new NullPointerException("name is null");
> + if (prefix == null) throw new NullPointerException("prefix is null");
> +
> + CompositeName result = new CompositeName(prefix);
> + result.addAll(new CompositeName(name));
> + return result.toString();
> + }
> +
> + //
> + // Unsupported Operations
> + //
> +
> + public final Object addToEnvironment(String propName, Object propVal) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final Object removeFromEnvironment(String propName) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void bind(Name name, Object obj) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void bind(String name, Object obj) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void close() throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final Context createSubcontext(Name name) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final Context createSubcontext(String name) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void destroySubcontext(Name name) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void destroySubcontext(String name) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void rebind(Name name, Object obj) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void rebind(String name, Object obj) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void rename(Name oldName, Name newName) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void rename(String oldName, String newName) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void unbind(Name name) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +
> + public final void unbind(String name) throws NamingException {
> + throw new OperationNotSupportedException("Context is read only");
> + }
> +}
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,27 @@
> +/**
> + *
> + * Copyright 2006 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.xbean.naming.context;
> +
> +import javax.naming.Context;
> +import java.util.Map;
> +
> +/**
> + * @version $Rev$ $Date$
> + */
> +public interface ContextFactory {
> + Context createContext(String path, Map bindings);
> +}
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,146 @@
> +/**
> + *
> + * Copyright 2006 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.xbean.naming.context;
> +
> +import javax.naming.Context;
> +import javax.naming.NamingException;
> +import javax.naming.Name;
> +import javax.naming.NamingEnumeration;
> +import javax.naming.NameParser;
> +import java.util.Hashtable;
> +
> +/**
> + * @version $Rev$ $Date$
> + */
> +public abstract class ContextFlyweight implements Context {
> + protected abstract Context getContext() throws NamingException;
> +
> + public void close() throws NamingException {
> + }
> +
> + public String getNameInNamespace() throws NamingException {
> + return getContext().getNameInNamespace();
> + }
> +
> + public Object lookup(Name name) throws NamingException {
> + return getContext().lookup(name);
> + }
> +
> + public Object lookup(String name) throws NamingException {
> + return getContext().lookup(name);
> + }
> +
> + public void bind(Name name, Object obj) throws NamingException {
> + getContext().bind(name, obj);
> + }
> +
> + public void bind(String name, Object obj) throws NamingException {
> + getContext().bind(name, obj);
> + }
> +
> + public void rebind(Name name, Object obj) throws NamingException {
> + getContext().rebind(name, obj);
> + }
> +
> + public void rebind(String name, Object obj) throws NamingException {
> + getContext().rebind(name, obj);
> + }
> +
> + public void unbind(Name name) throws NamingException {
> + getContext().unbind(name);
> + }
> +
> + public void unbind(String name) throws NamingException {
> + getContext().unbind(name);
> + }
> +
> + public void rename(Name oldName, Name newName) throws NamingException {
> + getContext().rename(oldName, newName);
> + }
> +
> + public void rename(String oldName, String newName) throws NamingException {
> + getContext().rename(oldName, newName);
> + }
> +
> + public NamingEnumeration list(Name name) throws NamingException {
> + return getContext().list(name);
> + }
> +
> + public NamingEnumeration list(String name) throws NamingException {
> + return getContext().list(name);
> + }
> +
> + public NamingEnumeration listBindings(Name name) throws NamingException {
> + return getContext().listBindings(name);
> + }
> +
> + public NamingEnumeration listBindings(String name) throws NamingException {
> + return getContext().listBindings(name);
> + }
> +
> + public void destroySubcontext(Name name) throws NamingException {
> + getContext().destroySubcontext(name);
> + }
> +
> + public void destroySubcontext(String name) throws NamingException {
> + getContext().destroySubcontext(name);
> + }
> +
> + public Context createSubcontext(Name name) throws NamingException {
> + return getContext().createSubcontext(name);
> + }
> +
> + public Context createSubcontext(String name) throws NamingException {
> + return getContext().createSubcontext(name);
> + }
> +
> + public Object lookupLink(Name name) throws NamingException {
> + return getContext().lookupLink(name);
> + }
> +
> + public Object lookupLink(String name) throws NamingException {
> + return getContext().lookupLink(name);
> + }
> +
> + public NameParser getNameParser(Name name) throws NamingException {
> + return getContext().getNameParser(name);
> + }
> +
> + public NameParser getNameParser(String name) throws NamingException {
> + return getContext().getNameParser(name);
> + }
> +
> + public Name composeName(Name name, Name prefix) throws NamingException {
> + return getContext().composeName(name, prefix);
> + }
> +
> + public String composeName(String name, String prefix) throws NamingException {
> + return getContext().composeName(name, prefix);
> + }
> +
> + public Object addToEnvironment(String propName, Object propVal) throws NamingException {
> + return getContext().addToEnvironment(propName, propVal);
> + }
> +
> + public Object removeFromEnvironment(String propName) throws NamingException {
> + return getContext().removeFromEnvironment(propName);
> + }
> +
> + public Hashtable getEnvironment() throws NamingException {
> + return getContext().getEnvironment();
> + }
> +}
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,290 @@
> +/**
> + *
> + * Copyright 2006 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.xbean.naming.context;
> +
> +import org.apache.xbean.naming.reference.SimpleReference;
> +
> +import javax.naming.Binding;
> +import javax.naming.CompoundName;
> +import javax.naming.Name;
> +import javax.naming.NameClassPair;
> +import javax.naming.NameParser;
> +import javax.naming.NamingEnumeration;
> +import javax.naming.NamingException;
> +import javax.naming.Reference;
> +import javax.naming.Context;
> +import javax.naming.spi.NamingManager;
> +import java.util.Hashtable;
> +import java.util.Iterator;
> +import java.util.Map;
> +import java.util.Properties;
> +import java.util.HashMap;
> +import java.util.Enumeration;
> +
> +/**
> + * @version $Rev$ $Date$
> + */
> +public final class ContextUtil {
> + private ContextUtil() {
> + }
> +
> + public final static NameParser NAME_PARSER = new SimpleNameParser();
> +
> + public static Name parseName(String name) throws NamingException {
> + return NAME_PARSER.parse(name);
> + }
> +
> + public static Object resolve(String name, Object value) throws NamingException {
> + if (!(value instanceof Reference)) {
> + return value;
> + }
> +
> + Reference reference = (Reference) value;
> +
> + // for SimpleReference we can just call the getContext method
> + if (reference instanceof SimpleReference) {
> + try {
> + return ((SimpleReference) reference).getContent();
> + } catch (NamingException e) {
> + throw e;
> + } catch (Exception e) {
> + throw (NamingException) new NamingException("Could not look up : " + name).initCause(e);
> + }
> + }
> +
> + if (reference instanceof org.apache.geronimo.naming.reference.SimpleReference) {
> + try {
> + return ((org.apache.geronimo.naming.reference.SimpleReference) reference).getContent();
> + } catch (NamingException e) {
> + throw e;
> + } catch (Exception e) {
> + throw (NamingException) new NamingException("Could not look up : " + name).initCause(e);
> + }
> + }
> +
> + // for normal References we have to do it the slow way
> + try {
> + return NamingManager.getObjectInstance(reference, null, null, new Hashtable());
> + } catch (NamingException e) {
> + throw e;
> + } catch (Exception e) {
> + throw (NamingException) new NamingException("Could not look up : " + name).initCause(e);
> + }
> + }
> +
> + public static final class ListEnumeration implements NamingEnumeration {
> + private final Iterator iterator;
> +
> + public ListEnumeration(Map localBindings) {
> + this.iterator = localBindings.entrySet().iterator();
> + }
> +
> + public boolean hasMore() {
> + return iterator.hasNext();
> + }
> +
> + public boolean hasMoreElements() {
> + return iterator.hasNext();
> + }
> +
> + public Object next() {
> + return nextElement();
> + }
> +
> + public Object nextElement() {
> + Map.Entry entry = (Map.Entry) iterator.next();
> + String name = (String) entry.getKey();
> + Object value = entry.getValue();
> + String className = null;
> + if (value instanceof Reference) {
> + Reference reference = (Reference) value;
> + className = reference.getClassName();
> + } else {
> + className = value.getClass().getName();
> + }
> + return new NameClassPair(name, className);
> + }
> +
> + public void close() {
> + }
> + }
> +
> + public static final class ListBindingEnumeration implements NamingEnumeration {
> + private final Iterator iterator;
> +
> + public ListBindingEnumeration(Map localBindings) {
> + this.iterator = localBindings.entrySet().iterator();
> + }
> +
> + public boolean hasMore() {
> + return iterator.hasNext();
> + }
> +
> + public boolean hasMoreElements() {
> + return iterator.hasNext();
> + }
> +
> + public Object next() {
> + return nextElement();
> + }
> +
> + public Object nextElement() {
> + Map.Entry entry = (Map.Entry) iterator.next();
> + String name = (String) entry.getKey();
> + Object value = entry.getValue();
> + return new ReadOnlyBinding(name, value);
> + }
> +
> + public void close() {
> + }
> + }
> +
> + public static final class ReadOnlyBinding extends Binding {
> + private final Object value;
> +
> + public ReadOnlyBinding(String name, Object value) {
> + super(name, value);
> + this.value = value;
> + }
> +
> + public void setName(String name) {
> + throw new UnsupportedOperationException("Context is read only");
> + }
> +
> + public String getClassName() {
> + if (value instanceof Reference) {
> + Reference reference = (Reference) value;
> + return reference.getClassName();
> + }
> + return value.getClass().getName();
> + }
> +
> + public void setClassName(String name) {
> + throw new UnsupportedOperationException("Context is read only");
> + }
> +
> + public Object getObject() {
> + try {
> + return resolve(getName(), value);
> + } catch (NamingException e) {
> + throw new RuntimeException(e);
> + }
> + }
> +
> + public void setObject(Object obj) {
> + throw new UnsupportedOperationException("Context is read only");
> + }
> +
> + public boolean isRelative() {
> + return false;
> + }
> +
> + public void setRelative(boolean r) {
> + throw new UnsupportedOperationException("Context is read only");
> + }
> + }
> +
> +
> + private static final class SimpleNameParser implements NameParser {
> + private static final Properties PARSER_PROPERTIES = new Properties();
> +
> + static {
> + PARSER_PROPERTIES.put("jndi.syntax.direction", "left_to_right");
> + PARSER_PROPERTIES.put("jndi.syntax.separator", "/");
> + }
> +
> +
> + private SimpleNameParser() {
> + }
> +
> + public Name parse(String name) throws NamingException {
> + return new CompoundName(name, PARSER_PROPERTIES);
> + }
> + }
> +
> + public static Map createBindings(Map absoluteBindings, ContextFactory factory) throws NamingException {
> + // create a tree of Nodes using the absolute bindings
> + Node node = buildMapTree(absoluteBindings);
> +
> + // convert the node tree into a tree of context objects
> + Map localBindings = ContextUtil.createBindings(null, node, factory);
> +
> + return localBindings;
> + }
> +
> + private static Map createBindings(String nameInNameSpace, Node node, ContextFactory factory) {
> + Map bindings = new HashMap(node.size());
> + for (Iterator iterator = node.entrySet().iterator(); iterator.hasNext();) {
> + Map.Entry entry = (Map.Entry) iterator.next();
> + String name = (String) entry.getKey();
> + Object value = entry.getValue();
> +
> + // if this is a nested node we need to create a context for the node
> + if (value instanceof Node) {
> + Node nestedNode = (Node) value;
> +
> + // recursive call create bindings to cause building the context depth first
> + String path = nameInNameSpace == null ? name : nameInNameSpace + "/" + name;
> +
> + Map nestedBindings = createBindings(path, nestedNode, factory);
> + Context nestedContext = factory.createContext(path, nestedBindings);
> + bindings.put(name, nestedContext);
> + } else {
> + bindings.put(name, value);
> + }
> + }
> + return bindings;
> + }
> +
> +
> + /**
> + * Do nothing subclass of hashmap used to differentiate between a Map in the tree an a nested element during tree building
> + */
> + public static final class Node extends HashMap {
> + }
> +
> + public static Node buildMapTree(Map absoluteBindings) throws NamingException {
> + Node rootContext = new Node();
> +
> + for (Iterator iterator = absoluteBindings.entrySet().iterator(); iterator.hasNext();) {
> + Map.Entry entry = (Map.Entry) iterator.next();
> + String name = (String) entry.getKey();
> + Object value = entry.getValue();
> +
> + Node parentContext = rootContext;
> +
> + Name compoundName = ContextUtil.parseName(name);
> + for (Enumeration parts = compoundName.getAll(); parts.hasMoreElements(); ) {
> + String part = (String) parts.nextElement();
> + // the last element in the path is the name of the value
> + if (parts.hasMoreElements()) {
> + // nest node into parent
> + Node bindings = (Node) parentContext.get(part);
> + if (bindings == null) {
> + bindings = new Node();
> + parentContext.put(part, bindings);
> + }
> +
> + parentContext = bindings;
> + }
> + }
> +
> + parentContext.put(compoundName.get(compoundName.size() - 1), value);
> + }
> + return rootContext;
> + }
> +}
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,136 @@
> +/**
> + *
> + * Copyright 2006 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.xbean.naming.context;
> +
> +import org.apache.xbean.naming.reference.CachingReference;
> +
> +import javax.naming.Context;
> +import javax.naming.NamingException;
> +import javax.naming.OperationNotSupportedException;
> +import java.util.Collections;
> +import java.util.HashMap;
> +import java.util.Iterator;
> +import java.util.Map;
> +
> +/**
> + *
> + * @version $Rev: 417891 $ $Date: 2006-06-28 15:45:07 -0700 (Wed, 28 Jun 2006) $
> + */
> +public class ImmutableContext extends AbstractReadOnlyContext {
> + private final Map localBindings;
> + private final Map absoluteIndex;
> +
> + public ImmutableContext(Map bindings) throws NamingException {
> + this("", bindings, true);
> + }
> +
> + public ImmutableContext(Map bindings, boolean cacheReferences) throws NamingException {
> + this("", bindings, cacheReferences);
> + }
> +
> + public ImmutableContext(String nameInNamespace, Map bindings, boolean cacheReferences) throws NamingException {
> + super(nameInNamespace);
> +
> + if (cacheReferences) {
> + bindings = CachingReference.wrapReferences(bindings);
> + }
> +
> + Map localBindings = ContextUtil.createBindings(bindings, this);
> + this.localBindings = Collections.unmodifiableMap(localBindings);
> +
> + Map globalBindings = ImmutableContext.buildAbsoluteIndex("", localBindings);
> + this.absoluteIndex = Collections.unmodifiableMap(globalBindings);
> + }
> +
> + private static Map buildAbsoluteIndex(String nameInNamespace, Map bindings) {
> + String path = nameInNamespace;
> + if (path.length() > 0) {
> + path += "/";
> + }
> +
> + Map globalBindings = new HashMap();
> + for (Iterator iterator = bindings.entrySet().iterator(); iterator.hasNext();) {
> + Map.Entry entry = (Map.Entry) iterator.next();
> + String name = (String) entry.getKey();
> + Object value = entry.getValue();
> + if (value instanceof ImmutableContext.NestedMapContext) {
> + ImmutableContext.NestedMapContext nestedContext = (ImmutableContext.NestedMapContext)value;
> + globalBindings.putAll(ImmutableContext.buildAbsoluteIndex(nestedContext.getNameInNamespace(), nestedContext.localBindings));
> + }
> + globalBindings.put(path + name, value);
> + }
> + return globalBindings;
> + }
> +
> + protected Object getDeepBinding(String name) {
> + return absoluteIndex.get(name);
> + }
> +
> + protected Map getBindings() {
> + return localBindings;
> + }
> +
> + protected void addDeepBinding(String name, Object value) throws NamingException {
> + throw new OperationNotSupportedException("Context is immutable");
> + }
> +
> + protected void removeDeepBinding(String name, Object value) throws NamingException {
> + throw new OperationNotSupportedException("Context is immutable");
> + }
> +
> + public Context createContext(String path, Map bindings) {
> + return new NestedMapContext(path, bindings);
> + }
> +
> + /**
> + * Nested context which shares the absolute index map in MapContext.
> + */
> + public final class NestedMapContext extends AbstractReadOnlyContext {
> + private final Map localBindings;
> + private final String pathWithSlash;
> +
> + public NestedMapContext(String path, Map bindings) {
> + super(ImmutableContext.this.getNameInNamespace(path));
> +
> + if (!path.endsWith("/")) path += "/";
> + this.pathWithSlash = path;
> +
> + this.localBindings = Collections.unmodifiableMap(bindings);
> + }
> +
> + protected Object getDeepBinding(String name) {
> + String absoluteName = pathWithSlash + name;
> + return absoluteIndex.get(absoluteName);
> + }
> +
> + protected Map getBindings() {
> + return localBindings;
> + }
> +
> + protected void addDeepBinding(String name, Object value) throws NamingException {
> + throw new OperationNotSupportedException("Context is immutable");
> + }
> +
> + protected void removeDeepBinding(String name, Object value) throws NamingException {
> + throw new OperationNotSupportedException("Context is immutable");
> + }
> +
> + public Context createContext(String path, Map bindings) {
> + return new NestedMapContext(path, bindings);
> + }
> + }
> +}
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,228 @@
> +/**
> + *
> + * Copyright 2006 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.xbean.naming.context;
> +
> +import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicReference;
> +import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock;
> +import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock;
> +import org.apache.xbean.naming.reference.CachingReference;
> +
> +import javax.naming.NameAlreadyBoundException;
> +import javax.naming.NamingException;
> +import javax.naming.Context;
> +import javax.naming.NameNotFoundException;
> +import java.util.Collections;
> +import java.util.HashMap;
> +import java.util.Iterator;
> +import java.util.Map;
> +
> +/**
> + * @version $Rev: 417891 $ $Date: 2006-06-28 15:45:07 -0700 (Wed, 28 Jun 2006) $
> + */
> +public class UnmodifiableContext extends AbstractReadOnlyContext {
> + private final Lock writeLock = new ReentrantLock();
> + private final AtomicReference bindingsRef;
> + private final AtomicReference indexRef;
> + public static final int MAX_WRITE_ATTEMPTS = 3;
> +
> + public UnmodifiableContext(Map bindings) throws NamingException {
> + this("", bindings, true);
> + }
> +
> + public UnmodifiableContext(Map bindings, boolean cacheReferences) throws NamingException {
> + this("", bindings, cacheReferences);
> + }
> +
> + public UnmodifiableContext(String nameInNamespace, Map bindings, boolean cacheReferences) throws NamingException {
> + super(nameInNamespace);
> +
> + if (cacheReferences) {
> + bindings = CachingReference.wrapReferences(bindings);
> + }
> +
> + Map localBindings = ContextUtil.createBindings(bindings, this);
> +
> + this.bindingsRef = new AtomicReference(Collections.unmodifiableMap(localBindings));
> + this.indexRef = new AtomicReference(Collections.unmodifiableMap(buildIndex("", localBindings)));
> + }
> +
> + protected void addBinding(String name, Object value) throws NamingException {
> + writeLock.lock();
> + try {
> + Map bindings = (Map) bindingsRef.get();
> + if (bindings.containsKey(name)) {
> + throw new NameAlreadyBoundException(name);
> + }
> +
> + Map newBindings = new HashMap(bindings);
> + newBindings.put(name,value);
> + bindingsRef.set(newBindings);
> +
> + Map newIndex = addToIndex(name, value);
> + indexRef.set(newIndex);
> + } finally {
> + writeLock.unlock();
> + }
> + }
> +
> + private Map addToIndex(String name, Object value) {
> + Map index = (Map) indexRef.get();
> + Map newIndex = new HashMap(index);
> + newIndex.put(name, value);
> + if (value instanceof NestedMapContext) {
> + NestedMapContext nestedcontext = (NestedMapContext) value;
> + Map newIndexValues = buildIndex(name, nestedcontext.getBindings());
> + newIndex.putAll(newIndexValues);
> + }
> + return newIndex;
> + }
> +
> + protected void removeBinding(String name) throws NamingException {
> + writeLock.lock();
> + try {
> + Map bindings = (Map) bindingsRef.get();
> + if (!bindings.containsKey(name)) {
> + throw new NameNotFoundException(name);
> + }
> +
> + Map newBindings = new HashMap(bindings);
> + newBindings.remove(name);
> + bindingsRef.set(newBindings);
> +
> + Map newIndex = removeFromIndex(name);
> + indexRef.set(newIndex);
> + } finally {
> + writeLock.unlock();
> + }
> + }
> +
> + private Map removeFromIndex(String name) {
> + Map index = (Map) indexRef.get();
> + Map newIndex = new HashMap(index);
> + Object oldValue = newIndex.remove(name);
> + if (oldValue instanceof NestedMapContext) {
> + NestedMapContext nestedcontext = (NestedMapContext) oldValue;
> + Map removedIndexValues = buildIndex(name, nestedcontext.getBindings());
> + for (Iterator iterator = removedIndexValues.keySet().iterator(); iterator.hasNext();) {
> + String key = (String) iterator.next();
> + newIndex.remove(key);
> + }
> + }
> + return newIndex;
> + }
> +
> + public Context createContext(String path, Map bindings) {
> + return new NestedMapContext(path,bindings);
> + }
> +
> + private static Map buildIndex(String nameInNamespace, Map bindings) {
> + String path = nameInNamespace;
> + if (path.length() > 0 && !path.endsWith("/")) {
> + path += "/";
> + }
> +
> + Map absoluteIndex = new HashMap();
> + for (Iterator iterator = bindings.entrySet().iterator(); iterator.hasNext();) {
> + Map.Entry entry = (Map.Entry) iterator.next();
> + String name = (String) entry.getKey();
> + Object value = entry.getValue();
> + if (value instanceof UnmodifiableContext.NestedMapContext) {
> + UnmodifiableContext.NestedMapContext nestedContext = (UnmodifiableContext.NestedMapContext)value;
> + absoluteIndex.putAll(UnmodifiableContext.buildIndex(nestedContext.pathWithSlash, nestedContext.getBindings()));
> + }
> + absoluteIndex.put(path + name, value);
> + }
> + return absoluteIndex;
> + }
> +
> + protected Object getDeepBinding(String name) {
> + Map index = (Map) indexRef.get();
> + return index.get(name);
> + }
> +
> + protected Map getBindings() {
> + Map bindings = (Map) bindingsRef.get();
> + return bindings;
> + }
> +
> + /**
> + * Nested context which shares the absolute index map in MapContext.
> + */
> + public final class NestedMapContext extends AbstractReadOnlyContext {
> + private final AtomicReference bindingsRef;
> + private final String pathWithSlash;
> +
> + public NestedMapContext(String path, String key, Object value) {
> + this(path, Collections.singletonMap(key, value));
> + }
> +
> + public NestedMapContext(String path, Map bindings) {
> + super(UnmodifiableContext.this.getNameInNamespace(path));
> +
> + if (!path.endsWith("/")) path += "/";
> + this.pathWithSlash = path;
> +
> + this.bindingsRef = new AtomicReference(Collections.unmodifiableMap(bindings));
> + }
> +
> + public Context createContext(String path, Map bindings) {
> + return new NestedMapContext(path, bindings);
> + }
> +
> + protected Object getDeepBinding(String name) {
> + String absoluteName = pathWithSlash + name;
> + return UnmodifiableContext.this.getDeepBinding(absoluteName);
> + }
> +
> + protected Map getBindings() {
> + Map bindings = (Map) bindingsRef.get();
> + return bindings;
> + }
> +
> + protected void addBinding(String name, Object value) {
> + writeLock.lock();
> + try {
> + Map currentBindings = (Map) bindingsRef.get();
> + Map newBindings = new HashMap(currentBindings);
> + newBindings.put(name, value);
> + newBindings = Collections.unmodifiableMap(newBindings);
> + bindingsRef.set(newBindings);
> +
> + Map newIndex = addToIndex(name, value);
> + indexRef.set(newIndex);
> + } finally {
> + writeLock.unlock();
> + }
> + }
> +
> + protected void removeBinding(String name) {
> + writeLock.lock();
> + try {
> + Map currentBindings = (Map) bindingsRef.get();
> + Map newBindings = new HashMap(currentBindings);
> + newBindings.remove(name);
> + newBindings = Collections.unmodifiableMap(newBindings);
> + bindingsRef.set(newBindings);
> +
> + Map newIndex = removeFromIndex(name);
> + indexRef.set(newIndex);
> + } finally {
> + writeLock.unlock();
> + }
> + }
> + }
> +}
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/global/GlobalContextManager.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/global/GlobalContextManager.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/global/GlobalContextManager.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/global/GlobalContextManager.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,106 @@
> +/**
> + *
> + * Copyright 2006 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.xbean.naming.global;
> +
> +import org.apache.xbean.naming.context.ContextFlyweight;
> +
> +import javax.naming.Context;
> +import javax.naming.Name;
> +import javax.naming.OperationNotSupportedException;
> +import javax.naming.NoInitialContextException;
> +import javax.naming.spi.InitialContextFactory;
> +import javax.naming.spi.ObjectFactory;
> +import java.util.Hashtable;
> +
> +/**
> + * The GlobalContextManager contains the static global context object. JNDI effectively requires a single global static
> + * to resolve the root context, and this class manages that static. This class is also an URLContextFactory and
> + * an InitialContextFactory which returns the registered global context.
> + *
> + * To use this factory simply set the following system property or pass the property in the environment to new InitialContext:
> + *
> + * java.naming.factory.initial = org.apache.xbean.naming.global.GlobalContextManager
> + *
> + * @version $Rev$ $Date$
> + */
> +public class GlobalContextManager implements ObjectFactory, InitialContextFactory {
> + private static Context DEFAULT_CONTEXT = new DefaultGlobalContext();
> + private static Context globalContext;
> +
> + /**
> + * Gets the global context. This context is the root of all contexts and will contain entries such as "java:comp".
> + * @return the global context
> + */
> + public static synchronized Context getGlobalContext() {
> + if (globalContext == null) return DEFAULT_CONTEXT;
> + return globalContext;
> + }
> +
> + /**
> + * Sets the global context. To invoke this method the calling code must have "setFactory" RuntimePermission.
> + * @param globalContext the new global context
> + */
> + public static synchronized void setGlobalContext(Context globalContext) {
> + SecurityManager security = System.getSecurityManager();
> + if (security != null) {
> + security.checkSetFactory();
> + }
> + GlobalContextManager.globalContext = globalContext;
> + }
> +
> + /**
> + * Returns the Context registered with the GlobalManager. This method is equivalent to:
> + *
> + * return GlobalContextManager.getGlobalContext();
> + *
> + * @param obj must be null
> + * @param name ignored
> + * @param nameCtx ignored
> + * @param environment ignored
> + * @return GlobalManager.getGlobalContext()
> + * @throws javax.naming.OperationNotSupportedException if obj is not null
> + */
> + public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
> + if (obj == null) {
> + return GlobalContextManager.getGlobalContext();
> + } else {
> + throw new OperationNotSupportedException();
> + }
> + }
> +
> +
> + /**
> + * Returns the Context registered with the GlobalManager. This method is equivalent to:
> + *
> + * return GlobalContextManager.getGlobalContext();
> + *
> + * @param environment ignored
> + * @return GlobalContextManager.getGlobalContext()
> + */
> + public Context getInitialContext(Hashtable environment) {
> + return GlobalContextManager.getGlobalContext();
> + }
> +
> + private static class DefaultGlobalContext extends ContextFlyweight {
> + protected Context getContext() throws NoInitialContextException {
> + synchronized (GlobalContextManager.class) {
> + if (globalContext == null) throw new NoInitialContextException("Global context has not been set");
> + return globalContext;
> + }
> + }
> + }
> +}
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,28 @@
> +/**
> + *
> + * Copyright 2003-2004 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +package org.apache.xbean.naming.java;
> +
> +import org.apache.xbean.naming.global.GlobalContextManager;
> +
> +/**
> + * URLContextFactory for the java: namespace.
> + *
> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
> + */
> +public class javaURLContextFactory extends GlobalContextManager {
> +}
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,68 @@
> +/**
> + *
> + * Copyright 2006 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.xbean.naming.reference;
> +
> +import org.apache.xbean.naming.context.ContextUtil;
> +
> +import javax.naming.Reference;
> +import javax.naming.NamingException;
> +import java.util.Map;
> +import java.util.LinkedHashMap;
> +import java.util.Iterator;
> +
> +/**
> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
> + */
> +public class CachingReference extends SimpleReference {
> + public static Map wrapReferences(Map bindings) {
> + LinkedHashMap newBindings = new LinkedHashMap(bindings);
> + for (Iterator iterator = bindings.entrySet().iterator(); iterator.hasNext();) {
> + Map.Entry entry = (Map.Entry) iterator.next();
> + String name = (String) entry.getKey();
> + Object value = entry.getValue();
> + if (value instanceof Reference && !(value instanceof CachingReference)) {
> + newBindings.put(name, new CachingReference(name, (Reference)value));
> + }
> + }
> + return newBindings;
> + }
> +
> + private final Object lock = new Object();
> + private final String fullName;
> + private final Reference reference;
> + private final String className;
> + private Object value;
> +
> + public CachingReference(String fullName, Reference reference) {
> + this.fullName = fullName;
> + this.reference = reference;
> + className = reference.getClassName();
> + }
> +
> + public Object getContent() throws NamingException {
> + synchronized(lock) {
> + if (value == null) {
> + value = ContextUtil.resolve(fullName, reference);
> + }
> + return value;
> + }
> + }
> +
> + public String getClassName() {
> + return className;
> + }
> +}
>
> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/SimpleReference.java
> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/SimpleReference.java?rev=432088&view=auto
> ==============================================================================
> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/SimpleReference.java (added)
> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/reference/SimpleReference.java Wed Aug 16 17:50:03 2006
> @@ -0,0 +1,141 @@
> +/**
> + *
> + * Copyright 2004 The Apache Software Foundation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.xbean.naming.reference;
> +
> +import java.util.Enumeration;
> +import java.util.Hashtable;
> +import java.util.NoSuchElementException;
> +import javax.naming.Context;
> +import javax.naming.Name;
> +import javax.naming.RefAddr;
> +import javax.naming.Reference;
> +import javax.naming.NamingException;
> +import javax.naming.spi.ObjectFactory;
> +
> +/**
> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
> + */
> +public abstract class SimpleReference extends Reference {
> + private static final Enumeration EMPTY_ENUMERATION = new Enumeration() {
> + public boolean hasMoreElements() {
> + return false;
> + }
> +
> + public Object nextElement() {
> + return new NoSuchElementException();
> + }
> + };
> +
> + public SimpleReference() {
> + super(null);
> + }
> +
> + /**
> + * Gets the actual referenced Object.
> + * @return the referenced object
> + */
> + public abstract Object getContent() throws NamingException;
> +
> + /**
> + * We will atleast return an Object. Subclasses may want to provide a more specific class.
> + * @return "java.lang.Object"
> + */
> + public String getClassName() {
> + return "java.lang.Object";
> + }
> +
> + /**
> + * If the JNDI context does not understand simple references, this method will be called
> + * to obtain the class name of a factory. This factory in turn understands the simple
> + * reference. This style is much slower because JNDI will use reflection to load and
> + * create this class.
> + * @return
> + */
> + public final String getFactoryClassName() {
> + return SimpleObjectFactory.class.getName();
> + }
> +
> + //
> + // Disabled methods that we no longer need
> + //
> + public final String getFactoryClassLocation() {
> + return null;
> + }
> +
> + public final RefAddr get(String addrType) {
> + return null;
> + }
> +
> + public final RefAddr get(int posn) {
> + throw new ArrayIndexOutOfBoundsException(posn);
> + }
> +
> + public final Enumeration getAll() {
> + return EMPTY_ENUMERATION;
> + }
> +
> + public final int size() {
> + return 0;
> + }
> +
> + public final void add(RefAddr addr) {
> + throw new UnsupportedOperationException("SimpleReference has no addresses so none can be added");
> + }
> +
> + public final void add(int posn, RefAddr addr) {
> + throw new UnsupportedOperationException("SimpleReference has no addresses so none can be added");
> + }
> +
> + public final Object remove(int posn) {
> + throw new ArrayIndexOutOfBoundsException(posn);
> + }
> +
> + public final void clear() {
> + }
> +
> + //
> + // Reset the java.lang.Object methods back to default implementations
> + //
> + public boolean equals(Object obj) {
> + return this == obj;
> + }
> +
> + public int hashCode() {
> + return System.identityHashCode(this);
> + }
> +
> + public String toString() {
> + return getClass().getName() + "@" + Integer.toHexString(hashCode());
> + }
> +
> + public Object clone() {
> + throw new UnsupportedOperationException("SimpleReference can not be cloned");
> + }
> +
> + /**
> + * Simply calls getContent() on the SimpleReference
> + */
> + public static final class SimpleObjectFactory implements ObjectFactory {
> + public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
> + if (obj instanceof SimpleReference) {
> + SimpleReference reference = (SimpleReference) obj;
> + return reference.getContent();
> + }
> + return null;
> + }
> + }
> +}
>
>
>
--
Cheers,
Guillaume Nodet
Re: svn commit: r432088 [1/2] - in /geronimo/xbean/branches/colossus: ./ xbean-naming/ xbean-naming/src/ xbean-naming/src/main/ xbean-naming/src/main/java/ xbean-naming/src/main/java/org/ xbean-naming/src/main/java/org/apache/ xbean-naming/src/main/j
Posted by Guillaume Nodet <gn...@gmail.com>.
I will do it :)
On 8/17/06, Dain Sundstrom <da...@iq80.com> wrote:
> I've been wanting to but I've been too busy.
>
> -dain
>
> On Aug 16, 2006, at 6:05 PM, Guillaume Nodet wrote:
>
> > Maybe we should also put the classloader stuff in its own module,
> > as it
> > is really reusable and completely independant of the rest of xbean-
> > server.
> >
> > On 8/17/06, dain@apache.org <da...@apache.org> wrote:
> >> Author: dain
> >> Date: Wed Aug 16 17:50:03 2006
> >> New Revision: 432088
> >>
> >> URL: http://svn.apache.org/viewvc?rev=432088&view=rev
> >> Log:
> >> Global, unmodifiable and immutable JNDI contexts.
> >>
> >> Added:
> >> geronimo/xbean/branches/colossus/xbean-naming/
> >> geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt
> >> geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt
> >> geronimo/xbean/branches/colossus/xbean-naming/pom.xml
> >> geronimo/xbean/branches/colossus/xbean-naming/src/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/AbstractReadOnlyContext.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextFactory.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextFlyweight.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextUtil.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ImmutableContext.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/UnmodifiableContext.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/global/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/global/GlobalContextManager.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/java/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/java/javaURLContextFactory.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/reference/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/reference/CachingReference.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/reference/SimpleReference.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test-data/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> org/apache/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> org/apache/xbean/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> org/apache/xbean/naming/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> org/apache/xbean/naming/context/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> org/apache/xbean/naming/context/AbstractContextTest.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> org/apache/xbean/naming/context/ImmutableContextTest.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> org/apache/xbean/naming/context/UnmodifiableContextTest.java
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> org/apache/xbean/naming/global/
> >> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
> >> org/apache/xbean/naming/global/GlobalContextManagerTest.java
> >> Modified:
> >> geronimo/xbean/branches/colossus/pom.xml
> >>
> >> Modified: geronimo/xbean/branches/colossus/pom.xml
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> pom.xml?rev=432088&r1=432087&r2=432088&view=diff
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/pom.xml (original)
> >> +++ geronimo/xbean/branches/colossus/pom.xml Wed Aug 16 17:50:03 2006
> >> @@ -179,6 +179,7 @@
> >> -->
> >> <module>xbean-colossus</module>
> >> <module>xbean-kernel</module>
> >> + <module>xbean-naming</module>
> >> <module>xbean-osgi</module>
> >> <module>xbean-reflect</module>
> >> <module>xbean-server</module>
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/LICENSE.txt?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt Wed
> >> Aug 16 17:50:03 2006
> >> @@ -0,0 +1,203 @@
> >> +
> >> + Apache License
> >> + Version 2.0, January 2004
> >> + http://www.apache.org/licenses/
> >> +
> >> + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
> >> +
> >> + 1. Definitions.
> >> +
> >> + "License" shall mean the terms and conditions for use,
> >> reproduction,
> >> + and distribution as defined by Sections 1 through 9 of this
> >> document.
> >> +
> >> + "Licensor" shall mean the copyright owner or entity
> >> authorized by
> >> + the copyright owner that is granting the License.
> >> +
> >> + "Legal Entity" shall mean the union of the acting entity
> >> and all
> >> + other entities that control, are controlled by, or are
> >> under common
> >> + control with that entity. For the purposes of this definition,
> >> + "control" means (i) the power, direct or indirect, to cause
> >> the
> >> + direction or management of such entity, whether by contract or
> >> + otherwise, or (ii) ownership of fifty percent (50%) or more
> >> of the
> >> + outstanding shares, or (iii) beneficial ownership of such
> >> entity.
> >> +
> >> + "You" (or "Your") shall mean an individual or Legal Entity
> >> + exercising permissions granted by this License.
> >> +
> >> + "Source" form shall mean the preferred form for making
> >> modifications,
> >> + including but not limited to software source code,
> >> documentation
> >> + source, and configuration files.
> >> +
> >> + "Object" form shall mean any form resulting from mechanical
> >> + transformation or translation of a Source form, including but
> >> + not limited to compiled object code, generated documentation,
> >> + and conversions to other media types.
> >> +
> >> + "Work" shall mean the work of authorship, whether in Source or
> >> + Object form, made available under the License, as indicated
> >> by a
> >> + copyright notice that is included in or attached to the work
> >> + (an example is provided in the Appendix below).
> >> +
> >> + "Derivative Works" shall mean any work, whether in Source
> >> or Object
> >> + form, that is based on (or derived from) the Work and for
> >> which the
> >> + editorial revisions, annotations, elaborations, or other
> >> modifications
> >> + represent, as a whole, an original work of authorship. For
> >> the purposes
> >> + of this License, Derivative Works shall not include works
> >> that remain
> >> + separable from, or merely link (or bind by name) to the
> >> interfaces of,
> >> + the Work and Derivative Works thereof.
> >> +
> >> + "Contribution" shall mean any work of authorship, including
> >> + the original version of the Work and any modifications or
> >> additions
> >> + to that Work or Derivative Works thereof, that is
> >> intentionally
> >> + submitted to Licensor for inclusion in the Work by the
> >> copyright owner
> >> + or by an individual or Legal Entity authorized to submit on
> >> behalf of
> >> + the copyright owner. For the purposes of this definition,
> >> "submitted"
> >> + means any form of electronic, verbal, or written
> >> communication sent
> >> + to the Licensor or its representatives, including but not
> >> limited to
> >> + communication on electronic mailing lists, source code
> >> control systems,
> >> + and issue tracking systems that are managed by, or on
> >> behalf of, the
> >> + Licensor for the purpose of discussing and improving the
> >> Work, but
> >> + excluding communication that is conspicuously marked or
> >> otherwise
> >> + designated in writing by the copyright owner as "Not a
> >> Contribution."
> >> +
> >> + "Contributor" shall mean Licensor and any individual or
> >> Legal Entity
> >> + on behalf of whom a Contribution has been received by
> >> Licensor and
> >> + subsequently incorporated within the Work.
> >> +
> >> + 2. Grant of Copyright License. Subject to the terms and
> >> conditions of
> >> + this License, each Contributor hereby grants to You a
> >> perpetual,
> >> + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
> >> + copyright license to reproduce, prepare Derivative Works of,
> >> + publicly display, publicly perform, sublicense, and
> >> distribute the
> >> + Work and such Derivative Works in Source or Object form.
> >> +
> >> + 3. Grant of Patent License. Subject to the terms and
> >> conditions of
> >> + this License, each Contributor hereby grants to You a
> >> perpetual,
> >> + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
> >> + (except as stated in this section) patent license to make,
> >> have made,
> >> + use, offer to sell, sell, import, and otherwise transfer
> >> the Work,
> >> + where such license applies only to those patent claims
> >> licensable
> >> + by such Contributor that are necessarily infringed by their
> >> + Contribution(s) alone or by combination of their
> >> Contribution(s)
> >> + with the Work to which such Contribution(s) was submitted.
> >> If You
> >> + institute patent litigation against any entity (including a
> >> + cross-claim or counterclaim in a lawsuit) alleging that the
> >> Work
> >> + or a Contribution incorporated within the Work constitutes
> >> direct
> >> + or contributory patent infringement, then any patent licenses
> >> + granted to You under this License for that Work shall
> >> terminate
> >> + as of the date such litigation is filed.
> >> +
> >> + 4. Redistribution. You may reproduce and distribute copies of the
> >> + Work or Derivative Works thereof in any medium, with or
> >> without
> >> + modifications, and in Source or Object form, provided that You
> >> + meet the following conditions:
> >> +
> >> + (a) You must give any other recipients of the Work or
> >> + Derivative Works a copy of this License; and
> >> +
> >> + (b) You must cause any modified files to carry prominent
> >> notices
> >> + stating that You changed the files; and
> >> +
> >> + (c) You must retain, in the Source form of any Derivative
> >> Works
> >> + that You distribute, all copyright, patent, trademark, and
> >> + attribution notices from the Source form of the Work,
> >> + excluding those notices that do not pertain to any part of
> >> + the Derivative Works; and
> >> +
> >> + (d) If the Work includes a "NOTICE" text file as part of its
> >> + distribution, then any Derivative Works that You
> >> distribute must
> >> + include a readable copy of the attribution notices
> >> contained
> >> + within such NOTICE file, excluding those notices that
> >> do not
> >> + pertain to any part of the Derivative Works, in at
> >> least one
> >> + of the following places: within a NOTICE text file
> >> distributed
> >> + as part of the Derivative Works; within the Source form or
> >> + documentation, if provided along with the Derivative
> >> Works; or,
> >> + within a display generated by the Derivative Works, if and
> >> + wherever such third-party notices normally appear. The
> >> contents
> >> + of the NOTICE file are for informational purposes only and
> >> + do not modify the License. You may add Your own
> >> attribution
> >> + notices within Derivative Works that You distribute,
> >> alongside
> >> + or as an addendum to the NOTICE text from the Work,
> >> provided
> >> + that such additional attribution notices cannot be
> >> construed
> >> + as modifying the License.
> >> +
> >> + You may add Your own copyright statement to Your
> >> modifications and
> >> + may provide additional or different license terms and
> >> conditions
> >> + for use, reproduction, or distribution of Your
> >> modifications, or
> >> + for any such Derivative Works as a whole, provided Your use,
> >> + reproduction, and distribution of the Work otherwise
> >> complies with
> >> + the conditions stated in this License.
> >> +
> >> + 5. Submission of Contributions. Unless You explicitly state
> >> otherwise,
> >> + any Contribution intentionally submitted for inclusion in
> >> the Work
> >> + by You to the Licensor shall be under the terms and
> >> conditions of
> >> + this License, without any additional terms or conditions.
> >> + Notwithstanding the above, nothing herein shall supersede
> >> or modify
> >> + the terms of any separate license agreement you may have
> >> executed
> >> + with Licensor regarding such Contributions.
> >> +
> >> + 6. Trademarks. This License does not grant permission to use
> >> the trade
> >> + names, trademarks, service marks, or product names of the
> >> Licensor,
> >> + except as required for reasonable and customary use in
> >> describing the
> >> + origin of the Work and reproducing the content of the
> >> NOTICE file.
> >> +
> >> + 7. Disclaimer of Warranty. Unless required by applicable law or
> >> + agreed to in writing, Licensor provides the Work (and each
> >> + Contributor provides its Contributions) on an "AS IS" BASIS,
> >> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
> >> express or
> >> + implied, including, without limitation, any warranties or
> >> conditions
> >> + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
> >> + PARTICULAR PURPOSE. You are solely responsible for
> >> determining the
> >> + appropriateness of using or redistributing the Work and
> >> assume any
> >> + risks associated with Your exercise of permissions under
> >> this License.
> >> +
> >> + 8. Limitation of Liability. In no event and under no legal
> >> theory,
> >> + whether in tort (including negligence), contract, or
> >> otherwise,
> >> + unless required by applicable law (such as deliberate and
> >> grossly
> >> + negligent acts) or agreed to in writing, shall any
> >> Contributor be
> >> + liable to You for damages, including any direct, indirect,
> >> special,
> >> + incidental, or consequential damages of any character
> >> arising as a
> >> + result of this License or out of the use or inability to
> >> use the
> >> + Work (including but not limited to damages for loss of
> >> goodwill,
> >> + work stoppage, computer failure or malfunction, or any and all
> >> + other commercial damages or losses), even if such Contributor
> >> + has been advised of the possibility of such damages.
> >> +
> >> + 9. Accepting Warranty or Additional Liability. While
> >> redistributing
> >> + the Work or Derivative Works thereof, You may choose to offer,
> >> + and charge a fee for, acceptance of support, warranty,
> >> indemnity,
> >> + or other liability obligations and/or rights consistent
> >> with this
> >> + License. However, in accepting such obligations, You may
> >> act only
> >> + on Your own behalf and on Your sole responsibility, not on
> >> behalf
> >> + of any other Contributor, and only if You agree to indemnify,
> >> + defend, and hold each Contributor harmless for any liability
> >> + incurred by, or claims asserted against, such Contributor
> >> by reason
> >> + of your accepting any such warranty or additional liability.
> >> +
> >> + END OF TERMS AND CONDITIONS
> >> +
> >> + APPENDIX: How to apply the Apache License to your work.
> >> +
> >> + To apply the Apache License to your work, attach the following
> >> + boilerplate notice, with the fields enclosed by brackets "[]"
> >> + replaced with your own identifying information. (Don't include
> >> + the brackets!) The text should be enclosed in the appropriate
> >> + comment syntax for the file format. We also recommend that a
> >> + file or class name and description of purpose be included
> >> on the
> >> + same "printed page" as the copyright notice for easier
> >> + identification within third-party archives.
> >> +
> >> + Copyright [yyyy] [name of copyright owner]
> >> +
> >> + Licensed under the Apache License, Version 2.0 (the "License");
> >> + you may not use this file except in compliance with the License.
> >> + You may obtain a copy of the License at
> >> +
> >> + http://www.apache.org/licenses/LICENSE-2.0
> >> +
> >> + Unless required by applicable law or agreed to in writing,
> >> software
> >> + distributed under the License is distributed on an "AS IS" BASIS,
> >> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + See the License for the specific language governing
> >> permissions and
> >> + limitations under the License.
> >> +
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/NOTICE.txt?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt Wed
> >> Aug 16 17:50:03 2006
> >> @@ -0,0 +1,3 @@
> >> +This product includes software developed by
> >> +The Apache Software Foundation (http://www.apache.org/).
> >> +
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/pom.xml
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/pom.xml?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/pom.xml (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/pom.xml Wed Aug
> >> 16 17:50:03 2006
> >> @@ -0,0 +1,40 @@
> >> +<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://
> >> maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/
> >> XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/
> >> POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
> >> + <parent>
> >> + <artifactId>xbean</artifactId>
> >> + <groupId>org.apache.xbean</groupId>
> >> + <version>COL-SNAPSHOT</version>
> >> + </parent>
> >> + <modelVersion>4.0.0</modelVersion>
> >> + <artifactId>xbean-naming</artifactId>
> >> + <name>XBean :: Naming</name>
> >> + <version>COL-SNAPSHOT</version>
> >> + <build>
> >> + <plugins>
> >> + <plugin>
> >> + <artifactId>maven-compiler-plugin</artifactId>
> >> + <configuration>
> >> + <source>1.4</source>
> >> + <target>1.4</target>
> >> + </configuration>
> >> + </plugin>
> >> + <plugin>
> >> + <artifactId>maven-surefire-plugin</artifactId>
> >> + <configuration>
> >> + <excludes/>
> >> + </configuration>
> >> + </plugin>
> >> + </plugins>
> >> + </build>
> >> + <dependencies>
> >> + <dependency>
> >> + <groupId>backport-util-concurrent</groupId>
> >> + <artifactId>backport-util-concurrent</artifactId>
> >> + </dependency>
> >> + <dependency>
> >> + <groupId>org.apache.geronimo.modules</groupId>
> >> + <artifactId>geronimo-naming</artifactId>
> >> + <version>1.2-SNAPSHOT</version>
> >> + <optional>true</optional>
> >> + </dependency>
> >> + </dependencies>
> >> +</project>
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/AbstractReadOnlyContext.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/context/
> >> AbstractReadOnlyContext.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/AbstractReadOnlyContext.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/AbstractReadOnlyContext.java Wed
> >> Aug 16 17:50:03 2006
> >> @@ -0,0 +1,560 @@
> >> +/**
> >> + *
> >> + * Copyright 2003-2004 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +
> >> +package org.apache.xbean.naming.context;
> >> +
> >> +import javax.naming.CompositeName;
> >> +import javax.naming.Context;
> >> +import javax.naming.InitialContext;
> >> +import javax.naming.Name;
> >> +import javax.naming.NameNotFoundException;
> >> +import javax.naming.NameParser;
> >> +import javax.naming.NamingEnumeration;
> >> +import javax.naming.NamingException;
> >> +import javax.naming.NotContextException;
> >> +import javax.naming.OperationNotSupportedException;
> >> +import javax.naming.InvalidNameException;
> >> +import javax.naming.LinkRef;
> >> +import java.io.Serializable;
> >> +import java.util.Hashtable;
> >> +import java.util.Map;
> >> +import java.util.Collections;
> >> +
> >> +/**
> >> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat,
> >> 10 Dec 2005) $
> >> + */
> >> +public abstract class AbstractReadOnlyContext implements Context,
> >> ContextFactory, Serializable {
> >> + private static final long serialVersionUID =
> >> 3808693663629444493L;
> >> + private final String nameInNamespace;
> >> +
> >> + protected AbstractReadOnlyContext(String nameInNamespace) {
> >> + this.nameInNamespace = nameInNamespace;
> >> + }
> >> +
> >> + /**
> >> + * Gets the name of this context withing the global
> >> namespace. This method may return null
> >> + * if the location of the node in the global namespace is not
> >> known
> >> + * @return the name of this context within the global
> >> namespace or null if unknown.
> >> + */
> >> + public String getNameInNamespace() {
> >> + return nameInNamespace;
> >> + }
> >> +
> >> + /**
> >> + * Gets the name of a path withing the global namespace context.
> >> + */
> >> + protected String getNameInNamespace(String path) {
> >> + String nameInNamespace = getNameInNamespace();
> >> + if (nameInNamespace == null || nameInNamespace.length()
> >> == 0) {
> >> + return path;
> >> + } else {
> >> + return nameInNamespace + "/" + path;
> >> + }
> >> + }
> >> +
> >> +
> >> + /**
> >> + * Always returns a new (empty) Hashtable.
> >> + * @return a new (empty) Hashtable
> >> + */
> >> + public Hashtable getEnvironment() {
> >> + return new Hashtable();
> >> + }
> >> +
> >> + /**
> >> + * A parser that can turn Strings into javax.naming.Name
> >> objects.
> >> + * @return ContextUtil.NAME_PARSER
> >> + */
> >> + protected NameParser getNameParser() {
> >> + return ContextUtil.NAME_PARSER;
> >> + }
> >> +
> >> + //
> >> + // Lookup Binding
> >> + //
> >> +
> >> + /**
> >> + * Gets the object bound to the name. The name may contain
> >> slashes.
> >> + * @param name the name
> >> + * @return the object bound to the name, or null if not found
> >> + */
> >> + protected Object getDeepBinding(String name) {
> >> + return null;
> >> + }
> >> +
> >> + /**
> >> + * Gets the object bound to the name. The name will not
> >> contain slashes.
> >> + * @param name the name
> >> + * @return the object bound to the name, or null if not found
> >> + */
> >> + protected Object getBinding(String name) throws
> >> NamingException {
> >> + Map bindings = getBindings();
> >> + return bindings.get(name);
> >> + }
> >> +
> >> + /**
> >> + * Finds the specified entry. Normally there is no need to
> >> override this method; insted you should
> >> + * simply implement the getBindings(String) method.
> >> + *
> >> + * @param stringName the string version of the name; maybe null
> >> + * @param parsedName the parsed name; may be null
> >> + * @return the value bound to the name
> >> + * @throws NamingException if no value is bound to that name
> >> or if a problem occurs during the lookup
> >> + */
> >> + protected Object lookup(String stringName, Name parsedName)
> >> throws NamingException {
> >> + if (stringName == null && parsedName == null) {
> >> + throw new IllegalArgumentException("Both stringName
> >> and parsedName are null");
> >> + }
> >> + if (stringName == null) stringName = parsedName.toString();
> >> +
> >> + // try to look up the name directly (this is the fastest
> >> path)
> >> + Object directLookup = getDeepBinding(stringName);
> >> + if (directLookup != null) {
> >> + return ContextUtil.resolve(stringName, directLookup);
> >> + }
> >> +
> >> + // if the parsed name has no parts, they are asking for
> >> the current context
> >> + if (parsedName == null) parsedName = getNameParser().parse
> >> (stringName);
> >> + if (parsedName.size() == 0) {
> >> + return this;
> >> + }
> >> +
> >> +
> >> + // we didn't find an entry, pop the first element off the
> >> parsed name and attempt to
> >> + // get a context from the bindings and delegate to that
> >> context
> >> + Object localValue;
> >> + String firstNameElement = parsedName.get(0);
> >> + if (firstNameElement.length() == 0) {
> >> + // the element is null... this is normally caused by
> >> looking up with a trailing '/' character
> >> + localValue = this;
> >> + } else {
> >> + localValue = getBinding(firstNameElement);
> >> + }
> >> +
> >> + if (localValue != null) {
> >> +
> >> + // if the name only had one part, we've looked up
> >> everything
> >> + if (parsedName.size() == 1) {
> >> + localValue = ContextUtil.resolve(stringName,
> >> localValue);
> >> + return localValue;
> >> + }
> >> +
> >> + // if we have a link ref, follow it
> >> + if (localValue instanceof LinkRef) {
> >> + LinkRef linkRef = (LinkRef) localValue;
> >> + localValue = lookup(linkRef.getLinkName());
> >> + }
> >> +
> >> + // we have more to lookup so we better have a context
> >> object
> >> + if (!(localValue instanceof Context)) {
> >> + throw new NameNotFoundException(stringName);
> >> + }
> >> +
> >> + // delegate to the sub-context
> >> + return ((Context) localValue).lookup
> >> (parsedName.getSuffix(1));
> >> + }
> >> +
> >> + // if we didn't find an entry, it may be an absolute name
> >> + if (stringName.indexOf(':') > 0) {
> >> + Context ctx = new InitialContext();
> >> + return ctx.lookup(parsedName);
> >> + }
> >> + throw new NameNotFoundException(stringName);
> >> + }
> >> +
> >> + //
> >> + // List Bindings
> >> + //
> >> +
> >> + /**
> >> + * Gets a map of the bindings for the current node (i.e., no
> >> names with slashes).
> >> + * This method must not return null.
> >> + */
> >> + protected Map getBindings() throws NamingException {
> >> + throw new OperationNotSupportedException("This context is
> >> not listable");
> >> + }
> >> +
> >> + protected NamingEnumeration list() throws NamingException {
> >> + Map bindings = getBindings();
> >> + return new ContextUtil.ListEnumeration(bindings);
> >> + }
> >> +
> >> + protected NamingEnumeration listBindings() throws
> >> NamingException {
> >> + Map bindings = getBindings();
> >> + return new ContextUtil.ListBindingEnumeration(bindings);
> >> + }
> >> +
> >> + //
> >> + // Add Binding
> >> + //
> >> +
> >> + /**
> >> + * Add the binding to the context. The name will not contain
> >> a path but the value may
> >> + * be a nested context which should be indexed for indexing
> >> contexts.
> >> + * @param name name under which the value should be bound
> >> + * @param value the value to bind
> >> + * @throws NamingException if a problem occurs during the
> >> bind such as a value already being bound
> >> + */
> >> + protected void addBinding(String name, Object value) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + protected void addDeepBinding(String name, Object value)
> >> throws NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> + if (value == null) throw new NullPointerException("value
> >> is null");
> >> +
> >> + Name compoundName = ContextUtil.parseName(name);
> >> + if (compoundName.isEmpty()) {
> >> + throw new InvalidNameException("Name is empty");
> >> + }
> >> +
> >> + AbstractReadOnlyContext currentContext = this;
> >> + for (int i = 0; i < compoundName.size(); i++) {
> >> + String part = compoundName.get(i);
> >> +
> >> + // empty path parts are not allowed
> >> + if (part.length() == 0) {
> >> + throw new InvalidNameException("Name part " + i +
> >> " is empty: " + name);
> >> + }
> >> +
> >> + // Is this the last element in the name?
> >> + if (i == compoundName.size() - 1) {
> >> + // we're at the end... bind the value into the
> >> parent context
> >> + currentContext.addBinding(part, value);
> >> +
> >> + // all done... this is redundant but makes the
> >> code more readable
> >> + break;
> >> + } else {
> >> + Map currentBindings = currentContext.getBindings();
> >> + Object currentValue = currentBindings.get(part);
> >> + if (currentValue == null) {
> >> + // the next step in the tree is not present,
> >> so create everything down
> >> + // and add it to the current bindings
> >> + Context context =
> >> currentContext.createContextTree(compoundName.getPrefix(i).toString
> >> (),
> >> + compoundName.getSuffix(i),
> >> + value);
> >> + currentContext.addBinding(part, context);
> >> +
> >> + // all done
> >> + break;
> >> + } else {
> >> + // the current value must be an abstract read
> >> only context
> >> + // todo this is a problem since a nested node
> >> could be an AbstractReadOnlyContext but not one of our contexts
> >> + if (!(currentValue instanceof
> >> AbstractReadOnlyContext)) {
> >> + throw new NotContextException("Expected
> >> an instance of AbstractReadOnlyContext to be bound at " +
> >> + part + " but found an instance of
> >> " + currentValue.getClass().getName());
> >> + }
> >> + currentContext = (AbstractReadOnlyContext)
> >> currentValue;
> >> + // now we recurse into the current context
> >> + }
> >> + }
> >> + }
> >> + }
> >> +
> >> + /**
> >> + * Creates a context tree which will be rooted at the
> >> specified path and contain a single entry located down
> >> + * a path specified by the name. All necessary intermediate
> >> contexts will be created using the createContext method.
> >> + * @param path the path to the context that will contains
> >> this context
> >> + * @param name the name under which the value should be bound
> >> + * @param value the vale
> >> + * @return a context with the value bound at the specified name
> >> + * @throws NamingException
> >> + */
> >> + protected Context createContextTree(String path, Name name,
> >> Object value) throws NamingException {
> >> + if (path == null) throw new NullPointerException("path is
> >> null");
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> + if (name.size() < 2) throw new InvalidNameException("name
> >> must have at least 2 parts " + name);
> >> +
> >> + if (!path.endsWith("/")) path += "/";
> >> +
> >> + for (int i = name.size() - 2; i >= 0; i--) {
> >> + String fullPath = path + name.getSuffix(i);
> >> + String key = name.get(i + 1);
> >> + value = createContext(fullPath,
> >> Collections.singletonMap(key, value));
> >> + }
> >> + return (AbstractReadOnlyContext) value;
> >> + }
> >> +
> >> + //
> >> + // Remove Binding
> >> + //
> >> +
> >> + /**
> >> + * Removes the binding from the context. The name will not
> >> contain a path and the value will not
> >> + * be a nested context although it may be a foreign context.
> >> + * @param name name under which the value should be bound
> >> + * @throws NamingException if a problem occurs during the
> >> bind such as a value already being bound
> >> + */
> >> + protected void removeBinding(String name) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + protected void removeDeepBinding(String name) throws
> >> NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> +
> >> + Name compoundName = ContextUtil.parseName(name);
> >> + if (compoundName.isEmpty()) {
> >> + throw new InvalidNameException("Name is empty");
> >> + }
> >> +
> >> + // we serch the tree for a target context and name to remove
> >> + // this is normally the last context in the tree and the
> >> final name part, but
> >> + // it may be farther up the path if the intervening nodes
> >> are empty
> >> + AbstractReadOnlyContext targetContext = this;
> >> + String targetName = compoundName.get(0);
> >> +
> >> + AbstractReadOnlyContext currentContext = this;
> >> + for (int i = 0; i < compoundName.size(); i++) {
> >> + String part = compoundName.get(i);
> >> +
> >> + // empty path parts are not allowed
> >> + if (part.length() == 0) {
> >> + throw new InvalidNameException("Name part " + i +
> >> " is empty: " + name);
> >> + }
> >> +
> >> + Map currentBindings = currentContext.getBindings();
> >> +
> >> + // update targets
> >> + if (currentBindings.size() > 1) {
> >> + targetContext = currentContext;
> >> + targetName = part;
> >> + }
> >> +
> >> +
> >> + // Is this the last element in the name?
> >> + if (i == compoundName.size() - 1) {
> >> + // we're at the end... bind the value into the
> >> parent context
> >> + targetContext.removeBinding(targetName);
> >> +
> >> + // all done... this is redundant but makes the
> >> code more readable
> >> + break;
> >> + } else {
> >> + Object currentValue = currentBindings.get(part);
> >> + if (currentValue == null) {
> >> + // path not found we are done
> >> + break;
> >> + } else {
> >> + // the current value must be an abstract read
> >> only context
> >> + // todo this is a problem since a nested node
> >> could be an AbstractReadOnlyContext but not one of our contexts
> >> + if (!(currentValue instanceof
> >> AbstractReadOnlyContext)) {
> >> + throw new NotContextException("Expected
> >> an instance of AbstractReadOnlyContext to be bound at " +
> >> + part + " but found an instance of
> >> " + currentValue.getClass().getName());
> >> + }
> >> + currentContext = (AbstractReadOnlyContext)
> >> currentValue;
> >> + // now we recurse into the current context
> >> + }
> >> + }
> >> + }
> >> + }
> >> +
> >> + //
> >> =====================================================================
> >> =============
> >> + // =================== Final Methods (see methods above)
> >> ============================
> >> + //
> >> =====================================================================
> >> =============
> >> +
> >> + //
> >> + // Lookup methods
> >> + //
> >> +
> >> + public final Object lookup(String name) throws NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> +
> >> + Object value = lookup(name, null);
> >> +
> >> + // if we got a link back we need to resolve it
> >> + if (value instanceof LinkRef) {
> >> + LinkRef linkRef = (LinkRef) value;
> >> + value = lookup(linkRef.getLinkName());
> >> + }
> >> + return value;
> >> + }
> >> +
> >> + public final Object lookup(Name name) throws NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> +
> >> + Object value = lookup(null, name);
> >> +
> >> + // if we got a link back we need to resolve it
> >> + if (value instanceof LinkRef) {
> >> + LinkRef linkRef = (LinkRef) value;
> >> + value = lookup(linkRef.getLinkName());
> >> + }
> >> +
> >> + return value;
> >> + }
> >> +
> >> + public final Object lookupLink(String name) throws
> >> NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> +
> >> + return lookup(name, null);
> >> + }
> >> +
> >> + public final Object lookupLink(Name name) throws
> >> NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> +
> >> + return lookup(null, name);
> >> + }
> >> +
> >> + //
> >> + // List Operations
> >> + //
> >> +
> >> + public final NamingEnumeration list(String name) throws
> >> NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> +
> >> + Object o = lookup(name);
> >> + if (o == this) {
> >> + return list();
> >> + } else if (o instanceof Context) {
> >> + return ((Context) o).list("");
> >> + } else {
> >> + throw new NotContextException();
> >> + }
> >> + }
> >> +
> >> + public final NamingEnumeration listBindings(String name)
> >> throws NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> +
> >> + Object o = lookup(name);
> >> + if (o == this) {
> >> + return listBindings();
> >> + } else if (o instanceof Context) {
> >> + return ((Context) o).listBindings("");
> >> + } else {
> >> + throw new NotContextException();
> >> + }
> >> + }
> >> +
> >> + public final NamingEnumeration list(Name name) throws
> >> NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> +
> >> + Object o = lookup(name);
> >> + if (o == this) {
> >> + return list();
> >> + } else if (o instanceof Context) {
> >> + return ((Context) o).list("");
> >> + } else {
> >> + throw new NotContextException();
> >> + }
> >> + }
> >> +
> >> + public final NamingEnumeration listBindings(Name name) throws
> >> NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> +
> >> + Object o = lookup(name);
> >> + if (o == this) {
> >> + return listBindings();
> >> + } else if (o instanceof Context) {
> >> + return ((Context) o).listBindings("");
> >> + } else {
> >> + throw new NotContextException();
> >> + }
> >> + }
> >> +
> >> + //
> >> + // Name manipulation
> >> + //
> >> +
> >> + public final NameParser getNameParser(Name name) {
> >> + return getNameParser();
> >> + }
> >> +
> >> + public final NameParser getNameParser(String name) {
> >> + return getNameParser();
> >> + }
> >> +
> >> + public final Name composeName(Name name, Name prefix) throws
> >> NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> + if (prefix == null) throw new NullPointerException
> >> ("prefix is null");
> >> +
> >> + Name result = (Name) prefix.clone();
> >> + result.addAll(name);
> >> + return result;
> >> + }
> >> +
> >> + public final String composeName(String name, String prefix)
> >> throws NamingException {
> >> + if (name == null) throw new NullPointerException("name is
> >> null");
> >> + if (prefix == null) throw new NullPointerException
> >> ("prefix is null");
> >> +
> >> + CompositeName result = new CompositeName(prefix);
> >> + result.addAll(new CompositeName(name));
> >> + return result.toString();
> >> + }
> >> +
> >> + //
> >> + // Unsupported Operations
> >> + //
> >> +
> >> + public final Object addToEnvironment(String propName, Object
> >> propVal) throws NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final Object removeFromEnvironment(String propName)
> >> throws NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void bind(Name name, Object obj) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void bind(String name, Object obj) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void close() throws NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final Context createSubcontext(Name name) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final Context createSubcontext(String name) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void destroySubcontext(Name name) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void destroySubcontext(String name) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void rebind(Name name, Object obj) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void rebind(String name, Object obj) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void rename(Name oldName, Name newName) throws
> >> NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void rename(String oldName, String newName)
> >> throws NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void unbind(Name name) throws NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +
> >> + public final void unbind(String name) throws NamingException {
> >> + throw new OperationNotSupportedException("Context is read
> >> only");
> >> + }
> >> +}
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextFactory.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/context/
> >> ContextFactory.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextFactory.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextFactory.java Wed Aug 16
> >> 17:50:03 2006
> >> @@ -0,0 +1,27 @@
> >> +/**
> >> + *
> >> + * Copyright 2006 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +package org.apache.xbean.naming.context;
> >> +
> >> +import javax.naming.Context;
> >> +import java.util.Map;
> >> +
> >> +/**
> >> + * @version $Rev$ $Date$
> >> + */
> >> +public interface ContextFactory {
> >> + Context createContext(String path, Map bindings);
> >> +}
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextFlyweight.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/context/
> >> ContextFlyweight.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextFlyweight.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextFlyweight.java Wed Aug 16
> >> 17:50:03 2006
> >> @@ -0,0 +1,146 @@
> >> +/**
> >> + *
> >> + * Copyright 2006 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +package org.apache.xbean.naming.context;
> >> +
> >> +import javax.naming.Context;
> >> +import javax.naming.NamingException;
> >> +import javax.naming.Name;
> >> +import javax.naming.NamingEnumeration;
> >> +import javax.naming.NameParser;
> >> +import java.util.Hashtable;
> >> +
> >> +/**
> >> + * @version $Rev$ $Date$
> >> + */
> >> +public abstract class ContextFlyweight implements Context {
> >> + protected abstract Context getContext() throws NamingException;
> >> +
> >> + public void close() throws NamingException {
> >> + }
> >> +
> >> + public String getNameInNamespace() throws NamingException {
> >> + return getContext().getNameInNamespace();
> >> + }
> >> +
> >> + public Object lookup(Name name) throws NamingException {
> >> + return getContext().lookup(name);
> >> + }
> >> +
> >> + public Object lookup(String name) throws NamingException {
> >> + return getContext().lookup(name);
> >> + }
> >> +
> >> + public void bind(Name name, Object obj) throws NamingException {
> >> + getContext().bind(name, obj);
> >> + }
> >> +
> >> + public void bind(String name, Object obj) throws
> >> NamingException {
> >> + getContext().bind(name, obj);
> >> + }
> >> +
> >> + public void rebind(Name name, Object obj) throws
> >> NamingException {
> >> + getContext().rebind(name, obj);
> >> + }
> >> +
> >> + public void rebind(String name, Object obj) throws
> >> NamingException {
> >> + getContext().rebind(name, obj);
> >> + }
> >> +
> >> + public void unbind(Name name) throws NamingException {
> >> + getContext().unbind(name);
> >> + }
> >> +
> >> + public void unbind(String name) throws NamingException {
> >> + getContext().unbind(name);
> >> + }
> >> +
> >> + public void rename(Name oldName, Name newName) throws
> >> NamingException {
> >> + getContext().rename(oldName, newName);
> >> + }
> >> +
> >> + public void rename(String oldName, String newName) throws
> >> NamingException {
> >> + getContext().rename(oldName, newName);
> >> + }
> >> +
> >> + public NamingEnumeration list(Name name) throws
> >> NamingException {
> >> + return getContext().list(name);
> >> + }
> >> +
> >> + public NamingEnumeration list(String name) throws
> >> NamingException {
> >> + return getContext().list(name);
> >> + }
> >> +
> >> + public NamingEnumeration listBindings(Name name) throws
> >> NamingException {
> >> + return getContext().listBindings(name);
> >> + }
> >> +
> >> + public NamingEnumeration listBindings(String name) throws
> >> NamingException {
> >> + return getContext().listBindings(name);
> >> + }
> >> +
> >> + public void destroySubcontext(Name name) throws
> >> NamingException {
> >> + getContext().destroySubcontext(name);
> >> + }
> >> +
> >> + public void destroySubcontext(String name) throws
> >> NamingException {
> >> + getContext().destroySubcontext(name);
> >> + }
> >> +
> >> + public Context createSubcontext(Name name) throws
> >> NamingException {
> >> + return getContext().createSubcontext(name);
> >> + }
> >> +
> >> + public Context createSubcontext(String name) throws
> >> NamingException {
> >> + return getContext().createSubcontext(name);
> >> + }
> >> +
> >> + public Object lookupLink(Name name) throws NamingException {
> >> + return getContext().lookupLink(name);
> >> + }
> >> +
> >> + public Object lookupLink(String name) throws NamingException {
> >> + return getContext().lookupLink(name);
> >> + }
> >> +
> >> + public NameParser getNameParser(Name name) throws
> >> NamingException {
> >> + return getContext().getNameParser(name);
> >> + }
> >> +
> >> + public NameParser getNameParser(String name) throws
> >> NamingException {
> >> + return getContext().getNameParser(name);
> >> + }
> >> +
> >> + public Name composeName(Name name, Name prefix) throws
> >> NamingException {
> >> + return getContext().composeName(name, prefix);
> >> + }
> >> +
> >> + public String composeName(String name, String prefix) throws
> >> NamingException {
> >> + return getContext().composeName(name, prefix);
> >> + }
> >> +
> >> + public Object addToEnvironment(String propName, Object
> >> propVal) throws NamingException {
> >> + return getContext().addToEnvironment(propName, propVal);
> >> + }
> >> +
> >> + public Object removeFromEnvironment(String propName) throws
> >> NamingException {
> >> + return getContext().removeFromEnvironment(propName);
> >> + }
> >> +
> >> + public Hashtable getEnvironment() throws NamingException {
> >> + return getContext().getEnvironment();
> >> + }
> >> +}
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextUtil.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/context/
> >> ContextUtil.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextUtil.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ContextUtil.java Wed Aug 16
> >> 17:50:03 2006
> >> @@ -0,0 +1,290 @@
> >> +/**
> >> + *
> >> + * Copyright 2006 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +package org.apache.xbean.naming.context;
> >> +
> >> +import org.apache.xbean.naming.reference.SimpleReference;
> >> +
> >> +import javax.naming.Binding;
> >> +import javax.naming.CompoundName;
> >> +import javax.naming.Name;
> >> +import javax.naming.NameClassPair;
> >> +import javax.naming.NameParser;
> >> +import javax.naming.NamingEnumeration;
> >> +import javax.naming.NamingException;
> >> +import javax.naming.Reference;
> >> +import javax.naming.Context;
> >> +import javax.naming.spi.NamingManager;
> >> +import java.util.Hashtable;
> >> +import java.util.Iterator;
> >> +import java.util.Map;
> >> +import java.util.Properties;
> >> +import java.util.HashMap;
> >> +import java.util.Enumeration;
> >> +
> >> +/**
> >> + * @version $Rev$ $Date$
> >> + */
> >> +public final class ContextUtil {
> >> + private ContextUtil() {
> >> + }
> >> +
> >> + public final static NameParser NAME_PARSER = new
> >> SimpleNameParser();
> >> +
> >> + public static Name parseName(String name) throws
> >> NamingException {
> >> + return NAME_PARSER.parse(name);
> >> + }
> >> +
> >> + public static Object resolve(String name, Object value)
> >> throws NamingException {
> >> + if (!(value instanceof Reference)) {
> >> + return value;
> >> + }
> >> +
> >> + Reference reference = (Reference) value;
> >> +
> >> + // for SimpleReference we can just call the getContext
> >> method
> >> + if (reference instanceof SimpleReference) {
> >> + try {
> >> + return ((SimpleReference) reference).getContent();
> >> + } catch (NamingException e) {
> >> + throw e;
> >> + } catch (Exception e) {
> >> + throw (NamingException) new NamingException
> >> ("Could not look up : " + name).initCause(e);
> >> + }
> >> + }
> >> +
> >> + if (reference instanceof
> >> org.apache.geronimo.naming.reference.SimpleReference) {
> >> + try {
> >> + return
> >> ((org.apache.geronimo.naming.reference.SimpleReference)
> >> reference).getContent();
> >> + } catch (NamingException e) {
> >> + throw e;
> >> + } catch (Exception e) {
> >> + throw (NamingException) new NamingException
> >> ("Could not look up : " + name).initCause(e);
> >> + }
> >> + }
> >> +
> >> + // for normal References we have to do it the slow way
> >> + try {
> >> + return NamingManager.getObjectInstance(reference,
> >> null, null, new Hashtable());
> >> + } catch (NamingException e) {
> >> + throw e;
> >> + } catch (Exception e) {
> >> + throw (NamingException) new NamingException("Could
> >> not look up : " + name).initCause(e);
> >> + }
> >> + }
> >> +
> >> + public static final class ListEnumeration implements
> >> NamingEnumeration {
> >> + private final Iterator iterator;
> >> +
> >> + public ListEnumeration(Map localBindings) {
> >> + this.iterator = localBindings.entrySet().iterator();
> >> + }
> >> +
> >> + public boolean hasMore() {
> >> + return iterator.hasNext();
> >> + }
> >> +
> >> + public boolean hasMoreElements() {
> >> + return iterator.hasNext();
> >> + }
> >> +
> >> + public Object next() {
> >> + return nextElement();
> >> + }
> >> +
> >> + public Object nextElement() {
> >> + Map.Entry entry = (Map.Entry) iterator.next();
> >> + String name = (String) entry.getKey();
> >> + Object value = entry.getValue();
> >> + String className = null;
> >> + if (value instanceof Reference) {
> >> + Reference reference = (Reference) value;
> >> + className = reference.getClassName();
> >> + } else {
> >> + className = value.getClass().getName();
> >> + }
> >> + return new NameClassPair(name, className);
> >> + }
> >> +
> >> + public void close() {
> >> + }
> >> + }
> >> +
> >> + public static final class ListBindingEnumeration implements
> >> NamingEnumeration {
> >> + private final Iterator iterator;
> >> +
> >> + public ListBindingEnumeration(Map localBindings) {
> >> + this.iterator = localBindings.entrySet().iterator();
> >> + }
> >> +
> >> + public boolean hasMore() {
> >> + return iterator.hasNext();
> >> + }
> >> +
> >> + public boolean hasMoreElements() {
> >> + return iterator.hasNext();
> >> + }
> >> +
> >> + public Object next() {
> >> + return nextElement();
> >> + }
> >> +
> >> + public Object nextElement() {
> >> + Map.Entry entry = (Map.Entry) iterator.next();
> >> + String name = (String) entry.getKey();
> >> + Object value = entry.getValue();
> >> + return new ReadOnlyBinding(name, value);
> >> + }
> >> +
> >> + public void close() {
> >> + }
> >> + }
> >> +
> >> + public static final class ReadOnlyBinding extends Binding {
> >> + private final Object value;
> >> +
> >> + public ReadOnlyBinding(String name, Object value) {
> >> + super(name, value);
> >> + this.value = value;
> >> + }
> >> +
> >> + public void setName(String name) {
> >> + throw new UnsupportedOperationException("Context is
> >> read only");
> >> + }
> >> +
> >> + public String getClassName() {
> >> + if (value instanceof Reference) {
> >> + Reference reference = (Reference) value;
> >> + return reference.getClassName();
> >> + }
> >> + return value.getClass().getName();
> >> + }
> >> +
> >> + public void setClassName(String name) {
> >> + throw new UnsupportedOperationException("Context is
> >> read only");
> >> + }
> >> +
> >> + public Object getObject() {
> >> + try {
> >> + return resolve(getName(), value);
> >> + } catch (NamingException e) {
> >> + throw new RuntimeException(e);
> >> + }
> >> + }
> >> +
> >> + public void setObject(Object obj) {
> >> + throw new UnsupportedOperationException("Context is
> >> read only");
> >> + }
> >> +
> >> + public boolean isRelative() {
> >> + return false;
> >> + }
> >> +
> >> + public void setRelative(boolean r) {
> >> + throw new UnsupportedOperationException("Context is
> >> read only");
> >> + }
> >> + }
> >> +
> >> +
> >> + private static final class SimpleNameParser implements
> >> NameParser {
> >> + private static final Properties PARSER_PROPERTIES = new
> >> Properties();
> >> +
> >> + static {
> >> + PARSER_PROPERTIES.put("jndi.syntax.direction",
> >> "left_to_right");
> >> + PARSER_PROPERTIES.put("jndi.syntax.separator", "/");
> >> + }
> >> +
> >> +
> >> + private SimpleNameParser() {
> >> + }
> >> +
> >> + public Name parse(String name) throws NamingException {
> >> + return new CompoundName(name, PARSER_PROPERTIES);
> >> + }
> >> + }
> >> +
> >> + public static Map createBindings(Map absoluteBindings,
> >> ContextFactory factory) throws NamingException {
> >> + // create a tree of Nodes using the absolute bindings
> >> + Node node = buildMapTree(absoluteBindings);
> >> +
> >> + // convert the node tree into a tree of context objects
> >> + Map localBindings = ContextUtil.createBindings(null,
> >> node, factory);
> >> +
> >> + return localBindings;
> >> + }
> >> +
> >> + private static Map createBindings(String nameInNameSpace,
> >> Node node, ContextFactory factory) {
> >> + Map bindings = new HashMap(node.size());
> >> + for (Iterator iterator = node.entrySet().iterator();
> >> iterator.hasNext();) {
> >> + Map.Entry entry = (Map.Entry) iterator.next();
> >> + String name = (String) entry.getKey();
> >> + Object value = entry.getValue();
> >> +
> >> + // if this is a nested node we need to create a
> >> context for the node
> >> + if (value instanceof Node) {
> >> + Node nestedNode = (Node) value;
> >> +
> >> + // recursive call create bindings to cause
> >> building the context depth first
> >> + String path = nameInNameSpace == null ? name :
> >> nameInNameSpace + "/" + name;
> >> +
> >> + Map nestedBindings = createBindings(path,
> >> nestedNode, factory);
> >> + Context nestedContext = factory.createContext
> >> (path, nestedBindings);
> >> + bindings.put(name, nestedContext);
> >> + } else {
> >> + bindings.put(name, value);
> >> + }
> >> + }
> >> + return bindings;
> >> + }
> >> +
> >> +
> >> + /**
> >> + * Do nothing subclass of hashmap used to differentiate
> >> between a Map in the tree an a nested element during tree building
> >> + */
> >> + public static final class Node extends HashMap {
> >> + }
> >> +
> >> + public static Node buildMapTree(Map absoluteBindings) throws
> >> NamingException {
> >> + Node rootContext = new Node();
> >> +
> >> + for (Iterator iterator = absoluteBindings.entrySet
> >> ().iterator(); iterator.hasNext();) {
> >> + Map.Entry entry = (Map.Entry) iterator.next();
> >> + String name = (String) entry.getKey();
> >> + Object value = entry.getValue();
> >> +
> >> + Node parentContext = rootContext;
> >> +
> >> + Name compoundName = ContextUtil.parseName(name);
> >> + for (Enumeration parts = compoundName.getAll();
> >> parts.hasMoreElements(); ) {
> >> + String part = (String) parts.nextElement();
> >> + // the last element in the path is the name of
> >> the value
> >> + if (parts.hasMoreElements()) {
> >> + // nest node into parent
> >> + Node bindings = (Node) parentContext.get(part);
> >> + if (bindings == null) {
> >> + bindings = new Node();
> >> + parentContext.put(part, bindings);
> >> + }
> >> +
> >> + parentContext = bindings;
> >> + }
> >> + }
> >> +
> >> + parentContext.put(compoundName.get(compoundName.size
> >> () - 1), value);
> >> + }
> >> + return rootContext;
> >> + }
> >> +}
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ImmutableContext.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/context/
> >> ImmutableContext.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ImmutableContext.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/ImmutableContext.java Wed Aug 16
> >> 17:50:03 2006
> >> @@ -0,0 +1,136 @@
> >> +/**
> >> + *
> >> + * Copyright 2006 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +package org.apache.xbean.naming.context;
> >> +
> >> +import org.apache.xbean.naming.reference.CachingReference;
> >> +
> >> +import javax.naming.Context;
> >> +import javax.naming.NamingException;
> >> +import javax.naming.OperationNotSupportedException;
> >> +import java.util.Collections;
> >> +import java.util.HashMap;
> >> +import java.util.Iterator;
> >> +import java.util.Map;
> >> +
> >> +/**
> >> + *
> >> + * @version $Rev: 417891 $ $Date: 2006-06-28 15:45:07 -0700 (Wed,
> >> 28 Jun 2006) $
> >> + */
> >> +public class ImmutableContext extends AbstractReadOnlyContext {
> >> + private final Map localBindings;
> >> + private final Map absoluteIndex;
> >> +
> >> + public ImmutableContext(Map bindings) throws NamingException {
> >> + this("", bindings, true);
> >> + }
> >> +
> >> + public ImmutableContext(Map bindings, boolean
> >> cacheReferences) throws NamingException {
> >> + this("", bindings, cacheReferences);
> >> + }
> >> +
> >> + public ImmutableContext(String nameInNamespace, Map bindings,
> >> boolean cacheReferences) throws NamingException {
> >> + super(nameInNamespace);
> >> +
> >> + if (cacheReferences) {
> >> + bindings = CachingReference.wrapReferences(bindings);
> >> + }
> >> +
> >> + Map localBindings = ContextUtil.createBindings(bindings,
> >> this);
> >> + this.localBindings = Collections.unmodifiableMap
> >> (localBindings);
> >> +
> >> + Map globalBindings = ImmutableContext.buildAbsoluteIndex
> >> ("", localBindings);
> >> + this.absoluteIndex = Collections.unmodifiableMap
> >> (globalBindings);
> >> + }
> >> +
> >> + private static Map buildAbsoluteIndex(String nameInNamespace,
> >> Map bindings) {
> >> + String path = nameInNamespace;
> >> + if (path.length() > 0) {
> >> + path += "/";
> >> + }
> >> +
> >> + Map globalBindings = new HashMap();
> >> + for (Iterator iterator = bindings.entrySet().iterator();
> >> iterator.hasNext();) {
> >> + Map.Entry entry = (Map.Entry) iterator.next();
> >> + String name = (String) entry.getKey();
> >> + Object value = entry.getValue();
> >> + if (value instanceof
> >> ImmutableContext.NestedMapContext) {
> >> + ImmutableContext.NestedMapContext nestedContext =
> >> (ImmutableContext.NestedMapContext)value;
> >> + globalBindings.putAll
> >> (ImmutableContext.buildAbsoluteIndex
> >> (nestedContext.getNameInNamespace(), nestedContext.localBindings));
> >> + }
> >> + globalBindings.put(path + name, value);
> >> + }
> >> + return globalBindings;
> >> + }
> >> +
> >> + protected Object getDeepBinding(String name) {
> >> + return absoluteIndex.get(name);
> >> + }
> >> +
> >> + protected Map getBindings() {
> >> + return localBindings;
> >> + }
> >> +
> >> + protected void addDeepBinding(String name, Object value)
> >> throws NamingException {
> >> + throw new OperationNotSupportedException("Context is
> >> immutable");
> >> + }
> >> +
> >> + protected void removeDeepBinding(String name, Object value)
> >> throws NamingException {
> >> + throw new OperationNotSupportedException("Context is
> >> immutable");
> >> + }
> >> +
> >> + public Context createContext(String path, Map bindings) {
> >> + return new NestedMapContext(path, bindings);
> >> + }
> >> +
> >> + /**
> >> + * Nested context which shares the absolute index map in
> >> MapContext.
> >> + */
> >> + public final class NestedMapContext extends
> >> AbstractReadOnlyContext {
> >> + private final Map localBindings;
> >> + private final String pathWithSlash;
> >> +
> >> + public NestedMapContext(String path, Map bindings) {
> >> + super(ImmutableContext.this.getNameInNamespace(path));
> >> +
> >> + if (!path.endsWith("/")) path += "/";
> >> + this.pathWithSlash = path;
> >> +
> >> + this.localBindings = Collections.unmodifiableMap
> >> (bindings);
> >> + }
> >> +
> >> + protected Object getDeepBinding(String name) {
> >> + String absoluteName = pathWithSlash + name;
> >> + return absoluteIndex.get(absoluteName);
> >> + }
> >> +
> >> + protected Map getBindings() {
> >> + return localBindings;
> >> + }
> >> +
> >> + protected void addDeepBinding(String name, Object value)
> >> throws NamingException {
> >> + throw new OperationNotSupportedException("Context is
> >> immutable");
> >> + }
> >> +
> >> + protected void removeDeepBinding(String name, Object
> >> value) throws NamingException {
> >> + throw new OperationNotSupportedException("Context is
> >> immutable");
> >> + }
> >> +
> >> + public Context createContext(String path, Map bindings) {
> >> + return new NestedMapContext(path, bindings);
> >> + }
> >> + }
> >> +}
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/UnmodifiableContext.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/context/
> >> UnmodifiableContext.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/UnmodifiableContext.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/context/UnmodifiableContext.java Wed Aug
> >> 16 17:50:03 2006
> >> @@ -0,0 +1,228 @@
> >> +/**
> >> + *
> >> + * Copyright 2006 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +package org.apache.xbean.naming.context;
> >> +
> >> +import
> >> edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicReference
> >> ;
> >> +import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock;
> >> +import
> >> edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock;
> >> +import org.apache.xbean.naming.reference.CachingReference;
> >> +
> >> +import javax.naming.NameAlreadyBoundException;
> >> +import javax.naming.NamingException;
> >> +import javax.naming.Context;
> >> +import javax.naming.NameNotFoundException;
> >> +import java.util.Collections;
> >> +import java.util.HashMap;
> >> +import java.util.Iterator;
> >> +import java.util.Map;
> >> +
> >> +/**
> >> + * @version $Rev: 417891 $ $Date: 2006-06-28 15:45:07 -0700 (Wed,
> >> 28 Jun 2006) $
> >> + */
> >> +public class UnmodifiableContext extends AbstractReadOnlyContext {
> >> + private final Lock writeLock = new ReentrantLock();
> >> + private final AtomicReference bindingsRef;
> >> + private final AtomicReference indexRef;
> >> + public static final int MAX_WRITE_ATTEMPTS = 3;
> >> +
> >> + public UnmodifiableContext(Map bindings) throws
> >> NamingException {
> >> + this("", bindings, true);
> >> + }
> >> +
> >> + public UnmodifiableContext(Map bindings, boolean
> >> cacheReferences) throws NamingException {
> >> + this("", bindings, cacheReferences);
> >> + }
> >> +
> >> + public UnmodifiableContext(String nameInNamespace, Map
> >> bindings, boolean cacheReferences) throws NamingException {
> >> + super(nameInNamespace);
> >> +
> >> + if (cacheReferences) {
> >> + bindings = CachingReference.wrapReferences(bindings);
> >> + }
> >> +
> >> + Map localBindings = ContextUtil.createBindings(bindings,
> >> this);
> >> +
> >> + this.bindingsRef = new AtomicReference
> >> (Collections.unmodifiableMap(localBindings));
> >> + this.indexRef = new AtomicReference
> >> (Collections.unmodifiableMap(buildIndex("", localBindings)));
> >> + }
> >> +
> >> + protected void addBinding(String name, Object value) throws
> >> NamingException {
> >> + writeLock.lock();
> >> + try {
> >> + Map bindings = (Map) bindingsRef.get();
> >> + if (bindings.containsKey(name)) {
> >> + throw new NameAlreadyBoundException(name);
> >> + }
> >> +
> >> + Map newBindings = new HashMap(bindings);
> >> + newBindings.put(name,value);
> >> + bindingsRef.set(newBindings);
> >> +
> >> + Map newIndex = addToIndex(name, value);
> >> + indexRef.set(newIndex);
> >> + } finally {
> >> + writeLock.unlock();
> >> + }
> >> + }
> >> +
> >> + private Map addToIndex(String name, Object value) {
> >> + Map index = (Map) indexRef.get();
> >> + Map newIndex = new HashMap(index);
> >> + newIndex.put(name, value);
> >> + if (value instanceof NestedMapContext) {
> >> + NestedMapContext nestedcontext = (NestedMapContext)
> >> value;
> >> + Map newIndexValues = buildIndex(name,
> >> nestedcontext.getBindings());
> >> + newIndex.putAll(newIndexValues);
> >> + }
> >> + return newIndex;
> >> + }
> >> +
> >> + protected void removeBinding(String name) throws
> >> NamingException {
> >> + writeLock.lock();
> >> + try {
> >> + Map bindings = (Map) bindingsRef.get();
> >> + if (!bindings.containsKey(name)) {
> >> + throw new NameNotFoundException(name);
> >> + }
> >> +
> >> + Map newBindings = new HashMap(bindings);
> >> + newBindings.remove(name);
> >> + bindingsRef.set(newBindings);
> >> +
> >> + Map newIndex = removeFromIndex(name);
> >> + indexRef.set(newIndex);
> >> + } finally {
> >> + writeLock.unlock();
> >> + }
> >> + }
> >> +
> >> + private Map removeFromIndex(String name) {
> >> + Map index = (Map) indexRef.get();
> >> + Map newIndex = new HashMap(index);
> >> + Object oldValue = newIndex.remove(name);
> >> + if (oldValue instanceof NestedMapContext) {
> >> + NestedMapContext nestedcontext = (NestedMapContext)
> >> oldValue;
> >> + Map removedIndexValues = buildIndex(name,
> >> nestedcontext.getBindings());
> >> + for (Iterator iterator = removedIndexValues.keySet
> >> ().iterator(); iterator.hasNext();) {
> >> + String key = (String) iterator.next();
> >> + newIndex.remove(key);
> >> + }
> >> + }
> >> + return newIndex;
> >> + }
> >> +
> >> + public Context createContext(String path, Map bindings) {
> >> + return new NestedMapContext(path,bindings);
> >> + }
> >> +
> >> + private static Map buildIndex(String nameInNamespace, Map
> >> bindings) {
> >> + String path = nameInNamespace;
> >> + if (path.length() > 0 && !path.endsWith("/")) {
> >> + path += "/";
> >> + }
> >> +
> >> + Map absoluteIndex = new HashMap();
> >> + for (Iterator iterator = bindings.entrySet().iterator();
> >> iterator.hasNext();) {
> >> + Map.Entry entry = (Map.Entry) iterator.next();
> >> + String name = (String) entry.getKey();
> >> + Object value = entry.getValue();
> >> + if (value instanceof
> >> UnmodifiableContext.NestedMapContext) {
> >> + UnmodifiableContext.NestedMapContext
> >> nestedContext = (UnmodifiableContext.NestedMapContext)value;
> >> + absoluteIndex.putAll
> >> (UnmodifiableContext.buildIndex(nestedContext.pathWithSlash,
> >> nestedContext.getBindings()));
> >> + }
> >> + absoluteIndex.put(path + name, value);
> >> + }
> >> + return absoluteIndex;
> >> + }
> >> +
> >> + protected Object getDeepBinding(String name) {
> >> + Map index = (Map) indexRef.get();
> >> + return index.get(name);
> >> + }
> >> +
> >> + protected Map getBindings() {
> >> + Map bindings = (Map) bindingsRef.get();
> >> + return bindings;
> >> + }
> >> +
> >> + /**
> >> + * Nested context which shares the absolute index map in
> >> MapContext.
> >> + */
> >> + public final class NestedMapContext extends
> >> AbstractReadOnlyContext {
> >> + private final AtomicReference bindingsRef;
> >> + private final String pathWithSlash;
> >> +
> >> + public NestedMapContext(String path, String key, Object
> >> value) {
> >> + this(path, Collections.singletonMap(key, value));
> >> + }
> >> +
> >> + public NestedMapContext(String path, Map bindings) {
> >> + super(UnmodifiableContext.this.getNameInNamespace
> >> (path));
> >> +
> >> + if (!path.endsWith("/")) path += "/";
> >> + this.pathWithSlash = path;
> >> +
> >> + this.bindingsRef = new AtomicReference
> >> (Collections.unmodifiableMap(bindings));
> >> + }
> >> +
> >> + public Context createContext(String path, Map bindings) {
> >> + return new NestedMapContext(path, bindings);
> >> + }
> >> +
> >> + protected Object getDeepBinding(String name) {
> >> + String absoluteName = pathWithSlash + name;
> >> + return UnmodifiableContext.this.getDeepBinding
> >> (absoluteName);
> >> + }
> >> +
> >> + protected Map getBindings() {
> >> + Map bindings = (Map) bindingsRef.get();
> >> + return bindings;
> >> + }
> >> +
> >> + protected void addBinding(String name, Object value) {
> >> + writeLock.lock();
> >> + try {
> >> + Map currentBindings = (Map) bindingsRef.get();
> >> + Map newBindings = new HashMap(currentBindings);
> >> + newBindings.put(name, value);
> >> + newBindings = Collections.unmodifiableMap
> >> (newBindings);
> >> + bindingsRef.set(newBindings);
> >> +
> >> + Map newIndex = addToIndex(name, value);
> >> + indexRef.set(newIndex);
> >> + } finally {
> >> + writeLock.unlock();
> >> + }
> >> + }
> >> +
> >> + protected void removeBinding(String name) {
> >> + writeLock.lock();
> >> + try {
> >> + Map currentBindings = (Map) bindingsRef.get();
> >> + Map newBindings = new HashMap(currentBindings);
> >> + newBindings.remove(name);
> >> + newBindings = Collections.unmodifiableMap
> >> (newBindings);
> >> + bindingsRef.set(newBindings);
> >> +
> >> + Map newIndex = removeFromIndex(name);
> >> + indexRef.set(newIndex);
> >> + } finally {
> >> + writeLock.unlock();
> >> + }
> >> + }
> >> + }
> >> +}
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/global/GlobalContextManager.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/global/
> >> GlobalContextManager.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/global/GlobalContextManager.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/global/GlobalContextManager.java Wed Aug
> >> 16 17:50:03 2006
> >> @@ -0,0 +1,106 @@
> >> +/**
> >> + *
> >> + * Copyright 2006 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +package org.apache.xbean.naming.global;
> >> +
> >> +import org.apache.xbean.naming.context.ContextFlyweight;
> >> +
> >> +import javax.naming.Context;
> >> +import javax.naming.Name;
> >> +import javax.naming.OperationNotSupportedException;
> >> +import javax.naming.NoInitialContextException;
> >> +import javax.naming.spi.InitialContextFactory;
> >> +import javax.naming.spi.ObjectFactory;
> >> +import java.util.Hashtable;
> >> +
> >> +/**
> >> + * The GlobalContextManager contains the static global context
> >> object. JNDI effectively requires a single global static
> >> + * to resolve the root context, and this class manages that
> >> static. This class is also an URLContextFactory and
> >> + * an InitialContextFactory which returns the registered global
> >> context.
> >> + *
> >> + * To use this factory simply set the following system property
> >> or pass the property in the environment to new InitialContext:
> >> + *
> >> + * java.naming.factory.initial =
> >> org.apache.xbean.naming.global.GlobalContextManager
> >> + *
> >> + * @version $Rev$ $Date$
> >> + */
> >> +public class GlobalContextManager implements ObjectFactory,
> >> InitialContextFactory {
> >> + private static Context DEFAULT_CONTEXT = new
> >> DefaultGlobalContext();
> >> + private static Context globalContext;
> >> +
> >> + /**
> >> + * Gets the global context. This context is the root of all
> >> contexts and will contain entries such as "java:comp".
> >> + * @return the global context
> >> + */
> >> + public static synchronized Context getGlobalContext() {
> >> + if (globalContext == null) return DEFAULT_CONTEXT;
> >> + return globalContext;
> >> + }
> >> +
> >> + /**
> >> + * Sets the global context. To invoke this method the calling
> >> code must have "setFactory" RuntimePermission.
> >> + * @param globalContext the new global context
> >> + */
> >> + public static synchronized void setGlobalContext(Context
> >> globalContext) {
> >> + SecurityManager security = System.getSecurityManager();
> >> + if (security != null) {
> >> + security.checkSetFactory();
> >> + }
> >> + GlobalContextManager.globalContext = globalContext;
> >> + }
> >> +
> >> + /**
> >> + * Returns the Context registered with the GlobalManager.
> >> This method is equivalent to:
> >> + *
> >> + * return GlobalContextManager.getGlobalContext();
> >> + *
> >> + * @param obj must be null
> >> + * @param name ignored
> >> + * @param nameCtx ignored
> >> + * @param environment ignored
> >> + * @return GlobalManager.getGlobalContext()
> >> + * @throws javax.naming.OperationNotSupportedException if obj
> >> is not null
> >> + */
> >> + public Object getObjectInstance(Object obj, Name name,
> >> Context nameCtx, Hashtable environment) throws Exception {
> >> + if (obj == null) {
> >> + return GlobalContextManager.getGlobalContext();
> >> + } else {
> >> + throw new OperationNotSupportedException();
> >> + }
> >> + }
> >> +
> >> +
> >> + /**
> >> + * Returns the Context registered with the GlobalManager.
> >> This method is equivalent to:
> >> + *
> >> + * return GlobalContextManager.getGlobalContext();
> >> + *
> >> + * @param environment ignored
> >> + * @return GlobalContextManager.getGlobalContext()
> >> + */
> >> + public Context getInitialContext(Hashtable environment) {
> >> + return GlobalContextManager.getGlobalContext();
> >> + }
> >> +
> >> + private static class DefaultGlobalContext extends
> >> ContextFlyweight {
> >> + protected Context getContext() throws
> >> NoInitialContextException {
> >> + synchronized (GlobalContextManager.class) {
> >> + if (globalContext == null) throw new
> >> NoInitialContextException("Global context has not been set");
> >> + return globalContext;
> >> + }
> >> + }
> >> + }
> >> +}
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/java/javaURLContextFactory.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/java/
> >> javaURLContextFactory.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/java/javaURLContextFactory.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/java/javaURLContextFactory.java Wed Aug 16
> >> 17:50:03 2006
> >> @@ -0,0 +1,28 @@
> >> +/**
> >> + *
> >> + * Copyright 2003-2004 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +
> >> +package org.apache.xbean.naming.java;
> >> +
> >> +import org.apache.xbean.naming.global.GlobalContextManager;
> >> +
> >> +/**
> >> + * URLContextFactory for the java: namespace.
> >> + *
> >> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat,
> >> 10 Dec 2005) $
> >> + */
> >> +public class javaURLContextFactory extends GlobalContextManager {
> >> +}
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/reference/CachingReference.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/reference/
> >> CachingReference.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/reference/CachingReference.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/reference/CachingReference.java Wed Aug 16
> >> 17:50:03 2006
> >> @@ -0,0 +1,68 @@
> >> +/**
> >> + *
> >> + * Copyright 2006 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +package org.apache.xbean.naming.reference;
> >> +
> >> +import org.apache.xbean.naming.context.ContextUtil;
> >> +
> >> +import javax.naming.Reference;
> >> +import javax.naming.NamingException;
> >> +import java.util.Map;
> >> +import java.util.LinkedHashMap;
> >> +import java.util.Iterator;
> >> +
> >> +/**
> >> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat,
> >> 10 Dec 2005) $
> >> + */
> >> +public class CachingReference extends SimpleReference {
> >> + public static Map wrapReferences(Map bindings) {
> >> + LinkedHashMap newBindings = new LinkedHashMap(bindings);
> >> + for (Iterator iterator = bindings.entrySet().iterator();
> >> iterator.hasNext();) {
> >> + Map.Entry entry = (Map.Entry) iterator.next();
> >> + String name = (String) entry.getKey();
> >> + Object value = entry.getValue();
> >> + if (value instanceof Reference && !(value instanceof
> >> CachingReference)) {
> >> + newBindings.put(name, new CachingReference(name,
> >> (Reference)value));
> >> + }
> >> + }
> >> + return newBindings;
> >> + }
> >> +
> >> + private final Object lock = new Object();
> >> + private final String fullName;
> >> + private final Reference reference;
> >> + private final String className;
> >> + private Object value;
> >> +
> >> + public CachingReference(String fullName, Reference reference) {
> >> + this.fullName = fullName;
> >> + this.reference = reference;
> >> + className = reference.getClassName();
> >> + }
> >> +
> >> + public Object getContent() throws NamingException {
> >> + synchronized(lock) {
> >> + if (value == null) {
> >> + value = ContextUtil.resolve(fullName, reference);
> >> + }
> >> + return value;
> >> + }
> >> + }
> >> +
> >> + public String getClassName() {
> >> + return className;
> >> + }
> >> +}
> >>
> >> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/reference/SimpleReference.java
> >> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
> >> xbean-naming/src/main/java/org/apache/xbean/naming/reference/
> >> SimpleReference.java?rev=432088&view=auto
> >> =====================================================================
> >> =========
> >> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/reference/SimpleReference.java (added)
> >> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
> >> org/apache/xbean/naming/reference/SimpleReference.java Wed Aug 16
> >> 17:50:03 2006
> >> @@ -0,0 +1,141 @@
> >> +/**
> >> + *
> >> + * Copyright 2004 The Apache Software Foundation
> >> + *
> >> + * Licensed under the Apache License, Version 2.0 (the "License");
> >> + * you may not use this file except in compliance with the License.
> >> + * You may obtain a copy of the License at
> >> + *
> >> + * http://www.apache.org/licenses/LICENSE-2.0
> >> + *
> >> + * Unless required by applicable law or agreed to in writing,
> >> software
> >> + * distributed under the License is distributed on an "AS IS"
> >> BASIS,
> >> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
> >> or implied.
> >> + * See the License for the specific language governing
> >> permissions and
> >> + * limitations under the License.
> >> + */
> >> +package org.apache.xbean.naming.reference;
> >> +
> >> +import java.util.Enumeration;
> >> +import java.util.Hashtable;
> >> +import java.util.NoSuchElementException;
> >> +import javax.naming.Context;
> >> +import javax.naming.Name;
> >> +import javax.naming.RefAddr;
> >> +import javax.naming.Reference;
> >> +import javax.naming.NamingException;
> >> +import javax.naming.spi.ObjectFactory;
> >> +
> >> +/**
> >> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat,
> >> 10 Dec 2005) $
> >> + */
> >> +public abstract class SimpleReference extends Reference {
> >> + private static final Enumeration EMPTY_ENUMERATION = new
> >> Enumeration() {
> >> + public boolean hasMoreElements() {
> >> + return false;
> >> + }
> >> +
> >> + public Object nextElement() {
> >> + return new NoSuchElementException();
> >> + }
> >> + };
> >> +
> >> + public SimpleReference() {
> >> + super(null);
> >> + }
> >> +
> >> + /**
> >> + * Gets the actual referenced Object.
> >> + * @return the referenced object
> >> + */
> >> + public abstract Object getContent() throws NamingException;
> >> +
> >> + /**
> >> + * We will atleast return an Object. Subclasses may want to
> >> provide a more specific class.
> >> + * @return "java.lang.Object"
> >> + */
> >> + public String getClassName() {
> >> + return "java.lang.Object";
> >> + }
> >> +
> >> + /**
> >> + * If the JNDI context does not understand simple references,
> >> this method will be called
> >> + * to obtain the class name of a factory. This factory in
> >> turn understands the simple
> >> + * reference. This style is much slower because JNDI will
> >> use reflection to load and
> >> + * create this class.
> >> + * @return
> >> + */
> >> + public final String getFactoryClassName() {
> >> + return SimpleObjectFactory.class.getName();
> >> + }
> >> +
> >> + //
> >> + // Disabled methods that we no longer need
> >> + //
> >> + public final String getFactoryClassLocation() {
> >> + return null;
> >> + }
> >> +
> >> + public final RefAddr get(String addrType) {
> >> + return null;
> >> + }
> >> +
> >> + public final RefAddr get(int posn) {
> >> + throw new ArrayIndexOutOfBoundsException(posn);
> >> + }
> >> +
> >> + public final Enumeration getAll() {
> >> + return EMPTY_ENUMERATION;
> >> + }
> >> +
> >> + public final int size() {
> >> + return 0;
> >> + }
> >> +
> >> + public final void add(RefAddr addr) {
> >> + throw new UnsupportedOperationException("SimpleReference
> >> has no addresses so none can be added");
> >> + }
> >> +
> >> + public final void add(int posn, RefAddr addr) {
> >> + throw new UnsupportedOperationException("SimpleReference
> >> has no addresses so none can be added");
> >> + }
> >> +
> >> + public final Object remove(int posn) {
> >> + throw new ArrayIndexOutOfBoundsException(posn);
> >> + }
> >> +
> >> + public final void clear() {
> >> + }
> >> +
> >> + //
> >> + // Reset the java.lang.Object methods back to default
> >> implementations
> >> + //
> >> + public boolean equals(Object obj) {
> >> + return this == obj;
> >> + }
> >> +
> >> + public int hashCode() {
> >> + return System.identityHashCode(this);
> >> + }
> >> +
> >> + public String toString() {
> >> + return getClass().getName() + "@" + Integer.toHexString
> >> (hashCode());
> >> + }
> >> +
> >> + public Object clone() {
> >> + throw new UnsupportedOperationException("SimpleReference
> >> can not be cloned");
> >> + }
> >> +
> >> + /**
> >> + * Simply calls getContent() on the SimpleReference
> >> + */
> >> + public static final class SimpleObjectFactory implements
> >> ObjectFactory {
> >> + public Object getObjectInstance(Object obj, Name name,
> >> Context nameCtx, Hashtable environment) throws Exception {
> >> + if (obj instanceof SimpleReference) {
> >> + SimpleReference reference = (SimpleReference) obj;
> >> + return reference.getContent();
> >> + }
> >> + return null;
> >> + }
> >> + }
> >> +}
> >>
> >>
> >>
> >
> >
> > --
> > Cheers,
> > Guillaume Nodet
>
>
--
Cheers,
Guillaume Nodet
Re: svn commit: r432088 [1/2] - in /geronimo/xbean/branches/colossus: ./ xbean-naming/ xbean-naming/src/ xbean-naming/src/main/ xbean-naming/src/main/java/ xbean-naming/src/main/java/org/ xbean-naming/src/main/java/org/apache/ xbean-naming/src/main/j
Posted by Dain Sundstrom <da...@iq80.com>.
I've been wanting to but I've been too busy.
-dain
On Aug 16, 2006, at 6:05 PM, Guillaume Nodet wrote:
> Maybe we should also put the classloader stuff in its own module,
> as it
> is really reusable and completely independant of the rest of xbean-
> server.
>
> On 8/17/06, dain@apache.org <da...@apache.org> wrote:
>> Author: dain
>> Date: Wed Aug 16 17:50:03 2006
>> New Revision: 432088
>>
>> URL: http://svn.apache.org/viewvc?rev=432088&view=rev
>> Log:
>> Global, unmodifiable and immutable JNDI contexts.
>>
>> Added:
>> geronimo/xbean/branches/colossus/xbean-naming/
>> geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt
>> geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt
>> geronimo/xbean/branches/colossus/xbean-naming/pom.xml
>> geronimo/xbean/branches/colossus/xbean-naming/src/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/AbstractReadOnlyContext.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextFactory.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextFlyweight.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextUtil.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ImmutableContext.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/UnmodifiableContext.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/global/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/global/GlobalContextManager.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/java/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/java/javaURLContextFactory.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/reference/
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/reference/CachingReference.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/reference/SimpleReference.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/
>> geronimo/xbean/branches/colossus/xbean-naming/src/test-data/
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> org/apache/
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> org/apache/xbean/
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> org/apache/xbean/naming/
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> org/apache/xbean/naming/context/
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> org/apache/xbean/naming/context/AbstractContextTest.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> org/apache/xbean/naming/context/ImmutableContextTest.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> org/apache/xbean/naming/context/UnmodifiableContextTest.java
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> org/apache/xbean/naming/global/
>> geronimo/xbean/branches/colossus/xbean-naming/src/test/java/
>> org/apache/xbean/naming/global/GlobalContextManagerTest.java
>> Modified:
>> geronimo/xbean/branches/colossus/pom.xml
>>
>> Modified: geronimo/xbean/branches/colossus/pom.xml
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> pom.xml?rev=432088&r1=432087&r2=432088&view=diff
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/pom.xml (original)
>> +++ geronimo/xbean/branches/colossus/pom.xml Wed Aug 16 17:50:03 2006
>> @@ -179,6 +179,7 @@
>> -->
>> <module>xbean-colossus</module>
>> <module>xbean-kernel</module>
>> + <module>xbean-naming</module>
>> <module>xbean-osgi</module>
>> <module>xbean-reflect</module>
>> <module>xbean-server</module>
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/LICENSE.txt?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/LICENSE.txt Wed
>> Aug 16 17:50:03 2006
>> @@ -0,0 +1,203 @@
>> +
>> + Apache License
>> + Version 2.0, January 2004
>> + http://www.apache.org/licenses/
>> +
>> + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
>> +
>> + 1. Definitions.
>> +
>> + "License" shall mean the terms and conditions for use,
>> reproduction,
>> + and distribution as defined by Sections 1 through 9 of this
>> document.
>> +
>> + "Licensor" shall mean the copyright owner or entity
>> authorized by
>> + the copyright owner that is granting the License.
>> +
>> + "Legal Entity" shall mean the union of the acting entity
>> and all
>> + other entities that control, are controlled by, or are
>> under common
>> + control with that entity. For the purposes of this definition,
>> + "control" means (i) the power, direct or indirect, to cause
>> the
>> + direction or management of such entity, whether by contract or
>> + otherwise, or (ii) ownership of fifty percent (50%) or more
>> of the
>> + outstanding shares, or (iii) beneficial ownership of such
>> entity.
>> +
>> + "You" (or "Your") shall mean an individual or Legal Entity
>> + exercising permissions granted by this License.
>> +
>> + "Source" form shall mean the preferred form for making
>> modifications,
>> + including but not limited to software source code,
>> documentation
>> + source, and configuration files.
>> +
>> + "Object" form shall mean any form resulting from mechanical
>> + transformation or translation of a Source form, including but
>> + not limited to compiled object code, generated documentation,
>> + and conversions to other media types.
>> +
>> + "Work" shall mean the work of authorship, whether in Source or
>> + Object form, made available under the License, as indicated
>> by a
>> + copyright notice that is included in or attached to the work
>> + (an example is provided in the Appendix below).
>> +
>> + "Derivative Works" shall mean any work, whether in Source
>> or Object
>> + form, that is based on (or derived from) the Work and for
>> which the
>> + editorial revisions, annotations, elaborations, or other
>> modifications
>> + represent, as a whole, an original work of authorship. For
>> the purposes
>> + of this License, Derivative Works shall not include works
>> that remain
>> + separable from, or merely link (or bind by name) to the
>> interfaces of,
>> + the Work and Derivative Works thereof.
>> +
>> + "Contribution" shall mean any work of authorship, including
>> + the original version of the Work and any modifications or
>> additions
>> + to that Work or Derivative Works thereof, that is
>> intentionally
>> + submitted to Licensor for inclusion in the Work by the
>> copyright owner
>> + or by an individual or Legal Entity authorized to submit on
>> behalf of
>> + the copyright owner. For the purposes of this definition,
>> "submitted"
>> + means any form of electronic, verbal, or written
>> communication sent
>> + to the Licensor or its representatives, including but not
>> limited to
>> + communication on electronic mailing lists, source code
>> control systems,
>> + and issue tracking systems that are managed by, or on
>> behalf of, the
>> + Licensor for the purpose of discussing and improving the
>> Work, but
>> + excluding communication that is conspicuously marked or
>> otherwise
>> + designated in writing by the copyright owner as "Not a
>> Contribution."
>> +
>> + "Contributor" shall mean Licensor and any individual or
>> Legal Entity
>> + on behalf of whom a Contribution has been received by
>> Licensor and
>> + subsequently incorporated within the Work.
>> +
>> + 2. Grant of Copyright License. Subject to the terms and
>> conditions of
>> + this License, each Contributor hereby grants to You a
>> perpetual,
>> + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
>> + copyright license to reproduce, prepare Derivative Works of,
>> + publicly display, publicly perform, sublicense, and
>> distribute the
>> + Work and such Derivative Works in Source or Object form.
>> +
>> + 3. Grant of Patent License. Subject to the terms and
>> conditions of
>> + this License, each Contributor hereby grants to You a
>> perpetual,
>> + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
>> + (except as stated in this section) patent license to make,
>> have made,
>> + use, offer to sell, sell, import, and otherwise transfer
>> the Work,
>> + where such license applies only to those patent claims
>> licensable
>> + by such Contributor that are necessarily infringed by their
>> + Contribution(s) alone or by combination of their
>> Contribution(s)
>> + with the Work to which such Contribution(s) was submitted.
>> If You
>> + institute patent litigation against any entity (including a
>> + cross-claim or counterclaim in a lawsuit) alleging that the
>> Work
>> + or a Contribution incorporated within the Work constitutes
>> direct
>> + or contributory patent infringement, then any patent licenses
>> + granted to You under this License for that Work shall
>> terminate
>> + as of the date such litigation is filed.
>> +
>> + 4. Redistribution. You may reproduce and distribute copies of the
>> + Work or Derivative Works thereof in any medium, with or
>> without
>> + modifications, and in Source or Object form, provided that You
>> + meet the following conditions:
>> +
>> + (a) You must give any other recipients of the Work or
>> + Derivative Works a copy of this License; and
>> +
>> + (b) You must cause any modified files to carry prominent
>> notices
>> + stating that You changed the files; and
>> +
>> + (c) You must retain, in the Source form of any Derivative
>> Works
>> + that You distribute, all copyright, patent, trademark, and
>> + attribution notices from the Source form of the Work,
>> + excluding those notices that do not pertain to any part of
>> + the Derivative Works; and
>> +
>> + (d) If the Work includes a "NOTICE" text file as part of its
>> + distribution, then any Derivative Works that You
>> distribute must
>> + include a readable copy of the attribution notices
>> contained
>> + within such NOTICE file, excluding those notices that
>> do not
>> + pertain to any part of the Derivative Works, in at
>> least one
>> + of the following places: within a NOTICE text file
>> distributed
>> + as part of the Derivative Works; within the Source form or
>> + documentation, if provided along with the Derivative
>> Works; or,
>> + within a display generated by the Derivative Works, if and
>> + wherever such third-party notices normally appear. The
>> contents
>> + of the NOTICE file are for informational purposes only and
>> + do not modify the License. You may add Your own
>> attribution
>> + notices within Derivative Works that You distribute,
>> alongside
>> + or as an addendum to the NOTICE text from the Work,
>> provided
>> + that such additional attribution notices cannot be
>> construed
>> + as modifying the License.
>> +
>> + You may add Your own copyright statement to Your
>> modifications and
>> + may provide additional or different license terms and
>> conditions
>> + for use, reproduction, or distribution of Your
>> modifications, or
>> + for any such Derivative Works as a whole, provided Your use,
>> + reproduction, and distribution of the Work otherwise
>> complies with
>> + the conditions stated in this License.
>> +
>> + 5. Submission of Contributions. Unless You explicitly state
>> otherwise,
>> + any Contribution intentionally submitted for inclusion in
>> the Work
>> + by You to the Licensor shall be under the terms and
>> conditions of
>> + this License, without any additional terms or conditions.
>> + Notwithstanding the above, nothing herein shall supersede
>> or modify
>> + the terms of any separate license agreement you may have
>> executed
>> + with Licensor regarding such Contributions.
>> +
>> + 6. Trademarks. This License does not grant permission to use
>> the trade
>> + names, trademarks, service marks, or product names of the
>> Licensor,
>> + except as required for reasonable and customary use in
>> describing the
>> + origin of the Work and reproducing the content of the
>> NOTICE file.
>> +
>> + 7. Disclaimer of Warranty. Unless required by applicable law or
>> + agreed to in writing, Licensor provides the Work (and each
>> + Contributor provides its Contributions) on an "AS IS" BASIS,
>> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
>> express or
>> + implied, including, without limitation, any warranties or
>> conditions
>> + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
>> + PARTICULAR PURPOSE. You are solely responsible for
>> determining the
>> + appropriateness of using or redistributing the Work and
>> assume any
>> + risks associated with Your exercise of permissions under
>> this License.
>> +
>> + 8. Limitation of Liability. In no event and under no legal
>> theory,
>> + whether in tort (including negligence), contract, or
>> otherwise,
>> + unless required by applicable law (such as deliberate and
>> grossly
>> + negligent acts) or agreed to in writing, shall any
>> Contributor be
>> + liable to You for damages, including any direct, indirect,
>> special,
>> + incidental, or consequential damages of any character
>> arising as a
>> + result of this License or out of the use or inability to
>> use the
>> + Work (including but not limited to damages for loss of
>> goodwill,
>> + work stoppage, computer failure or malfunction, or any and all
>> + other commercial damages or losses), even if such Contributor
>> + has been advised of the possibility of such damages.
>> +
>> + 9. Accepting Warranty or Additional Liability. While
>> redistributing
>> + the Work or Derivative Works thereof, You may choose to offer,
>> + and charge a fee for, acceptance of support, warranty,
>> indemnity,
>> + or other liability obligations and/or rights consistent
>> with this
>> + License. However, in accepting such obligations, You may
>> act only
>> + on Your own behalf and on Your sole responsibility, not on
>> behalf
>> + of any other Contributor, and only if You agree to indemnify,
>> + defend, and hold each Contributor harmless for any liability
>> + incurred by, or claims asserted against, such Contributor
>> by reason
>> + of your accepting any such warranty or additional liability.
>> +
>> + END OF TERMS AND CONDITIONS
>> +
>> + APPENDIX: How to apply the Apache License to your work.
>> +
>> + To apply the Apache License to your work, attach the following
>> + boilerplate notice, with the fields enclosed by brackets "[]"
>> + replaced with your own identifying information. (Don't include
>> + the brackets!) The text should be enclosed in the appropriate
>> + comment syntax for the file format. We also recommend that a
>> + file or class name and description of purpose be included
>> on the
>> + same "printed page" as the copyright notice for easier
>> + identification within third-party archives.
>> +
>> + Copyright [yyyy] [name of copyright owner]
>> +
>> + Licensed under the Apache License, Version 2.0 (the "License");
>> + you may not use this file except in compliance with the License.
>> + You may obtain a copy of the License at
>> +
>> + http://www.apache.org/licenses/LICENSE-2.0
>> +
>> + Unless required by applicable law or agreed to in writing,
>> software
>> + distributed under the License is distributed on an "AS IS" BASIS,
>> + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + See the License for the specific language governing
>> permissions and
>> + limitations under the License.
>> +
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/NOTICE.txt?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/NOTICE.txt Wed
>> Aug 16 17:50:03 2006
>> @@ -0,0 +1,3 @@
>> +This product includes software developed by
>> +The Apache Software Foundation (http://www.apache.org/).
>> +
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/pom.xml
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/pom.xml?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/pom.xml (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/pom.xml Wed Aug
>> 16 17:50:03 2006
>> @@ -0,0 +1,40 @@
>> +<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://
>> maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/
>> XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/
>> POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
>> + <parent>
>> + <artifactId>xbean</artifactId>
>> + <groupId>org.apache.xbean</groupId>
>> + <version>COL-SNAPSHOT</version>
>> + </parent>
>> + <modelVersion>4.0.0</modelVersion>
>> + <artifactId>xbean-naming</artifactId>
>> + <name>XBean :: Naming</name>
>> + <version>COL-SNAPSHOT</version>
>> + <build>
>> + <plugins>
>> + <plugin>
>> + <artifactId>maven-compiler-plugin</artifactId>
>> + <configuration>
>> + <source>1.4</source>
>> + <target>1.4</target>
>> + </configuration>
>> + </plugin>
>> + <plugin>
>> + <artifactId>maven-surefire-plugin</artifactId>
>> + <configuration>
>> + <excludes/>
>> + </configuration>
>> + </plugin>
>> + </plugins>
>> + </build>
>> + <dependencies>
>> + <dependency>
>> + <groupId>backport-util-concurrent</groupId>
>> + <artifactId>backport-util-concurrent</artifactId>
>> + </dependency>
>> + <dependency>
>> + <groupId>org.apache.geronimo.modules</groupId>
>> + <artifactId>geronimo-naming</artifactId>
>> + <version>1.2-SNAPSHOT</version>
>> + <optional>true</optional>
>> + </dependency>
>> + </dependencies>
>> +</project>
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/AbstractReadOnlyContext.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/context/
>> AbstractReadOnlyContext.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/AbstractReadOnlyContext.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/AbstractReadOnlyContext.java Wed
>> Aug 16 17:50:03 2006
>> @@ -0,0 +1,560 @@
>> +/**
>> + *
>> + * Copyright 2003-2004 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +
>> +package org.apache.xbean.naming.context;
>> +
>> +import javax.naming.CompositeName;
>> +import javax.naming.Context;
>> +import javax.naming.InitialContext;
>> +import javax.naming.Name;
>> +import javax.naming.NameNotFoundException;
>> +import javax.naming.NameParser;
>> +import javax.naming.NamingEnumeration;
>> +import javax.naming.NamingException;
>> +import javax.naming.NotContextException;
>> +import javax.naming.OperationNotSupportedException;
>> +import javax.naming.InvalidNameException;
>> +import javax.naming.LinkRef;
>> +import java.io.Serializable;
>> +import java.util.Hashtable;
>> +import java.util.Map;
>> +import java.util.Collections;
>> +
>> +/**
>> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat,
>> 10 Dec 2005) $
>> + */
>> +public abstract class AbstractReadOnlyContext implements Context,
>> ContextFactory, Serializable {
>> + private static final long serialVersionUID =
>> 3808693663629444493L;
>> + private final String nameInNamespace;
>> +
>> + protected AbstractReadOnlyContext(String nameInNamespace) {
>> + this.nameInNamespace = nameInNamespace;
>> + }
>> +
>> + /**
>> + * Gets the name of this context withing the global
>> namespace. This method may return null
>> + * if the location of the node in the global namespace is not
>> known
>> + * @return the name of this context within the global
>> namespace or null if unknown.
>> + */
>> + public String getNameInNamespace() {
>> + return nameInNamespace;
>> + }
>> +
>> + /**
>> + * Gets the name of a path withing the global namespace context.
>> + */
>> + protected String getNameInNamespace(String path) {
>> + String nameInNamespace = getNameInNamespace();
>> + if (nameInNamespace == null || nameInNamespace.length()
>> == 0) {
>> + return path;
>> + } else {
>> + return nameInNamespace + "/" + path;
>> + }
>> + }
>> +
>> +
>> + /**
>> + * Always returns a new (empty) Hashtable.
>> + * @return a new (empty) Hashtable
>> + */
>> + public Hashtable getEnvironment() {
>> + return new Hashtable();
>> + }
>> +
>> + /**
>> + * A parser that can turn Strings into javax.naming.Name
>> objects.
>> + * @return ContextUtil.NAME_PARSER
>> + */
>> + protected NameParser getNameParser() {
>> + return ContextUtil.NAME_PARSER;
>> + }
>> +
>> + //
>> + // Lookup Binding
>> + //
>> +
>> + /**
>> + * Gets the object bound to the name. The name may contain
>> slashes.
>> + * @param name the name
>> + * @return the object bound to the name, or null if not found
>> + */
>> + protected Object getDeepBinding(String name) {
>> + return null;
>> + }
>> +
>> + /**
>> + * Gets the object bound to the name. The name will not
>> contain slashes.
>> + * @param name the name
>> + * @return the object bound to the name, or null if not found
>> + */
>> + protected Object getBinding(String name) throws
>> NamingException {
>> + Map bindings = getBindings();
>> + return bindings.get(name);
>> + }
>> +
>> + /**
>> + * Finds the specified entry. Normally there is no need to
>> override this method; insted you should
>> + * simply implement the getBindings(String) method.
>> + *
>> + * @param stringName the string version of the name; maybe null
>> + * @param parsedName the parsed name; may be null
>> + * @return the value bound to the name
>> + * @throws NamingException if no value is bound to that name
>> or if a problem occurs during the lookup
>> + */
>> + protected Object lookup(String stringName, Name parsedName)
>> throws NamingException {
>> + if (stringName == null && parsedName == null) {
>> + throw new IllegalArgumentException("Both stringName
>> and parsedName are null");
>> + }
>> + if (stringName == null) stringName = parsedName.toString();
>> +
>> + // try to look up the name directly (this is the fastest
>> path)
>> + Object directLookup = getDeepBinding(stringName);
>> + if (directLookup != null) {
>> + return ContextUtil.resolve(stringName, directLookup);
>> + }
>> +
>> + // if the parsed name has no parts, they are asking for
>> the current context
>> + if (parsedName == null) parsedName = getNameParser().parse
>> (stringName);
>> + if (parsedName.size() == 0) {
>> + return this;
>> + }
>> +
>> +
>> + // we didn't find an entry, pop the first element off the
>> parsed name and attempt to
>> + // get a context from the bindings and delegate to that
>> context
>> + Object localValue;
>> + String firstNameElement = parsedName.get(0);
>> + if (firstNameElement.length() == 0) {
>> + // the element is null... this is normally caused by
>> looking up with a trailing '/' character
>> + localValue = this;
>> + } else {
>> + localValue = getBinding(firstNameElement);
>> + }
>> +
>> + if (localValue != null) {
>> +
>> + // if the name only had one part, we've looked up
>> everything
>> + if (parsedName.size() == 1) {
>> + localValue = ContextUtil.resolve(stringName,
>> localValue);
>> + return localValue;
>> + }
>> +
>> + // if we have a link ref, follow it
>> + if (localValue instanceof LinkRef) {
>> + LinkRef linkRef = (LinkRef) localValue;
>> + localValue = lookup(linkRef.getLinkName());
>> + }
>> +
>> + // we have more to lookup so we better have a context
>> object
>> + if (!(localValue instanceof Context)) {
>> + throw new NameNotFoundException(stringName);
>> + }
>> +
>> + // delegate to the sub-context
>> + return ((Context) localValue).lookup
>> (parsedName.getSuffix(1));
>> + }
>> +
>> + // if we didn't find an entry, it may be an absolute name
>> + if (stringName.indexOf(':') > 0) {
>> + Context ctx = new InitialContext();
>> + return ctx.lookup(parsedName);
>> + }
>> + throw new NameNotFoundException(stringName);
>> + }
>> +
>> + //
>> + // List Bindings
>> + //
>> +
>> + /**
>> + * Gets a map of the bindings for the current node (i.e., no
>> names with slashes).
>> + * This method must not return null.
>> + */
>> + protected Map getBindings() throws NamingException {
>> + throw new OperationNotSupportedException("This context is
>> not listable");
>> + }
>> +
>> + protected NamingEnumeration list() throws NamingException {
>> + Map bindings = getBindings();
>> + return new ContextUtil.ListEnumeration(bindings);
>> + }
>> +
>> + protected NamingEnumeration listBindings() throws
>> NamingException {
>> + Map bindings = getBindings();
>> + return new ContextUtil.ListBindingEnumeration(bindings);
>> + }
>> +
>> + //
>> + // Add Binding
>> + //
>> +
>> + /**
>> + * Add the binding to the context. The name will not contain
>> a path but the value may
>> + * be a nested context which should be indexed for indexing
>> contexts.
>> + * @param name name under which the value should be bound
>> + * @param value the value to bind
>> + * @throws NamingException if a problem occurs during the
>> bind such as a value already being bound
>> + */
>> + protected void addBinding(String name, Object value) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + protected void addDeepBinding(String name, Object value)
>> throws NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> + if (value == null) throw new NullPointerException("value
>> is null");
>> +
>> + Name compoundName = ContextUtil.parseName(name);
>> + if (compoundName.isEmpty()) {
>> + throw new InvalidNameException("Name is empty");
>> + }
>> +
>> + AbstractReadOnlyContext currentContext = this;
>> + for (int i = 0; i < compoundName.size(); i++) {
>> + String part = compoundName.get(i);
>> +
>> + // empty path parts are not allowed
>> + if (part.length() == 0) {
>> + throw new InvalidNameException("Name part " + i +
>> " is empty: " + name);
>> + }
>> +
>> + // Is this the last element in the name?
>> + if (i == compoundName.size() - 1) {
>> + // we're at the end... bind the value into the
>> parent context
>> + currentContext.addBinding(part, value);
>> +
>> + // all done... this is redundant but makes the
>> code more readable
>> + break;
>> + } else {
>> + Map currentBindings = currentContext.getBindings();
>> + Object currentValue = currentBindings.get(part);
>> + if (currentValue == null) {
>> + // the next step in the tree is not present,
>> so create everything down
>> + // and add it to the current bindings
>> + Context context =
>> currentContext.createContextTree(compoundName.getPrefix(i).toString
>> (),
>> + compoundName.getSuffix(i),
>> + value);
>> + currentContext.addBinding(part, context);
>> +
>> + // all done
>> + break;
>> + } else {
>> + // the current value must be an abstract read
>> only context
>> + // todo this is a problem since a nested node
>> could be an AbstractReadOnlyContext but not one of our contexts
>> + if (!(currentValue instanceof
>> AbstractReadOnlyContext)) {
>> + throw new NotContextException("Expected
>> an instance of AbstractReadOnlyContext to be bound at " +
>> + part + " but found an instance of
>> " + currentValue.getClass().getName());
>> + }
>> + currentContext = (AbstractReadOnlyContext)
>> currentValue;
>> + // now we recurse into the current context
>> + }
>> + }
>> + }
>> + }
>> +
>> + /**
>> + * Creates a context tree which will be rooted at the
>> specified path and contain a single entry located down
>> + * a path specified by the name. All necessary intermediate
>> contexts will be created using the createContext method.
>> + * @param path the path to the context that will contains
>> this context
>> + * @param name the name under which the value should be bound
>> + * @param value the vale
>> + * @return a context with the value bound at the specified name
>> + * @throws NamingException
>> + */
>> + protected Context createContextTree(String path, Name name,
>> Object value) throws NamingException {
>> + if (path == null) throw new NullPointerException("path is
>> null");
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> + if (name.size() < 2) throw new InvalidNameException("name
>> must have at least 2 parts " + name);
>> +
>> + if (!path.endsWith("/")) path += "/";
>> +
>> + for (int i = name.size() - 2; i >= 0; i--) {
>> + String fullPath = path + name.getSuffix(i);
>> + String key = name.get(i + 1);
>> + value = createContext(fullPath,
>> Collections.singletonMap(key, value));
>> + }
>> + return (AbstractReadOnlyContext) value;
>> + }
>> +
>> + //
>> + // Remove Binding
>> + //
>> +
>> + /**
>> + * Removes the binding from the context. The name will not
>> contain a path and the value will not
>> + * be a nested context although it may be a foreign context.
>> + * @param name name under which the value should be bound
>> + * @throws NamingException if a problem occurs during the
>> bind such as a value already being bound
>> + */
>> + protected void removeBinding(String name) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + protected void removeDeepBinding(String name) throws
>> NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> +
>> + Name compoundName = ContextUtil.parseName(name);
>> + if (compoundName.isEmpty()) {
>> + throw new InvalidNameException("Name is empty");
>> + }
>> +
>> + // we serch the tree for a target context and name to remove
>> + // this is normally the last context in the tree and the
>> final name part, but
>> + // it may be farther up the path if the intervening nodes
>> are empty
>> + AbstractReadOnlyContext targetContext = this;
>> + String targetName = compoundName.get(0);
>> +
>> + AbstractReadOnlyContext currentContext = this;
>> + for (int i = 0; i < compoundName.size(); i++) {
>> + String part = compoundName.get(i);
>> +
>> + // empty path parts are not allowed
>> + if (part.length() == 0) {
>> + throw new InvalidNameException("Name part " + i +
>> " is empty: " + name);
>> + }
>> +
>> + Map currentBindings = currentContext.getBindings();
>> +
>> + // update targets
>> + if (currentBindings.size() > 1) {
>> + targetContext = currentContext;
>> + targetName = part;
>> + }
>> +
>> +
>> + // Is this the last element in the name?
>> + if (i == compoundName.size() - 1) {
>> + // we're at the end... bind the value into the
>> parent context
>> + targetContext.removeBinding(targetName);
>> +
>> + // all done... this is redundant but makes the
>> code more readable
>> + break;
>> + } else {
>> + Object currentValue = currentBindings.get(part);
>> + if (currentValue == null) {
>> + // path not found we are done
>> + break;
>> + } else {
>> + // the current value must be an abstract read
>> only context
>> + // todo this is a problem since a nested node
>> could be an AbstractReadOnlyContext but not one of our contexts
>> + if (!(currentValue instanceof
>> AbstractReadOnlyContext)) {
>> + throw new NotContextException("Expected
>> an instance of AbstractReadOnlyContext to be bound at " +
>> + part + " but found an instance of
>> " + currentValue.getClass().getName());
>> + }
>> + currentContext = (AbstractReadOnlyContext)
>> currentValue;
>> + // now we recurse into the current context
>> + }
>> + }
>> + }
>> + }
>> +
>> + //
>> =====================================================================
>> =============
>> + // =================== Final Methods (see methods above)
>> ============================
>> + //
>> =====================================================================
>> =============
>> +
>> + //
>> + // Lookup methods
>> + //
>> +
>> + public final Object lookup(String name) throws NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> +
>> + Object value = lookup(name, null);
>> +
>> + // if we got a link back we need to resolve it
>> + if (value instanceof LinkRef) {
>> + LinkRef linkRef = (LinkRef) value;
>> + value = lookup(linkRef.getLinkName());
>> + }
>> + return value;
>> + }
>> +
>> + public final Object lookup(Name name) throws NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> +
>> + Object value = lookup(null, name);
>> +
>> + // if we got a link back we need to resolve it
>> + if (value instanceof LinkRef) {
>> + LinkRef linkRef = (LinkRef) value;
>> + value = lookup(linkRef.getLinkName());
>> + }
>> +
>> + return value;
>> + }
>> +
>> + public final Object lookupLink(String name) throws
>> NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> +
>> + return lookup(name, null);
>> + }
>> +
>> + public final Object lookupLink(Name name) throws
>> NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> +
>> + return lookup(null, name);
>> + }
>> +
>> + //
>> + // List Operations
>> + //
>> +
>> + public final NamingEnumeration list(String name) throws
>> NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> +
>> + Object o = lookup(name);
>> + if (o == this) {
>> + return list();
>> + } else if (o instanceof Context) {
>> + return ((Context) o).list("");
>> + } else {
>> + throw new NotContextException();
>> + }
>> + }
>> +
>> + public final NamingEnumeration listBindings(String name)
>> throws NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> +
>> + Object o = lookup(name);
>> + if (o == this) {
>> + return listBindings();
>> + } else if (o instanceof Context) {
>> + return ((Context) o).listBindings("");
>> + } else {
>> + throw new NotContextException();
>> + }
>> + }
>> +
>> + public final NamingEnumeration list(Name name) throws
>> NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> +
>> + Object o = lookup(name);
>> + if (o == this) {
>> + return list();
>> + } else if (o instanceof Context) {
>> + return ((Context) o).list("");
>> + } else {
>> + throw new NotContextException();
>> + }
>> + }
>> +
>> + public final NamingEnumeration listBindings(Name name) throws
>> NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> +
>> + Object o = lookup(name);
>> + if (o == this) {
>> + return listBindings();
>> + } else if (o instanceof Context) {
>> + return ((Context) o).listBindings("");
>> + } else {
>> + throw new NotContextException();
>> + }
>> + }
>> +
>> + //
>> + // Name manipulation
>> + //
>> +
>> + public final NameParser getNameParser(Name name) {
>> + return getNameParser();
>> + }
>> +
>> + public final NameParser getNameParser(String name) {
>> + return getNameParser();
>> + }
>> +
>> + public final Name composeName(Name name, Name prefix) throws
>> NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> + if (prefix == null) throw new NullPointerException
>> ("prefix is null");
>> +
>> + Name result = (Name) prefix.clone();
>> + result.addAll(name);
>> + return result;
>> + }
>> +
>> + public final String composeName(String name, String prefix)
>> throws NamingException {
>> + if (name == null) throw new NullPointerException("name is
>> null");
>> + if (prefix == null) throw new NullPointerException
>> ("prefix is null");
>> +
>> + CompositeName result = new CompositeName(prefix);
>> + result.addAll(new CompositeName(name));
>> + return result.toString();
>> + }
>> +
>> + //
>> + // Unsupported Operations
>> + //
>> +
>> + public final Object addToEnvironment(String propName, Object
>> propVal) throws NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final Object removeFromEnvironment(String propName)
>> throws NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void bind(Name name, Object obj) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void bind(String name, Object obj) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void close() throws NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final Context createSubcontext(Name name) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final Context createSubcontext(String name) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void destroySubcontext(Name name) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void destroySubcontext(String name) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void rebind(Name name, Object obj) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void rebind(String name, Object obj) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void rename(Name oldName, Name newName) throws
>> NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void rename(String oldName, String newName)
>> throws NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void unbind(Name name) throws NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +
>> + public final void unbind(String name) throws NamingException {
>> + throw new OperationNotSupportedException("Context is read
>> only");
>> + }
>> +}
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextFactory.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/context/
>> ContextFactory.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextFactory.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextFactory.java Wed Aug 16
>> 17:50:03 2006
>> @@ -0,0 +1,27 @@
>> +/**
>> + *
>> + * Copyright 2006 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.xbean.naming.context;
>> +
>> +import javax.naming.Context;
>> +import java.util.Map;
>> +
>> +/**
>> + * @version $Rev$ $Date$
>> + */
>> +public interface ContextFactory {
>> + Context createContext(String path, Map bindings);
>> +}
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextFlyweight.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/context/
>> ContextFlyweight.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextFlyweight.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextFlyweight.java Wed Aug 16
>> 17:50:03 2006
>> @@ -0,0 +1,146 @@
>> +/**
>> + *
>> + * Copyright 2006 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.xbean.naming.context;
>> +
>> +import javax.naming.Context;
>> +import javax.naming.NamingException;
>> +import javax.naming.Name;
>> +import javax.naming.NamingEnumeration;
>> +import javax.naming.NameParser;
>> +import java.util.Hashtable;
>> +
>> +/**
>> + * @version $Rev$ $Date$
>> + */
>> +public abstract class ContextFlyweight implements Context {
>> + protected abstract Context getContext() throws NamingException;
>> +
>> + public void close() throws NamingException {
>> + }
>> +
>> + public String getNameInNamespace() throws NamingException {
>> + return getContext().getNameInNamespace();
>> + }
>> +
>> + public Object lookup(Name name) throws NamingException {
>> + return getContext().lookup(name);
>> + }
>> +
>> + public Object lookup(String name) throws NamingException {
>> + return getContext().lookup(name);
>> + }
>> +
>> + public void bind(Name name, Object obj) throws NamingException {
>> + getContext().bind(name, obj);
>> + }
>> +
>> + public void bind(String name, Object obj) throws
>> NamingException {
>> + getContext().bind(name, obj);
>> + }
>> +
>> + public void rebind(Name name, Object obj) throws
>> NamingException {
>> + getContext().rebind(name, obj);
>> + }
>> +
>> + public void rebind(String name, Object obj) throws
>> NamingException {
>> + getContext().rebind(name, obj);
>> + }
>> +
>> + public void unbind(Name name) throws NamingException {
>> + getContext().unbind(name);
>> + }
>> +
>> + public void unbind(String name) throws NamingException {
>> + getContext().unbind(name);
>> + }
>> +
>> + public void rename(Name oldName, Name newName) throws
>> NamingException {
>> + getContext().rename(oldName, newName);
>> + }
>> +
>> + public void rename(String oldName, String newName) throws
>> NamingException {
>> + getContext().rename(oldName, newName);
>> + }
>> +
>> + public NamingEnumeration list(Name name) throws
>> NamingException {
>> + return getContext().list(name);
>> + }
>> +
>> + public NamingEnumeration list(String name) throws
>> NamingException {
>> + return getContext().list(name);
>> + }
>> +
>> + public NamingEnumeration listBindings(Name name) throws
>> NamingException {
>> + return getContext().listBindings(name);
>> + }
>> +
>> + public NamingEnumeration listBindings(String name) throws
>> NamingException {
>> + return getContext().listBindings(name);
>> + }
>> +
>> + public void destroySubcontext(Name name) throws
>> NamingException {
>> + getContext().destroySubcontext(name);
>> + }
>> +
>> + public void destroySubcontext(String name) throws
>> NamingException {
>> + getContext().destroySubcontext(name);
>> + }
>> +
>> + public Context createSubcontext(Name name) throws
>> NamingException {
>> + return getContext().createSubcontext(name);
>> + }
>> +
>> + public Context createSubcontext(String name) throws
>> NamingException {
>> + return getContext().createSubcontext(name);
>> + }
>> +
>> + public Object lookupLink(Name name) throws NamingException {
>> + return getContext().lookupLink(name);
>> + }
>> +
>> + public Object lookupLink(String name) throws NamingException {
>> + return getContext().lookupLink(name);
>> + }
>> +
>> + public NameParser getNameParser(Name name) throws
>> NamingException {
>> + return getContext().getNameParser(name);
>> + }
>> +
>> + public NameParser getNameParser(String name) throws
>> NamingException {
>> + return getContext().getNameParser(name);
>> + }
>> +
>> + public Name composeName(Name name, Name prefix) throws
>> NamingException {
>> + return getContext().composeName(name, prefix);
>> + }
>> +
>> + public String composeName(String name, String prefix) throws
>> NamingException {
>> + return getContext().composeName(name, prefix);
>> + }
>> +
>> + public Object addToEnvironment(String propName, Object
>> propVal) throws NamingException {
>> + return getContext().addToEnvironment(propName, propVal);
>> + }
>> +
>> + public Object removeFromEnvironment(String propName) throws
>> NamingException {
>> + return getContext().removeFromEnvironment(propName);
>> + }
>> +
>> + public Hashtable getEnvironment() throws NamingException {
>> + return getContext().getEnvironment();
>> + }
>> +}
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextUtil.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/context/
>> ContextUtil.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextUtil.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ContextUtil.java Wed Aug 16
>> 17:50:03 2006
>> @@ -0,0 +1,290 @@
>> +/**
>> + *
>> + * Copyright 2006 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.xbean.naming.context;
>> +
>> +import org.apache.xbean.naming.reference.SimpleReference;
>> +
>> +import javax.naming.Binding;
>> +import javax.naming.CompoundName;
>> +import javax.naming.Name;
>> +import javax.naming.NameClassPair;
>> +import javax.naming.NameParser;
>> +import javax.naming.NamingEnumeration;
>> +import javax.naming.NamingException;
>> +import javax.naming.Reference;
>> +import javax.naming.Context;
>> +import javax.naming.spi.NamingManager;
>> +import java.util.Hashtable;
>> +import java.util.Iterator;
>> +import java.util.Map;
>> +import java.util.Properties;
>> +import java.util.HashMap;
>> +import java.util.Enumeration;
>> +
>> +/**
>> + * @version $Rev$ $Date$
>> + */
>> +public final class ContextUtil {
>> + private ContextUtil() {
>> + }
>> +
>> + public final static NameParser NAME_PARSER = new
>> SimpleNameParser();
>> +
>> + public static Name parseName(String name) throws
>> NamingException {
>> + return NAME_PARSER.parse(name);
>> + }
>> +
>> + public static Object resolve(String name, Object value)
>> throws NamingException {
>> + if (!(value instanceof Reference)) {
>> + return value;
>> + }
>> +
>> + Reference reference = (Reference) value;
>> +
>> + // for SimpleReference we can just call the getContext
>> method
>> + if (reference instanceof SimpleReference) {
>> + try {
>> + return ((SimpleReference) reference).getContent();
>> + } catch (NamingException e) {
>> + throw e;
>> + } catch (Exception e) {
>> + throw (NamingException) new NamingException
>> ("Could not look up : " + name).initCause(e);
>> + }
>> + }
>> +
>> + if (reference instanceof
>> org.apache.geronimo.naming.reference.SimpleReference) {
>> + try {
>> + return
>> ((org.apache.geronimo.naming.reference.SimpleReference)
>> reference).getContent();
>> + } catch (NamingException e) {
>> + throw e;
>> + } catch (Exception e) {
>> + throw (NamingException) new NamingException
>> ("Could not look up : " + name).initCause(e);
>> + }
>> + }
>> +
>> + // for normal References we have to do it the slow way
>> + try {
>> + return NamingManager.getObjectInstance(reference,
>> null, null, new Hashtable());
>> + } catch (NamingException e) {
>> + throw e;
>> + } catch (Exception e) {
>> + throw (NamingException) new NamingException("Could
>> not look up : " + name).initCause(e);
>> + }
>> + }
>> +
>> + public static final class ListEnumeration implements
>> NamingEnumeration {
>> + private final Iterator iterator;
>> +
>> + public ListEnumeration(Map localBindings) {
>> + this.iterator = localBindings.entrySet().iterator();
>> + }
>> +
>> + public boolean hasMore() {
>> + return iterator.hasNext();
>> + }
>> +
>> + public boolean hasMoreElements() {
>> + return iterator.hasNext();
>> + }
>> +
>> + public Object next() {
>> + return nextElement();
>> + }
>> +
>> + public Object nextElement() {
>> + Map.Entry entry = (Map.Entry) iterator.next();
>> + String name = (String) entry.getKey();
>> + Object value = entry.getValue();
>> + String className = null;
>> + if (value instanceof Reference) {
>> + Reference reference = (Reference) value;
>> + className = reference.getClassName();
>> + } else {
>> + className = value.getClass().getName();
>> + }
>> + return new NameClassPair(name, className);
>> + }
>> +
>> + public void close() {
>> + }
>> + }
>> +
>> + public static final class ListBindingEnumeration implements
>> NamingEnumeration {
>> + private final Iterator iterator;
>> +
>> + public ListBindingEnumeration(Map localBindings) {
>> + this.iterator = localBindings.entrySet().iterator();
>> + }
>> +
>> + public boolean hasMore() {
>> + return iterator.hasNext();
>> + }
>> +
>> + public boolean hasMoreElements() {
>> + return iterator.hasNext();
>> + }
>> +
>> + public Object next() {
>> + return nextElement();
>> + }
>> +
>> + public Object nextElement() {
>> + Map.Entry entry = (Map.Entry) iterator.next();
>> + String name = (String) entry.getKey();
>> + Object value = entry.getValue();
>> + return new ReadOnlyBinding(name, value);
>> + }
>> +
>> + public void close() {
>> + }
>> + }
>> +
>> + public static final class ReadOnlyBinding extends Binding {
>> + private final Object value;
>> +
>> + public ReadOnlyBinding(String name, Object value) {
>> + super(name, value);
>> + this.value = value;
>> + }
>> +
>> + public void setName(String name) {
>> + throw new UnsupportedOperationException("Context is
>> read only");
>> + }
>> +
>> + public String getClassName() {
>> + if (value instanceof Reference) {
>> + Reference reference = (Reference) value;
>> + return reference.getClassName();
>> + }
>> + return value.getClass().getName();
>> + }
>> +
>> + public void setClassName(String name) {
>> + throw new UnsupportedOperationException("Context is
>> read only");
>> + }
>> +
>> + public Object getObject() {
>> + try {
>> + return resolve(getName(), value);
>> + } catch (NamingException e) {
>> + throw new RuntimeException(e);
>> + }
>> + }
>> +
>> + public void setObject(Object obj) {
>> + throw new UnsupportedOperationException("Context is
>> read only");
>> + }
>> +
>> + public boolean isRelative() {
>> + return false;
>> + }
>> +
>> + public void setRelative(boolean r) {
>> + throw new UnsupportedOperationException("Context is
>> read only");
>> + }
>> + }
>> +
>> +
>> + private static final class SimpleNameParser implements
>> NameParser {
>> + private static final Properties PARSER_PROPERTIES = new
>> Properties();
>> +
>> + static {
>> + PARSER_PROPERTIES.put("jndi.syntax.direction",
>> "left_to_right");
>> + PARSER_PROPERTIES.put("jndi.syntax.separator", "/");
>> + }
>> +
>> +
>> + private SimpleNameParser() {
>> + }
>> +
>> + public Name parse(String name) throws NamingException {
>> + return new CompoundName(name, PARSER_PROPERTIES);
>> + }
>> + }
>> +
>> + public static Map createBindings(Map absoluteBindings,
>> ContextFactory factory) throws NamingException {
>> + // create a tree of Nodes using the absolute bindings
>> + Node node = buildMapTree(absoluteBindings);
>> +
>> + // convert the node tree into a tree of context objects
>> + Map localBindings = ContextUtil.createBindings(null,
>> node, factory);
>> +
>> + return localBindings;
>> + }
>> +
>> + private static Map createBindings(String nameInNameSpace,
>> Node node, ContextFactory factory) {
>> + Map bindings = new HashMap(node.size());
>> + for (Iterator iterator = node.entrySet().iterator();
>> iterator.hasNext();) {
>> + Map.Entry entry = (Map.Entry) iterator.next();
>> + String name = (String) entry.getKey();
>> + Object value = entry.getValue();
>> +
>> + // if this is a nested node we need to create a
>> context for the node
>> + if (value instanceof Node) {
>> + Node nestedNode = (Node) value;
>> +
>> + // recursive call create bindings to cause
>> building the context depth first
>> + String path = nameInNameSpace == null ? name :
>> nameInNameSpace + "/" + name;
>> +
>> + Map nestedBindings = createBindings(path,
>> nestedNode, factory);
>> + Context nestedContext = factory.createContext
>> (path, nestedBindings);
>> + bindings.put(name, nestedContext);
>> + } else {
>> + bindings.put(name, value);
>> + }
>> + }
>> + return bindings;
>> + }
>> +
>> +
>> + /**
>> + * Do nothing subclass of hashmap used to differentiate
>> between a Map in the tree an a nested element during tree building
>> + */
>> + public static final class Node extends HashMap {
>> + }
>> +
>> + public static Node buildMapTree(Map absoluteBindings) throws
>> NamingException {
>> + Node rootContext = new Node();
>> +
>> + for (Iterator iterator = absoluteBindings.entrySet
>> ().iterator(); iterator.hasNext();) {
>> + Map.Entry entry = (Map.Entry) iterator.next();
>> + String name = (String) entry.getKey();
>> + Object value = entry.getValue();
>> +
>> + Node parentContext = rootContext;
>> +
>> + Name compoundName = ContextUtil.parseName(name);
>> + for (Enumeration parts = compoundName.getAll();
>> parts.hasMoreElements(); ) {
>> + String part = (String) parts.nextElement();
>> + // the last element in the path is the name of
>> the value
>> + if (parts.hasMoreElements()) {
>> + // nest node into parent
>> + Node bindings = (Node) parentContext.get(part);
>> + if (bindings == null) {
>> + bindings = new Node();
>> + parentContext.put(part, bindings);
>> + }
>> +
>> + parentContext = bindings;
>> + }
>> + }
>> +
>> + parentContext.put(compoundName.get(compoundName.size
>> () - 1), value);
>> + }
>> + return rootContext;
>> + }
>> +}
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ImmutableContext.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/context/
>> ImmutableContext.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ImmutableContext.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/ImmutableContext.java Wed Aug 16
>> 17:50:03 2006
>> @@ -0,0 +1,136 @@
>> +/**
>> + *
>> + * Copyright 2006 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.xbean.naming.context;
>> +
>> +import org.apache.xbean.naming.reference.CachingReference;
>> +
>> +import javax.naming.Context;
>> +import javax.naming.NamingException;
>> +import javax.naming.OperationNotSupportedException;
>> +import java.util.Collections;
>> +import java.util.HashMap;
>> +import java.util.Iterator;
>> +import java.util.Map;
>> +
>> +/**
>> + *
>> + * @version $Rev: 417891 $ $Date: 2006-06-28 15:45:07 -0700 (Wed,
>> 28 Jun 2006) $
>> + */
>> +public class ImmutableContext extends AbstractReadOnlyContext {
>> + private final Map localBindings;
>> + private final Map absoluteIndex;
>> +
>> + public ImmutableContext(Map bindings) throws NamingException {
>> + this("", bindings, true);
>> + }
>> +
>> + public ImmutableContext(Map bindings, boolean
>> cacheReferences) throws NamingException {
>> + this("", bindings, cacheReferences);
>> + }
>> +
>> + public ImmutableContext(String nameInNamespace, Map bindings,
>> boolean cacheReferences) throws NamingException {
>> + super(nameInNamespace);
>> +
>> + if (cacheReferences) {
>> + bindings = CachingReference.wrapReferences(bindings);
>> + }
>> +
>> + Map localBindings = ContextUtil.createBindings(bindings,
>> this);
>> + this.localBindings = Collections.unmodifiableMap
>> (localBindings);
>> +
>> + Map globalBindings = ImmutableContext.buildAbsoluteIndex
>> ("", localBindings);
>> + this.absoluteIndex = Collections.unmodifiableMap
>> (globalBindings);
>> + }
>> +
>> + private static Map buildAbsoluteIndex(String nameInNamespace,
>> Map bindings) {
>> + String path = nameInNamespace;
>> + if (path.length() > 0) {
>> + path += "/";
>> + }
>> +
>> + Map globalBindings = new HashMap();
>> + for (Iterator iterator = bindings.entrySet().iterator();
>> iterator.hasNext();) {
>> + Map.Entry entry = (Map.Entry) iterator.next();
>> + String name = (String) entry.getKey();
>> + Object value = entry.getValue();
>> + if (value instanceof
>> ImmutableContext.NestedMapContext) {
>> + ImmutableContext.NestedMapContext nestedContext =
>> (ImmutableContext.NestedMapContext)value;
>> + globalBindings.putAll
>> (ImmutableContext.buildAbsoluteIndex
>> (nestedContext.getNameInNamespace(), nestedContext.localBindings));
>> + }
>> + globalBindings.put(path + name, value);
>> + }
>> + return globalBindings;
>> + }
>> +
>> + protected Object getDeepBinding(String name) {
>> + return absoluteIndex.get(name);
>> + }
>> +
>> + protected Map getBindings() {
>> + return localBindings;
>> + }
>> +
>> + protected void addDeepBinding(String name, Object value)
>> throws NamingException {
>> + throw new OperationNotSupportedException("Context is
>> immutable");
>> + }
>> +
>> + protected void removeDeepBinding(String name, Object value)
>> throws NamingException {
>> + throw new OperationNotSupportedException("Context is
>> immutable");
>> + }
>> +
>> + public Context createContext(String path, Map bindings) {
>> + return new NestedMapContext(path, bindings);
>> + }
>> +
>> + /**
>> + * Nested context which shares the absolute index map in
>> MapContext.
>> + */
>> + public final class NestedMapContext extends
>> AbstractReadOnlyContext {
>> + private final Map localBindings;
>> + private final String pathWithSlash;
>> +
>> + public NestedMapContext(String path, Map bindings) {
>> + super(ImmutableContext.this.getNameInNamespace(path));
>> +
>> + if (!path.endsWith("/")) path += "/";
>> + this.pathWithSlash = path;
>> +
>> + this.localBindings = Collections.unmodifiableMap
>> (bindings);
>> + }
>> +
>> + protected Object getDeepBinding(String name) {
>> + String absoluteName = pathWithSlash + name;
>> + return absoluteIndex.get(absoluteName);
>> + }
>> +
>> + protected Map getBindings() {
>> + return localBindings;
>> + }
>> +
>> + protected void addDeepBinding(String name, Object value)
>> throws NamingException {
>> + throw new OperationNotSupportedException("Context is
>> immutable");
>> + }
>> +
>> + protected void removeDeepBinding(String name, Object
>> value) throws NamingException {
>> + throw new OperationNotSupportedException("Context is
>> immutable");
>> + }
>> +
>> + public Context createContext(String path, Map bindings) {
>> + return new NestedMapContext(path, bindings);
>> + }
>> + }
>> +}
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/UnmodifiableContext.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/context/
>> UnmodifiableContext.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/UnmodifiableContext.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/context/UnmodifiableContext.java Wed Aug
>> 16 17:50:03 2006
>> @@ -0,0 +1,228 @@
>> +/**
>> + *
>> + * Copyright 2006 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.xbean.naming.context;
>> +
>> +import
>> edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicReference
>> ;
>> +import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock;
>> +import
>> edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock;
>> +import org.apache.xbean.naming.reference.CachingReference;
>> +
>> +import javax.naming.NameAlreadyBoundException;
>> +import javax.naming.NamingException;
>> +import javax.naming.Context;
>> +import javax.naming.NameNotFoundException;
>> +import java.util.Collections;
>> +import java.util.HashMap;
>> +import java.util.Iterator;
>> +import java.util.Map;
>> +
>> +/**
>> + * @version $Rev: 417891 $ $Date: 2006-06-28 15:45:07 -0700 (Wed,
>> 28 Jun 2006) $
>> + */
>> +public class UnmodifiableContext extends AbstractReadOnlyContext {
>> + private final Lock writeLock = new ReentrantLock();
>> + private final AtomicReference bindingsRef;
>> + private final AtomicReference indexRef;
>> + public static final int MAX_WRITE_ATTEMPTS = 3;
>> +
>> + public UnmodifiableContext(Map bindings) throws
>> NamingException {
>> + this("", bindings, true);
>> + }
>> +
>> + public UnmodifiableContext(Map bindings, boolean
>> cacheReferences) throws NamingException {
>> + this("", bindings, cacheReferences);
>> + }
>> +
>> + public UnmodifiableContext(String nameInNamespace, Map
>> bindings, boolean cacheReferences) throws NamingException {
>> + super(nameInNamespace);
>> +
>> + if (cacheReferences) {
>> + bindings = CachingReference.wrapReferences(bindings);
>> + }
>> +
>> + Map localBindings = ContextUtil.createBindings(bindings,
>> this);
>> +
>> + this.bindingsRef = new AtomicReference
>> (Collections.unmodifiableMap(localBindings));
>> + this.indexRef = new AtomicReference
>> (Collections.unmodifiableMap(buildIndex("", localBindings)));
>> + }
>> +
>> + protected void addBinding(String name, Object value) throws
>> NamingException {
>> + writeLock.lock();
>> + try {
>> + Map bindings = (Map) bindingsRef.get();
>> + if (bindings.containsKey(name)) {
>> + throw new NameAlreadyBoundException(name);
>> + }
>> +
>> + Map newBindings = new HashMap(bindings);
>> + newBindings.put(name,value);
>> + bindingsRef.set(newBindings);
>> +
>> + Map newIndex = addToIndex(name, value);
>> + indexRef.set(newIndex);
>> + } finally {
>> + writeLock.unlock();
>> + }
>> + }
>> +
>> + private Map addToIndex(String name, Object value) {
>> + Map index = (Map) indexRef.get();
>> + Map newIndex = new HashMap(index);
>> + newIndex.put(name, value);
>> + if (value instanceof NestedMapContext) {
>> + NestedMapContext nestedcontext = (NestedMapContext)
>> value;
>> + Map newIndexValues = buildIndex(name,
>> nestedcontext.getBindings());
>> + newIndex.putAll(newIndexValues);
>> + }
>> + return newIndex;
>> + }
>> +
>> + protected void removeBinding(String name) throws
>> NamingException {
>> + writeLock.lock();
>> + try {
>> + Map bindings = (Map) bindingsRef.get();
>> + if (!bindings.containsKey(name)) {
>> + throw new NameNotFoundException(name);
>> + }
>> +
>> + Map newBindings = new HashMap(bindings);
>> + newBindings.remove(name);
>> + bindingsRef.set(newBindings);
>> +
>> + Map newIndex = removeFromIndex(name);
>> + indexRef.set(newIndex);
>> + } finally {
>> + writeLock.unlock();
>> + }
>> + }
>> +
>> + private Map removeFromIndex(String name) {
>> + Map index = (Map) indexRef.get();
>> + Map newIndex = new HashMap(index);
>> + Object oldValue = newIndex.remove(name);
>> + if (oldValue instanceof NestedMapContext) {
>> + NestedMapContext nestedcontext = (NestedMapContext)
>> oldValue;
>> + Map removedIndexValues = buildIndex(name,
>> nestedcontext.getBindings());
>> + for (Iterator iterator = removedIndexValues.keySet
>> ().iterator(); iterator.hasNext();) {
>> + String key = (String) iterator.next();
>> + newIndex.remove(key);
>> + }
>> + }
>> + return newIndex;
>> + }
>> +
>> + public Context createContext(String path, Map bindings) {
>> + return new NestedMapContext(path,bindings);
>> + }
>> +
>> + private static Map buildIndex(String nameInNamespace, Map
>> bindings) {
>> + String path = nameInNamespace;
>> + if (path.length() > 0 && !path.endsWith("/")) {
>> + path += "/";
>> + }
>> +
>> + Map absoluteIndex = new HashMap();
>> + for (Iterator iterator = bindings.entrySet().iterator();
>> iterator.hasNext();) {
>> + Map.Entry entry = (Map.Entry) iterator.next();
>> + String name = (String) entry.getKey();
>> + Object value = entry.getValue();
>> + if (value instanceof
>> UnmodifiableContext.NestedMapContext) {
>> + UnmodifiableContext.NestedMapContext
>> nestedContext = (UnmodifiableContext.NestedMapContext)value;
>> + absoluteIndex.putAll
>> (UnmodifiableContext.buildIndex(nestedContext.pathWithSlash,
>> nestedContext.getBindings()));
>> + }
>> + absoluteIndex.put(path + name, value);
>> + }
>> + return absoluteIndex;
>> + }
>> +
>> + protected Object getDeepBinding(String name) {
>> + Map index = (Map) indexRef.get();
>> + return index.get(name);
>> + }
>> +
>> + protected Map getBindings() {
>> + Map bindings = (Map) bindingsRef.get();
>> + return bindings;
>> + }
>> +
>> + /**
>> + * Nested context which shares the absolute index map in
>> MapContext.
>> + */
>> + public final class NestedMapContext extends
>> AbstractReadOnlyContext {
>> + private final AtomicReference bindingsRef;
>> + private final String pathWithSlash;
>> +
>> + public NestedMapContext(String path, String key, Object
>> value) {
>> + this(path, Collections.singletonMap(key, value));
>> + }
>> +
>> + public NestedMapContext(String path, Map bindings) {
>> + super(UnmodifiableContext.this.getNameInNamespace
>> (path));
>> +
>> + if (!path.endsWith("/")) path += "/";
>> + this.pathWithSlash = path;
>> +
>> + this.bindingsRef = new AtomicReference
>> (Collections.unmodifiableMap(bindings));
>> + }
>> +
>> + public Context createContext(String path, Map bindings) {
>> + return new NestedMapContext(path, bindings);
>> + }
>> +
>> + protected Object getDeepBinding(String name) {
>> + String absoluteName = pathWithSlash + name;
>> + return UnmodifiableContext.this.getDeepBinding
>> (absoluteName);
>> + }
>> +
>> + protected Map getBindings() {
>> + Map bindings = (Map) bindingsRef.get();
>> + return bindings;
>> + }
>> +
>> + protected void addBinding(String name, Object value) {
>> + writeLock.lock();
>> + try {
>> + Map currentBindings = (Map) bindingsRef.get();
>> + Map newBindings = new HashMap(currentBindings);
>> + newBindings.put(name, value);
>> + newBindings = Collections.unmodifiableMap
>> (newBindings);
>> + bindingsRef.set(newBindings);
>> +
>> + Map newIndex = addToIndex(name, value);
>> + indexRef.set(newIndex);
>> + } finally {
>> + writeLock.unlock();
>> + }
>> + }
>> +
>> + protected void removeBinding(String name) {
>> + writeLock.lock();
>> + try {
>> + Map currentBindings = (Map) bindingsRef.get();
>> + Map newBindings = new HashMap(currentBindings);
>> + newBindings.remove(name);
>> + newBindings = Collections.unmodifiableMap
>> (newBindings);
>> + bindingsRef.set(newBindings);
>> +
>> + Map newIndex = removeFromIndex(name);
>> + indexRef.set(newIndex);
>> + } finally {
>> + writeLock.unlock();
>> + }
>> + }
>> + }
>> +}
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/global/GlobalContextManager.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/global/
>> GlobalContextManager.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/global/GlobalContextManager.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/global/GlobalContextManager.java Wed Aug
>> 16 17:50:03 2006
>> @@ -0,0 +1,106 @@
>> +/**
>> + *
>> + * Copyright 2006 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.xbean.naming.global;
>> +
>> +import org.apache.xbean.naming.context.ContextFlyweight;
>> +
>> +import javax.naming.Context;
>> +import javax.naming.Name;
>> +import javax.naming.OperationNotSupportedException;
>> +import javax.naming.NoInitialContextException;
>> +import javax.naming.spi.InitialContextFactory;
>> +import javax.naming.spi.ObjectFactory;
>> +import java.util.Hashtable;
>> +
>> +/**
>> + * The GlobalContextManager contains the static global context
>> object. JNDI effectively requires a single global static
>> + * to resolve the root context, and this class manages that
>> static. This class is also an URLContextFactory and
>> + * an InitialContextFactory which returns the registered global
>> context.
>> + *
>> + * To use this factory simply set the following system property
>> or pass the property in the environment to new InitialContext:
>> + *
>> + * java.naming.factory.initial =
>> org.apache.xbean.naming.global.GlobalContextManager
>> + *
>> + * @version $Rev$ $Date$
>> + */
>> +public class GlobalContextManager implements ObjectFactory,
>> InitialContextFactory {
>> + private static Context DEFAULT_CONTEXT = new
>> DefaultGlobalContext();
>> + private static Context globalContext;
>> +
>> + /**
>> + * Gets the global context. This context is the root of all
>> contexts and will contain entries such as "java:comp".
>> + * @return the global context
>> + */
>> + public static synchronized Context getGlobalContext() {
>> + if (globalContext == null) return DEFAULT_CONTEXT;
>> + return globalContext;
>> + }
>> +
>> + /**
>> + * Sets the global context. To invoke this method the calling
>> code must have "setFactory" RuntimePermission.
>> + * @param globalContext the new global context
>> + */
>> + public static synchronized void setGlobalContext(Context
>> globalContext) {
>> + SecurityManager security = System.getSecurityManager();
>> + if (security != null) {
>> + security.checkSetFactory();
>> + }
>> + GlobalContextManager.globalContext = globalContext;
>> + }
>> +
>> + /**
>> + * Returns the Context registered with the GlobalManager.
>> This method is equivalent to:
>> + *
>> + * return GlobalContextManager.getGlobalContext();
>> + *
>> + * @param obj must be null
>> + * @param name ignored
>> + * @param nameCtx ignored
>> + * @param environment ignored
>> + * @return GlobalManager.getGlobalContext()
>> + * @throws javax.naming.OperationNotSupportedException if obj
>> is not null
>> + */
>> + public Object getObjectInstance(Object obj, Name name,
>> Context nameCtx, Hashtable environment) throws Exception {
>> + if (obj == null) {
>> + return GlobalContextManager.getGlobalContext();
>> + } else {
>> + throw new OperationNotSupportedException();
>> + }
>> + }
>> +
>> +
>> + /**
>> + * Returns the Context registered with the GlobalManager.
>> This method is equivalent to:
>> + *
>> + * return GlobalContextManager.getGlobalContext();
>> + *
>> + * @param environment ignored
>> + * @return GlobalContextManager.getGlobalContext()
>> + */
>> + public Context getInitialContext(Hashtable environment) {
>> + return GlobalContextManager.getGlobalContext();
>> + }
>> +
>> + private static class DefaultGlobalContext extends
>> ContextFlyweight {
>> + protected Context getContext() throws
>> NoInitialContextException {
>> + synchronized (GlobalContextManager.class) {
>> + if (globalContext == null) throw new
>> NoInitialContextException("Global context has not been set");
>> + return globalContext;
>> + }
>> + }
>> + }
>> +}
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/java/javaURLContextFactory.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/java/
>> javaURLContextFactory.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/java/javaURLContextFactory.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/java/javaURLContextFactory.java Wed Aug 16
>> 17:50:03 2006
>> @@ -0,0 +1,28 @@
>> +/**
>> + *
>> + * Copyright 2003-2004 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +
>> +package org.apache.xbean.naming.java;
>> +
>> +import org.apache.xbean.naming.global.GlobalContextManager;
>> +
>> +/**
>> + * URLContextFactory for the java: namespace.
>> + *
>> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat,
>> 10 Dec 2005) $
>> + */
>> +public class javaURLContextFactory extends GlobalContextManager {
>> +}
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/reference/CachingReference.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/reference/
>> CachingReference.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/reference/CachingReference.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/reference/CachingReference.java Wed Aug 16
>> 17:50:03 2006
>> @@ -0,0 +1,68 @@
>> +/**
>> + *
>> + * Copyright 2006 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.xbean.naming.reference;
>> +
>> +import org.apache.xbean.naming.context.ContextUtil;
>> +
>> +import javax.naming.Reference;
>> +import javax.naming.NamingException;
>> +import java.util.Map;
>> +import java.util.LinkedHashMap;
>> +import java.util.Iterator;
>> +
>> +/**
>> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat,
>> 10 Dec 2005) $
>> + */
>> +public class CachingReference extends SimpleReference {
>> + public static Map wrapReferences(Map bindings) {
>> + LinkedHashMap newBindings = new LinkedHashMap(bindings);
>> + for (Iterator iterator = bindings.entrySet().iterator();
>> iterator.hasNext();) {
>> + Map.Entry entry = (Map.Entry) iterator.next();
>> + String name = (String) entry.getKey();
>> + Object value = entry.getValue();
>> + if (value instanceof Reference && !(value instanceof
>> CachingReference)) {
>> + newBindings.put(name, new CachingReference(name,
>> (Reference)value));
>> + }
>> + }
>> + return newBindings;
>> + }
>> +
>> + private final Object lock = new Object();
>> + private final String fullName;
>> + private final Reference reference;
>> + private final String className;
>> + private Object value;
>> +
>> + public CachingReference(String fullName, Reference reference) {
>> + this.fullName = fullName;
>> + this.reference = reference;
>> + className = reference.getClassName();
>> + }
>> +
>> + public Object getContent() throws NamingException {
>> + synchronized(lock) {
>> + if (value == null) {
>> + value = ContextUtil.resolve(fullName, reference);
>> + }
>> + return value;
>> + }
>> + }
>> +
>> + public String getClassName() {
>> + return className;
>> + }
>> +}
>>
>> Added: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/reference/SimpleReference.java
>> URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/
>> xbean-naming/src/main/java/org/apache/xbean/naming/reference/
>> SimpleReference.java?rev=432088&view=auto
>> =====================================================================
>> =========
>> --- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/reference/SimpleReference.java (added)
>> +++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/
>> org/apache/xbean/naming/reference/SimpleReference.java Wed Aug 16
>> 17:50:03 2006
>> @@ -0,0 +1,141 @@
>> +/**
>> + *
>> + * Copyright 2004 The Apache Software Foundation
>> + *
>> + * Licensed under the Apache License, Version 2.0 (the "License");
>> + * you may not use this file except in compliance with the License.
>> + * You may obtain a copy of the License at
>> + *
>> + * http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> software
>> + * distributed under the License is distributed on an "AS IS"
>> BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
>> or implied.
>> + * See the License for the specific language governing
>> permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.xbean.naming.reference;
>> +
>> +import java.util.Enumeration;
>> +import java.util.Hashtable;
>> +import java.util.NoSuchElementException;
>> +import javax.naming.Context;
>> +import javax.naming.Name;
>> +import javax.naming.RefAddr;
>> +import javax.naming.Reference;
>> +import javax.naming.NamingException;
>> +import javax.naming.spi.ObjectFactory;
>> +
>> +/**
>> + * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat,
>> 10 Dec 2005) $
>> + */
>> +public abstract class SimpleReference extends Reference {
>> + private static final Enumeration EMPTY_ENUMERATION = new
>> Enumeration() {
>> + public boolean hasMoreElements() {
>> + return false;
>> + }
>> +
>> + public Object nextElement() {
>> + return new NoSuchElementException();
>> + }
>> + };
>> +
>> + public SimpleReference() {
>> + super(null);
>> + }
>> +
>> + /**
>> + * Gets the actual referenced Object.
>> + * @return the referenced object
>> + */
>> + public abstract Object getContent() throws NamingException;
>> +
>> + /**
>> + * We will atleast return an Object. Subclasses may want to
>> provide a more specific class.
>> + * @return "java.lang.Object"
>> + */
>> + public String getClassName() {
>> + return "java.lang.Object";
>> + }
>> +
>> + /**
>> + * If the JNDI context does not understand simple references,
>> this method will be called
>> + * to obtain the class name of a factory. This factory in
>> turn understands the simple
>> + * reference. This style is much slower because JNDI will
>> use reflection to load and
>> + * create this class.
>> + * @return
>> + */
>> + public final String getFactoryClassName() {
>> + return SimpleObjectFactory.class.getName();
>> + }
>> +
>> + //
>> + // Disabled methods that we no longer need
>> + //
>> + public final String getFactoryClassLocation() {
>> + return null;
>> + }
>> +
>> + public final RefAddr get(String addrType) {
>> + return null;
>> + }
>> +
>> + public final RefAddr get(int posn) {
>> + throw new ArrayIndexOutOfBoundsException(posn);
>> + }
>> +
>> + public final Enumeration getAll() {
>> + return EMPTY_ENUMERATION;
>> + }
>> +
>> + public final int size() {
>> + return 0;
>> + }
>> +
>> + public final void add(RefAddr addr) {
>> + throw new UnsupportedOperationException("SimpleReference
>> has no addresses so none can be added");
>> + }
>> +
>> + public final void add(int posn, RefAddr addr) {
>> + throw new UnsupportedOperationException("SimpleReference
>> has no addresses so none can be added");
>> + }
>> +
>> + public final Object remove(int posn) {
>> + throw new ArrayIndexOutOfBoundsException(posn);
>> + }
>> +
>> + public final void clear() {
>> + }
>> +
>> + //
>> + // Reset the java.lang.Object methods back to default
>> implementations
>> + //
>> + public boolean equals(Object obj) {
>> + return this == obj;
>> + }
>> +
>> + public int hashCode() {
>> + return System.identityHashCode(this);
>> + }
>> +
>> + public String toString() {
>> + return getClass().getName() + "@" + Integer.toHexString
>> (hashCode());
>> + }
>> +
>> + public Object clone() {
>> + throw new UnsupportedOperationException("SimpleReference
>> can not be cloned");
>> + }
>> +
>> + /**
>> + * Simply calls getContent() on the SimpleReference
>> + */
>> + public static final class SimpleObjectFactory implements
>> ObjectFactory {
>> + public Object getObjectInstance(Object obj, Name name,
>> Context nameCtx, Hashtable environment) throws Exception {
>> + if (obj instanceof SimpleReference) {
>> + SimpleReference reference = (SimpleReference) obj;
>> + return reference.getContent();
>> + }
>> + return null;
>> + }
>> + }
>> +}
>>
>>
>>
>
>
> --
> Cheers,
> Guillaume Nodet