[seam-commits] Seam SVN: r11697 - modules/trunk/remoting/src/main/java/org/jboss/seam/remoting.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sat Nov 28 10:42:16 EST 2009


Author: shane.bryzak at jboss.com
Date: 2009-11-28 10:42:15 -0500 (Sat, 28 Nov 2009)
New Revision: 11697

Removed:
   modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/BaseRequestHandler.java
Modified:
   modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/Call.java
   modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/CallContext.java
   modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java
   modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java
   modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/PollHandler.java
   modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/Remoting.java
   modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/RequestHandler.java
   modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/SubscriptionHandler.java
Log:
got remoting example working, cleaned up code


Deleted: modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/BaseRequestHandler.java
===================================================================
--- modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/BaseRequestHandler.java	2009-11-28 14:03:05 UTC (rev 11696)
+++ modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/BaseRequestHandler.java	2009-11-28 15:42:15 UTC (rev 11697)
@@ -1,18 +0,0 @@
-package org.jboss.seam.remoting;
-
-import javax.enterprise.inject.spi.BeanManager;
-import javax.servlet.ServletContext;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author Shane Bryzak
- */
-public abstract class BaseRequestHandler implements RequestHandler
-{
-   protected static final Logger log = LoggerFactory.getLogger(BaseRequestHandler.class);
-   
-   public void setServletContext(ServletContext context) {}
-}

Modified: modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/Call.java
===================================================================
--- modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/Call.java	2009-11-28 14:03:05 UTC (rev 11696)
+++ modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/Call.java	2009-11-28 15:42:15 UTC (rev 11697)
@@ -8,9 +8,10 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.Map.Entry;
 
-import javax.ejb.Local;
+import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 
@@ -147,71 +148,82 @@
       }
    }
 
