KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > builders > MuleClasspathConfigurationBuilder


1 /*
2  * $Id: MuleClasspathConfigurationBuilder.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.config.builders;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStreamReader JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.apache.commons.lang.ObjectUtils;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.mule.config.ConfigurationException;
23 import org.mule.config.ReaderResource;
24 import org.mule.config.i18n.Message;
25 import org.mule.config.i18n.Messages;
26 import org.mule.umo.manager.UMOManager;
27 import org.mule.util.StringUtils;
28
29 /**
30  * <code>MuleClasspathConfigurationBuilder</code> can be used to configure a
31  * MuleManager based on the configuration files on the classpath. the default config
32  * resource name is <b>mule-config.xml</b> but this can be overrided by passing a
33  * config resourse name or a list of resource names (comma separated) to the
34  * configure method.
35  *
36  * @deprecated The functionality of this configuration builder (loading resources
37  * from the classpath) is now available in the standard
38  * MuleXmlConfigurationBuilder. If you are using this builder, please
39  * verify whether your configuration will work with
40  * org.mule.config.builders.MuleXmlConfigurationBuilder as this class is
41  * deprecated and is soon to be removed.
42  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
43  * @version $Revision: 3798 $
44  */

45 public class MuleClasspathConfigurationBuilder extends MuleXmlConfigurationBuilder
46 {
47     /**
48      * logger used by this class
49      */

50     protected static Log logger = LogFactory.getLog(MuleClasspathConfigurationBuilder.class);
51
52     public static final String JavaDoc MULE_CONFIGURATION_RESOURCE = "mule-config.xml";
53
54     public MuleClasspathConfigurationBuilder() throws ConfigurationException
55     {
56         super();
57     }
58
59     /**
60      * Will configure a UMOManager based on the configuration file(s) provided.
61      *
62      * @param configResources can be null or a comma separated resources name string
63      * that will be used to search the classpath. The default is
64      * mule-config.xml.
65      * @return A configured UMOManager
66      * @throws org.mule.config.ConfigurationException if the configResources param is
67      * invalid or the configurations fail to load
68      */

69     public UMOManager configure(String JavaDoc configResources, String JavaDoc startupPropertiesFile)
70         throws ConfigurationException
71     {
72         if (StringUtils.isBlank(configResources))
73         {
74             configResources = MULE_CONFIGURATION_RESOURCE;
75         }
76
77         URL JavaDoc url = null;
78         List JavaDoc list = new ArrayList JavaDoc();
79         String JavaDoc[] resString;
80         int i = 0;
81
82         try
83         {
84             resString = StringUtils.splitAndTrim(configResources, ",");
85             for (i = 0; i < resString.length; i++)
86             {
87                 url = Thread.currentThread().getContextClassLoader().getResource(resString[i]);
88                 if (url == null) break;
89                 list.add(new ReaderResource(url.toExternalForm(), new InputStreamReader JavaDoc(url.openStream())));
90             }
91         }
92         catch (IOException JavaDoc ioe)
93         {
94             throw new ConfigurationException(new Message(Messages.FAILED_LOAD_X, "Config: "
95                                                                                  + ObjectUtils.toString(url,
96                                                                                      "null")), ioe);
97         }
98
99         if (list.size() != resString.length)
100         {
101             throw new ConfigurationException(new Message(Messages.FAILED_LOAD_X,
102                 "Not all resources specified loaded: " + resString[i]));
103         }
104
105         ReaderResource[] resources = new ReaderResource[list.size()];
106         resources = (ReaderResource[])list.toArray(resources);
107         configure(resources, null);
108         return manager;
109     }
110 }
111
Popular Tags