KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > tools > ajdoc > DocletProxy


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22
23 package org.aspectj.tools.ajdoc;
24 import org.aspectj.tools.doclets.standard.AbstractStandard;
25 import org.aspectj.tools.doclets.standard.Standard;
26
27 import com.sun.javadoc.DocErrorReporter;
28 import com.sun.javadoc.RootDoc;
29
30 import java.io.IOException JavaDoc;
31 import java.util.List JavaDoc;
32
33 /**
34  */

35 public interface DocletProxy {
36     public static final DocletProxy STANDARD
37         = JavadocStandardProxy.SINGLETON;
38     public static final DocletProxy DEFAULT
39         = StandardProxy.SINGLETON;
40     public int optionLength(String JavaDoc arg);
41     public boolean start(RootDoc root)
42         throws IOException JavaDoc;
43     public boolean validOptions(List JavaDoc options, DocErrorReporter handler)
44         throws IOException JavaDoc;
45 }
46
47 /**
48  * This proxy delegates to Standard singleton,
49  * but delays alerts about it being unavailable until first use
50  */

51 class StandardProxy implements DocletProxy {
52     public static final DocletProxy SINGLETON = new StandardProxy();
53     private StandardProxy() { }
54
55     /** check and delegate to standard */
56     public int optionLength(String JavaDoc arg) {
57         return Standard.optionLength(arg);
58     }
59     /** check and delegate to standard */
60     public boolean validOptions(List JavaDoc options, DocErrorReporter handler)
61         throws IOException JavaDoc {
62         return AbstractStandard.validOptions(docletOptions(options), handler);
63     }
64     // todo: validate that this is the expected format for doclet options
65
protected String JavaDoc[][] docletOptions(List JavaDoc options) {
66         if ((null == options) || (1 > options.size())) {
67             return new String JavaDoc[][]{};
68         }
69         Object JavaDoc[] ra = options.toArray();
70         String JavaDoc[] strs = new String JavaDoc[ra.length];
71         for (int i = 0; i < ra.length; i++) {
72             strs[i] = (null == ra[i] ? null : ra[i].toString());
73         }
74         return new String JavaDoc[][] {strs};
75     }
76
77     /** check and delegate to standard */
78     public boolean start(RootDoc root) throws IOException JavaDoc {
79         return Standard.start(root);
80     }
81 } // StandardProxy
82

83 /**
84  * This proxy delegates to javadoc Standard singleton.
85  */

86 class JavadocStandardProxy implements DocletProxy {
87     public static final DocletProxy SINGLETON = new JavadocStandardProxy();
88     private JavadocStandardProxy() { }
89
90     /** check and delegate to standard */
91     public int optionLength(String JavaDoc arg) {
92         return com.sun.tools.doclets.standard.Standard.optionLength(arg);
93     }
94     /** check and delegate to standard */
95     public boolean validOptions(List JavaDoc options, DocErrorReporter handler)
96         throws IOException JavaDoc {
97         return com.sun.tools.doclets.standard.Standard.validOptions(docletOptions(options), handler);
98     }
99     // todo: validate that this is the expected format for doclet options
100
protected String JavaDoc[][] docletOptions(List JavaDoc options) {
101         if ((null == options) || (1 > options.size())) {
102             return new String JavaDoc[][]{};
103         }
104         Object JavaDoc[] ra = options.toArray();
105         String JavaDoc[] strs = new String JavaDoc[ra.length];
106         for (int i = 0; i < ra.length; i++) {
107             strs[i] = (null == ra[i] ? null : ra[i].toString());
108         }
109         return new String JavaDoc[][] {strs};
110     }
111
112     /** check and delegate to standard */
113     public boolean start(RootDoc root) throws IOException JavaDoc {
114         return com.sun.tools.doclets.standard.Standard.start(root);
115     }
116 } // JavadocStandardProxy
117

118 /** Wrap a Throwable as a RuntimeException
119  * This will render stack trace as the delegate stack trace,
120  * notwithstanding any call to fillInStackTrace.
121 class ExceptionWrapper extends RuntimeException {
122     Throwable delegate;
123     public ExceptionWrapper(Throwable t) {
124         delegate = (null == t ? new Error("null") : t);
125     }
126     public void printStackTrace() {
127         delegate.printStackTrace();
128     }
129     public void printStackTrace(PrintStream stream) {
130         delegate.printStackTrace(stream);
131     }
132     public void printStackTrace(PrintWriter stream) {
133         delegate.printStackTrace(stream);
134     }
135     public String getMessage() {
136         return delegate.getMessage();
137     }
138     public String getLocalizedMessage() {
139         return delegate.getLocalizedMessage();
140     }
141     public Throwable fillInStackTrace() {
142         return delegate.fillInStackTrace();
143     }
144 }
145 */

146
Popular Tags