Project Report: fawkez

Packagesummary org.jcoderz.phoenix.sqlparser

org.jcoderz.phoenix.sqlparser.SpecialColumnComment

LineHitsNoteSource
1  /*
2   * $Id: SpecialColumnComment.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.phoenix.sqlparser;
34  
35  import java.util.StringTokenizer;
36  
37  /**
38   * This class represents a special comment in the following form
39   * -- &cmpgen.java-type org.jcoderz.ipp.Msisdn
40   * -- &cmpgen.storeMethod="toString()"
41   * -- &cmpgen.loadMethod="fromString(java.lang.String)".
42   *
43   * @author Albrecht Messner
44   */
45100 public class SpecialColumnComment
46  {
47     private String mJavaType;
48     private String mStoreMethod;
49     private String mLoadMethod;
50     private String mCurrencyColumn;
51     private String mPeriodFieldName;
52     private String mPeriodEndDateColumn;
53     private String mWeblogicColumnType;
54100    private boolean mSkipInInterface = false;
55  
56     /** {@inheritDoc} */
57     public final String toString ()
58     {
590       return "[SpecialColumnComment "
60              + "java-type=" + mJavaType
61              + ", store-method=" + mStoreMethod
62              + ", load-method=" + mLoadMethod
63              + "]";
64     }
65     
66     /**
67      * Parse a special comment.
68      * @param t the token to parse
69      * @throws ParseException if the comment has a syntax error
70      */
71 (1)   public final void parseComment (Token t) throws ParseException
72     {
73100       final String s = t.getValue();
74100       if (s.indexOf("@cmpgen") != -1)
75        {
76100          if (s.indexOf("java-type") != -1)
77           {
78100             if (isSetJavaType())
79              {
800(2)               throw new ParseException(
81                         "Duplicate special comment 'java-type'", -1, -1);
82              }
83100             mJavaType = getValue(s);
84           }
85100          else if (s.indexOf("store-method") != -1)
86           {
87100             if (isSetStoreMethod())
88              {
890(3)               throw new ParseException(
90                    "Duplicate special comment 'store-method'", -1, -1);
91              }
92100             mStoreMethod = getValue(s);
93           }
94100          else if (s.indexOf("load-method") != -1)
95           {
96100             if (isSetLoadMethod())
97              {
980(4)               throw new ParseException(
99                    "Duplicate special comment 'load-method'", -1, -1);
100              }
101100             mLoadMethod = getValue(s);
102           }
1030          else if (s.indexOf("currency-column") != -1)
104           {
1050             if (isSetCurrencyColumn())
106              {
1070(5)               throw new ParseException(
108                       "Duplicate special comment 'currency-column'", -1, -1);
109              }
1100             mCurrencyColumn = getValue(s);
111           }
1120          else if (s.indexOf("period-field-name") != -1)
113           {
1140             if (isSetPeriodFieldName())
115              {
1160(6)               throw new ParseException(
117                       "Duplicate special comment 'period-field-name'", -1, -1);
118              }
1190             mPeriodFieldName = getValue(s);
120           }
1210          else if (s.indexOf("period-end-date-column") != -1)
122           {
1230             if (isSetPeriodEndDateColumn())
124              {
1250(7)               throw new ParseException(
126                       "Duplicate special comment 'period-end-date-column'",
127                       -1, -1);
128              }
1290             mPeriodEndDateColumn = getValue(s);
130           }
1310          else if (s.indexOf("skip-in-interface") != -1)
132           {
1330             mSkipInInterface = true;
134           }
1350          else if (s.indexOf("weblogic-dbms-column-type") != -1)
136           {
1370             if (isSetWeblogicColumnType())
138              {
1390(8)               throw new ParseException(
140                       "Duplicate special comment 'weblogic.dbms-column-type'",
141                       -1, -1);
142              }
1430             mWeblogicColumnType = getValue(s);
144           }
145           else
146           {
1470(9)            throw new ParseException("Invalid special comment", -1, -1);
148           }
149        }
150100    }
151     
152     private String getValue (String s)
153     {
154100       final StringTokenizer tok = new StringTokenizer(s, "=");
155100       tok.nextToken(); // just skip first token
156100       String secondPart = tok.nextToken();
157100       secondPart = secondPart.trim();
158100       if (secondPart.startsWith("\""))
159        {
160100          secondPart = secondPart.substring(1);
161        }
162100       if (secondPart.endsWith("\""))
163        {
164100          secondPart = secondPart.substring(0, secondPart.length() - 1);
165        }
166100       return secondPart.trim();
167     }
168  
169     /**
170      * Returns the period field name.
171      * @return the period field name
172      */
173     public final String getPeriodFieldName ()
174     {
175100       return mPeriodFieldName;
176     }
177  
178     /**
179      * Returns the end date column.
180      * @return the end date column
181      */
182     public final String getPeriodEndDateColumn ()
183     {
184100       return mPeriodEndDateColumn;
185     }
186  
187     /**
188      * Returns the currency column.
189      * @return the currency column
190      */
191     public final String getCurrencyColumn ()
192     {
193100       return mCurrencyColumn;
194     }
195  
196     /**
197      * Returns the java type.
198      * @return the java type
199      */
200     public final String getJavaType ()
201     {
202100       return mJavaType;
203     }
204  
205     /**
206      * Returns the load method.
207      * @return the load method
208      */
209     public final String getLoadMethod ()
210     {
211100       return mLoadMethod;
212     }
213  
214     /**
215      * Returns the store method.
216      * @return the store method
217      */
218     public final String getStoreMethod ()
219     {
220100       return mStoreMethod;
221     }
222  
223     /**
224      * Check whether all required fields have been set.
225      * @throws ParseException if the comment is invalid
226      */
227     public final void validate () throws ParseException
228     {
22950       if (isSetLoadMethod() || isSetStoreMethod())
230        {
231           // if one is set, both must be present
232100          if (! (isSetLoadMethod() && isSetStoreMethod()))
233           {
2340             throw new ParseException(
235                 "'store-method' and 'load-method' must be "
236                 + "both present or both absent",
237                 -1,
238                 -1);
239           }
240  
241           // if we have load and store methods, we also need the
242           // java type
243100          if (! isSetJavaType())
244           {
2450             throw new ParseException(
246                 "Invalid special comment, mandatory field missing",
247                 -1,
248                 -1);
249           }
250        }
251  
252100       if (isSetPeriodFieldName())
253        {
254           // if one is set, both must be present
2550          if (! (isSetPeriodEndDateColumn()))
256           {
2570             throw new ParseException(
258                 "'period-end-date-column' must be"
259                 + " present when 'period-field-name' has been specified.",
260                 -1,
261                 -1);
262           }
263        }
264100    }
265  
266 (10)   public final boolean isSkipInInterface ()
267     {
268100       return mSkipInInterface;
269     }
270     
271     /**
272      * Check whether the field mJavaType has been set.
273      * @return true if the field is not-null, false otherwise
274      */
275     public final boolean isSetJavaType ()
276     {
277100       return mJavaType != null;
278     }
279  
280     /**
281      * Check whether the field mStoreMethod has been set.
282      * @return true if the field is not-null, false otherwise
283      */
284     public final boolean isSetStoreMethod ()
285     {
286100       return mStoreMethod != null;
287     }
288  
289     /**
290      * Check whether the field mLoadMethod has been set.
291      * @return true if the field is not-null, false otherwise
292      */
293     public final boolean isSetLoadMethod ()
294     {
295100       return mLoadMethod != null;
296     }
297     
298     /**
299      * Check whether the field mCurrencyColumn has been set.
300      * @return true if the field is not-null, false otherwise
301      */
302     public final boolean isSetCurrencyColumn ()
303     {
3040       return mCurrencyColumn != null;
305     }
306  
307     /**
308      * Check whether the field mPeriodFieldName has been set.
309      * @return true if the field is not-null, false otherwise
310      */
311     public final boolean isSetPeriodFieldName ()
312     {
31375       return mPeriodFieldName != null;
314     }
315  
316     /**
317      * Check whether the field mPeriodEndDateColumn has been set.
318      * @return true if the field is not-null, false otherwise
319      */
320     public final boolean isSetPeriodEndDateColumn ()
321     {
3220       return mPeriodEndDateColumn != null;
323     }
324  
325 (11)   public String getWeblogicColumnType ()
326     {
327100       return mWeblogicColumnType;
328     }
329     
330 (12)   public boolean isSetWeblogicColumnType ()
331     {
3320       return mWeblogicColumnType != null;
333     }
334  }

