View Javadoc
1   /*
2    * Copyright 2005 Werner Guttmann
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package org.exolab.castor.xml;
15  
16  import java.lang.reflect.Method;
17  
18  /**
19   * Xerces-specific OutputFormat instance.
20   * 
21   * @author <a href="mailto:werner DOT guttmann AT gmx DOT net">Werner Guttmann</a>
22   * @version $Revision: 7951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
23   */
24  public class BaseXercesOutputFormat implements OutputFormat {
25  
26    protected Object _outputFormat;
27  
28    public Object getFormat() {
29      return _outputFormat;
30    }
31  
32    public void setMethod(final String method) {
33      Method aMethod;
34      try {
35        aMethod = _outputFormat.getClass().getMethod("setMethod", new Class[] {String.class});
36        aMethod.invoke(_outputFormat, new Object[] {method});
37      } catch (Exception e) {
38        throw new RuntimeException("Problem invoking OutputFormat.setMethod()", e);
39      }
40    }
41  
42    public void setIndenting(final boolean indent) {
43      Method method;
44      try {
45        method = _outputFormat.getClass().getMethod("setIndenting", new Class[] {boolean.class});
46        method.invoke(_outputFormat, new Object[] {Boolean.valueOf(indent)});
47      } catch (Exception e) {
48        throw new RuntimeException("Problem invoking OutputFormat.setIndenting()", e);
49      }
50    }
51  
52    public void setPreserveSpace(final boolean preserveSpace) {
53      Method method;
54      try {
55        method = _outputFormat.getClass().getMethod("setPreserveSpace", new Class[] {boolean.class});
56        method.invoke(_outputFormat, new Object[] {Boolean.valueOf(preserveSpace)});
57      } catch (Exception e) {
58        throw new RuntimeException("Problem invoking OutputFormat.setPreserveSpace()", e);
59      }
60    }
61  
62    public void setDoctype(final String type1, final String type2) {
63      Method method;
64      try {
65        method = _outputFormat.getClass().getMethod("setDoctype",
66            new Class[] {String.class, String.class});
67        method.invoke(_outputFormat, new Object[] {type1, type2});
68      } catch (Exception e) {
69        throw new RuntimeException("Problem invoking OutputFormat.setDoctype()", e);
70      }
71    }
72  
73    public void setOmitXMLDeclaration(final boolean omitXMLDeclaration) {
74      Method method;
75      try {
76        method =
77            _outputFormat.getClass().getMethod("setOmitXMLDeclaration", new Class[] {boolean.class});
78        method.invoke(_outputFormat, new Object[] {Boolean.valueOf(omitXMLDeclaration)});
79      } catch (Exception e) {
80        throw new RuntimeException("Problem invoking OutputFormat.setOmitXMLDeclaration()", e);
81      }
82    }
83  
84    public void setOmitDocumentType(final boolean omitDocumentType) {
85      Method method;
86      try {
87        method = _outputFormat.getClass().getMethod("setOmitDocumentType", boolean.class);
88        method.invoke(_outputFormat, Boolean.valueOf(omitDocumentType));
89      } catch (Exception e) {
90        throw new RuntimeException("Problem invoking OutputFormat.setOmitDocumentType()", e);
91      }
92    }
93  
94    public void setEncoding(final String encoding) {
95      Method method;
96      try {
97        method = _outputFormat.getClass().getMethod("setEncoding", String.class);
98        method.invoke(_outputFormat, encoding);
99      } catch (Exception e) {
100       throw new RuntimeException("Problem invoking OutputFormat.setEncoding()", e);
101     }
102   }
103 
104   public void setVersion(final String version) {
105     Method method;
106     try {
107       method = _outputFormat.getClass().getMethod("setVersion", new Class[] {String.class});
108       method.invoke(_outputFormat, new Object[] {version});
109     } catch (Exception e) {
110       throw new RuntimeException("Problem invoking OutputFormat.setVersion()", e);
111     }
112   }
113 
114 }