geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r777752 - in /geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming: context/AbstractContext.java context/ContextUtil.java context/ImmutableContext.java context/WritableContext.java reference/CachingReference.java
Date Sat, 23 May 2009 00:30:20 GMT
Author: djencks
Date: Sat May 23 00:30:19 2009
New Revision: 777752

URL: http://svn.apache.org/viewvc?rev=777752&view=rev
Log:
XBEAN-130 pass name and context into NamingManager.getObjectInstance()

Modified:
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java?rev=777752&r1=777751&r2=777752&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
Sat May 23 00:30:19 2009
@@ -113,7 +113,7 @@
         // try to look up the name directly (this is the fastest path)
         Object directLookup = getDeepBinding(stringName);
         if (directLookup != null) {
-            return ContextUtil.resolve(stringName, directLookup);
+            return ContextUtil.resolve(directLookup, stringName, parsedName, this);
         }
 
         // if the parsed name has no parts, they are asking for the current context
@@ -137,7 +137,7 @@
 
             // if the name only had one part, we've looked up everything
             if (parsedName.size() == 1) {
-                localValue = ContextUtil.resolve(stringName, localValue);
+                localValue = ContextUtil.resolve(localValue, stringName, parsedName, this);
                 return localValue;
             }
 
@@ -719,7 +719,7 @@
 
     protected NamingEnumeration<Binding> listBindings() throws NamingException {
         Map<String, Object> bindings = getBindings();
-        return new ContextUtil.ListBindingEnumeration(bindings);
+        return new ContextUtil.ListBindingEnumeration(bindings, this);
     }
 
     public NamingEnumeration<NameClassPair> list(String name) throws NamingException
{

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java?rev=777752&r1=777751&r2=777752&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
Sat May 23 00:30:19 2009
@@ -48,7 +48,7 @@
         return NAME_PARSER.parse(name);
     }
 
-    public static Object resolve(String name, Object value) throws NamingException {
+    public static Object resolve(Object value, String stringName, Name parsedName, Context
nameCtx) throws NamingException {
         if (!(value instanceof Reference)) {
             return value;
         }
@@ -62,17 +62,20 @@
             } catch (NamingException e) {
                 throw e;
             } catch (Exception e) {
-                throw (NamingException) new NamingException("Could not look up : " + name).initCause(e);
+                throw (NamingException) new NamingException("Could not look up : " + stringName
== null? parsedName.toString(): stringName).initCause(e);
             }
         }
 
         // for normal References we have to do it the slow way
         try {
-            return NamingManager.getObjectInstance(reference, null, null, new Hashtable());
+            if (parsedName == null) {
+                parsedName = NAME_PARSER.parse(stringName);
+            }
+            return NamingManager.getObjectInstance(reference, parsedName, nameCtx, new Hashtable());
         } catch (NamingException e) {
             throw e;
         } catch (Exception e) {
-            throw (NamingException) new NamingException("Could not look up : " + name).initCause(e);
+            throw (NamingException) new NamingException("Could not look up : " + stringName
== null? parsedName.toString(): stringName).initCause(e);
         }
     }
 