+   @SuppressWarnings("unchecked")
    private void processInvocation() throws Exception
    {
       // Find the component we're calling
-      Bean bean = beanManager.getBeans(componentName).iterator().next();
-
-      if (bean == null)
+      Set<Bean<?>> beans = beanManager.getBeans(componentName);
+      
+      if (beans.isEmpty())
       {
-         throw new RuntimeException("No such component: " + componentName);
+         throw new RuntimeException("No such component: " + componentName);         
       }
-
-      // Create an instance of the component
-      Object instance = bean.create(beanManager.createCreationalContext(bean));
-
-      if (instance == null)
-      {
-         throw new RuntimeException(String.format(
-               "Could not create instance of component %s", componentName));
-      }
-
-      Class type = null;
-
-      if (true) //(component.getType().isSessionBean()
-            //&& component.getBusinessInterfaces().size() > 0)
-      {
-         //for (Class c : component.getBusinessInterfaces())
+      else
+      {      
+         Bean<?> bean = beans.iterator().next();
+   
+         CreationalContext ctx = beanManager.createCreationalContext(bean);
+         
+         // Create an instance of the component
+         Object instance = bean.create(ctx); 
+   
+         if (instance == null)
+         {
+            throw new RuntimeException(String.format(
+                  "Could not create instance of bean %s", componentName));
+         }
+   
+         Class<?> type = null;
+   
+         //if (component.getType().isSessionBean()
+               //&& component.getBusinessInterfaces().size() > 0)
          //{
-            //if (c.isAnnotationPresent(Local.class))
+            //for (Class c : component.getBusinessInterfaces())
             //{
-               //type = c;
-               //break;
+               //if (c.isAnnotationPresent(Local.class))
+               //{
+                  //type = c;
+                  //break;
+               //}
             //}
+   
+            //if (type == null)
+            //{
+            //   throw new RuntimeException(String.format(
+            //     "Type cannot be determined for bean [%s]. Please ensure that it has a local interface.",
+            //                     bean));
+            //}
          //}
-
+   
          if (type == null)
          {
-            throw new RuntimeException(String.format(
-              "Type cannot be determined for bean [%s]. Please ensure that it has a local interface.",
-                              bean));
+            type = bean.getBeanClass();
          }
+   
+         // Find the method according to the method name and the parameter classes
+         Method m = findMethod(methodName, type);
+         if (m == null)
+         {
+            throw new RuntimeException("No compatible method found.");
+         }
+   
+         if (m.getAnnotation(WebRemote.class).exclude().length > 0)
+         {
+            constraints = Arrays.asList(m.getAnnotation(WebRemote.class).exclude());
+         }
+   
+         Object[] params = convertParams(m.getGenericParameterTypes());
+   
+         // Invoke!
+         try
+         {
+            result = m.invoke(instance, params);
+         } 
+         catch (InvocationTargetException e)
+         {
+            this.exception = e.getCause();
+         }
       }
-
-      if (type == null)
-      {
-         type = bean.getBeanClass();
-      }
-
-      // Find the method according to the method name and the parameter classes
-      Method m = findMethod(methodName, type);
-      if (m == null)
-         throw new RuntimeException("No compatible method found.");
-
-      if (m.getAnnotation(WebRemote.class).exclude().length > 0)
-         constraints = Arrays
-               .asList(m.getAnnotation(WebRemote.class).exclude());
-
-      Object[] params = convertParams(m.getGenericParameterTypes());
-
-      // Invoke!
-      try
-      {
-         result = m.invoke(instance, params);
-      } catch (InvocationTargetException e)
-      {
-         this.exception = e.getCause();
-      }
    }
 
    /**
@@ -245,7 +257,7 @@
     *           Class The Class to search in.
     * @return Method The best matching method.
     */
-   private Method findMethod(String name, Class cls)
+   private Method findMethod(String name, Class<?> cls)
    {
       Map<Method, Integer> candidates = new HashMap<Method, Integer>();
 

Modified: modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/CallContext.java
===================================================================
--- modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/CallContext.java	2009-11-28 14:03:05 UTC (rev 11696)
+++ modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/CallContext.java	2009-11-28 15:42:15 UTC (rev 11697)
@@ -13,108 +13,114 @@
 
 /**
  * Represents the context of an individual call.
- *
+ * 
  * @author Shane Bryzak
  */
 public class CallContext
 {
    private BeanManager beanManager;
-   
+
    public CallContext(BeanManager beanManager)
    {
       this.beanManager = beanManager;
    }
-   
-  /**
-   * Contains references to inbound bean objects identified by their ref.
-   */
-  private Map<String, Wrapper> inRefs = new HashMap<String, Wrapper>();
 
-  /**
-   * Contains references to outbound bean objects identified by their object.
-   */
-  private List<Wrapper> outRefs = new ArrayList<Wrapper>();
+   /**
+    * Contains references to inbound bean objects identified by their ref.
+    */
+   private Map<String, Wrapper> inRefs = new HashMap<String, Wrapper>();
 
-  /**
-   *
-   * @param element Element
-   * @return Wrapper
-   */
-  public Wrapper createWrapperFromElement(Element element)
-  {
-    if ("ref".equals(element.getQualifiedName()))
-    {
-      if (inRefs.containsKey(element.attributeValue("id")))
-        return inRefs.get(element.attributeValue("id"));
+   /**
+    * Contains references to outbound bean objects identified by their object.
+    */
+   private List<Wrapper> outRefs = new ArrayList<Wrapper>();
+
+   /**
+    * 
+    * @param element
+    *           Element
+    * @return Wrapper
+    */
+   public Wrapper createWrapperFromElement(Element element)
+   {
+      if ("ref".equals(element.getQualifiedName()))
+      {
+         if (inRefs.containsKey(element.attributeValue("id")))
+         {
+            return inRefs.get(element.attributeValue("id"));
+         }
+         else
+         {
+            Element value = (Element) element.elements().get(0);
+
+            Wrapper w = WrapperFactory.getInstance().createWrapper(
+                  value.getQualifiedName(), beanManager);
+            w.setElement(value);
+            w.setCallContext(this);
+            inRefs.put(element.attributeValue("id"), w);
+            return w;
+         }
+      }
       else
       {
-        Element value = (Element) element.elements().get(0);
+         Wrapper w = WrapperFactory.getInstance().createWrapper(
+               element.getQualifiedName(), beanManager);
+         w.setElement(element);
+         w.setCallContext(this);
+         return w;
+      }
+   }
 
-        Wrapper w = WrapperFactory.getInstance().createWrapper(
-              value.getQualifiedName(), beanManager);
-        w.setElement(value);
-        w.setCallContext(this);
-        inRefs.put(element.attributeValue("id"), w);
-        return w;
+   /**
+    * 
+    * @return Wrapper
+    */
+   public Wrapper createWrapperFromObject(Object value, String path)
+   {
+      // Not very efficient but has to be done - may implement something better
+      // later
+      for (Wrapper ref : outRefs)
+      {
+         if (ref.getValue().equals(value))
+            return ref;
       }
-    }
-    else
-    {
-      Wrapper w = WrapperFactory.getInstance().createWrapper(
-            element.getQualifiedName(), beanManager);
-      w.setElement(element);
+
+      Wrapper w = WrapperFactory.getInstance().getWrapperForObject(value,
+            beanManager);
       w.setCallContext(this);
+      w.setPath(path);
       return w;
-    }
-  }
+   }
 
-  /**
-   *
-   * @return Wrapper
-   */
-  public Wrapper createWrapperFromObject(Object value, String path)
-  {
-    // Not very efficient but has to be done - may implement something better later
-    for (Wrapper ref : outRefs)
-    {
-      if (ref.getValue().equals(value))
-        return ref;
-    }
+   /**
+    * Returns the inbound object references
+    * 
+    * @return Map
+    */
+   public Map<String, Wrapper> getInRefs()
+   {
+      return inRefs;
+   }
 
-    Wrapper w = WrapperFactory.getInstance().getWrapperForObject(value, beanManager);
-    w.setCallContext(this);
-    w.setPath(path);
-    return w;
-  }
+   /**
+    * Returns the outbound object references
+    * 
+    * @return List
+    */
+   public List<Wrapper> getOutRefs()
+   {
+      return outRefs;
+   }
 
-  /**
-   * Returns the inbound object references
-   *
-   * @return Map
-   */
-  public Map<String, Wrapper> getInRefs()
-  {
-    return inRefs;
-  }
-
-  /**
-   * Returns the outbound object references
-   *
-   * @return List
-   */
-  public List<Wrapper> getOutRefs()
-  {
-    return outRefs;
-  }
-
-  /**
-   * Add an outbound object reference
-   *
-   * @param w Wrapper
-   */
-  public void addOutRef(Wrapper w)
-  {
-    if (!outRefs.contains(w))
-      outRefs.add(w);
-  }
+   /**
+    * Add an outbound object reference
+    * 
+    * @param w
+    *           Wrapper
+    */
+   public void addOutRef(Wrapper w)
+   {
+      if (!outRefs.contains(w))
+         outRefs.add(w);
+   }
 }

Modified: modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java
===================================================================
--- modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java	2009-11-28 14:03:05 UTC (rev 11696)
+++ modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/ExecutionHandler.java	2009-11-28 15:42:15 UTC (rev 11697)
@@ -18,6 +18,8 @@
 import org.dom4j.Element;
 import org.dom4j.io.SAXReader;
 import org.jboss.seam.remoting.wrapper.Wrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Unmarshals the calls from an HttpServletRequest, executes them in order and
@@ -25,9 +27,11 @@
  * 
  * @author Shane Bryzak
  */
-public class ExecutionHandler extends BaseRequestHandler implements
-      RequestHandler
+public class ExecutionHandler implements RequestHandler
 {
+   private static final Logger log = LoggerFactory
+         .getLogger(ExecutionHandler.class);
+
    private static final byte[] HEADER_OPEN = "<header>".getBytes();
    private static final byte[] HEADER_CLOSE = "</header>".getBytes();
    private static final byte[] CONVERSATION_ID_TAG_OPEN = "<conversationId>"
@@ -38,9 +42,11 @@
    private static final byte[] CONTEXT_TAG_OPEN = "<context>".getBytes();
    private static final byte[] CONTEXT_TAG_CLOSE = "</context>".getBytes();
 
-   @Inject BeanManager beanManager;
-   @Inject Conversation conversation;
-   
+   @Inject
+   BeanManager beanManager;
+   @Inject
+   Conversation conversation;
+
    /**
     * The entry point for handling a request.
     * 
@@ -128,6 +134,7 @@
     *           Element
     * @throws Exception
     */
+   @SuppressWarnings("unchecked")
    private List<Call> unmarshalCalls(Element env) throws Exception
    {
       try
@@ -173,7 +180,8 @@
          }
 
          return calls;
-      } catch (Exception ex)
+      }
+      catch (Exception ex)
       {
          log.error("Error unmarshalling calls from request", ex);
          throw ex;

Modified: modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java
===================================================================
--- modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java	2009-11-28 14:03:05 UTC (rev 11696)
+++ modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/InterfaceGenerator.java	2009-11-28 15:42:15 UTC (rev 11697)
@@ -19,8 +19,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import javax.ejb.Local;
-import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.inject.Inject;
@@ -29,7 +27,6 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.hibernate.type.ComponentType;
 import org.jboss.seam.remoting.annotations.WebRemote;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,20 +36,21 @@
  * 
  * @author Shane Bryzak
  */
-public class InterfaceGenerator extends BaseRequestHandler implements
-      RequestHandler
-{ 
+public class InterfaceGenerator implements RequestHandler
+{
+   private static final Logger log = LoggerFactory.getLogger(InterfaceGenerator.class);
+   
    @Inject BeanManager beanManager;
 
    /**
     * Maintain a cache of the accessible fields
     */
-   private static Map<Class, Set<String>> accessibleProperties = new HashMap<Class, Set<String>>();
+   private static Map<Class<?>, Set<String>> accessibleProperties = new HashMap<Class<?>, Set<String>>();
 
    /**
     * A cache of component interfaces, keyed by component name.
     */
-   private Map<String, byte[]> interfaceCache = new HashMap<String, byte[]>();
+   private Map<Class<?>, byte[]> interfaceCache = new HashMap<Class<?>, byte[]>();
 
    /**
     * 
@@ -91,16 +89,18 @@
          {
             try
             {
-               Class c = Class.forName(componentName);
+               Class<?> c = Class.forName(componentName);
                appendClassSource(response.getOutputStream(), c, types);
-            } catch (ClassNotFoundException ex)
+            }
+            catch (ClassNotFoundException ex)
             {
                log.error(String.format("Component not found: [%s]",
                      componentName));
                throw new ServletException(
                      "Invalid request - component not found.");
             }
-         } else
+         }
+         else
          {
             beansCached.add(bean);
          }
@@ -121,26 +121,27 @@
     * @throws IOException
     *            Thrown if there is an error writing to the OutputStream
     */
-   public void generateBeanInterface(Set<Bean<?>> beans,
-         OutputStream out, Set<Type> types) throws IOException
+   public void generateBeanInterface(Set<Bean<?>> beans, OutputStream out,
+         Set<Type> types) throws IOException
    {
       for (Bean<?> bean : beans)
       {
          if (bean != null)
          {
-            if (!interfaceCache.containsKey(bean.getName()))
+            if (!interfaceCache.containsKey(bean.getBeanClass()))
             {
                synchronized (interfaceCache)
                {
-                  if (!interfaceCache.containsKey(bean.getName()))
+                  if (!interfaceCache.containsKey(bean.getBeanClass()))
                   {
                      ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                      appendBeanSource(bOut, bean, types);
-                     interfaceCache.put(bean.getName(), bOut.toByteArray());
+                     interfaceCache
+                           .put(bean.getBeanClass(), bOut.toByteArray());
                   }
                }
             }
-            out.write(interfaceCache.get(bean.getName()));
+            out.write(interfaceCache.get(bean.getBeanClass()));
          }
       }
    }
@@ -172,7 +173,7 @@
             {
                Set<String> properties = new HashSet<String>();
 
-               Class c = cls;
+               Class<?> c = cls;
                while (c != null && !c.equals(Object.class))
                {
                   for (Field f : c.getDeclaredFields())
@@ -191,16 +192,19 @@
                         try
                         {
                            getMethod = c.getMethod(getterName);
-                        } catch (SecurityException ex)
+                        }
+                        catch (SecurityException ex)
                         {
-                        } catch (NoSuchMethodException ex)
+                        }
+                        catch (NoSuchMethodException ex)
                         {
                            // it might be an "is" method...
                            getterName = String.format("is%s", fieldName);
                            try
                            {
                               getMethod = c.getMethod(getterName);
-                           } catch (NoSuchMethodException ex2)
+                           }
+                           catch (NoSuchMethodException ex2)
                            { /* don't care */
                            }
                         }
@@ -209,9 +213,11 @@
                         {
                            setMethod = c.getMethod(setterName, new Class[] { f
                                  .getType() });
-                        } catch (SecurityException ex)
+                        }
+                        catch (SecurityException ex)
                         {
-                        } catch (NoSuchMethodException ex)
+                        }
+                        catch (NoSuchMethodException ex)
                         { /* don't care */
                         }
 
@@ -238,7 +244,8 @@
                         {
                            c.getMethod(String.format("set%s", m.getName()
                                  .substring(startIdx)), m.getReturnType());
-                        } catch (NoSuchMethodException ex)
+                        }
+                        catch (NoSuchMethodException ex)
                         {
                            continue;
                         }
