KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > ReaderResource


1 /*
2  * $Id: ReaderResource.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;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.io.InputStreamReader JavaDoc;
16 import java.io.Reader JavaDoc;
17
18 import org.mule.MuleManager;
19 import org.mule.util.IOUtils;
20 import org.mule.util.StringUtils;
21
22 /**
23  * <code>ReaderResource</code> is a reader with a description associated with it.
24  * This is useful for error resolution as the reader description can be included when
25  * reporting errors during reading the resource.
26  *
27  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
28  * @version $Revision: 3798 $
29  */

30 public class ReaderResource
31 {
32
33     private String JavaDoc description;
34     private Reader JavaDoc reader;
35
36     public ReaderResource(String JavaDoc description, Reader JavaDoc reader)
37     {
38         this.description = description;
39         this.reader = reader;
40     }
41
42     public String JavaDoc getDescription()
43     {
44         return description;
45     }
46
47     public Reader JavaDoc getReader()
48     {
49         return reader;
50     }
51
52     public static ReaderResource[] parseResources(String JavaDoc configResources, String JavaDoc encoding) throws IOException JavaDoc
53     {
54         String JavaDoc[] resources = StringUtils.splitAndTrim(configResources, ",");
55         MuleManager.getConfiguration().setConfigResources(resources);
56         ReaderResource[] readers = new ReaderResource[resources.length];
57         for (int i = 0; i < resources.length; i++)
58         {
59             InputStream JavaDoc is = IOUtils.getResourceAsStream(resources[i].trim(), ReaderResource.class);
60             if (is == null)
61             {
62                 throw new IOException JavaDoc("could not load resource: " + resources[i].trim());
63             }
64             readers[i] = new ReaderResource(resources[i].trim(), new InputStreamReader JavaDoc(is, encoding));
65         }
66         return readers;
67     }
68
69     public static ReaderResource[] parseResources(String JavaDoc configResources) throws IOException JavaDoc
70     {
71         return parseResources(configResources, MuleManager.getConfiguration().getEncoding());
72     }
73 }
74
Popular Tags