@@ -135,9 +138,11 @@
 
     public static final class ListBindingEnumeration implements NamingEnumeration<Binding>
{
         private final Iterator iterator;
+        private final Context context;
 
-        public ListBindingEnumeration(Map localBindings) {
+        public ListBindingEnumeration(Map localBindings, Context context) {
             this.iterator = localBindings.entrySet().iterator();
+            this.context = context;
         }
 
         public boolean hasMore() {
@@ -156,7 +161,7 @@
             Map.Entry entry = (Map.Entry) iterator.next();
             String name = (String) entry.getKey();
             Object value = entry.getValue();
-            return new ReadOnlyBinding(name, value);
+            return new ReadOnlyBinding(name, value, context);
         }
 
         public void close() {
@@ -165,10 +170,12 @@
 
     public static final class ReadOnlyBinding extends Binding {
         private final Object value;
+        private final Context context;
 
-        public ReadOnlyBinding(String name, Object value) {
+        public ReadOnlyBinding(String name, Object value, Context context) {
             super(name, value);
             this.value = value;
+            this.context = context;
         }
 
         public void setName(String name) {
@@ -189,7 +196,7 @@
 
         public Object getObject() {
             try {
-                return resolve(getName(), value);
+                return resolve(value, getName(), null, context);
             } catch (NamingException e) {
                 throw new RuntimeException(e);
             }

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java?rev=777752&r1=777751&r2=777752&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
Sat May 23 00:30:19 2009
@@ -47,7 +47,7 @@
         super(nameInNamespace, ContextAccess.UNMODIFIABLE);
 
         if (cacheReferences) {
-            bindings = CachingReference.wrapReferences(bindings);
+            bindings = CachingReference.wrapReferences(bindings, this);
         }
 
         Map<String, Object> localBindings = ContextUtil.createBindings(bindings, this);

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java?rev=777752&r1=777751&r2=777752&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
Sat May 23 00:30:19 2009
@@ -71,7 +71,7 @@
 
         this.cacheReferences = cacheReferences;
         if (this.cacheReferences) {
-            bindings = CachingReference.wrapReferences(bindings);
+            bindings = CachingReference.wrapReferences(bindings, this);
         }
 
         Map<String, Object> localBindings = ContextUtil.createBindings(bindings, this);
@@ -111,7 +111,7 @@
 
         }
         if (cacheReferences) {
-            value = CachingReference.wrapReference(getNameInNamespace(name), value);
+            value = CachingReference.wrapReference(name, value, this);
         }
 
         writeLock.lock();

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java?rev=777752&r1=777751&r2=777752&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/reference/CachingReference.java
Sat May 23 00:30:19 2009
@@ -21,6 +21,7 @@
 
 import javax.naming.NamingException;
 import javax.naming.Reference;
+import javax.naming.Context;
 
 import org.apache.xbean.naming.context.ContextUtil;
 
@@ -28,41 +29,44 @@
  * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
  */
 public class CachingReference extends SimpleReference {
-    public static Object wrapReference(String fullName, Object value) {
+
+    public static Object wrapReference(String fullName, Object value, Context context) {
         if (value instanceof Reference && !(value instanceof CachingReference)) {
-            return new CachingReference(fullName, (Reference)value);
+            return new CachingReference(fullName, (Reference)value, context);
         }
         return value;
     }
 
-    public static Map<String, Object> wrapReferences(Map<String, Object> bindings)
{
+    public static Map<String, Object> wrapReferences(Map<String, Object> bindings,
Context context) {
         LinkedHashMap<String, Object> newBindings = new LinkedHashMap<String, Object>(bindings);
         for (Map.Entry<String, Object> entry : bindings.entrySet()) {
             String name = entry.getKey();
             Object value = entry.getValue();
             if (value instanceof Reference && !(value instanceof CachingReference))
{
-                newBindings.put(name, new CachingReference(name, (Reference) value));
+                newBindings.put(name, new CachingReference(name, (Reference) value, context));
             }
         }
         return newBindings;
     }
 
     private final Object lock = new Object();
-    private final String fullName;
+    private final String stringName;
+    private final Context context;
     private final Reference reference;
     private final String className;
     private Object value;
 
-    public CachingReference(String fullName, Reference reference) {
-        this.fullName = fullName;
+    public CachingReference(String fullName, Reference reference, Context context) {
+        this.stringName = fullName;
         this.reference = reference;
         className = reference.getClassName();
+        this.context = context;
     }
 
     public Object getContent() throws NamingException {
         synchronized(lock) {
             if (value == null) {
-                value = ContextUtil.resolve(fullName, reference);
+                value = ContextUtil.resolve(reference, stringName, null, context);
             }
             return value;
         }



Mime
View raw message