jdk/make/tools/swing-beans/GenDocletBeanInfo.java
author jiangli
Thu, 26 Jul 2012 17:24:31 -0400
changeset 13311 71effe5a1069
parent 5506 202f599c92aa
permissions -rw-r--r--
7187046: Crash in ClassFileParser on solaris-ia32 during RetransformClasses. Summary: Lower compiler optimization level when compiling jvmtiClassFileReconstituter.cpp as a workaround for the solaris x86 5.10 cc bug. Reviewed-by: kvn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import com.sun.javadoc.ClassDoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import com.sun.javadoc.MethodDoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.javadoc.RootDoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.javadoc.Tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.beans.Introspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Properties supported and tag syntax:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *      bound: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      constrained: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      expert: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      hidden: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      preferred: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      description: string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      displayname: string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      propertyeditorclass: string (with dots: foo.bar.MyPropertyEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      customizerclass: string (w/dots: foo.bar.MyCustomizer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      attribute: key1 value1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      attribute: key2 value2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * TODO: getValue and genDocletInfo needs some cleaning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Rich Schiavi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Mark Davidson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class GenDocletBeanInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static String[] ATTRIBUTE_NAMES = { "bound",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                     "constrained",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                     "expert",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                     "hidden",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                     "preferred",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                     "displayname",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                     "propertyeditorclass",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                     "customizerclass",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                     "displayname",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                     "description",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                     "enum",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                     "attribute" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static boolean DEBUG = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static String fileDir = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static String templateDir = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static final String TRUE = "true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static final String FALSE = "false";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Method called from the javadoc environment to determint the options length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Doclet options:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *      -t template location
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *      -d outputdir
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *      -x true Enable debug output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static int optionLength(String option) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        // remind: this needs to be cleaned up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (option.equals("-t"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (option.equals("-d"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (option.equals("-x"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /** @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * bound:true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * constrained:false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * expert:true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * hidden:true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * preferred:false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * description: the description of this method can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *              do all sorts of funky things. if it \n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *              is indented like this, we have to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *              all char spaces greater than 2 and also any hard-coded \n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *              newline characters and all newlines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * displayname: theString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * propertyeditorclass: foo.bar.MyPropertyEditorClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * customizerclass: foo.bar.MyCustomizerClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * attribute:key1 value1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * attribute: key2  value2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public static boolean start(RootDoc doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        readOptions(doc.options());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (templateDir.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            System.err.println("-t option not specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (fileDir.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            System.err.println("-d option not specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        GenSwingBeanInfo generator = new GenSwingBeanInfo(fileDir, templateDir, DEBUG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        Hashtable dochash = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        DocBeanInfo dbi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        /* "javadoc Foo.java Bar.java" will return:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        *         "Foo Foo.I1 Foo.I2 Bar Bar.I1 Bar.I2"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        * i.e., with all the innerclasses of classes specified in the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        * line.  We don't want to generate BeanInfo for any of these inner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        * classes, so we ignore these by remembering what the last outer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        * class was.  A hack, I admit, but makes the build faster.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        String previousClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        ClassDoc[] classes = doc.classes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        for (int cnt = 0; cnt < classes.length; cnt++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            String className = classes[cnt].qualifiedName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (previousClass != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                className.startsWith(previousClass) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                className.charAt(previousClass.length()) == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            previousClass = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            // XXX - debug
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            System.out.println("\n>>> Generating beaninfo for " + className + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            // Examine the javadoc tags and look for the the @beaninfo tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            // This first block looks at the javadoc for the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            Tag[] tags = classes[cnt].tags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            for (int i = 0; i < tags.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                if (tags[i].kind().equalsIgnoreCase("@beaninfo")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                       System.out.println("GenDocletBeanInfo: found @beaninfo tagged Class: " + tags[i].text());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    dbi = genDocletInfo(tags[i].text(), classes[cnt].name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    dochash.put(dbi.name, dbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            // This block looks at the javadoc for the class methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            int startPos = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            MethodDoc[] methods = classes[cnt].methods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            for (int j = 0; j < methods.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                // actually don't "introspect" - look for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                // methods with a @beaninfo tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                tags = methods[j].tags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                for (int x = 0; x < tags.length; x++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    if (tags[x].kind().equalsIgnoreCase("@beaninfo")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        if ((methods[j].name().startsWith("get")) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                            (methods[j].name().startsWith("set")))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                            startPos = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        else if (methods[j].name().startsWith("is"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                            startPos = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                            startPos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        String propDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            Introspector.decapitalize((methods[j].name()).substring(startPos));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                            System.out.println("GenDocletBeanInfo: found @beaninfo tagged Method: " + tags[x].text());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        dbi = genDocletInfo(tags[x].text(), propDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        dochash.put(dbi.name, dbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                // dump our classes doc beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                System.out.println(">>>>DocletBeanInfo for class: " + classes[cnt].name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                Enumeration e = dochash.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    DocBeanInfo db = (DocBeanInfo)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    System.out.println(db.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            // Use the generator to create the beaninfo code for the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            generator.genBeanInfo(classes[cnt].containingPackage().name(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                        classes[cnt].name(), dochash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // reset the values!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            dochash.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        } // end for loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Reads the command line options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Side Effect, sets class variables templateDir, fileDir and DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private static void readOptions(String[][] options)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        // Parse the command line args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        for (int i = 0; i < options.length; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (options[i][0].equals("-t")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                templateDir = options[i][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            } else if (options[i][0].equals("-d")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                fileDir = options[i][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            } else if (options[i][0].equals("-x")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                if (options[i][1].equals("true"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    DEBUG=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    DEBUG=false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Create a "BeanInfo" data structure from the tag. This is a data structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * which contains all beaninfo data for a method or a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param text All the text after the @beaninfo tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param name Name of the property i.e., mnemonic for setMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    private static DocBeanInfo genDocletInfo(String text, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int beanflags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        String desc = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        String displayname = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        String propertyeditorclass = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        String customizerclass = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        String value = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        HashMap attribs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        HashMap enums = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        for (int j = 0; j < ATTRIBUTE_NAMES.length; j++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            if ((index = text.indexOf(ATTRIBUTE_NAMES[j])) != -1){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                value = getValue((text).substring(index),ATTRIBUTE_NAMES[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("attribute")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    attribs = getAttributeMap(value, " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("enum")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    enums = getAttributeMap(value, " \n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                else if (ATTRIBUTE_NAMES[j].equals("displayname")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    displayname = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                else if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("propertyeditorclass")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    propertyeditorclass = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                else if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("customizerclass")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    customizerclass = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("bound"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    beanflags = beanflags | DocBeanInfo.BOUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("expert"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    beanflags = beanflags | DocBeanInfo.EXPERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("constrained"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    beanflags = beanflags | DocBeanInfo.CONSTRAINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("hidden"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    beanflags = beanflags | DocBeanInfo.HIDDEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("preferred"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    beanflags = beanflags | DocBeanInfo.PREFERRED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                else if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("description")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    desc = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        /** here we create our doclet-beaninfo data structure, which we read in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         *  later if it has anything worthwhile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // Construct a new Descriptor class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return new DocBeanInfo(name, beanflags, desc,displayname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                         propertyeditorclass, customizerclass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                         attribs, enums);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Parses the substring and returns the cleaned up value for the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @param substring Full String of the attrib tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *       i.e., "attribute: visualUpdate true" will return "visualUpdate true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    private static String getValue(String substring, String prop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        StringTokenizer t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        String value = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            /** if the ATTRIBUTE_NAMES is NOT the description, then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
             *  parse until newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
             *  if it is the description we read until the next token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
             *  and then look for a match in the last MAXMATCH index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
             *  and truncate the description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
             *  if it is the attribute we wead until no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            if (prop.equalsIgnoreCase("attribute")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                StringBuffer tmp = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    t = new StringTokenizer(substring, " :\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    t.nextToken().trim();//the prop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    // we want to return : key1 value1 key2 value2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    while (t.hasMoreTokens()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                        tmp.append(t.nextToken().trim()).append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        tmp.append(t.nextToken().trim()).append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                        String test = t.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                        if (!(test.equalsIgnoreCase("attribute")))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                } catch (Exception e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                value = tmp.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            else if (prop.equalsIgnoreCase("enum")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                t = new StringTokenizer(substring, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                t.nextToken().trim(); // the prop we already know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                StringBuffer tmp = new StringBuffer(t.nextToken().trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                for (int i = 0; i < ATTRIBUTE_NAMES.length; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    if (tmp.toString().endsWith(ATTRIBUTE_NAMES[i])){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        int len = ATTRIBUTE_NAMES[i].length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                        // trim off that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                        tmp.setLength(tmp.length() - len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                value = tmp.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            else if (prop.equalsIgnoreCase("description")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                t = new StringTokenizer(substring, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                t.nextToken().trim(); // the prop we already know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                StringBuffer tmp = new StringBuffer(t.nextToken().trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                for (int i = 0; i < ATTRIBUTE_NAMES.length; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    if (tmp.toString().endsWith(ATTRIBUTE_NAMES[i])){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                        int len = ATTRIBUTE_NAMES[i].length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                        // trim off that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        tmp.setLength(tmp.length() - len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                value = hansalizeIt(tmp.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                // Single value properties like bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                t = new StringTokenizer(substring, ":\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                t.nextToken().trim(); // the prop we already know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                value = t.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            // now we need to look for a match of any of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            // property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        catch (Exception e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            return "invalidValue";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Creates a HashMap containing the key value pair for the parsed values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * of the "attributes" and "enum" tags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * ie. For attribute value: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *     The HashMap will have key: visualUpdate, value: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    private static HashMap getAttributeMap(String str, String delim)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        StringTokenizer t = new StringTokenizer(str, delim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        HashMap map = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        String key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        String value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        int num = t.countTokens()/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (num > 0)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            map = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                key = t.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                value = t.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                map.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    // looks for extra spaces, \n hard-coded and invisible,etc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    private static String hansalizeIt(String from){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        char [] chars = from.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        int len = chars.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        int toss = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        // remove double spaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        for (int i = 0; i < len; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if ((chars[i] == ' ')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                if (i+1 < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    if ((chars[i+1] == ' ' ) || (chars[i+1] == '\n'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                            --len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                            System.arraycopy(chars,i+1,chars,i,len-i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                            --i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            if (chars[i] == '\n'){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                chars[i] = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                i -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if (chars[i] == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                if (i+1 < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    if (chars[i+1] == 'n'){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        chars[i+1] = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        --len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        System.arraycopy(chars,i+1, chars,i, len-i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        --i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return new String(chars,0,len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
}