Source Code Cross Referenced for EnumerationFactory.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » util » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.util 
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:        // This software is provided as is in the hope that it might be found
019:        // useful.
020:        // You may use and modify it freely provided you keep this copyright
021:        // notice unchanged and mark modifications appropriately.
022:        //
023:        // Bug reports and proposals for improvements are welcome. Please send
024:        // them to the eMail address below.
025:        //
026:        // Christoph Karl Walter Grein
027:        // Hauptstr. 42
028:        // D-86926 Greifenberg
029:        // Germany
030:        //
031:        // eMail: Christ-Usch.Grein@T-Online.de
032:        //
033:        // Copyright (c) 1998 Christoph Karl Walter Grein
034:        //----------------------------------------------------------------------
035:        //====================================================================
036:        // Author    Christoph Grein <Christ-Usch.Grein@T-Online.de>
037:        // Version   1.1
038:        // Date      7 February 1998
039:        //====================================================================
040:        // A factory for the creation of enumeration types (missing in Java).
041:        // The same operations are provided as for Ada, only representation
042:        // specification is missing (which does not seem to make much sense
043:        // in Java).
044:        //
045:        // The idea behind this implementation model is the following:
046:        //
047:        // Each enumeration object [or literal as called in Ada] is internally
048:        // represented by its position number [like in Ada] starting with 0
049:        // for the first one. For external representation, an image string
050:        // may also be defined.
051:        // All operations on enumerations (order relations between objects,
052:        // iterators [in the Ada sense for getting the successor and predeces-
053:        // sor of an object]) are implemented on the internal position number.
054:        //
055:        // Implementing the Ada 'Pos attribute as a function getPos () is
056:        // straight forward as is the implementation of 'Image as a function
057:        // toString () [*], whereas their reverse operations 'Val and 'Value
058:        // present a bit of a problem.
059:        // In order to be able to access all objects created for the given
060:        // class, we define a vector and let the constructors add each object
061:        // upon creation to this vector. Thus each object's position number
062:        // is also its vector index. So getVal [Ada's 'Val] simply returns
063:        // the object stored at the given place; getObject [Ada's 'Value]
064:        // loops thru the vector until it finds the object with the given
065:        // string.
066:        //
067:        // [*] The name toString has deliberately been chosen because of
068:        // Java's convention of calling an operation with this name whenever
069:        // an object's name appears in string context.
070:        //
071:        // There is one last point to take care of. An enumeration class has
072:        // only a fixed number of objects, so we must inhibit the creation of
073:        // new objects (with the "new" operator) outside of the enumeration
074:        // class. However, in order to make this EnumerationFactory class
075:        // work, the constructors need to be public. Therefore we set up the
076:        // requirement that upon derivation from class EnumerationFactory all
077:        // objects be created in the derivation class (using all capital
078:        // letters according to Java's convention) and the constructors be
079:        // made private.
080:        //
081:        // For this class at work, see the example classes EnumerationExample
082:        // and Test_EnumerationExample, which present a few objects and opera-
083:        // tions on them.
084:        //
085:        // Comments and improvements are welcome, see e-mail address above.
086:        //====================================================================
087:        // History:
088:        // Author Version   Date    Reason for Change
089:        //  C.G.   1.0  03.02.1998
090:        //  C.G.   1.1  07.02.1998  getObject returns null if nothing found
091:        //====================================================================
092:        package org.apache.cocoon.util;
093:
094:        import java.util.Vector;
095:
096:        /**
097:         * A factory for the creation of enumeration types (missing in Java).
098:         * The same operations are provided as for Ada, only representation
099:         * specification is missing (which does not seem to make much sense
100:         * in Java).
101:         * Enumeration classes are to be derived from this class thereby
102:         * making the constructors private to inhibit creation outside of
103:         * the derived class.
104:         *
105:         * @author Christoph Grein
106:         * @version CVS $Id: EnumerationFactory.java 433543 2006-08-22 06:22:54Z crossley $
107:         */
108:        public class EnumerationFactory {
109:
110:            private static Vector allObjects = // must be here JDK 1.1.3
111:            new Vector(0, 1); // empty, increment by 1
112:
113:            private int pos;
114:            private String image;
115:
116:            /**
117:             * Constructors with and without a string representation (image).
118:             * Make constructors private upon derivation.
119:             * Be careful: No check is made that the image string is unique!
120:             * @param image
121:             */
122:            public EnumerationFactory(String image) {
123:                this .pos = allObjects.size();
124:                this .image = image;
125:                allObjects.addElement(this );
126:            }
127:
128:            public EnumerationFactory() {
129:                this ("");
130:            }
131:
132:            //--------------------------------------------------------------------------
133:            // Order relations:
134:
135:            /**
136:             * Order relations Object.op (OtherObject) representing the relation
137:             * Object op OtherObject.
138:             * @param e the right operand
139:             */
140:            public boolean lt(EnumerationFactory e) { // "<"
141:                return this .getPos() < e.getPos();
142:            }
143:
144:            public boolean le(EnumerationFactory e) { // "<="
145:                return this .getPos() <= e.getPos();
146:            }
147:
148:            public boolean gt(EnumerationFactory e) { // ">"
149:                return this .getPos() > e.getPos();
150:            }
151:
152:            public boolean ge(EnumerationFactory e) { // ">="
153:                return this .getPos() >= e.getPos();
154:            }
155:
156:            // "==" and "equals" are inherited.
157:
158:            //--------------------------------------------------------------------------
159:            // Numeric representation:
160:
161:            public int getPos() { // Ada'Pos
162:                return pos;
163:            }
164:
165:            /**
166:             * Access to the numeric representation.
167:             * @param value the numeric value
168:             */
169:            public static EnumerationFactory getVal(int value) { // Ada'Val
170:                return (EnumerationFactory) allObjects.elementAt(value);
171:            }
172:
173:            //--------------------------------------------------------------------------
174:            // Iterator:
175:
176:            public static EnumerationFactory getFirst() { // Ada'First
177:                return getVal(0);
178:            }
179:
180:            public static EnumerationFactory getLast() { // Ada'Last
181:                return getVal(allObjects.size() - 1);
182:            }
183:
184:            public EnumerationFactory getNext() { // Ada'Succ
185:                return getVal(this .getPos() + 1);
186:            }
187:
188:            public EnumerationFactory getPrev() { // Ada'Pred
189:                return getVal(this .getPos() - 1);
190:            }
191:
192:            //--------------------------------------------------------------------------
193:            // String representation:
194:
195:            public String toString() { // Ada'Image
196:                return image;
197:            }
198:
199:            public static EnumerationFactory getObject(String image) { // Ada'Value
200:                EnumerationFactory found;
201:                // Linear search seems good enough because there presumably
202:                // will not be too many literals.
203:                for (int i = 0; i < allObjects.size(); i++) {
204:                    found = (EnumerationFactory) allObjects.elementAt(i);
205:                    if (found.toString().equals(image)) {
206:                        return found;
207:                    }
208:                }
209:                return null;
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.