View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
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  package org.openehealth.ipf.commons.xml;
17  
18  import org.openehealth.ipf.commons.xml.svrl.SchematronOutput;
19  
20  import javax.xml.transform.dom.DOMResult;
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  import java.io.Writer;
24  
25  /**
26   * @author Christian Ohr
27   */
28  class ResultHolderFactory {
29  
30      @SuppressWarnings("unchecked")
31      public static <T> ResultHolder<T> create(Class<T> clazz) {
32          if (String.class == clazz) {
33              return (ResultHolder<T>) new StringResultHolder();
34          } else if (InputStream.class == clazz) {
35              return (ResultHolder<T>) new InputStreamResultHolder();
36          } else if (OutputStream.class == clazz) {
37              return (ResultHolder<T>) new OutputStreamResultHolder();
38          } else if (Writer.class == clazz) {
39              return (ResultHolder<T>) new WriterResultHolder();
40          } else if (DOMResult.class == clazz) {
41              return (ResultHolder<T>) new DOMResultHolder();
42          } else if (SchematronOutput.class == clazz) {
43              return (ResultHolder<T>) new SvrlResultHolder();
44          } else {
45              return null;
46          }
47      }
48  
49  }