01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.config.schema.dynamic;
05:
06: import org.apache.xmlbeans.XmlObject;
07:
08: import com.tc.config.schema.context.ConfigContext;
09:
10: import java.io.File;
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
17: implements FileConfigItem {
18:
19: private final File relativeTo;
20:
21: public FileXPathBasedConfigItem(ConfigContext context,
22: String xpath, File relativeTo) {
23: super (context, xpath);
24: this .relativeTo = relativeTo;
25: }
26:
27: public FileXPathBasedConfigItem(ConfigContext context, String xpath) {
28: this (context, xpath, null);
29: }
30:
31: protected Object fetchDataFromXmlObject(XmlObject xmlObject) {
32: String theString = (String) super
33: .fetchDataFromXmlObjectByReflection(xmlObject,
34: "getStringValue");
35: if (theString == null || theString.trim().length() == 0)
36: return null;
37:
38: File out = new File(theString);
39: if (this .relativeTo != null && !out.isAbsolute())
40: out = new File(this .relativeTo, theString);
41: return out;
42: }
43:
44: protected final File relativeTo() {
45: return this .relativeTo;
46: }
47:
48: public File getFile() {
49: return (File) getObject();
50: }
51:
52: }
|