KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > setup > sources > ResourceConfigurationSource


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.setup.sources;
5
6 import com.tc.config.schema.setup.ConfigurationSetupException;
7 import com.tc.util.Assert;
8
9 import java.io.File JavaDoc;
10 import java.io.InputStream JavaDoc;
11
12 /**
13  * A {@link ConfigurationSource} that returns data from a Java resource.
14  */

15 public class ResourceConfigurationSource implements ConfigurationSource {
16
17   private final String JavaDoc path;
18   private final Class JavaDoc relativeTo;
19
20   public ResourceConfigurationSource(String JavaDoc path, Class JavaDoc relativeTo) {
21     Assert.assertNotBlank(path);
22     Assert.assertNotNull(relativeTo);
23
24     this.path = path;
25     this.relativeTo = relativeTo;
26   }
27
28   public InputStream JavaDoc getInputStream(long maxTimeoutMillis) throws ConfigurationSetupException {
29     InputStream JavaDoc out = this.relativeTo.getResourceAsStream(this.path);
30     if (out == null) throw new ConfigurationSetupException("Resource '" + this.path + "', relative to class "
31                                                            + this.relativeTo.getName() + ", does not exist");
32     return out;
33   }
34   
35   public File JavaDoc directoryLoadedFrom() {
36     return null;
37   }
38
39   public boolean isTrusted() {
40     return false;
41   }
42
43   public String JavaDoc toString() {
44     return "Java resource at '" + this.path + "', relative to class " + this.relativeTo.getName();
45   }
46
47 }
48
Popular Tags