View Javadoc

    1   /***************************************************************************************
    2    * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved.                 *
    3    * http://aspectwerkz.codehaus.org                                                    *
    4    * ---------------------------------------------------------------------------------- *
    5    * The software in this package is published under the terms of the LGPL license      *
    6    * a copy of which has been included with this distribution in the license.txt file.  *
    7    **************************************************************************************/
    8   package org.codehaus.aspectwerkz.definition;
    9
    10  import java.io.File;
    11  import java.net.MalformedURLException;
    12  import java.util.Set;
    13  import java.util.HashSet;
    14
    15  /***
    16   * TODO remove class and move single method to SystemDefinitionContainer?s
    17   * <p/>
    18   * Handles the loading of the definition in various ways and formats.
    19   *
    20   * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
    21   */
    22  public class DefinitionLoader {
    23      /***
    24       * The UUID of the single AspectWerkz system if only one definition is used.
    25       */
    26      public static final String DEFAULT_SYSTEM = "default";
    27
    28      /***
    29       * The path to the definition file.
    30       */
    31      public static final String DEFINITION_FILE = System.getProperty("aspectwerkz.definition.file", null);
    32
    33      /***
    34       * The default name for the definition file.
    35       */
    36      public static final String DEFAULT_DEFINITION_FILE_NAME = "aspectwerkz.xml";
    37
    38      /***
    39       * Returns the default defintion.
    40       *
    41       * @param loader
    42       * @return the default defintion
    43       */
    44      public static Set getDefaultDefinition(final ClassLoader loader) {
    45          if (DEFINITION_FILE != null) {
    46              File file = new File(DEFINITION_FILE);
    47              if (file.canRead()) {
    48                  try {
    49                      return XmlParser.parseNoCache(loader, file.toURL());
    50                  } catch (MalformedURLException e) {
    51                      System.err.println("<WARN> Cannot read " + DEFINITION_FILE);
    52                      e.printStackTrace();
    53                  }
    54              } else {
    55                  System.err.println("<WARN> Cannot read " + DEFINITION_FILE);
    56              }
    57          }
    58          return new HashSet();
    59      }
    60  }