@@ -248,7 +255,9 @@
                               .getName().substring(startIdx + 1));
 
                         if (!properties.contains(propertyName))
+                        {
                            properties.add(propertyName);
+                        }
                      }
                   }
 
@@ -278,68 +287,33 @@
     * @throws IOException
     *            If there is an error writing to the OutputStream.
     */
-   private void appendBeanSource(OutputStream out, Bean bean,
-         Set<Type> types) throws IOException
+   private void appendBeanSource(OutputStream out, Bean<?> bean, Set<Type> types)
+         throws IOException
    {
       StringBuilder componentSrc = new StringBuilder();
 
-      Set<Class> componentTypes = new HashSet<Class>();
+      Set<Class<?>> componentTypes = new HashSet<Class<?>>();
 
-//      if (bean.getType().isSessionBean()
-//            && bean.getBusinessInterfaces().size() > 0)
-      if (true)
+      // Check if any of the methods are annotated with @WebRemote, and if so
+      // treat it as an "action" component instead of a type component
+      for (Method m : bean.getBeanClass().getDeclaredMethods())
       {
-         //for (Class c : bean.getBusinessInterfaces())
-         //{
-            // Use the Local interface
-            // TODO remove dependency on javax.ejb - iterate through the annotations
-            // instead and do a string comparison
-            //if (c.isAnnotationPresent(Local.class))
-            //{
-               //componentTypes.add(c);
-               //break;
-            //}
-         //}
+         if (m.getAnnotation(WebRemote.class) != null)
+         {
+            componentTypes.add(bean.getBeanClass());
+            break;
+         }
+      }
 
-         if (componentTypes.isEmpty())
-            throw new RuntimeException(
-                  String
-                        .format(
-                              "Type cannot be determined for component [%s]. Please ensure that it has a local interface.",
-                              bean));
-      } 
-      else if (false) //(bean.getType().equals(ComponentType.ENTITY_BEAN))
+      if (componentTypes.isEmpty())
       {
          appendTypeSource(out, bean.getBeanClass(), types);
          return;
-      } 
-      else if (false) //(component.getType().equals(ComponentType.JAVA_BEAN))
-      {
-         // Check if any of the methods are annotated with @WebRemote, and if so
-         // treat it as an "action" component instead of a type component
-         for (Method m : bean.getBeanClass().getDeclaredMethods())
-         {
-            if (m.getAnnotation(WebRemote.class) != null)
-            {
-               componentTypes.add(bean.getBeanClass());
-               break;
-            }
-         }
-
-         if (componentTypes.isEmpty())
-         {
-            appendTypeSource(out, bean.getBeanClass(), types);
-            return;
-         }
-      } 
-      else
-      {
-         componentTypes.add(bean.getBeanClass());
       }
 
       // If types already contains all the component types, then return
       boolean foundNew = false;
