Source Code Cross Referenced for Assertions.java in  » Build » ANT » org » apache » tools » ant » types » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Build » ANT » org.apache.tools.ant.types 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.tools.ant.types;
020:
021:        import org.apache.tools.ant.BuildException;
022:        import org.apache.tools.ant.Project;
023:
024:        import java.util.ArrayList;
025:        import java.util.Iterator;
026:        import java.util.List;
027:        import java.util.ListIterator;
028:
029:        /**
030:         * The assertion datatype. This type describes
031:         * assertion settings for the <java> task and others.
032:         * One can set the system assertions, and enable/disable those in
033:         * packages and classes.
034:         * Assertions can only be enabled or disabled when forking Java.
035:         *
036:         * Example: set system assertions and all org.apache packages except
037:         * for ant, and the class org.apache.tools.ant.Main.
038:         * <pre>
039:         * &lt;assertions enableSystemAssertions="true" &gt;
040:         *   &lt;enable package="org.apache" /&gt;
041:         *   &lt;disable package="org.apache.ant" /&gt;
042:         *   &lt;enable class="org.apache.tools.ant.Main"/&gt;
043:         * &lt;/assertions&gt;
044:         *</pre>
045:         * Disable system assertions; enable those in the anonymous package
046:         * <pre>
047:         * &lt;assertions enableSystemAssertions="false" &gt;
048:         *   &lt;enable package="..." /&gt;
049:         * &lt;/assertions&gt;
050:         * </pre>
051:         * enable assertions in a class called Test
052:         * <pre>
053:         * &lt;assertions &gt;
054:         *   &lt;enable class="Test" /&gt;
055:         * &lt;/assertions&gt;
056:         * </pre>
057:         * This type is a datatype, so you can declare assertions and use them later
058:         *
059:         * <pre>
060:         * &lt;assertions id="project.assertions" &gt;
061:         *   &lt;enable project="org.apache.test" /&gt;
062:         * &lt;/assertions&gt;
063:         *
064:         * &lt;assertions refid="project.assertions" /&gt;
065:         *
066:         * </pre>
067:         * @since Ant 1.6
068:         */
069:        public class Assertions extends DataType implements  Cloneable {
070:
071:            /**
072:             * enable/disable sys assertions; null means undefined
073:             */
074:            private Boolean enableSystemAssertions;
075:
076:            /**
077:             * list of type BaseAssertion
078:             */
079:            private ArrayList assertionList = new ArrayList();
080:
081:            /**
082:             * enable assertions
083:             * @param assertion an enable assertion nested element
084:             */
085:            public void addEnable(EnabledAssertion assertion) {
086:                checkChildrenAllowed();
087:                assertionList.add(assertion);
088:            }
089:
090:            /**
091:             * disable assertions
092:             * @param assertion a disable assertion nested element
093:             */
094:            public void addDisable(DisabledAssertion assertion) {
095:                checkChildrenAllowed();
096:                assertionList.add(assertion);
097:            }
098:
099:            /**
100:             * enable or disable system assertions.
101:             * Default is not set (neither -enablesystemassersions or -disablesytemassertions
102:             * are used on the command line).
103:             * @param enableSystemAssertions if true enable system assertions
104:             */
105:            public void setEnableSystemAssertions(Boolean enableSystemAssertions) {
106:                checkAttributesAllowed();
107:                this .enableSystemAssertions = enableSystemAssertions;
108:            }
109:
110:            /**
111:             * Set the value of the refid attribute.
112:             *
113:             * <p>Subclasses may need to check whether any other attributes
114:             * have been set as well or child elements have been created and
115:             * thus override this method. if they do the must call
116:             * <code>super.setRefid</code>.</p>
117:             * @param ref the reference to use
118:             */
119:            public void setRefid(Reference ref) {
120:                if (assertionList.size() > 0 || enableSystemAssertions != null) {
121:                    throw tooManyAttributes();
122:                }
123:                super .setRefid(ref);
124:            }
125:
126:            /**
127:             * get whatever we are referencing to. This could be ourself.
128:             * @return the object that contains the assertion info
129:             */
130:            private Assertions getFinalReference() {
131:                if (getRefid() == null) {
132:                    return this ;
133:                } else {
134:                    Object o = getRefid().getReferencedObject(getProject());
135:                    if (!(o instanceof  Assertions)) {
136:                        throw new BuildException("reference is of wrong type");
137:                    }
138:                    return (Assertions) o;
139:                }
140:            }
141:
142:            /**
143:             * how many assertions are made...will resolve references before returning
144:             * @return total # of commands to make
145:             */
146:            public int size() {
147:                Assertions clause = getFinalReference();
148:                return clause.getFinalSize();
149:            }
150:
151:            /**
152:             * what is the final size of this object
153:             * @return
154:             */
155:            private int getFinalSize() {
156:                return assertionList.size()
157:                        + (enableSystemAssertions != null ? 1 : 0);
158:            }
159:
160:            /**
161:             * add the assertions to a list in a format suitable
162:             * for adding to a command line
163:             * @param commandList the command line to format
164:             */
165:            public void applyAssertions(List commandList) {
166:                getProject().log("Applying assertions", Project.MSG_DEBUG);
167:                Assertions clause = getFinalReference();
168:                //do the system assertions
169:                if (Boolean.TRUE.equals(clause.enableSystemAssertions)) {
170:                    getProject().log("Enabling system assertions",
171:                            Project.MSG_DEBUG);
172:                    commandList.add("-enablesystemassertions");
173:                } else if (Boolean.FALSE.equals(clause.enableSystemAssertions)) {
174:                    getProject().log("disabling system assertions",
175:                            Project.MSG_DEBUG);
176:                    commandList.add("-disablesystemassertions");
177:                }
178:
179:                //now any inner assertions
180:                Iterator it = clause.assertionList.iterator();
181:                while (it.hasNext()) {
182:                    BaseAssertion assertion = (BaseAssertion) it.next();
183:                    String arg = assertion.toCommand();
184:                    getProject().log("adding assertion " + arg,
185:                            Project.MSG_DEBUG);
186:                    commandList.add(arg);
187:                }
188:            }
189:
190:            /**
191:             * apply all the assertions to the command.
192:             * @param command the command line to format
193:             */
194:            public void applyAssertions(CommandlineJava command) {
195:                Assertions clause = getFinalReference();
196:                //do the system assertions
197:                if (Boolean.TRUE.equals(clause.enableSystemAssertions)) {
198:                    addVmArgument(command, "-enablesystemassertions");
199:                } else if (Boolean.FALSE.equals(clause.enableSystemAssertions)) {
200:                    addVmArgument(command, "-disablesystemassertions");
201:                }
202:
203:                //now any inner assertions
204:                Iterator it = clause.assertionList.iterator();
205:                while (it.hasNext()) {
206:                    BaseAssertion assertion = (BaseAssertion) it.next();
207:                    String arg = assertion.toCommand();
208:                    addVmArgument(command, arg);
209:                }
210:            }
211:
212:            /**
213:             * add the assertions to a list in a format suitable
214:             * for adding to a command line
215:             * @param commandIterator list of commands
216:             */
217:            public void applyAssertions(final ListIterator commandIterator) {
218:                getProject().log("Applying assertions", Project.MSG_DEBUG);
219:                Assertions clause = getFinalReference();
220:                //do the system assertions
221:                if (Boolean.TRUE.equals(clause.enableSystemAssertions)) {
222:                    getProject().log("Enabling system assertions",
223:                            Project.MSG_DEBUG);
224:                    commandIterator.add("-enablesystemassertions");
225:                } else if (Boolean.FALSE.equals(clause.enableSystemAssertions)) {
226:                    getProject().log("disabling system assertions",
227:                            Project.MSG_DEBUG);
228:                    commandIterator.add("-disablesystemassertions");
229:                }
230:
231:                //now any inner assertions
232:                Iterator it = clause.assertionList.iterator();
233:                while (it.hasNext()) {
234:                    BaseAssertion assertion = (BaseAssertion) it.next();
235:                    String arg = assertion.toCommand();
236:                    getProject().log("adding assertion " + arg,
237:                            Project.MSG_DEBUG);
238:                    commandIterator.add(arg);
239:                }
240:            }
241:
242:            /**
243:             * helper method to add a string JVM argument to a command
244:             * @param command
245:             * @param arg
246:             */
247:            private static void addVmArgument(CommandlineJava command,
248:                    String arg) {
249:                Commandline.Argument argument;
250:                argument = command.createVmArgument();
251:                argument.setValue(arg);
252:            }
253:
254:            /**
255:             * clone the objects.
256:             * This is not a full depth clone; the list of assertions is cloned,
257:             * but it does not clone the underlying assertions.
258:             * @return a cli
259:             * @throws CloneNotSupportedException if the super class does not support cloning
260:             */
261:            public Object clone() throws CloneNotSupportedException {
262:                Assertions that = (Assertions) super .clone();
263:                that.assertionList = (ArrayList) assertionList.clone();
264:                return that;
265:            }
266:
267:            /**
268:             * base class for our assertion elements.
269:             */
270:
271:            public abstract static class BaseAssertion {
272:                private String packageName;
273:                private String className;
274:
275:                /**
276:                 * name a class
277:                 * @param className a class name
278:                 */
279:                public void setClass(String className) {
280:                    this .className = className;
281:                }
282:
283:                /**
284:                 * name a package
285:                 * @param packageName a package name
286:                 */
287:                public void setPackage(String packageName) {
288:                    this .packageName = packageName;
289:                }
290:
291:                /**
292:                 * what is the class name?
293:                 * @return classname or null
294:                 * @see #setClass
295:                 */
296:                protected String getClassName() {
297:                    return className;
298:                }
299:
300:                /**
301:                 * what is the package name?
302:                 * @return package name or null
303:                 * @see #setPackage
304:                 */
305:                protected String getPackageName() {
306:                    return packageName;
307:                }
308:
309:                /**
310:                 * get the prefix used to begin the command; -ea or -da.
311:                 * @return prefix
312:                 */
313:                public abstract String getCommandPrefix();
314:
315:                /**
316:                 * create a full command string from this class
317:                 * @throws BuildException in case of trouble
318:                 * @return The command string
319:                 */
320:                public String toCommand() {
321:                    //catch invalidness
322:                    if (getPackageName() != null && getClassName() != null) {
323:                        throw new BuildException(
324:                                "Both package and class have been set");
325:                    }
326:                    StringBuffer command = new StringBuffer(getCommandPrefix());
327:                    //see if it is a package or a class
328:                    if (getPackageName() != null) {
329:                        //packages get a ... prefix
330:                        command.append(':');
331:                        command.append(getPackageName());
332:                        if (!command.toString().endsWith("...")) {
333:                            //append the ... suffix if not there already
334:                            command.append("...");
335:                        }
336:                    } else if (getClassName() != null) {
337:                        //classes just get the classname
338:                        command.append(':');
339:                        command.append(getClassName());
340:                    }
341:                    return command.toString();
342:                }
343:            }
344:
345:            /**
346:             * an enabled assertion enables things
347:             */
348:            public static class EnabledAssertion extends BaseAssertion {
349:                /**
350:                 * get the prefix used to begin the command; -ea or -da.
351:                 * @return prefix
352:                 */
353:                public String getCommandPrefix() {
354:                    return "-ea";
355:                }
356:
357:            }
358:
359:            /**
360:             * A disabled assertion disables things
361:             */
362:            public static class DisabledAssertion extends BaseAssertion {
363:                /**
364:                 * get the prefix used to begin the command; -ea or -da.
365:                 * @return prefix
366:                 */
367:                public String getCommandPrefix() {
368:                    return "-da";
369:                }
370:
371:            }
372:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.