01: package org.compass.core.converter.xsem;
02:
03: import java.io.Reader;
04:
05: import org.compass.core.CompassException;
06: import org.compass.core.config.CompassConfigurable;
07: import org.compass.core.config.CompassSettings;
08: import org.compass.core.converter.ConversionException;
09: import org.compass.core.xml.AliasedXmlObject;
10: import org.compass.core.xml.XmlObject;
11:
12: /**
13: * An {@link XmlContentConverter} implementation that wraps the actual {@link XmlContentConverter}
14: * configured (based on the settings) and creates and configures a singleton (shared) {@link XmlContentConverter}
15: * for both {@link #toXml(org.compass.core.xml.XmlObject)} and {@link #fromXml(String, java.io.Reader)}.
16: *
17: * @author kimchy
18: */
19: public class SingletonXmlContentConverterWrapper implements
20: XmlContentConverter, CompassConfigurable {
21:
22: private XmlContentConverter xmlContentConverter;
23:
24: /**
25: * Creates and configures a singleton {@link XmlContentConverter}.
26: */
27: public void configure(CompassSettings settings)
28: throws CompassException {
29: this .xmlContentConverter = XmlContentConverterUtils
30: .createXmlContentConverter(settings);
31: }
32:
33: /**
34: * Converts the {@link XmlObject} into raw xml by using the shared
35: * {@link XmlContentConverter} implementation.
36: *
37: * @see XmlContentConverter#toXml(org.compass.core.xml.XmlObject)
38: */
39: public String toXml(XmlObject xmlObject) throws ConversionException {
40: return xmlContentConverter.toXml(xmlObject);
41: }
42:
43: /**
44: * Converts a raw xml and an alias into an {@link AliasedXmlObject} by using the shared
45: * {@link XmlContentConverter} implementation.
46: *
47: * @see XmlContentConverter#fromXml(String, java.io.Reader)
48: */
49: public AliasedXmlObject fromXml(String alias, Reader xml)
50: throws ConversionException {
51: return xmlContentConverter.fromXml(alias, xml);
52: }
53: }
|