-      for (Class type : componentTypes)
+      for (Class<?> type : componentTypes)
       {
          if (!types.contains(type))
          {
@@ -347,8 +321,11 @@
             break;
          }
       }
+
       if (!foundNew)
+      {
          return;
+      }
 
       if (bean.getName().contains("."))
       {
@@ -364,12 +341,13 @@
       componentSrc.append(" = function() {\n");
       componentSrc.append("  this.__callback = new Object();\n");
 
-      for (Class type : componentTypes)
+      for (Class<?> type : componentTypes)
       {
          if (types.contains(type))
          {
             break;
-         } else
+         }
+         else
          {
             types.add(type);
 
@@ -393,15 +371,17 @@
                   appendTypeSource(out, m.getGenericParameterTypes()[i], types);
 
                   if (i > 0)
+                  {
                      componentSrc.append(", ");
+                  }
                   componentSrc.append("p");
                   componentSrc.append(i);
                }
 
                if (m.getGenericParameterTypes().length > 0)
                   componentSrc.append(", ");
+
                componentSrc.append("callback, exceptionHandler) {\n");
-
                componentSrc.append("    return Seam.Remoting.execute(this, \"");
                componentSrc.append(m.getName());
                componentSrc.append("\", [");
@@ -415,7 +395,6 @@
                }
 
                componentSrc.append("], callback, exceptionHandler);\n");
