001 /*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016 package org.opengion.fukurou.taglet;
017
018 import org.opengion.fukurou.util.LogWriter;
019
020 import com.sun.javadoc.RootDoc;
021 import com.sun.javadoc.ClassDoc;
022 import com.sun.javadoc.Type;
023 import com.sun.javadoc.Tag;
024 import java.util.Map;
025 import java.util.HashMap;
026 import java.io.IOException;
027
028 /**
029 * ソースコメントから?属???を取り??Doclet クラスです?
030 *
031 * @version 4.0
032 * @author Kazuhiko Hasegawa
033 * @since JDK5.0,
034 */
035 public final class DocletPlugin {
036 private static Map<String,AttKeySet> map = new HashMap<String,AttKeySet>();
037
038 private static final String OG_FOR_SMPL = "og.formSample";
039 private static final String ENCODE = "UTF-8";
040
041 /**
042 * すべて?staticメソ?なので、コンストラクタを呼び出さなくしておきます?
043 *
044 */
045 private DocletPlugin() {}
046
047 /**
048 * Doclet のエントリポイントメソ?です?
049 *
050 * @og.rev 5.7.1.1 (2013/12/13) タグのイン?トを止める?
051 *
052 * @param root ドキュメントルートオブジェク?
053 *
054 * @return 正常実行時 true
055 */
056 public static boolean start( final RootDoc root ) {
057 String version = DocletUtil.getOption( "-version" , root.options() );
058 String file = DocletUtil.getOption( "-outfile" , root.options() );
059
060 mapInit();
061
062 DocletTagWriter writer = null;
063 try {
064 writer = new DocletTagWriter( file,ENCODE );
065
066 // 5.7.1.1 (2013/12/13) タグのイン?トを止める?
067 writer.printTag( "<?xml version=\"1.0\" encoding=\"", ENCODE, "\" ?>" );
068 writer.printTag( "<javadoc>" );
069 writer.printTag( "<version>",version,"</version>" );
070 writer.printTag( "<description></description>" );
071 writeContents( root.classes(),writer );
072 writer.printTag( "</javadoc>" );
073 }
074 catch( IOException ex ) {
075 LogWriter.log( ex );
076 }
077 finally {
078 if( writer != null ) { writer.close(); }
079 }
080 return true;
081 }
082
083 /**
084 * ClassDoc 配?よりコン??作?します?
085 * インターフェースも???対象とします?
086 *
087 * @og.rev 5.5.4.1 (2012/07/06) コメント???でなく?Tag配?として処?せる?
088 * @og.rev 5.7.1.1 (2013/12/13) タグのイン?トを止める?
089 *
090 * @param classes ClassDoc配?
091 * @param writer DocletTagWriterオブジェク?
092 */
093 private static void writeContents( final ClassDoc[] classes,final DocletTagWriter writer ) {
094 for(int i=0; i< classes.length; i++) {
095 ClassDoc classDoc = classes[i] ;
096 if( ! classDoc.isPublic() ) { continue; }
097
098 AttKeySet attSet = getAttGroupName( classDoc ) ;
099
100 if( attSet == null ) { continue; } // map に登録されて???
101
102 String attKey = attSet.getAttKey( classDoc.name() );
103
104 if( attKey == null ) { continue; } // 対象クラス名が、??しな??
105
106 String attClass = classDoc.qualifiedName() ; // Class Full Name
107 Tag[] desc = classDoc.firstSentenceTags();
108 // String cmnt = DocletUtil.htmlFilter( classDoc.commentText() ); // 5.5.4.1 (2012/07/06)
109 Tag[] cmnt = classDoc.inlineTags(); // 5.5.4.1 (2012/07/06)
110 Tag[] smplTags = classDoc.tags(OG_FOR_SMPL);
111
112 // 5.7.1.1 (2013/12/13) タグのイン?トを止める?
113 writer.printTag( "<classDoc>" );
114 writer.printTag( "<attClass>" ,attClass ,"</attClass>" );
115 writer.printTag( "<seq>" ,attSet.getSeq() ,"</seq>" );
116 writer.printTag( "<attKey>" ,attKey ,"</attKey>" );
117 writer.printTag( "<valueName>" ,attSet.getValueName() ,"</valueName>" );
118 writer.printTag( "<description>" ,desc ,"</description>" );
119 writer.printTag( "<contents>" ,cmnt ,"</contents>" );
120 writer.printTag( "<formSample>" ,smplTags ,"</formSample>" );
121 writer.printTag( "</classDoc>" );
122 }
123 }
124
125 /**
126 * 処?る属?クラスのMapを?期化します?
127 * ?できるのは、親クラスか?直接のインターフェースです?
128 *
129 * @og.rev 4.3.5.0 (2008/02/01) daemonパッケージ追?
130 * @og.rev 5.5.3.5 (2012/06/21) ChartWriter 削除、TransferExec,TransferRead 追?
131 * @og.rev 5.6.3.3 (2013/04/19) DBTableReport,CalendarData,DBConstValue,JspParserFilter,ConnectIF 追?
132 *
133 */
134 private static void mapInit() {
135 map.put( "org.opengion.hayabusa.db.Query" , new AttKeySet( "Query" ,0, "queryType" ));
136 map.put( "org.opengion.hayabusa.db.CellRenderer" , new AttKeySet( "Renderer" ,1, "renderer" ));
137 map.put( "org.opengion.hayabusa.db.CellEditor" , new AttKeySet( "Editor" ,2, "editor" ));
138 map.put( "org.opengion.hayabusa.db.DBType" , new AttKeySet( "DBType" ,3, "dbType" ));
139 map.put( "org.opengion.hayabusa.db.TableFilter" , new AttKeySet( "TableFilter" ,4, "tableFilter" ));
140 map.put( "org.opengion.hayabusa.db.Selection" , new AttKeySet( "Selection" ,5, "selection" ));
141 map.put( "org.opengion.hayabusa.html.ViewForm" , new AttKeySet( "ViewForm" ,6, "viewFormType" ));
142 map.put( "org.opengion.hayabusa.io.TableWriter" , new AttKeySet( "TableWriter" ,7, "writerClass" ));
143 map.put( "org.opengion.hayabusa.io.TableReader" , new AttKeySet( "TableReader" ,8, "readerClass" ));
144 // map.put( "org.opengion.hayabusa.io.ChartWriter" , new AttKeySet( "ChartWriter" ,9, "chartClass" )); // 5.5.3.5 (2012/06/21)
145 map.put( "org.opengion.hayabusa.resource.CalendarQuery" , new AttKeySet( "CalendarQuery" ,10, "calDB" ));
146 map.put( "org.opengion.fukurou.process.HybsProcess" , new AttKeySet( "Process" ,11, "process" ));
147 map.put( "org.opengion.fukurou.transfer.TransferExec" , new AttKeySet( "TransferExec" ,12, "kbExec" )); // 5.5.3.5 (2012/06/21)
148 map.put( "org.opengion.fukurou.transfer.TransferRead" , new AttKeySet( "TransferRead" ,13, "kbRead" )); // 5.5.3.5 (2012/06/21)
149 map.put( "org.opengion.fukurou.util.HybsTimerTask" , new AttKeySet( "Daemon" ,14, "daemon" )); // 4.3.4.4 (2009/01/01)
150
151 map.put( "org.opengion.hayabusa.report.DBTableReport" , new AttKeySet( "DBTableReport" ,15, "tableReport" )); // 5.6.3.3 (2013/04/19)
152 map.put( "org.opengion.hayabusa.resource.CalendarData" , new AttKeySet( "CalendarData" ,16, "calData" )); // 5.6.3.3 (2013/04/19)
153 map.put( "org.opengion.hayabusa.db.DBConstValue" , new AttKeySet( "DBConstValue" ,17, "cnstVal" )); // 5.6.3.3 (2013/04/19)
154 map.put( "org.opengion.fukurou.xml.JspParserFilter" , new AttKeySet( "JspCreate" ,18, "jspParser" )); // 5.6.3.3 (2013/04/19)
155 map.put( "org.opengion.fukurou.util.ConnectIF " , new AttKeySet( "ConnectIF" ,19, "connIF" )); // 5.6.3.3 (2013/04/19)
156 }
157
158 /**
159 * ?? ClassDoc が?処?る属?クラスのMapに含まれて?場合?
160 * そ? AttKeySet クラスのオブジェクトを返します?
161 * 存在しな??合?null を返します?
162 *
163 * @param classDoc ClassDocオブジェク?
164 *
165 * @return ClassDocに対応す?AttKeySetオブジェク?
166 */
167 private static AttKeySet getAttGroupName( final ClassDoc classDoc ) {
168 if( classDoc == null ) { return null; }
169
170 String classFullName = classDoc.qualifiedName() ;
171 AttKeySet attKey = map.get( classFullName );
172 if( attKey == null ) {
173 Type type = classDoc.superclassType(); // 親クラスタイ?
174 if( type != null ) {
175 attKey = getAttGroupName( type.asClassDoc() ); // 親クラス
176 }
177
178 if( attKey == null ) {
179 Type[] itface = classDoc.interfaceTypes(); // 直近インターフェース
180 for( int i=0; i<itface.length; i++ ) {
181 attKey = getAttGroupName( itface[i].asClassDoc() );
182 if( attKey != null ) { break; }
183 }
184 }
185 }
186 return attKey;
187 }
188
189 /**
190 * カスタ?プションを使用するドックレ?の??メソ? optionLength(String) です?
191 *
192 * ドックレ?に認識させる?スタ?プションに?optionLength がその
193 * オプションを構?する要?(ト?クン) の数を返さなければなりません?
194 * こ?カスタ?プションでは?-tag オプションそ?も?と
195 * そ?値の 2 つの要?構?される?で、作?するドックレ?の
196 * optionLengthメソ?は?-tag オプションに対して 2 を返さなくては
197 * なりません。また?認識できな?プションに対しては? を返します?
198 *
199 * @param option オプション??
200 *
201 * @return 要?(ト?クン) の数
202 */
203 public static int optionLength( final String option ) {
204 if(option.equalsIgnoreCase("-version")) {
205 return 2;
206 }
207 else if(option.equalsIgnoreCase("-outfile")) {
208 return 2;
209 }
210 return 0;
211 }
212 }