View Javadoc
1   /*
2    * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  package com.sun.tools.doclets.formats.html;
27  
28  import java.io.IOException;
29  
30  import com.sun.javadoc.*;
31  import com.sun.tools.javac.jvm.Profile;
32  import com.sun.tools.doclets.internal.toolkit.*;
33  import com.sun.tools.doclets.internal.toolkit.util.*;
34  
35  /**
36   * The factory that returns HTML writers.
37   *
38   *  <p><b>This is NOT part of any supported API.
39   *  If you write code that depends on this, you do so at your own risk.
40   *  This code and its internal interfaces are subject to change or
41   *  deletion without notice.</b>
42   *
43   * @author Jamie Ho
44   * @since 1.5
45   */
46  public class WriterFactoryImpl implements WriterFactory {
47  
48      private final ConfigurationImpl configuration;
49  
50      public WriterFactoryImpl(ConfigurationImpl configuration) {
51          this.configuration = configuration;
52      }
53  
54      /**
55       * {@inheritDoc}
56       */
57      public ConstantsSummaryWriter getConstantsSummaryWriter() throws Exception {
58          return new ConstantsSummaryWriterImpl(configuration);
59      }
60  
61      /**
62       * {@inheritDoc}
63       */
64      public PackageSummaryWriter getPackageSummaryWriter(PackageDoc packageDoc,
65          PackageDoc prevPkg, PackageDoc nextPkg) throws Exception {
66          return new PackageWriterImpl(configuration, packageDoc,
67              prevPkg, nextPkg);
68      }
69  
70      /**
71       * {@inheritDoc}
72       */
73      public ProfileSummaryWriter getProfileSummaryWriter(Profile profile,
74          Profile prevProfile, Profile nextProfile) throws Exception {
75          return new ProfileWriterImpl(configuration, profile,
76              prevProfile, nextProfile);
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      public ProfilePackageSummaryWriter getProfilePackageSummaryWriter(PackageDoc packageDoc,
83          PackageDoc prevPkg, PackageDoc nextPkg, Profile profile) throws Exception {
84          return new ProfilePackageWriterImpl(configuration, packageDoc,
85              prevPkg, nextPkg, profile);
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      public ClassWriter getClassWriter(ClassDoc classDoc, ClassDoc prevClass,
92              ClassDoc nextClass, ClassTree classTree) throws IOException {
93          return new ClassWriterImpl(configuration, classDoc,
94                  prevClass, nextClass, classTree);
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     public AnnotationTypeWriter getAnnotationTypeWriter(
101         AnnotationTypeDoc annotationType, Type prevType, Type nextType)
102     throws Exception {
103         return new AnnotationTypeWriterImpl(configuration,
104                 annotationType, prevType, nextType);
105     }
106 
107     /**
108      * {@inheritDoc}
109      */
110     public AnnotationTypeFieldWriter
111             getAnnotationTypeFieldWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception {
112         return new AnnotationTypeFieldWriterImpl(
113             (SubWriterHolderWriter) annotationTypeWriter,
114             annotationTypeWriter.getAnnotationTypeDoc());
115     }
116 
117     /**
118      * {@inheritDoc}
119      */
120     public AnnotationTypeOptionalMemberWriter
121             getAnnotationTypeOptionalMemberWriter(
122         AnnotationTypeWriter annotationTypeWriter) throws Exception {
123         return new AnnotationTypeOptionalMemberWriterImpl(
124             (SubWriterHolderWriter) annotationTypeWriter,
125             annotationTypeWriter.getAnnotationTypeDoc());
126     }
127 
128     /**
129      * {@inheritDoc}
130      */
131     public AnnotationTypeRequiredMemberWriter
132             getAnnotationTypeRequiredMemberWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception {
133         return new AnnotationTypeRequiredMemberWriterImpl(
134             (SubWriterHolderWriter) annotationTypeWriter,
135             annotationTypeWriter.getAnnotationTypeDoc());
136     }
137 
138     /**
139      * {@inheritDoc}
140      */
141     public EnumConstantWriterImpl getEnumConstantWriter(ClassWriter classWriter)
142             throws Exception {
143         return new EnumConstantWriterImpl((SubWriterHolderWriter) classWriter,
144             classWriter.getClassDoc());
145     }
146 
147     /**
148      * {@inheritDoc}
149      */
150     public FieldWriterImpl getFieldWriter(ClassWriter classWriter)
151             throws Exception {
152         return new FieldWriterImpl((SubWriterHolderWriter) classWriter,
153             classWriter.getClassDoc());
154     }
155 
156     /**
157      * {@inheritDoc}
158      */
159     public PropertyWriterImpl getPropertyWriter(ClassWriter classWriter)
160             throws Exception {
161         return new PropertyWriterImpl((SubWriterHolderWriter) classWriter,
162             classWriter.getClassDoc());
163     }
164 
165     /**
166      * {@inheritDoc}
167      */
168     public MethodWriterImpl getMethodWriter(ClassWriter classWriter)
169             throws Exception {
170         return new MethodWriterImpl((SubWriterHolderWriter) classWriter,
171             classWriter.getClassDoc());
172     }
173 
174     /**
175      * {@inheritDoc}
176      */
177     public ConstructorWriterImpl getConstructorWriter(ClassWriter classWriter)
178             throws Exception {
179         return new ConstructorWriterImpl((SubWriterHolderWriter) classWriter,
180             classWriter.getClassDoc());
181     }
182 
183     /**
184      * {@inheritDoc}
185      */
186     public MemberSummaryWriter getMemberSummaryWriter(
187             ClassWriter classWriter, int memberType)
188             throws Exception {
189         switch (memberType) {
190             case VisibleMemberMap.CONSTRUCTORS:
191                 return getConstructorWriter(classWriter);
192             case VisibleMemberMap.ENUM_CONSTANTS:
193                 return getEnumConstantWriter(classWriter);
194             case VisibleMemberMap.FIELDS:
195                 return getFieldWriter(classWriter);
196             case VisibleMemberMap.PROPERTIES:
197                 return getPropertyWriter(classWriter);
198             case VisibleMemberMap.INNERCLASSES:
199                 return new NestedClassWriterImpl((SubWriterHolderWriter)
200                     classWriter, classWriter.getClassDoc());
201             case VisibleMemberMap.METHODS:
202                 return getMethodWriter(classWriter);
203             default:
204                 return null;
205         }
206     }
207 
208     /**
209      * {@inheritDoc}
210      */
211     public MemberSummaryWriter getMemberSummaryWriter(
212         AnnotationTypeWriter annotationTypeWriter, int memberType)
213     throws Exception {
214         switch (memberType) {
215             case VisibleMemberMap.ANNOTATION_TYPE_FIELDS:
216                 return (AnnotationTypeFieldWriterImpl)
217                     getAnnotationTypeFieldWriter(annotationTypeWriter);
218             case VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL:
219                 return (AnnotationTypeOptionalMemberWriterImpl)
220                     getAnnotationTypeOptionalMemberWriter(annotationTypeWriter);
221             case VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED:
222                 return (AnnotationTypeRequiredMemberWriterImpl)
223                     getAnnotationTypeRequiredMemberWriter(annotationTypeWriter);
224             default:
225                 return null;
226         }
227     }
228 
229     /**
230      * {@inheritDoc}
231      */
232     public SerializedFormWriter getSerializedFormWriter() throws Exception {
233         return new SerializedFormWriterImpl(configuration);
234     }
235 }