-
                componentSrc.append("  }\n");
             }
          }
@@ -451,9 +430,9 @@
    private void appendTypeSource(OutputStream out, Type type, Set<Type> types)
          throws IOException
    {
-      if (type instanceof Class)
+      if (type instanceof Class<?>)
       {
-         Class classType = (Class) type;
+         Class<?> classType = (Class<?>) type;
 
          if (classType.isArray())
          {
@@ -463,16 +442,21 @@
 
          if (classType.getName().startsWith("java.") || types.contains(type)
                || classType.isPrimitive())
+         {
             return;
+         }
 
          // Keep track of which types we've already added
          types.add(type);
 
          appendClassSource(out, classType, types);
-      } else if (type instanceof ParameterizedType)
+      }
+      else if (type instanceof ParameterizedType)
       {
          for (Type t : ((ParameterizedType) type).getActualTypeArguments())
+         {
             appendTypeSource(out, t, types);
+         }
       }
    }
 
@@ -487,19 +471,21 @@
     *           Set
     * @throws IOException
     */
-   private void appendClassSource(OutputStream out, Class classType,
+   private void appendClassSource(OutputStream out, Class<?> classType,
          Set<Type> types) throws IOException
    {
       // Don't generate interfaces for enums
       if (classType.isEnum())
+      {
          return;
+      }
 
       StringBuilder typeSource = new StringBuilder();
 
       // Determine whether this class is a component; if so, use its name
       // otherwise use its class name.
-      Bean bean = beanManager.getBeans(classType).iterator().next();
-      String componentName = bean.getName();  
+      Bean<?> bean = beanManager.getBeans(classType).iterator().next();
+      String componentName = bean.getName();
       if (componentName == null)
          componentName = classType.getName();
 
@@ -526,7 +512,8 @@
          {
             f = classType.getDeclaredField(propertyName);
             propertyType = f.getGenericType();
-         } catch (NoSuchFieldException ex)
+         }
+         catch (NoSuchFieldException ex)
          {
             setMethodName = String.format("set%s%s", Character
                   .toUpperCase(propertyName.charAt(0)), propertyName
@@ -539,7 +526,8 @@
                      .substring(1));
                propertyType = classType.getMethod(getMethodName)
                      .getGenericReturnType();
-            } catch (NoSuchMethodException ex2)
+            }
+            catch (NoSuchMethodException ex2)
             {
                try
                {
@@ -549,7 +537,8 @@
 
                   propertyType = classType.getMethod(getMethodName)
                         .getGenericReturnType();
-               } catch (NoSuchMethodException ex3)
+               }
+               catch (NoSuchMethodException ex3)
                {
                   // ???
                   continue;
@@ -565,8 +554,10 @@
             for (Type t : ((ParameterizedType) propertyType)
                   .getActualTypeArguments())
             {
-               if (t instanceof Class)
+               if (t instanceof Class<?>)
+               {
                   appendTypeSource(out, t, types);
+               }
             }
          }
 