Findings in this File

c (1) 71 : 4 Cyclomatic Complexity is 17 (max allowed is 12).
i (2) 80 : 0 method org.jcoderz.phoenix.sqlparser.SpecialColumnComment.parseComment(Token) throws exception with static message string
i (3) 89 : 0 method org.jcoderz.phoenix.sqlparser.SpecialColumnComment.parseComment(Token) throws exception with static message string
i (4) 98 : 0 method org.jcoderz.phoenix.sqlparser.SpecialColumnComment.parseComment(Token) throws exception with static message string
i (5) 107 : 0 method org.jcoderz.phoenix.sqlparser.SpecialColumnComment.parseComment(Token) throws exception with static message string
i (6) 116 : 0 method org.jcoderz.phoenix.sqlparser.SpecialColumnComment.parseComment(Token) throws exception with static message string
i (7) 125 : 0 method org.jcoderz.phoenix.sqlparser.SpecialColumnComment.parseComment(Token) throws exception with static message string
i (8) 139 : 0 method org.jcoderz.phoenix.sqlparser.SpecialColumnComment.parseComment(Token) throws exception with static message string
i (9) 147 : 0 method org.jcoderz.phoenix.sqlparser.SpecialColumnComment.parseComment(Token) throws exception with static message string
c (10) 266 : 4 Missing a Javadoc comment.
c (11) 325 : 4 Missing a Javadoc comment.
c (12) 330 : 4 Missing a Javadoc comment.