Project Report: fawkez

Packagesummary org.jcoderz.commons.doclet

org.jcoderz.commons.doclet.XmlDocletConfig

LineHitsNoteSource
1  /*
2   * $Id: XmlDocletConfig.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.doclet;
34  
35  import java.io.File;
36  import java.io.Serializable;
37  import java.net.MalformedURLException;
38  import java.net.URL;
39  import java.util.ArrayList;
40  import java.util.Collections;
41  import java.util.HashMap;
42  import java.util.List;
43  import java.util.Map;
44  import java.util.logging.Level;
45  import java.util.logging.Logger;
46  
47  import org.jcoderz.commons.ArgumentMalformedException;
48  import org.jcoderz.commons.util.ArraysUtil;
49  import org.jcoderz.commons.util.Assert;
50  
51  
52  /**
53   * Value object for the XmlDoclet configuration values.
54   *
55   * @author Andreas Mandel
56   */
570 public final class XmlDocletConfig
58        implements Serializable, Cloneable
59  {
60     static final int OPTION_NOT_KNOWN = 0;
61     static final int ERROR_WITH_OPTION = -1;
62  
63     /** The full qualified name of this class. */
640    private static final String CLASSNAME = XmlDocletConfig.class.getName();
65  
66     /** The logger to use. */
670    private static final Logger logger = Logger.getLogger(CLASSNAME);
68  
69     private static final long serialVersionUID = -202900277699915981L;
70  
71     private static final Map OPTION_MAP;
72  
73     static
74     {
750       final Map tempMap = new HashMap();
76  
770       final XmlDocletOption outputDirectory
78              = new XmlDocletOption("-d", 2, "Output Directory")
790             {
80                 public boolean validOption (XmlDocletConfig cfg, String[] args)
81                       throws ArgumentMalformedException
82                 {
830                   return cfg.parseOutputDirectory(args);
84                 }
85              };
860       tempMap.put(outputDirectory.getOption(), outputDirectory);
870       final XmlDocletOption link
88              = new XmlDocletOption("-link", 2, "Link reference")
890             {
90                 public boolean validOption (XmlDocletConfig cfg, String[] args)
91                       throws ArgumentMalformedException
92                 {
930                   return cfg.parseLink(args);
94                 }
95              };
960       tempMap.put(link.getOption(), link);
97  
980       OPTION_MAP = Collections.unmodifiableMap(tempMap);
990    }
100  
101     /** Output directory, to generate the output to. */
102     private File mOutputDirectory;
103  
104     /** List of link urls. */
1050    private final List mLinkUrls = new ArrayList();
106  
107  
108     /** {@inheritDoc} */
109     public Object clone ()
110           throws CloneNotSupportedException
111     {
1120       return super.clone();
113     }
114  
115     /**
116      * Parses the given option with the arguments and updates this
117      * option object accordingly.
118      * @param optionValue the option to be set.
119      * @param args the arguments that came with this option.
120      * @throws ArgumentMalformedException if the option could not be
121      *       parsed.
122      * @see com.sun.javadoc.Doclet#validOptions(java.lang.String[][], com.sun.javadoc.DocErrorReporter)
123      */
124     public void parseOption (String optionValue, String[] args)
125           throws ArgumentMalformedException
126     {
1270       if (logger.isLoggable(Level.FINER))
128        {
1290          logger.entering(CLASSNAME, "parseOption(String, String[])",
130                 new Object [] {optionValue, ArraysUtil.toString(args)});
131        }
1320       final XmlDocletOption option
133              = (XmlDocletOption) OPTION_MAP.get(optionValue);
134  
1350       if (option == null)
136        {
1370           logger.fine("Gracefully ignoring unknown option " + optionValue
138                + " with value " + ArraysUtil.toString(args) + ".");
139        }
140        else
141        {
1420           if (args.length != (option.getNumberOfArguments() - 1))
143            {
1440              throw new ArgumentMalformedException("number of arguments",
145                     String.valueOf(args.length - 1), "The option '" + optionValue
146                     + "' expects " + (option.getNumberOfArguments() - 1)
147                     + " arguments.");
148            }
1490           option.validOption(this, args);
150        }
1510       if (logger.isLoggable(Level.FINER))
152        {
1530          logger.exiting(CLASSNAME, "parseOption(String, String[])");
154        }
1550    }
156  
157     /**
158      * Returns the option length for the given option. A value of 2
159      * implies that the argument takes one option. The value 0
160      * {@link #OPTION_NOT_KNOWN} means that the option is unknown and a
161      * value of -1 {@link #ERROR_WITH_OPTION} denotes an error.
162      * @param optionValue the option to be checked.
163      * @return the option length for the given option.
164      * @see com.sun.javadoc.Doclet#optionLength(java.lang.String)
165      */
166     public int optionLength (String optionValue)
167     {
1680       final XmlDocletOption option
169              = (XmlDocletOption) OPTION_MAP.get(optionValue);
170  
171        final int result;
1720       if (option == null)
173        {
1740          result = OPTION_NOT_KNOWN;
175        }
176        else
177        {
1780          result = option.getNumberOfArguments();
179        }
1800       return result;
181     }
182  
183     /**
184      * Returns the output directory set.
185      * @return the output directory set.
186      */
187     public File getOutputDirectory ()
188     {
1890       return mOutputDirectory;
190     }
191  
192     private boolean parseLink (String[] args)
193     {
194        URL url;
195        try
196        {
1970          url = new URL(args[0]);
1980          mLinkUrls.add(url);
199        }
2000       catch (MalformedURLException ex)
201        {
2020          throw new ArgumentMalformedException("link", args[0], ex.getMessage(),
203                 ex);
2040       }
205  
206 (1)      // TODO Auto-generated method stub
2070       return false;
208     }
209  
210  
211     private boolean parseOutputDirectory (String[] args)
212           throws ArgumentMalformedException
213     {
2140       Assert.notNull(args[0], "d");
2150       mOutputDirectory = new File(args[0]);
2160       if (!mOutputDirectory.isDirectory())
217        {
2180(2)         throw new ArgumentMalformedException("outputDirectory", args[0],
219                 "Output directory must be set to a directory.");
220        }
2210       return true;
222     }
223  
224  
2250    private abstract static class XmlDocletOption
226     {
227        private final String mOption;
228        private final int mNumberOfArguments;
229        private final String mShortDescription;
230  
231        XmlDocletOption (String option, int numberOfArguments, String description)
2320       {
2330          mOption = option;
2340          mNumberOfArguments = numberOfArguments;
2350          mShortDescription = description;
2360       }
237  
238        abstract boolean validOption (XmlDocletConfig cfg, String [] args)
239              throws ArgumentMalformedException;
240  
241        int getNumberOfArguments ()
242        {
2430          return mNumberOfArguments;
244        }
245  
246        String getOption ()
247        {
2480          return mOption;
249        }
250  
251        String getShortDescription ()
252        {
2530          return mShortDescription;
254        }
255     }
256  }

Findings in this File

i (1) 206 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
i (2) 218 : 0 method org.jcoderz.commons.doclet.XmlDocletConfig.parseOutputDirectory(String[]) throws exception with static message string