KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > capture > ResultsHelper


1 /**
2  * $Id: ResultsHelper.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The GNU LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.capture;
30
31 import java.util.Map JavaDoc;
32
33 import org.apache.tools.ant.Project;
34
35 import com.idaremedia.antx.ExportedProperties;
36 import com.idaremedia.antx.parameters.IsA;
37
38 /**
39  * Utility to assign the result values to the appropriate type of fixture element.
40  *
41  * @since JWare/AntX 0.5
42  * @author ssmc, &copy;2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
43  * @version 0.5
44  * @.safety multiple
45  * @.group impl,helper
46  **/

47
48 public final class ResultsHelper
49 {
50     /**
51      * Assign the result values to the appropriate type of fixture element. Note
52      * that the incoming conclusion must be one of the fixed interpreter
53      * constant values! If the result type is anything but write-once properties
54      * this helper will <em>clear</em> pre-existing values if results are clean.
55      * @param config call config (non-null)
56      * @param errs number of final errors as a string (non-null)
57      * @param warnings number of final warnings as a string (non-null)
58      * @param result the <em>normalized</em> conclusion (non-null)
59      **/

60     public static void set(InterpretParameters config, String JavaDoc errs, String JavaDoc warnings, String JavaDoc result)
61     {
62         final Project P = config.getProject();
63         if (config.updateProperties()) {
64             boolean unclean = !LogInterpreter.CLEAN.equals(result);
65             switch (config.getResultType().getIndex()) {
66                 case IsA.VARIABLE_INDEX: {
67                     if (unclean) {
68                         ExportedProperties.set(config.getErrorCountProperty(),errs);
69                         ExportedProperties.set(config.getWarningCountProperty(),warnings);
70                     } else {
71                         ExportedProperties.unset(config.getErrorCountProperty());
72                         ExportedProperties.unset(config.getWarningCountProperty());
73                     }
74                     ExportedProperties.set(config.getUpdateProperty(),result);
75                     break;
76                 }
77                 case IsA.REFERENCE_INDEX: {
78                     Map JavaDoc refstable = P.getReferences();
79                     synchronized(refstable) {
80                         if (unclean) {
81                             refstable.put(config.getErrorCountProperty(),errs);
82                             refstable.put(config.getWarningCountProperty(),warnings);
83                         } else {
84                             refstable.remove(config.getErrorCountProperty());
85                             refstable.remove(config.getWarningCountProperty());
86                         }
87                         refstable.put(config.getUpdateProperty(),result);
88                     }
89                     break;
90                 }
91                 default: {
92                     if (unclean) {
93                         P.setNewProperty(config.getErrorCountProperty(),errs);
94                         P.setNewProperty(config.getWarningCountProperty(),warnings);
95                     }
96                     P.setNewProperty(config.getUpdateProperty(),result);
97                 }
98             }//switch
99
}//do-updates
100
}
101
102
103
104     /**
105      * Like
106      * {@linkplain #set(InterpretParameters config, String errs, String warnings, String result)
107      * set(InterpretParameters,String,String,String)} but results are passed as scalar values.
108      **/

109     public static void set(InterpretParameters config, int nErrs, int nWarnings, String JavaDoc result)
110     {
111         set(config,String.valueOf(nErrs),String.valueOf(nWarnings),result);
112     }
113     
114
115     private ResultsHelper()
116     {
117         /*disallow*/
118     }
119 }
120
121 /* end-of-ResultsHelper.java */
Popular Tags