@@ -581,9 +572,11 @@
             {
                classType.getMethod(getterName);
                getMethodName = getterName;
-            } catch (SecurityException ex)
+            }
+            catch (SecurityException ex)
             {
-            } catch (NoSuchMethodException ex)
+            }
+            catch (NoSuchMethodException ex)
             {
                getterName = String.format("is%s", fieldName);
                try
@@ -591,7 +584,8 @@
                   if (Modifier.isPublic(classType.getMethod(getterName)
                         .getModifiers()))
                      getMethodName = getterName;
-               } catch (NoSuchMethodException ex2)
+               }
+               catch (NoSuchMethodException ex2)
                { /* don't care */
                }
             }
@@ -601,9 +595,11 @@
                if (Modifier.isPublic(classType.getMethod(setterName,
                      f.getType()).getModifiers()))
                   setMethodName = setterName;
-            } catch (SecurityException ex)
+            }
+            catch (SecurityException ex)
             {
-            } catch (NoSuchMethodException ex)
+            }
+            catch (NoSuchMethodException ex)
             { /* don't care */
             }
          }
@@ -686,9 +682,13 @@
 
       // TODO fix this - a bean might not be named
       if (classType.isAnnotationPresent(Named.class))
+      {
          typeSource.append("Seam.Component.register(Seam.Remoting.type.");
+      }
       else
+      {
          typeSource.append("Seam.Remoting.registerType(Seam.Remoting.type.");
+      }
 
       typeSource.append(typeName);
       typeSource.append(");\n\n");
@@ -706,40 +706,59 @@
    protected String getFieldType(Type type)
    {
       if (type.equals(String.class)
-            || (type instanceof Class && ((Class) type).isEnum())
+            || (type instanceof Class<?> && ((Class<?>) type).isEnum())
             || type.equals(BigInteger.class) || type.equals(BigDecimal.class))
+      {
          return "str";
+      }
       else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE))
