[jboss-cvs] JBossAS SVN: r72851 - trunk/ejb3/src/main/org/jboss/ejb3/client.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 29 00:47:35 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-04-29 00:47:35 -0400 (Tue, 29 Apr 2008)
New Revision: 72851
Added:
trunk/ejb3/src/main/org/jboss/ejb3/client/JndiPropertyInjector.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/client/Utils.java
Log:
Global lookup fallback
Added: trunk/ejb3/src/main/org/jboss/ejb3/client/JndiPropertyInjector.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/JndiPropertyInjector.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/JndiPropertyInjector.java 2008-04-29 04:47:35 UTC (rev 72851)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.client;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.ejb3.BeanContext;
+import org.jboss.injection.AbstractPropertyInjector;
+import org.jboss.injection.PojoInjector;
+import org.jboss.injection.lang.reflect.BeanProperty;
+import org.jboss.logging.Logger;
+
+/**
+ * Injects a jndi dependency into a bean property.
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: $
+ */
+public class JndiPropertyInjector extends AbstractPropertyInjector
+ implements PojoInjector
+{
+ private static final Logger log = Logger.getLogger(JndiPropertyInjector.class);
+
+ private String jndiName;
+ private Context ctx;
+
+ public JndiPropertyInjector(BeanProperty property, String jndiName,
+ Context ctx)
+ {
+ super(property);
+ this.jndiName = jndiName;
+ this.ctx = ctx;
+ }
+
+ public void inject(BeanContext bctx)
+ {
+ }
+
+ public Class<?> getInjectionClass()
+ {
+ return property.getType();
+ }
+
+ public void inject(BeanContext bctx, Object instance)
+ {
+ }
+
+ public void inject(Object instance)
+ {
+ Object value = lookup(jndiName);
+ log.trace("injecting " + value + " from " + jndiName + " into " + property + " of " + instance);
+ property.set(instance, value);
+ }
+
+ protected Object lookup(String jndiName)
+ {
+ Object dependency = null;
+ boolean trace = log.isTraceEnabled();
+ try
+ {
+ if(trace)
+ log.trace("Looking for enc entry: "+jndiName);
+ dependency = ctx.lookup(jndiName);
+ if(trace)
+ log.trace("Success: "+dependency);
+ }
+ catch (NamingException e)
+ {
+ // Try as a global jndi name
+ if(trace)
+ log.trace("Failed enc lookup: "+e.getExplanation());
+ try
+ {
+ if(trace)
+ log.trace("Failed trying as global entry: "+jndiName);
+ InitialContext ictx = new InitialContext(ctx.getEnvironment());
+ dependency = ictx.lookup(jndiName);
+ if(trace)
+ log.trace("Success: "+dependency);
+ }
+ catch(NamingException e2)
+ {
+ if(trace)
+ log.trace("Failed global lookup: "+e2.getExplanation());
+ }
+
+ Throwable cause = e;
+ while(cause.getCause() != null)
+ cause = cause.getCause();
+ throw new RuntimeException("Unable to inject jndi dependency: " + jndiName + " into property " + property + ": " + cause.getMessage(), e);
+ }
+ return dependency;
+ }
+}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/Utils.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/Utils.java 2008-04-29 04:46:54 UTC (rev 72850)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/Utils.java 2008-04-29 04:47:35 UTC (rev 72851)
@@ -25,16 +25,11 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.jboss.injection.InjectionContainer;
import org.jboss.injection.Injector;
import org.jboss.injection.InjectorFactory;
-import org.jboss.injection.JndiFieldInjector;
-import org.jboss.injection.JndiMethodInjector;
-import org.jboss.injection.JndiPropertyInjector;
import org.jboss.injection.lang.reflect.BeanProperty;
import org.jboss.injection.lang.reflect.BeanPropertyFactory;
import org.jboss.metadata.javaee.spec.ResourceInjectionMetaData;
More information about the jboss-cvs-commits
mailing list