Source Code Cross Referenced for SelectSelector.java in  » Build » ANT » org » apache » tools » ant » types » selectors » 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.selectors 
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.selectors;
020:
021:        import java.util.Enumeration;
022:        import java.io.File;
023:
024:        import org.apache.tools.ant.Project;
025:
026:        /**
027:         * This selector just holds one other selector and forwards all
028:         * requests to it. It exists so that there is a single selector
029:         * type that can exist outside of any targets, as an element of
030:         * project. It overrides all of the reference stuff so that it
031:         * works as expected. Note that this is the only selector you
032:         * can reference.
033:         *
034:         * @since 1.5
035:         */
036:        public class SelectSelector extends BaseSelectorContainer {
037:
038:            private String ifProperty;
039:            private String unlessProperty;
040:
041:            /**
042:             * Default constructor.
043:             */
044:            public SelectSelector() {
045:            }
046:
047:            /**
048:             * @return a string describing this object
049:             */
050:            public String toString() {
051:                StringBuffer buf = new StringBuffer();
052:                if (hasSelectors()) {
053:                    buf.append("{select");
054:                    if (ifProperty != null) {
055:                        buf.append(" if: ");
056:                        buf.append(ifProperty);
057:                    }
058:                    if (unlessProperty != null) {
059:                        buf.append(" unless: ");
060:                        buf.append(unlessProperty);
061:                    }
062:                    buf.append(" ");
063:                    buf.append(super .toString());
064:                    buf.append("}");
065:                }
066:                return buf.toString();
067:            }
068:
069:            /**
070:             * Performs the check for circular references and returns the
071:             * referenced Selector.
072:             */
073:            private SelectSelector getRef() {
074:                Object o = getCheckedRef(this .getClass(), "SelectSelector");
075:                return (SelectSelector) o;
076:            }
077:
078:            /**
079:             * Indicates whether there are any selectors here.
080:             * @return whether any selectors are in this container
081:             */
082:            public boolean hasSelectors() {
083:                if (isReference()) {
084:                    return getRef().hasSelectors();
085:                }
086:                return super .hasSelectors();
087:            }
088:
089:            /**
090:             * Gives the count of the number of selectors in this container
091:             * @return the number of selectors in this container
092:             */
093:            public int selectorCount() {
094:                if (isReference()) {
095:                    return getRef().selectorCount();
096:                }
097:                return super .selectorCount();
098:            }
099:
100:            /**
101:             * Returns the set of selectors as an array.
102:             * @param p the current project
103:             * @return an array of selectors in this container
104:             */
105:            public FileSelector[] getSelectors(Project p) {
106:                if (isReference()) {
107:                    return getRef().getSelectors(p);
108:                }
109:                return super .getSelectors(p);
110:            }
111:
112:            /**
113:             * Returns an enumerator for accessing the set of selectors.
114:             * @return an enumerator that goes through each of the selectors
115:             */
116:            public Enumeration selectorElements() {
117:                if (isReference()) {
118:                    return getRef().selectorElements();
119:                }
120:                return super .selectorElements();
121:            }
122:
123:            /**
124:             * Add a new selector into this container.
125:             *
126:             * @param selector the new selector to add
127:             */
128:            public void appendSelector(FileSelector selector) {
129:                if (isReference()) {
130:                    throw noChildrenAllowed();
131:                }
132:                super .appendSelector(selector);
133:            }
134:
135:            /**
136:             * Makes sure that there is only one entry, sets an error message if
137:             * not.
138:             */
139:            public void verifySettings() {
140:                int cnt = selectorCount();
141:                if (cnt < 0 || cnt > 1) {
142:                    setError("Only one selector is allowed within the "
143:                            + "<selector> tag");
144:                }
145:            }
146:
147:            /**
148:             * Ensures that the selector passes the conditions placed
149:             * on it with <code>if</code> and <code>unless</code>.
150:             * @return true if conditions are passed
151:             */
152:            public boolean passesConditions() {
153:                if (ifProperty != null
154:                        && getProject().getProperty(ifProperty) == null) {
155:                    return false;
156:                } else if (unlessProperty != null
157:                        && getProject().getProperty(unlessProperty) != null) {
158:                    return false;
159:                }
160:                return true;
161:            }
162:
163:            /**
164:             * Sets the if attribute to a property which must exist for the
165:             * selector to select any files.
166:             * @param ifProperty the property to check
167:             */
168:            public void setIf(String ifProperty) {
169:                this .ifProperty = ifProperty;
170:            }
171:
172:            /**
173:             * Sets the unless attribute to a property which cannot exist for the
174:             * selector to select any files.
175:             * @param unlessProperty the property to check
176:             */
177:            public void setUnless(String unlessProperty) {
178:                this .unlessProperty = unlessProperty;
179:            }
180:
181:            /**
182:             * Returns true (the file is selected) only if the if property (if any)
183:             * exists, the unless property (if any) doesn't exist, and the
184:             * contained selector (if any) selects the file. If there is no contained
185:             * selector, return true (because we assume that the point was to test
186:             * the if and unless conditions).
187:             *
188:             * @param basedir the base directory the scan is being done from
189:             * @param filename the name of the file to check
190:             * @param file a java.io.File object for the filename that the selector
191:             * can use
192:             * @return whether the file should be selected or not
193:             */
194:            public boolean isSelected(File basedir, String filename, File file) {
195:                validate();
196:
197:                // Deal with if and unless properties first
198:                if (!(passesConditions())) {
199:                    return false;
200:                }
201:
202:                Enumeration e = selectorElements();
203:                if (!(e.hasMoreElements())) {
204:                    return true;
205:                }
206:                FileSelector f = (FileSelector) e.nextElement();
207:                return f.isSelected(basedir, filename, file);
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.