[jboss-cvs] JBossAS SVN: r108596 - in trunk/ejb3/src/main/java/org/jboss/ejb3/client: injection and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Oct 15 06:06:01 EDT 2010
Author: jaikiran
Date: 2010-10-15 06:06:01 -0400 (Fri, 15 Oct 2010)
New Revision: 108596
Added:
trunk/ejb3/src/main/java/org/jboss/ejb3/client/injection/ClientWebServiceRefHandler.java
Modified:
trunk/ejb3/src/main/java/org/jboss/ejb3/client/ClientContainer.java
Log:
JBAS-8527 ClientContainer should not use server side WebServiceRefHandler
Modified: trunk/ejb3/src/main/java/org/jboss/ejb3/client/ClientContainer.java
===================================================================
--- trunk/ejb3/src/main/java/org/jboss/ejb3/client/ClientContainer.java 2010-10-15 09:46:32 UTC (rev 108595)
+++ trunk/ejb3/src/main/java/org/jboss/ejb3/client/ClientContainer.java 2010-10-15 10:06:01 UTC (rev 108596)
@@ -48,13 +48,13 @@
import org.jboss.ejb3.DependencyPolicy;
import org.jboss.ejb3.InitialContextFactory;
import org.jboss.ejb3.client.injection.ClientPersistenceUnitHandler;
+import org.jboss.ejb3.client.injection.ClientWebServiceRefHandler;
import org.jboss.ejb3.vfs.spi.VirtualFile;
import org.jboss.injection.DependsHandler;
import org.jboss.injection.EncInjector;
import org.jboss.injection.InjectionContainer;
import org.jboss.injection.InjectionHandler;
import org.jboss.injection.Injector;
-import org.jboss.injection.WebServiceRefHandler;
import org.jboss.logging.Logger;
import org.jboss.metadata.client.jboss.JBossClientMetaData;
import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
@@ -333,7 +333,7 @@
//handlers.add(new JndiInjectHandler<RemoteEnvironment>());
handlers.add(new ClientPersistenceUnitHandler<RemoteEnvironment>());
handlers.add(new ClientResourceHandler<RemoteEnvironment>(this.mainClass));
- handlers.add(new WebServiceRefHandler<RemoteEnvironment>());
+ handlers.add(new ClientWebServiceRefHandler<RemoteEnvironment>());
// TODO: we're going to use a jar class loader
// ClassLoader old = Thread.currentThread().getContextClassLoader();
Added: trunk/ejb3/src/main/java/org/jboss/ejb3/client/injection/ClientWebServiceRefHandler.java
===================================================================
--- trunk/ejb3/src/main/java/org/jboss/ejb3/client/injection/ClientWebServiceRefHandler.java (rev 0)
+++ trunk/ejb3/src/main/java/org/jboss/ejb3/client/injection/ClientWebServiceRefHandler.java 2010-10-15 10:06:01 UTC (rev 108596)
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.injection;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+
+
+import org.jboss.ejb3.client.JndiPropertyInjector;
+import org.jboss.injection.EncInjector;
+import org.jboss.injection.InjectionContainer;
+import org.jboss.injection.InjectionHandler;
+import org.jboss.injection.InjectionUtil;
+import org.jboss.injection.Injector;
+import org.jboss.injection.WebServiceRefHandler;
+import org.jboss.injection.lang.reflect.BeanProperty;
+import org.jboss.injection.lang.reflect.BeanPropertyFactory;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.javaee.spec.RemoteEnvironment;
+import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
+import org.jboss.metadata.javaee.spec.ServiceReferenceMetaData;
+import org.jboss.metadata.javaee.spec.ServiceReferencesMetaData;
+
+/**
+ * Handles service-ref and {@link WebServiceRef} on classes processed
+ * by the application client container.
+ *
+ * Unlike the {@link WebServiceRefHandler}, this class does not create
+ * {@link EncInjector}s for the service-ref(s), since the ENC injection
+ * should happen on the server. This class just creates the field/method
+ * {@link Injector}s for the service-ref(s)
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ClientWebServiceRefHandler<X extends RemoteEnvironment> implements InjectionHandler<X>
+{
+
+ /**
+ * Logger
+ */
+ private static Logger logger = Logger.getLogger(ClientWebServiceRefHandler.class);
+
+ /**
+ * Service references
+ */
+ private Map<String, ServiceReferenceMetaData> srefMap = new HashMap<String, ServiceReferenceMetaData>();
+
+ @Override
+ public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
+ {
+ throw new IllegalStateException("Annotations are not handled in the client");
+
+ }
+
+ @Override
+ public void handleFieldAnnotations(Field field, InjectionContainer container,
+ Map<AccessibleObject, Injector> injectors)
+ {
+ throw new IllegalStateException("Annotations are not handled in the client");
+
+ }
+
+ @Override
+ public void handleMethodAnnotations(Method method, InjectionContainer container,
+ Map<AccessibleObject, Injector> injectors)
+ {
+ throw new IllegalStateException("Annotations are not handled in the client");
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Note that this method does not create {@link EncInjector}s since the ENC injectors
+ * should be created on server side. This method just creates field/method {@link Injector}s for
+ * the service-ref(s)
+ */
+ @Override
+ public void loadXml(X xml, InjectionContainer container)
+ {
+ if (xml == null)
+ {
+ return;
+ }
+ ServiceReferencesMetaData serviceRefs = xml.getServiceReferences();
+ if (serviceRefs == null)
+ return;
+ for (ServiceReferenceMetaData sref : serviceRefs)
+ {
+ if (this.srefMap.get(sref.getServiceRefName()) != null)
+ {
+ throw new IllegalStateException("Duplicate <service-ref-name> in " + sref);
+ }
+
+ srefMap.put(sref.getServiceRefName(), sref);
+
+ String encName = "env/" + sref.getServiceRefName();
+ AnnotatedElement annotatedElement = sref.getAnnotatedElement();
+ if (annotatedElement == null)
+ {
+ if (sref.getInjectionTargets() != null && sref.getInjectionTargets().size() > 0)
+ {
+ for (ResourceInjectionTargetMetaData trg : sref.getInjectionTargets())
+ {
+ annotatedElement = InjectionUtil.findInjectionTarget(container.getClassloader(), trg);
+ addInjector(container, encName, annotatedElement);
+ }
+ }
+ else
+ {
+ logger.warn("No injection target for service-ref: " + sref.getServiceRefName());
+ }
+ }
+ // annotated classes do not specify injection target
+ else if (!(annotatedElement instanceof java.lang.reflect.Type))
+ {
+ addInjector(container, encName, annotatedElement);
+ }
+ }
+
+ }
+
+ /**
+ * Create and add a {@link Injector} into the <code>container</code>, for the passed <code>encName</code>
+ * and <code>annotatedElement</code>
+ *
+ * @param container The container to which the injector will be added
+ * @param encName The ENC name
+ * @param annotatedElement The annotated field/method
+ */
+ private void addInjector(InjectionContainer container, String encName, AnnotatedElement annotatedElement)
+ {
+
+ Injector jndiInjector;
+ if(annotatedElement instanceof Method)
+ {
+ BeanProperty prop = BeanPropertyFactory.create((Method) annotatedElement);
+ jndiInjector = new JndiPropertyInjector(prop, encName, container.getEnc());
+ }
+ else if(annotatedElement instanceof Field)
+ {
+ BeanProperty prop = BeanPropertyFactory.create((Field) annotatedElement);
+ jndiInjector = new JndiPropertyInjector(prop, encName, container.getEnc());
+ }
+ else
+ {
+ throw new IllegalStateException("Annotated element for '" + encName + "' is niether Method nor Field: " + annotatedElement);
+ }
+ // add the injector
+ container.getInjectors().add(jndiInjector);
+ }
+
+
+}
More information about the jboss-cvs-commits
mailing list