11 Replies Latest reply on Nov 20, 2008 4:54 AM by Pete Muir

    Web Bean Discovery

    Pete Muir Master

      In building the Web Beans RI we have decided from the outset to not provide any built in discovery of classes and xml files to deploy, but instead delegate to the container via an SPI. We need initially to build one that is suitable for JBoss 5.

      I have decided that the simplest approach is for the integration layer to implement the discovery rules, thus the SPI is very simple:

      public interface WebBeanDiscovery {
      
       public Set<Class<?>> discoverWebBeanClasses();
      
      }


      The returned Set<Class<?>> should comprise all classes which present in this archive (and any sub-deployments it has e.g. in the war for an ear):

      * any web-beans.xml file in any root directory of the application classpath,
      * any ejb-jar.xml file in any root directory of the application classpath that also has a web-beans.xml file, and
      * any Java class in any archive or directory in the classpath that has a web-beans.xml file in the root directory.

        • 1. Re: Web Bean Discovery
          Ales Justin Master

           

          "pete.muir@jboss.org" wrote:

          The returned Set<Class<?>> should comprise all classes which present in this archive (and any sub-deployments it has e.g. in the war for an ear):

          * any web-beans.xml file in any root directory of the application classpath,
          * any ejb-jar.xml file in any root directory of the application classpath that also has a web-beans.xml file, and
          * any Java class in any archive or directory in the classpath that has a web-beans.xml file in the root directory.

          Basically this is saying, give me all classes from classpath of a deployment which has web-beans.xml file in its metadata path?
          I don't understand other two restrictions - ejb-jar.xml and Java class.

          Note: I think web-beans.xml should be in META-INF (or WEB-INF), not in root

          • 2. Re: Web Bean Discovery
            Pete Muir Master

            I don't understand the second restriction great either. Gavin?

            The third one I think is saying "give me all the classes from any shared (lib/) jar that has web-beans.xml in it's metadata path". Gavin, is that right?

            • 3. Re: Web Bean Discovery
              Adrian Brock Master

               

              "pete.muir@jboss.org" wrote:
              I don't understand the second restriction great either. Gavin?

              The third one I think is saying "give me all the classes from any shared (lib/) jar that has web-beans.xml in it's metadata path". Gavin, is that right?


              He's talking about the spec defined behaviour
              (although it is not actually recommended that people use it)
              see the JavaEE5 spec 8.3.1.3.d

              Another exception to this rule is JAR files located in the library
              directory (usually named lib) in the application package. Note that the
              presence of component-declaring annotations in shared artifacts, such as
              libraries in the library directory and libraries referenced by more than one
              module through Class-Path references, can have unintended and
              undesirable consequences and is not recommended.


              The reason its not recommend is because if you have for example
              two ejb jars that reference the same helper jar via the manifest
              they could both get processed for an ejb contained in the helper jar
              which could in turn lead to the ejb constructed twice and then
              not able to bind the remote interface to the same jndi name twice.
              And other similar problems.

              • 4. Re: Web Bean Discovery
                Adrian Brock Master

                 

                "pete.muir@jboss.org" wrote:

                public interface WebBeanDiscovery {
                
                 public Set<Class<?>> discoverWebBeanClasses();
                
                }



                Isn't it more scalabe to use
                Iterable<class<?>>

                which could be a Set but also could be something more performant
                if there are a very large number of classes.

                • 5. Re: Web Bean Discovery
                  Gavin King Master

                  Pete, you slightly mangled the quote from the spec by removing it from context :-)

                  What its really saying is that the web bean manager needs to get given:

                  * a list of all web-beans.xml files in the app classpath
                  * a list of all classes in classpath archives with web-beans.xml files
                  * a list of all EJBs in the application, including their JNDI name and component type

                  • 6. Re: Web Bean Discovery
                    Pete Muir Master

                    Here's the updated SPI based on Gavin's clarification and Adrian's suggestion:

                    /**
                     * A container should implement this interface to allow the Web Beans RI to
                     * discover the Web Beans to deploy
                     *
                     * @author Pete Muir
                     *
                     */
                    public interface WebBeanDiscovery
                    {
                     /**
                     * @return A list of all classes in classpath archives with web-beans.xml files
                     */
                     public Iterable<Class<?>> discoverWebBeanClasses();
                    
                     /**
                     * @return A list of all web-beans.xml files in the app classpath
                     */
                     public Iterable<URL> discoverWebBeansXml();
                    
                     /**
                     * @return A Map of EJB descriptors, keyed by the EJB bean class
                     */
                     public Map<Class<?>, EjbDescriptor<?>> discoverEjbs();
                    
                    }


                    public interface EjbDescriptor<T>
                    {
                     /**
                     * @return The EJB Bean class
                     */
                     public Class<T> getType();
                    
                     /**
                     * @return The JNDI name under which the EJB is registered
                     */
                     public String getJndiName();
                    
                     /**
                     * @return The local interfaces of the EJB
                     */
                     public Iterator<Class<?>> getLocalInterfaces();
                    
                     /**
                     * @return The remove methods of the EJB
                     */
                     public Iterator<Method> getRemoveMethods();
                    
                    }


                    • 7. Re: Web Bean Discovery
                      Carlo de Wolf Master

                       

                      "pete.muir@jboss.org" wrote:
                      /**
                       * @return A Map of EJB descriptors, keyed by the EJB bean class
                       */
                       public Map<Class<?>, EjbDescriptor<?>> discoverEjbs();

                      A bean class can be used by multiple EJBs. So you'll have to come up with another key.

                      • 8. Re: Web Bean Discovery
                        Pete Muir Master

                         

                        "wolfc" wrote:
                        "pete.muir@jboss.org" wrote:
                        /**
                         * @return A Map of EJB descriptors, keyed by the EJB bean class
                         */
                         public Map<Class<?>, EjbDescriptor<?>> discoverEjbs();

                        A bean class can be used by multiple EJBs. So you'll have to come up with another key.


                        Ok. We should probably be using ejb name anyway. AFAIK that is unique within an ejb archive, so we may need some combination of the two.

                        • 9. Re: Web Bean Discovery
                          Ales Justin Master

                           

                          "gavin.king@jboss.com" wrote:

                          * a list of all classes in classpath archives with web-beans.xml files

                          Let me see if I got this. :-)

                          yes == includes web-beans.xml
                          no == doesn't include web-beans.xml

                          e.g.
                          - myapp.ear
                          -- lib
                          --- ext.jar // yes
                          --- util.jar // no
                          -- first.jar // yes
                          -- second.jar // no
                          -- users.war
                          --- WEB-INF
                          ---- web-beans.xml
                          ---- classes
                          ------ org/acme/...
                          ---- lib
                          ----- ui1.jar // yes
                          ----- ui2.jar // no
                          -- crm.war
                          --- WEB-INF
                          ---- classes
                          ----- com/foobar/crm/...
                          ---- lib
                          -----xyz.jar // yes

                          Classes from the following stuff should be returned:
                          - ext.jar
                          - first.jar
                          - users.war/WEB-INF/classes
                          - ui1.jar
                          - xyz.jar

                          But not the rest, as they don't have proper web-beans.xml in metadata.
                          Note: no crm.war/WEB-INF/classes, as crm.war/WEB-INF doesn't have web-beans.xml

                          • 10. Re: Web Bean Discovery
                            Gavin King Master

                            Looks right to me :-)