+      {
          return "bool";
+      }
       else if (type.equals(Short.class) || type.equals(Short.TYPE)
             || type.equals(Integer.class) || type.equals(Integer.TYPE)
             || type.equals(Long.class) || type.equals(Long.TYPE)
             || type.equals(Float.class) || type.equals(Float.TYPE)
             || type.equals(Double.class) || type.equals(Double.TYPE)
             || type.equals(Byte.class) || type.equals(Byte.TYPE))
+      {
          return "number";
-      else if (type instanceof Class)
+      }
+      else if (type instanceof Class<?>)
       {
-         Class cls = (Class) type;
+         Class<?> cls = (Class<?>) type;
          if (Date.class.isAssignableFrom(cls)
                || Calendar.class.isAssignableFrom(cls))
+         {
             return "date";
+         }
          else if (cls.isArray())
+         {
             return "bag";
+         }
          else if (cls.isAssignableFrom(Map.class))
+         {
             return "map";
+         }
          else if (cls.isAssignableFrom(Collection.class))
+         {
             return "bag";
-      } else if (type instanceof ParameterizedType)
+         }
+      }
+      else if (type instanceof ParameterizedType)
       {
          ParameterizedType pt = (ParameterizedType) type;
 
-         if (pt.getRawType() instanceof Class
-               && Map.class.isAssignableFrom((Class) pt.getRawType()))
+         if (pt.getRawType() instanceof Class<?>
+               && Map.class.isAssignableFrom((Class<?>) pt.getRawType()))
+         {
             return "map";
-         else if (pt.getRawType() instanceof Class
-               && Collection.class.isAssignableFrom((Class) pt.getRawType()))
+         }
+         else if (pt.getRawType() instanceof Class<?>
+               && Collection.class.isAssignableFrom((Class<?>) pt.getRawType()))
+         {
             return "bag";
+         }
       }
 
       return "bean";

Modified: modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/PollHandler.java
===================================================================
--- modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/PollHandler.java	2009-11-28 14:03:05 UTC (rev 11696)
+++ modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/PollHandler.java	2009-11-28 15:42:15 UTC (rev 11697)
@@ -21,14 +21,18 @@
 import org.jboss.seam.remoting.messaging.PollRequest;
 import org.jboss.seam.remoting.messaging.SubscriptionRegistry;
 import org.jboss.seam.remoting.wrapper.Wrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Handles JMS Message poll requests.
  * 
  * @author Shane Bryzak
  */
-public class PollHandler extends BaseRequestHandler implements RequestHandler
+public class PollHandler implements RequestHandler
 {
+   private static final Logger log = LoggerFactory.getLogger(PollHandler.class);
+
    private static final byte[] ERRORS_TAG_OPEN_START = "<errors token=\""
          .getBytes();
    private static final byte[] ERRORS_TAG_OPEN_END = "\">".getBytes();
@@ -51,9 +55,11 @@
    private static final byte[] VALUE_TAG_OPEN = "<value>".getBytes();
    private static final byte[] VALUE_TAG_CLOSE = "</value>".getBytes();
 
-   @Inject BeanManager beanManager;
-   @Inject SubscriptionRegistry registry;
-   
+   @Inject
+   BeanManager beanManager;
+   @Inject
+   SubscriptionRegistry registry;
+
    public void handle(HttpServletRequest request,
          final HttpServletResponse response) throws Exception
    {
@@ -77,6 +83,7 @@
       marshalResponse(polls, response.getOutputStream());
    }
 
+   @SuppressWarnings("unchecked")
    private List<PollRequest> unmarshalRequests(Element env) throws Exception
    {
       try
@@ -86,12 +93,13 @@
          List<Element> requestElements = env.element("body").elements("poll");
          for (Element e : requestElements)
          {
-            requests.add(new PollRequest(e.attributeValue("token"), 
-                  Integer.parseInt(e.attributeValue("timeout")), registry));
+            requests.add(new PollRequest(e.attributeValue("token"), Integer
+                  .parseInt(e.attributeValue("timeout")), registry));
          }
 
          return requests;
-      } catch (Exception ex)
+      }
+      catch (Exception ex)
       {
          log.error("Error unmarshalling subscriptions from request", ex);
          throw ex;
@@ -115,7 +123,8 @@
             {
                writeError(err, out);
             }
-         } else if (req.getMessages() != null && req.getMessages().size() > 0)
+         }
+         else if (req.getMessages() != null && req.getMessages().size() > 0)
          {
             out.write(MESSAGES_TAG_OPEN_START);
             out.write(req.getToken().getBytes());
@@ -125,9 +134,11 @@
                try
                {
                   writeMessage(m, out);
-               } catch (JMSException ex)
+               }
+               catch (JMSException ex)
                {
-               } catch (IOException ex)
+               }
+               catch (IOException ex)
                {
                }
             }
