Source Code Cross Referenced for EnumeratedAttribute.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:
023:        /**
024:         * Helper class for attributes that can only take one of a fixed list
025:         * of values.
026:         *
027:         * <p>See {@link org.apache.tools.ant.taskdefs.FixCRLF FixCRLF} for an
028:         * example.
029:         *
030:         */
031:        public abstract class EnumeratedAttribute {
032:            // CheckStyle:VisibilityModifier OFF - bc
033:            /**
034:             * The selected value in this enumeration.
035:             */
036:            protected String value;
037:
038:            // CheckStyle:VisibilityModifier ON
039:
040:            /**
041:             * the index of the selected value in the array.
042:             */
043:            private int index = -1;
044:
045:            /**
046:             * This is the only method a subclass needs to implement.
047:             *
048:             * @return an array holding all possible values of the enumeration.
049:             * The order of elements must be fixed so that <tt>indexOfValue(String)</tt>
050:             * always return the same index for the same value.
051:             */
052:            public abstract String[] getValues();
053:
054:            /** bean constructor */
055:            protected EnumeratedAttribute() {
056:            }
057:
058:            /**
059:             * Factory method for instantiating EAs via API in a more
060:             * developer friendly way.
061:             * @param clazz             Class, extending EA, which to instantiate
062:             * @param value             The value to set on that EA
063:             * @return                  Configured EA
064:             * @throws BuildException   If the class could not be found or the value
065:             *                          is not valid for the given EA-class.
066:             * @see <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=14831">
067:             * http://issues.apache.org/bugzilla/show_bug.cgi?id=14831</a>
068:             */
069:            public static EnumeratedAttribute getInstance(
070:                    Class/*<? extends EnumeratedAttribute>*/clazz, String value)
071:                    throws BuildException {
072:                if (!EnumeratedAttribute.class.isAssignableFrom(clazz)) {
073:                    throw new BuildException(
074:                            "You have to provide a subclass from EnumeratedAttribut as clazz-parameter.");
075:                }
076:                EnumeratedAttribute ea = null;
077:                try {
078:                    ea = (EnumeratedAttribute) clazz.newInstance();
079:                } catch (Exception e) {
080:                    throw new BuildException(e);
081:                }
082:                ea.setValue(value);
083:                return ea;
084:            }
085:
086:            /**
087:             * Invoked by {@link org.apache.tools.ant.IntrospectionHelper IntrospectionHelper}.
088:             * @param value the <code>String</code> value of the attribute
089:             * @throws BuildException if the value is not valid for the attribute
090:             */
091:            public final void setValue(String value) throws BuildException {
092:                int idx = indexOfValue(value);
093:                if (idx == -1) {
094:                    throw new BuildException(value
095:                            + " is not a legal value for this attribute");
096:                }
097:                this .index = idx;
098:                this .value = value;
099:            }
100:
101:            /**
102:             * Is this value included in the enumeration?
103:             * @param value the <code>String</code> value to look up
104:             * @return true if the value is valid
105:             */
106:            public final boolean containsValue(String value) {
107:                return (indexOfValue(value) != -1);
108:            }
109:
110:            /**
111:             * get the index of a value in this enumeration.
112:             * @param value the string value to look for.
113:             * @return the index of the value in the array of strings
114:             * or -1 if it cannot be found.
115:             * @see #getValues()
116:             */
117:            public final int indexOfValue(String value) {
118:                String[] values = getValues();
119:                if (values == null || value == null) {
120:                    return -1;
121:                }
122:                for (int i = 0; i < values.length; i++) {
123:                    if (value.equals(values[i])) {
124:                        return i;
125:                    }
126:                }
127:                return -1;
128:            }
129:
130:            /**
131:             * @return the selected value.
132:             */
133:            public final String getValue() {
134:                return value;
135:            }
136:
137:            /**
138:             * @return the index of the selected value in the array.
139:             * @see #getValues()
140:             */
141:            public final int getIndex() {
142:                return index;
143:            }
144:
145:            /**
146:             * Convert the value to its string form.
147:             *
148:             * @return the string form of the value.
149:             */
150:            public String toString() {
151:                return getValue();
152:            }
153:
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.