01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.xml;
18:
19: import java.io.Reader;
20:
21: import org.compass.core.CompassException;
22: import org.compass.core.util.reader.StringReader;
23:
24: /**
25: * <p>An {@link XmlObject} that has an xml string representation. Mainly used for simpliciy,
26: * where Compass will use the configured {@link org.compass.core.converter.xsem.XmlContentConverter}
27: * in order to convert to xml string into the actual {@link XmlObject} implementation.
28: * <p/>
29: * <p>This object will only be used when saving xml object into Compass. When Compass returns xml objects
30: * as a restult of a query or get/load operations, the actual {@link XmlObject} will be returned.
31: * <p/>
32: * <p>Naturally, since the xml string will only be parsed when Compass will convert this object, all the
33: * {@link XmlObject} methods are not implemented. The {@link XmlObject} is just used as a marker interface
34: * to use the correct xsem supported converters.
35: *
36: * @author kimchy
37: */
38: public class RawXmlObject implements XmlObject {
39:
40: private Reader xml;
41:
42: /**
43: * Creates a new String based xml object using a String holding the actual xml content.
44: */
45: public RawXmlObject(String xml) {
46: this .xml = new StringReader(xml);
47: }
48:
49: /**
50: * Creates a new String based xml object using a Reader holding the actual xml content.
51: */
52: public RawXmlObject(Reader xml) {
53: this .xml = xml;
54: }
55:
56: public Reader getXml() {
57: return this .xml;
58: }
59:
60: public String getName() {
61: throw new CompassException(
62: "Operation not allowed on StringXmlObject");
63: }
64:
65: public String getValue() {
66: throw new CompassException(
67: "Operation not allowed on StringXmlObject");
68: }
69:
70: public XmlObject[] selectPath(String path) throws Exception {
71: throw new CompassException(
72: "Operation not allowed on StringXmlObject");
73: }
74:
75: public boolean canCompileXpath() {
76: throw new CompassException(
77: "Operation not allowed on StringXmlObject");
78: }
79:
80: public XmlXPathExpression compile(String path) throws Exception {
81: throw new CompassException(
82: "Operation not allowed on StringXmlObject");
83: }
84: }
|