@@ -153,7 +164,8 @@
       {
          out.write("text".getBytes());
          value = ((TextMessage) m).getText();
-      } else if (m instanceof ObjectMessage)
+      }
+      else if (m instanceof ObjectMessage)
       {
          out.write("object".getBytes());
          value = ((ObjectMessage) m).getObject();

Modified: modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/Remoting.java
===================================================================
--- modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/Remoting.java	2009-11-28 14:03:05 UTC (rev 11696)
+++ modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/Remoting.java	2009-11-28 15:42:15 UTC (rev 11697)
@@ -27,9 +27,11 @@
  */
 public class Remoting extends HttpServlet
 {
+   private static final long serialVersionUID = -3911197516105313424L;
+   
    private static final String REQUEST_PATH_EXECUTE = "/execute";
-   private static final String REQUEST_PATH_SUBSCRIPTION = "/subscription";
-   private static final String REQUEST_PATH_POLL = "/poll";
+   //private static final String REQUEST_PATH_SUBSCRIPTION = "/subscription";
+   //private static final String REQUEST_PATH_POLL = "/poll";
    private static final String REQUEST_PATH_INTERFACE = "/interface.js";   
    
    @Inject Instance<ExecutionHandler> executionHandlerInstance;
@@ -197,20 +199,24 @@
    {
       try
       {
-        // String pathInfo = request.getPathInfo().substring(
-          //     servletConfig.getServletContext().getContextPath().length());
+         String pathInfo = request.getPathInfo();
+         
+         if (pathInfo.startsWith(servletConfig.getServletContext().getContextPath()))
+         {
+            pathInfo = pathInfo.substring(servletConfig.getServletContext().getContextPath().length());
+         }               
 
-         if (REQUEST_PATH_EXECUTE.equals(request.getPathInfo()))
+         if (REQUEST_PATH_EXECUTE.equals(pathInfo))
          {
             executionHandlerInstance.get().handle(request, response);
          }
-         else if (REQUEST_PATH_INTERFACE.equals(request.getPathInfo()))
+         else if (REQUEST_PATH_INTERFACE.equals(pathInfo))
          {
             interfaceHandlerInstance.get().handle(request, response);
          }
          else
          {
-            Matcher m = pathPattern.matcher(request.getPathInfo());
+            Matcher m = pathPattern.matcher(pathInfo);
             if (m.matches())
             {
                String path = m.group(1);

Modified: modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/RequestHandler.java
===================================================================
--- modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/RequestHandler.java	2009-11-28 14:03:05 UTC (rev 11696)
+++ modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/RequestHandler.java	2009-11-28 15:42:15 UTC (rev 11697)
@@ -1,6 +1,5 @@
 package org.jboss.seam.remoting;
 
-import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -22,5 +21,4 @@
 
   void handle(HttpServletRequest request, HttpServletResponse response)
       throws Exception;
-  void setServletContext(ServletContext context);
 }

Modified: modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/SubscriptionHandler.java
===================================================================
--- modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/SubscriptionHandler.java	2009-11-28 14:03:05 UTC (rev 11696)
+++ modules/trunk/remoting/src/main/java/org/jboss/seam/remoting/SubscriptionHandler.java	2009-11-28 15:42:15 UTC (rev 11697)
@@ -20,11 +20,11 @@
  * 
  * @author Shane Bryzak
  */
-public class SubscriptionHandler extends BaseRequestHandler implements
-      RequestHandler
+public class SubscriptionHandler implements RequestHandler
 {
-   @Inject SubscriptionRegistry registry;
-   
+   @Inject
+   SubscriptionRegistry registry;
+
    /**
     * The entry point for handling a request.
     * 
@@ -34,6 +34,7 @@
     *           HttpServletResponse
     * @throws Exception
     */
+   @SuppressWarnings("unchecked")
    public void handle(HttpServletRequest request, HttpServletResponse response)
          throws Exception
    {
@@ -54,7 +55,8 @@
       List<Element> elements = body.elements("subscribe");
       for (Element e : elements)
       {
-         requests.add(new SubscriptionRequest(e.attributeValue("topic"), registry));
+         requests.add(new SubscriptionRequest(e.attributeValue("topic"),
+               registry));
       }
 
       for (SubscriptionRequest req : requests)



More information about the seam-commits mailing list