KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > definition > DefinitionLoader


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 JavaDoc;
11 import java.net.MalformedURLException JavaDoc;
12 import java.util.Set JavaDoc;
13 import java.util.HashSet JavaDoc;
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 JavaDoc DEFAULT_SYSTEM = "default";
27
28     /**
29      * The path to the definition file.
30      */

31     public static final String JavaDoc DEFINITION_FILE = System.getProperty("aspectwerkz.definition.file", null);
32
33     /**
34      * The default name for the definition file.
35      */

36     public static final String JavaDoc 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 JavaDoc getDefaultDefinition(final ClassLoader JavaDoc loader) {
45         if (DEFINITION_FILE != null) {
46             File JavaDoc file = new File JavaDoc(DEFINITION_FILE);
47             if (file.canRead()) {
48                 try {
49                     return XmlParser.parseNoCache(loader, file.toURL());
50                 } catch (MalformedURLException JavaDoc 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 JavaDoc();
59     }
60 }
Popular Tags