9 Replies Latest reply on Mar 31, 2008 12:17 PM by Ales Justin

    Parsing more than one file

    Ales Justin Master

      What's the idea here:
      - http://jira.jboss.com/jira/browse/JBDEPLOY-4

      Should we currently just do this:

       if (files.size() == 0)
       {
       return null;
       }
       else if (files.size() > 1)
       {
       return parseMultipleFiles(files);
       }
       else
       {
       VirtualFile file = files.get(0);
       T result = parse(vfsDeploymentUnit, file, root);
       if (result != null)
       init(vfsDeploymentUnit, result, file);
       return result;
       }
       }
      
       /**
       * Handle multiple matching files.
       *
       * @param files the matching files
       * @return merged metadata or null if already handled
       * @throws Exception for any error
       */
       protected T parseMultipleFiles(List<VirtualFile> files) throws Exception
       {
       throw new DeploymentException("Handling multiple files not supported: " + files);
       }
      

      and let every sub-parser deployer take care of it as it knows best?

        • 1. Re: Parsing more than one file
          Adrian Brock Master

          The parsing multiple files has two parts:

          1) Being able to parse n files into one piece of metatdata from one parsing deployer

          This is so you can deploy something programmatically properly.
          e.g. You pass EjbJarMetaData. The current parsing deployers will say,
          ok I'm not going to reparse ejb-jar.xml but I will reparse jboss.xml
          which is wrong

          2) Being able to parse multiple files with the same suffix from META-INF.

          e.g.
          META-INF/a-beans.xml
          META-INF/b-beans.xml

          should create two KernelDeployment attachments (with the attachment names
          as the metadata url).

          But this requires the deployers further down the chain to understand it.
          i.e. not use getAttachments(KernelDeployment.class) but use
          getAllAttachments(KernelDeployment.class) and handle the multiple pieces
          of configuration correctly.

          • 2. Re: Parsing more than one file
            Adrian Brock Master

            Again these are implementation details i.e. not requirements for CR1

            • 3. Re: Parsing more than one file
              Ales Justin Master

               

              "adrian@jboss.org" wrote:

              Again these are implementation details i.e. not requirements for CR1

              But I can keep my 'parseMultipleFiles' hook?



              • 4. Re: Parsing more than one file
                Adrian Brock Master

                 

                "alesj" wrote:
                "adrian@jboss.org" wrote:

                Again these are implementation details i.e. not requirements for CR1

                But I can keep my 'parseMultipleFiles' hook?



                If you like, but provide a way to do what I said above
                i.e. create multiple attachments for each file which should be the usual implementation
                when not throwing an error because it is not supported. e.g. you can't have
                two web.xmls


                • 5. Re: Parsing more than one file
                  Ales Justin Master

                   

                  "adrian@jboss.org" wrote:

                  2) Being able to parse multiple files with the same suffix from META-INF.

                  e.g.
                  META-INF/a-beans.xml
                  META-INF/b-beans.xml

                  should create two KernelDeployment attachments (with the attachment names
                  as the metadata url).

                  But this requires the deployers further down the chain to understand it.
                  i.e. not use getAttachments(KernelDeployment.class) but use
                  getAllAttachments(KernelDeployment.class) and handle the multiple pieces
                  of configuration correctly.


                  This is done.
                  KernelDeploymentDeployer already handles KernelDeployments in such way - getAllMetaData(KernelDeployment.class).

                  "adrian@jboss.org" wrote:

                  1) Being able to parse n files into one piece of metatdata from one parsing deployer

                  This is so you can deploy something programmatically properly.
                  e.g. You pass EjbJarMetaData. The current parsing deployers will say,
                  ok I'm not going to reparse ejb-jar.xml but I will reparse jboss.xml
                  which is wrong


                  This probably requires change into AbstractParsingDeployerWithOutput, to take more than one name?

                  • 6. Re: Parsing more than one file
                    Ales Justin Master

                     

                    "alesj" wrote:

                    This probably requires change into AbstractParsingDeployerWithOutput, to take more than one name?


                    Is there a default impl we want/can do with these two new methods - handling multiple names in AbstractParsingDeployerWithOutput:
                     if (suffix == null)
                     {
                     if (hasSingleName())
                     result = parse(unit, getName(), result);
                     else
                     result = parse(unit, names, result);
                     }
                     else
                     {
                     if (hasSingleName())
                     result = parse(unit, getName(), suffix, result);
                     else
                     result = parse(unit, names, suffix, result);
                     }
                    
                    
                     protected T parse(DeploymentUnit unit, Set<String> names, T root) throws Exception
                     {
                     return null;
                     }
                    
                     protected T parse(DeploymentUnit unit, Set<String> names, String suffix, T root) throws Exception
                     {
                     return null;
                     }
                    


                    • 7. Re: Parsing more than one file
                      Ales Justin Master

                       

                      "alesj" wrote:

                      Is there a default impl we want/can do with these two new methods - handling multiple names in AbstractParsingDeployerWithOutput:
                       protected T parse(DeploymentUnit unit, Set<String> names, T root) throws Exception
                       {
                       return null;
                       }
                      

                      This one is no brainer. :-)
                       protected T parse(DeploymentUnit unit, Set<String> names, T root) throws Exception
                       {
                       if (names == null || names.isEmpty())
                       throw new IllegalArgumentException("Null or empty names.");
                      
                       VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit)unit;
                      
                       Set<VirtualFile> files = new HashSet<VirtualFile>();
                       Set<String> missingFiles = new HashSet<String>();
                      
                       for (String name : names)
                       {
                       VirtualFile file = vfsDeploymentUnit.getMetaDataFile(name);
                       if (file != null)
                       files.add(file);
                       else
                       missingFiles.add(name);
                       }
                      
                       if (missingFiles.size() == names.size())
                       return null;
                      
                       return mergeFiles(files, missingFiles);
                       }
                      
                       /**
                       * Merge files into one piece of metatdata
                       *
                       * @param files matching meta files
                       * @param missingFiles file names that are missing matching file
                       * @return merged metadata
                       */
                       protected T mergeFiles(Set<VirtualFile> files, Set<String> missingFiles)
                       {
                       return null;
                       }
                      


                      • 8. Re: Parsing more than one file
                        Ales Justin Master

                         

                        "alesj" wrote:

                        This one is no brainer. :-)

                        So it the second one. :-)
                        It just matches more files, due to additional suffix match.

                         protected T parse(DeploymentUnit unit, Set<String> names, String suffix, T root) throws Exception
                         {
                         if (names == null || names.isEmpty())
                         throw new IllegalArgumentException("Null or empty names.");
                        
                         VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit)unit;
                        
                         Set<VirtualFile> files = new HashSet<VirtualFile>();
                         Set<String> missingFiles = new HashSet<String>();
                        
                         for (String name : names)
                         {
                         List<VirtualFile> matched = vfsDeploymentUnit.getMetaDataFiles(name, suffix);
                         if (matched != null && matched.isEmpty() == false)
                         files.addAll(matched);
                         else
                         missingFiles.add(name);
                         }
                        
                         if (missingFiles.size() == names.size())
                         return null;
                        
                         return mergeFiles(files, missingFiles);
                         }
                        


                        • 9. Re: Parsing more than one file
                          Ales Justin Master

                          Merge method has been changed a bit:

                           /**
                           * Merge files into one piece of metatdata
                           *
                           * @param unit the unit
                           * @param root possibly null pre-existing root
                           * @param files matching meta files
                           * @param missingFiles file names that are missing matching file
                           * @return merged metadata
                           * @throws Exception for any error
                           */
                           protected T mergeFiles(VFSDeploymentUnit unit, T root, Set<VirtualFile> files, Set<String> missingFiles) throws Exception
                           {
                           return null;
                           }