3 Replies Latest reply on Dec 16, 2008 6:17 PM by Abraao Isvi Oliveira Souza do Carmo

    Another XML file for configuration.

    Guilherme Bautto Newbie

      Hello,


      I would like to know if is possible to have another XML file (instead of component.xml) or another complementary file.


      For example:
      I would like to have a component file in web-inf and another file, complementing in meta-inf.
      Is it possible?


      Regards,


      Guilherme Bautto

        • 1. Re: Another XML file for configuration.
          Abraao Isvi Oliveira Souza do Carmo Newbie

          I use something like this. I have a XML Property file in my applications. I put this file in the JBOSS's conf directory. I load him using this code:



          public class ConfigurationLoader {
             
              public static Configuration loadConfiguration(final String baseName) throws IOException {
                 
                  URL url = null;
                 
                  url = getResourceAsURL(baseName);
                 
                  final Properties properties = new Properties();
                 
                  if (baseName.matches("((.)*)\\.xml")) {
                      properties.loadFromXML(url.openStream());
                  } else if (baseName.matches("((.)*)\\.properties")) {
                      properties.load(url.openStream());
                  } else {
                      throw new UnsupportedOperationException("Tipo de arquivo não reconhecido!");
                  }
                 
                  return new Configuration(properties);
              }
             
              public static URL getResourceAsURL(final String resource) throws FileNotFoundException {
                  final String stripped = resource.startsWith("/") ? resource.substring(1) : resource;
                 
                  URL url = null;
                  final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
                  if (classLoader != null) {
                      url = classLoader.getResource(stripped);
                  }
                 
                  if (url == null) {
                      url = ConfigurationLoader.class.getResource(stripped);
                  }
                  if (url == null) {
                      url = ConfigurationLoader.class.getClassLoader().getResource(stripped);
                  }
                 
                  if (url == null) {
                      throw new FileNotFoundException(resource + " not found.");
                  }
                  return url;
              }
          }



          • 2. Re: Another XML file for configuration.
            Igor Guimarães Newbie

            hy Abraao,


            How am I going to pass this collected settings to Seam for will complement the original component.xml file?


            thanks


            Igor Guimarães