2 Replies Latest reply on Sep 9, 2008 4:24 PM by Alexei none

    How to deploy seam component manually ?

    Alexei none Apprentice

      I'd like to add seam components to my process archives. So I overrided Jbpm component with my own component capable to scan process archives.




      if(annotation instanceof org.jboss.seam.annotations.Name) {
                                      log.info("seam annotated class found " + ctc.getName());

                                      Class clazz = this.getClass().getClassLoader().loadClass(ctc.getName());
                                    
                                      Context context = Contexts.getApplicationContext();
                                      ComponentDescriptor descriptor = new ComponentDescriptor(clazz);
                                    
                                      String name = descriptor.getName();
                                      String componentName = name + ".component";
                                      try {
                                          log.info("Creating component "
                                                  + name
                                                  +" "+ descriptor.getScope()
                                                  +" "+ descriptor.isStartup()
                                                  +" "+ descriptor.getJndiName()
                                                  +" isAutoCreate="+descriptor.isAutoCreate());
                                          Component component = new Component(
                                              descriptor.getComponentClass(),
                                              name,
                                              descriptor.getScope(),
                                              descriptor.isStartup(),
                                              name//descriptor.getJndiName()
                                              );
                                          log.info("adding component to context "+context);
                                          context.set(componentName, component);
                                          log.info("lookup "+context.get(componentName));
                                        
                                          log.info(component.newInstance());
                                      }
                                      catch (Throwable e)
                                      {
                                          throw new RuntimeException("Could not create Component: " + name, e);
                                      }    
                                  }



      So obtained components occurring in application context wrapped by Component. But when I try to instantiate them I get following exception




      org.jboss.seam.InstantiationException: Could not instantiate Seam component: pro
      cessDataChangeFioV01
              at org.jboss.seam.Component.newInstance(Component.java:1970)
              at org.jboss.seam.Component.getInstance(Component.java:1873)
              ...................................

              Caused by: javax.naming.NameNotFoundException: local not bound
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
              at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
              at javax.naming.InitialContext.lookup(InitialContext.java:392)
              at org.jboss.seam.Component.instantiateSessionBean(Component.java:1287)
              at org.jboss.seam.Component.instantiate(Component.java:1273)
              at org.jboss.seam.Component.newInstance(Component.java:1966)
              ... 141 more



        • 1. Re: How to deploy seam component manually ?
          Alexei none Apprentice

               private List<String> scanLibForPackagesWithJaxbAnnotations(File jarFile) {

                    

                    List<String> jaxbAnnotatedPackages = new ArrayList<String>();

                    try {

                         

                         JarFile jar = new JarFile(jarFile);

                         Enumeration jarEntries = jar.entries();

                         

                         while (jarEntries.hasMoreElements()) {

                              

                              JarEntry je = (JarEntry) jarEntries.nextElement();

                              if(je.getName().endsWith(".class")) {

                                   

                                   ClassPool cp = ClassPool.getDefault();

                                   CtClass ctc = cp.makeClass(jar.getInputStream(je));

                                   

                                   

                                   try {

                                        

                                        for(Object annotation : ctc.getAnnotations()) {

                                             

                                             if(annotation instanceof javax.xml.bind.annotation.XmlSchema) {

                                                  log.info("jaxb annotated package found " + ctc.getPackageName());

                                                  jaxbAnnotatedPackages.add(ctc.getPackageName());

                                             }

                                             if(annotation instanceof org.jboss.seam.annotations.Name) {

                                                  log.info("seam annotated class found " + ctc.getName());

                                                  log.info("trying to use "+this.getClass().getClassLoader());

                                                  Class clazz = this.getClass().getClassLoader().loadClass(ctc.getName());

                                                  

                                                  Context context = Contexts.getApplicationContext();

                                                  ComponentDescriptor descriptor = new ComponentDescriptor(clazz);

                                                  

                                                  String name = descriptor.getName();

                                                  String componentName = name + ".component";

                                                  try {

                                                       log.info("Creating component "

                                                                 + name

                                                                 +" "+ descriptor.getScope()

                                                                 +" "+ descriptor.isStartup()

                                                                 +" "+ descriptor.getJndiName()

                                                                 +" isAutoCreate="+descriptor.isAutoCreate());

                                                       Component component = new Component(

                                                            descriptor.getComponentClass(),

                                                            name,

                                                            descriptor.getScope(),

                                                            descriptor.isStartup(),

                                                            name//descriptor.getJndiName()

                                                            );

                                                       

                                                       log.info("adding component to context "+context);

                                                       context.set(componentName, component);

                                                       log.info("lookup "+context.get(componentName));

                                                       //log.info(org.jboss.seam.util.Naming.getInitialContext().lookup(name));

                                                       log.info(Seam.componentForName(name));

                                                       log.info(Component.getInstance(name));

                                                       //log.info(component.get)

                                                       log.info(component.newInstance());

                                                  }

                                                  catch (Throwable e)

                                                  {

                                                       throw new RuntimeException("Could not create Component: " + name, e);

                                                  }     



                                                  

                                                  //Thread.currentThread().getContextClassLoader().loadClass(ctc.getName());

                                             }

                                             

                                        }

                                   } catch (ClassNotFoundException e) {

                                        // TODO Auto-generated catch block

                                        e.printStackTrace();

                                        e.getCause().printStackTrace();

                                   }

                                   

                              }

                              

                         }

                         

                    } catch (IOException e) {

                         // TODO Auto-generated catch block

                         e.printStackTrace();

                    }

                    return jaxbAnnotatedPackages;

               }

          • 2. Re: How to deploy seam component manually ?
            Alexei none Apprentice

                 private List<String> scanLibForPackagesWithJaxbAnnotations(File jarFile) {
            
                      
            
                      List<String> jaxbAnnotatedPackages = new ArrayList<String>();
            
                      try {
            
                           
            
                           JarFile jar = new JarFile(jarFile);
            
                           Enumeration jarEntries = jar.entries();
            
                           
            
                           while (jarEntries.hasMoreElements()) {
            
                                
            
                                JarEntry je = (JarEntry) jarEntries.nextElement();
            
                                if(je.getName().endsWith(".class")) {
            
                                     
            
                                     ClassPool cp = ClassPool.getDefault();
            
                                     CtClass ctc = cp.makeClass(jar.getInputStream(je));
            
                                     
            
                                     
            
                                     try {
            
                                          
            
                                          for(Object annotation : ctc.getAnnotations()) {
            
                                               
            
                                               if(annotation instanceof javax.xml.bind.annotation.XmlSchema) {
            
                                                    log.info("jaxb annotated package found " + ctc.getPackageName());
            
                                                    jaxbAnnotatedPackages.add(ctc.getPackageName());
            
                                               }
            
                                               if(annotation instanceof org.jboss.seam.annotations.Name) {
            
                                                    log.info("seam annotated class found " + ctc.getName());
            
                                                    log.info("trying to use "+this.getClass().getClassLoader());
            
                                                    Class clazz = this.getClass().getClassLoader().loadClass(ctc.getName());
            
                                                    
            
                                                    Context context = Contexts.getApplicationContext();
            
                                                    ComponentDescriptor descriptor = new ComponentDescriptor(clazz);
            
                                                    
            
                                                    String name = descriptor.getName();
            
                                                    String componentName = name + ".component";
            
                                                    try {
            
                                                         log.info("Creating component "
            
                                                                   + name
            
                                                                   +" "+ descriptor.getScope()
            
                                                                   +" "+ descriptor.isStartup()
            
                                                                   +" "+ descriptor.getJndiName()
            
                                                                   +" isAutoCreate="+descriptor.isAutoCreate());
            
                                                         Component component = new Component(
            
                                                              descriptor.getComponentClass(), 
            
                                                              name, 
            
                                                              descriptor.getScope(), 
            
                                                              descriptor.isStartup(),
            
                                                              name//descriptor.getJndiName()
            
                                                              );
            
                                                         
            
                                                         log.info("adding component to context "+context);
            
                                                         context.set(componentName, component);
            
                                                         log.info("lookup "+context.get(componentName));
            
                                                         //log.info(org.jboss.seam.util.Naming.getInitialContext().lookup(name));
            
                                                         log.info(Seam.componentForName(name));
            
                                                         log.info(Component.getInstance(name));
            
                                                         //log.info(component.get)
            
                                                         log.info(component.newInstance());
            
                                                    }
            
                                                    catch (Throwable e)
            
                                                    {
            
                                                         throw new RuntimeException("Could not create Component: " + name, e);
            
                                                    }      
            
            
            
                                                    
            
                                                    //Thread.currentThread().getContextClassLoader().loadClass(ctc.getName());
            
                                               }
            
                                               
            
                                          }
            
                                     } catch (ClassNotFoundException e) {
            
                                          // TODO Auto-generated catch block
            
                                          e.printStackTrace();
            
                                          e.getCause().printStackTrace();
            
                                     }
            
                                     
            
                                } 
            
                                
            
                           }
            
                           
            
                      } catch (IOException e) {
            
                           // TODO Auto-generated catch block
            
                           e.printStackTrace();
            
                      }
            
                      return jaxbAnnotatedPackages;
            
                 }