geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r776407 - in /geronimo/xbean/trunk/xbean-naming/src: main/java/org/apache/xbean/naming/context/ test/java/org/apache/xbean/naming/context/ test/java/org/apache/xbean/naming/referenceable/
Date Tue, 19 May 2009 18:37:13 GMT
Author: djencks
Date: Tue May 19 18:37:13 2009
New Revision: 776407

URL: http://svn.apache.org/viewvc?rev=776407&view=rev
Log:
XBEAN-127 support Referenceable

Added:
    geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
  (with props)
    geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/
    geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/Foo.java
  (with props)
    geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/FooFactory.java
  (with props)
Modified:
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java

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=776407&r1=776406&r2=776407&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
Tue May 19 18:37:13 2009
@@ -27,6 +27,7 @@
 import javax.naming.ContextNotEmptyException;
 import javax.naming.NameAlreadyBoundException;
 import javax.naming.NamingException;
+import javax.naming.Referenceable;
 
 import org.apache.xbean.naming.reference.CachingReference;
 
@@ -83,6 +84,13 @@
     }
 
     protected void addBinding(AtomicReference<Map<String, Object>> bindingsRef,
String name, String nameInNamespace, Object value, boolean rebind) throws NamingException
{
+        if (value instanceof Referenceable) {
+            value = ((Referenceable)value).getReference();
+        }
+        if (cacheReferences) {
+            value = CachingReference.wrapReference(getNameInNamespace(name), value);
+        }
+
         writeLock.lock();
         try {
             Map<String, Object> bindings = bindingsRef.get();
@@ -90,10 +98,6 @@
             if (!rebind && bindings.containsKey(name)) {
                 throw new NameAlreadyBoundException(name);
             }
-            if (cacheReferences) {
-                value = CachingReference.wrapReference(getNameInNamespace(name), value);
-            }
-
             Map<String, Object> newBindings = new HashMap<String, Object>(bindings);
             newBindings.put(name,value);
             bindingsRef.set(newBindings);

Added: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java?rev=776407&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
(added)
+++ geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
Tue May 19 18:37:13 2009
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.xbean.naming.referenceable.Foo;
+import org.apache.xbean.naming.referenceable.FooFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceableTest extends AbstractContextTest {
+    
+    public void testReferenceable() throws Exception {
+        Context context = new WritableContext();
+        context.createSubcontext("bar");
+
+        Foo foo1 = new Foo("foo1");
+        context.bind("bar/foo1", foo1);
+        Object o1 = context.lookup("bar/foo1");
+        assertEquals(foo1, o1);
+        assertNotSame(foo1, o1);
+    }
+    public void testReferenceable2() throws Exception {
+        Context context = new WritableContext();
+        context.createSubcontext("bar");
+
+        Foo foo1 = new Foo("foo1");
+        FooFactory fooFactory1 = new FooFactory(foo1);
+        context.bind("bar/foo1", fooFactory1);
+        Object o1 = context.lookup("bar/foo1");
+        assertEquals(foo1, o1);
+        assertNotSame(foo1, o1);
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/Foo.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/Foo.java?rev=776407&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/Foo.java
(added)
+++ geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/Foo.java
Tue May 19 18:37:13 2009
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.referenceable;
+
+import javax.naming.Referenceable;
+import javax.naming.Reference;
+import javax.naming.NamingException;
+import javax.naming.StringRefAddr;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Foo implements Referenceable {
+
+    private final String value;
+
+    public Foo(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public Reference getReference() throws NamingException {
+        return new Reference(Foo.class.getName(),
+                new StringRefAddr("value", value),
+                FooFactory.class.getName(),
+                null);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        Foo foo = (Foo) o;
+
+        if (value != null ? !value.equals(foo.value) : foo.value != null) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return value != null ? value.hashCode() : 0;
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/Foo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/Foo.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/Foo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/FooFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/FooFactory.java?rev=776407&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/FooFactory.java
(added)
+++ geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/FooFactory.java
Tue May 19 18:37:13 2009
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.referenceable;
+
+import java.util.Hashtable;
+
+import javax.naming.spi.ObjectFactory;
+import javax.naming.Referenceable;
+import javax.naming.Reference;
+import javax.naming.NamingException;
+import javax.naming.Name;
+import javax.naming.Context;
+import javax.naming.RefAddr;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class FooFactory implements Referenceable, ObjectFactory {
+
+    private Foo foo;
+
+    public FooFactory() {
+    }
+
+    public FooFactory(Foo foo) {
+        this.foo = foo;
+    }
+
+    public Foo getFoo() {
+        return foo;
+    }
+
+    public void setFoo(Foo foo) {
+        this.foo = foo;
+    }
+
+    public Reference getReference() throws NamingException {
+        return foo.getReference();
+    }
+
+    public Object getObjectInstance(Object o, Name name, Context context, Hashtable<?,
?> hashtable) throws Exception {
+        if (o instanceof Reference) {
+            Reference ref = (Reference) o;
+            if (Foo.class.getName().equals(ref.getClassName())) {
+                RefAddr addr = ref.get("value");
+                return new Foo((String) addr.getContent());
+            }
+        }
+        return null;
+    }
+    
+}

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/FooFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/FooFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/referenceable/FooFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message