[picocontainer-scm] [5681] java/2.x/trunk/pico/gems/src/test/org/picocontainer/gems/jndi: JNDI fixup as per PICO-370

paul-yCVjj/[email protected]
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <[email protected]>
Revision 5681
Author paul
Date 2010-05-24 08:25:45 -0500 (Mon, 24 May 2010)

Log Message

JNDI fixup as per PICO-370

Modified Paths

- java/2.x/trunk/pico/gems/src/java/org/picocontainer/gems/jndi/JNDIProvided.java

- java/2.x/trunk/pico/gems/src/test/org/picocontainer/gems/jndi/JNDIObjectReferenceTestCase.java

Diff

Modified: java/2.x/trunk/pico/gems/src/java/org/picocontainer/gems/jndi/JNDIProvided.java (5680 => 5681)

--- java/2.x/trunk/pico/gems/src/java/org/picocontainer/gems/jndi/JNDIProvided.java 2010-04-16 20:58:55 UTC (rev 5680)
+++ java/2.x/trunk/pico/gems/src/java/org/picocontainer/gems/jndi/JNDIProvided.java 2010-05-24 13:25:45 UTC (rev 5681)
@@ -20,49 +20,52 @@
import org.picocontainer.PicoVisitor;

/**
- * represents dependency provided via JNDI. This dependency is not
+ * Represents dependency provided via JNDI. This dependency is not
* to be managed by container at all, so there is no lifecycle, no
* monitoring etc.
* @author Konstantin Pribluda
*
*/
@SuppressWarnings("serial")
-public class JNDIProvided<T> implements ComponentAdapter<T> , Serializable {
+public class JNDIProvided<T> implements ComponentAdapter<T>, Serializable {

-
- JNDIObjectReference<T> jndiReference;
+ private JNDIObjectReference<T> jndiReference;
+ private Class<T> type;
+ private Object componentKey;

- Object componentKey;
-
/**
- * create adapter with specified key and reference
+ * Create adapter with specified key and reference
* @param componentKey component key
* @param reference JNDI reference storing component
+ * @param type the type that the JNDIObjectReference will return.
*/
- public JNDIProvided(final Object componentKey,final JNDIObjectReference<T> reference) {
+ public JNDIProvided(final Object componentKey,final JNDIObjectReference<T> reference, final Class<T> type) {
this.componentKey = componentKey;
this.jndiReference = reference;
+ this.type = type;
}

/**
- * create adapter with JNDI reference. referenced object class will be
+ * Create adapter with JNDI reference. referenced object class will be
* takes as key
* @param reference JNDI reference storing component
+ * @param type the type that the JNDIObjectReference will return.
*/
- public JNDIProvided(final JNDIObjectReference<T> reference) {
- this(reference.get().getClass(),reference);
+ public JNDIProvided(final JNDIObjectReference<T> reference, Class<T> type) {
+ this(reference.get().getClass(),reference, type);
}

/**
- * create adapter based on JNDI name. I leave this unchecked because
+ * Create adapter based on JNDI name. I leave this unchecked because
* type is really not known at this time
* @param jndiName name to be used
- * @throws NamingException will be thrown if something goes
+ * @param type the type that the JNDIObjectReference will return.
+ * @throws NamingException will be thrown if something goes
* wrong in JNDI
*/
@SuppressWarnings("unchecked")
- public JNDIProvided(final String jndiName) throws NamingException {
- this(new JNDIObjectReference(jndiName));
+ public JNDIProvided(final String jndiName, Class<T> type) throws NamingException {
+ this(new JNDIObjectReference(jndiName), type);
}

public Object getComponentKey() {
@@ -71,7 +74,7 @@

@SuppressWarnings("unchecked")
public Class<? extends T> getComponentImplementation() {
- return (Class<? extends T>) jndiReference.get().getClass();
+ return type;
}

public T getComponentInstance(final PicoContainer container) throws PicoCompositionException {
@@ -79,7 +82,7 @@
}

/**
- * retrieve instance out of JNDI
+ * Retrieve instance out of JNDI
*/
public T getComponentInstance(final PicoContainer container, final Type into)
throws PicoCompositionException {
@@ -88,12 +91,12 @@

/**
* we have nothing to verify here
- */
+ */
public void verify(final PicoContainer container) throws PicoCompositionException {
}

/**
- * as there is no puprose of proceeding further down,
+ * As there is no puprose of proceeding further down,
* we do nothing here
*/
public void accept(final PicoVisitor visitor) {

Modified: java/2.x/trunk/pico/gems/src/test/org/picocontainer/gems/jndi/JNDIObjectReferenceTestCase.java (5680 => 5681)

--- java/2.x/trunk/pico/gems/src/test/org/picocontainer/gems/jndi/JNDIObjectReferenceTestCase.java 2010-04-16 20:58:55 UTC (rev 5680)
+++ java/2.x/trunk/pico/gems/src/test/org/picocontainer/gems/jndi/JNDIObjectReferenceTestCase.java 2010-05-24 13:25:45 UTC (rev 5681)
@@ -9,17 +9,16 @@

package org.picocontainer.gems.jndi;

-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import org.junit.Before;
+import org.junit.Test;

-import java.util.Hashtable;
-
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import java.util.Hashtable;

-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;

/**
* test capabilities of object reference storing stuff in JNDI
@@ -42,7 +41,8 @@
* object shall be stored and returned back
* @throws NamingException
*/
- @Test public void testStorageAndRetrieval() throws NamingException {
+ @Test
+ public void testStorageAndRetrieval() throws NamingException {
reference = new JNDIObjectReference("glee:/glum/glarch/blurge", ctx);
String obj = new String("that's me");
reference.set(obj);

----------

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.