KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > dynamic > FileXPathBasedConfigItem


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.dynamic;
5
6 import org.apache.xmlbeans.XmlObject;
7
8 import com.tc.config.schema.context.ConfigContext;
9
10 import java.io.File JavaDoc;
11
12 /**
13  * An {@link XPathBasedConfigItem} that returns its data as a {@link File}. The data should be expressed in XML as some
14  * variant of an <code>xs:string</code>.
15  */

16 public class FileXPathBasedConfigItem extends XPathBasedConfigItem implements FileConfigItem {
17
18   private final File JavaDoc relativeTo;
19
20   public FileXPathBasedConfigItem(ConfigContext context, String JavaDoc xpath, File JavaDoc relativeTo) {
21     super(context, xpath);
22     this.relativeTo = relativeTo;
23   }
24
25   public FileXPathBasedConfigItem(ConfigContext context, String JavaDoc xpath) {
26     this(context, xpath, null);
27   }
28
29   protected Object JavaDoc fetchDataFromXmlObject(XmlObject xmlObject) {
30     String JavaDoc theString = (String JavaDoc) super.fetchDataFromXmlObjectByReflection(xmlObject, "getStringValue");
31     if (theString == null || theString.trim().length() == 0) return null;
32
33     File JavaDoc out = new File JavaDoc(theString);
34     if (this.relativeTo != null && !out.isAbsolute()) out = new File JavaDoc(this.relativeTo, theString);
35     return out;
36   }
37   
38   protected final File JavaDoc relativeTo() {
39     return this.relativeTo;
40   }
41
42   public File JavaDoc getFile() {
43     return (File JavaDoc) getObject();
44   }
45
46 }
47
Popular Tags