Skip to main content
summaryrefslogtreecommitdiffstats
blob: 98e90cc3c647ca9f571932a9bb107ea6db6b5150 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.internal.core.document;

import org.eclipse.wst.wsi.internal.core.WSIException;
import org.eclipse.wst.wsi.internal.core.analyzer.config.AnalyzerConfig;
import org.eclipse.wst.wsi.internal.core.analyzer.config.AnalyzerConfigReader;
import org.eclipse.wst.wsi.internal.core.log.Log;
import org.eclipse.wst.wsi.internal.core.log.LogReader;
import org.eclipse.wst.wsi.internal.core.log.LogWriter;
import org.eclipse.wst.wsi.internal.core.monitor.config.MonitorConfig;
import org.eclipse.wst.wsi.internal.core.monitor.config.MonitorConfigReader;
import org.eclipse.wst.wsi.internal.core.profile.ProfileAssertions;
import org.eclipse.wst.wsi.internal.core.profile.ProfileAssertionsReader;
import org.eclipse.wst.wsi.internal.core.report.Report;
import org.eclipse.wst.wsi.internal.core.report.ReportWriter;
import org.eclipse.wst.wsi.internal.core.util.WSIProperties;

/**
 * This abstract class defines the factory interface that can be used to 
 * read and write all of the Conformance XML documents.
 * 
 * @version 1.0.1
 * @author Peter Brittenham (peterbr@us.ibm.com)
 */
public abstract class DocumentFactory
{
  /**
   * Get a new instance of a DocumentFactory.
   * @return a new instance of a DocumentFactory.
   * @throws WSIException if problems occur during creation.
   */
  public static DocumentFactory newInstance() throws WSIException
  {
    // Return instance of factory
    return newInstance(getFactoryClassName());
  }

  /**
   * Get a new instance of a DocumentFactory using the specified
   * factory class name.
   * @param factoryClassName factory class name.
   * @return a new instance of a DocumentFactory.
   * @throws WSIException if problems occur during creation.
   */
  public static DocumentFactory newInstance(String factoryClassName)
    throws WSIException
  {
    DocumentFactory documentFactory = null;

    // If a factory class name was specified, then create object
    if (factoryClassName != null)
    {
      try
      {
        // Get class object
        Class factoryClass = Class.forName(factoryClassName);

        // Create new factory
        documentFactory = (DocumentFactory) factoryClass.newInstance();
      }

      catch (Exception e)
      {
        throw new WSIException(
          "Could not instantiate document factory class: "
            + factoryClassName
            + ".",
          e);
      }
    }
    else
    {
      throw new WSIException("A WSIDocumentFactory implementation class was not found.");
    }

    // Return factory
    return documentFactory;
  }

  // DOCUMENT TYPES

  /**
   * Create log file.
   * @return log file.
   */
  public abstract Log newLog();

  /**
   * Create monitor config.
   * @return newly created monitor config.
   */
  public abstract MonitorConfig newMonitorConfig();

  /**
   * Create analyzer config.
   * @return newly created analyzer config.
   */
  public abstract AnalyzerConfig newAnalyzerConfig();

  /**
   * Create profile assertions.
   * @return newly created profile assertions.
   */
  public abstract ProfileAssertions newProfileAssertions();

  /**
   * Create report.
   * @return newly created report.
   */
  public abstract Report newReport();

  // READERS

  /**
   * Create profile assertions reader.
   * @return newly created profile assertions reader.
   */
  public abstract ProfileAssertionsReader newProfileAssertionsReader();

  /**
   * Create monitor config reader.
   * @return newly created monitor config reader.
   */
  public abstract MonitorConfigReader newMonitorConfigReader();

  /**
   * Create analyzer config reader.
   * @return newly created analyzer config reader.
   */
  public abstract AnalyzerConfigReader newAnalyzerConfigReader();

  /**
   * Create log reader.
   * @return newly created log reader.
   */
  public abstract LogReader newLogReader();

  // ADD: Add other readers

  // WRITERS

  /**
   * Create report writer.
   * @return newly created report writer.
   */
  public abstract ReportWriter newReportWriter();

  /**
   * Create log writer.
   * @return newly created log writer.
   */
  public abstract LogWriter newLogWriter();

  // ADD: Add other writers

  /**
   * Find the factory class name which can be specified as a Java property.
   */
  private static String getFactoryClassName()
  {
    // Get property value
    return WSIProperties.getProperty(
      WSIProperties.PROP_DOCUMENT_FACTORY,
      WSIProperties.DEF_DOCUMENT_FACTORY);
  }
}

Back to the top