Source Code Cross Referenced for VeryLazyList.java in  » Development » ivatamasks » com » ivata » mask » 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 » Development » ivatamasks » com.ivata.mask.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001 - 2005 ivata limited.
003:         * All rights reserved.
004:         * -----------------------------------------------------------------------------
005:         * ivata masks may be redistributed under the GNU General Public
006:         * License as published by the Free Software Foundation;
007:         * version 2 of the License.
008:         *
009:         * These programs are free software; you can redistribute them and/or
010:         * modify them under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; version 2 of the License.
012:         *
013:         * These programs are distributed in the hope that they will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         *
017:         * See the GNU General Public License in the file LICENSE.txt for more
018:         * details.
019:         *
020:         * If you would like a copy of the GNU General Public License write to
021:         *
022:         * Free Software Foundation, Inc.
023:         * 59 Temple Place - Suite 330
024:         * Boston, MA 02111-1307, USA.
025:         *
026:         *
027:         * To arrange commercial support and licensing, contact ivata at
028:         *                  http://www.ivata.com/contact.jsp
029:         * -----------------------------------------------------------------------------
030:         * $Log: VeryLazyList.java,v $
031:         * Revision 1.5  2005/10/14 14:03:22  colinmacleod
032:         * Changed to use PrototypeFactory rather than IntantiateFactory.
033:         *
034:         * Revision 1.4  2005/10/11 18:55:29  colinmacleod
035:         * Fixed some checkstyle and javadoc issues.
036:         *
037:         * Revision 1.3  2005/10/03 10:17:24  colinmacleod
038:         * Fixed some style and javadoc issues.
039:         *
040:         * Revision 1.2  2005/10/02 14:06:32  colinmacleod
041:         * Added/improved log4j logging.
042:         *
043:         * Revision 1.1  2005/10/02 10:49:38  colinmacleod
044:         * First version. Simplifies handling of primitive types in Struts forms.
045:         *
046:         */
047:        package com.ivata.mask.util;
048:
049:        import java.util.List;
050:
051:        import org.apache.commons.collections.functors.PrototypeFactory;
052:        import org.apache.commons.collections.list.LazyList;
053:        import org.apache.log4j.Logger;
054:
055:        import com.ivata.mask.field.FieldValueConvertor;
056:
057:        /**
058:         * <p>
059:         * This factory class makes it simple to create a list of a primitive type (or
060:         * any type for which there is an <strong>ivata masks</strong> field value
061:         * convertor.
062:         * </p>
063:         * <p>
064:         * This list overrides <code>set</code> so it can be used to populate lists in
065:         * <em>Struts</em> forms.
066:         * </p>
067:         *
068:         * @since ivata masks 1.0 (29-Sep-2005)
069:         * @author Colin MacLeod
070:         * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
071:         * @version $Revision: 1.5 $
072:         */
073:        public class VeryLazyList extends LazyList {
074:            /**
075:             * Logger for this class.
076:             */
077:            private static final Logger logger = Logger
078:                    .getLogger(VeryLazyList.class);
079:
080:            /**
081:             * Serialization version (for <code>Serializable</code> interface)..
082:             */
083:            private static final long serialVersionUID = 1L;
084:
085:            /**
086:             * Create a vary lazy list.
087:             *
088:             * @param list
089:             * <copyDoc>Refer to {@link List#set}.</copyDoc>
090:             * @param targetClass The class of object you want to add to the list.
091:             *  The class you provide must be a primitive type,
092:             * or must have a constructor which accepts a string.
093:             * @return a new very lazy list.
094:             */
095:            public static List decorate(final List list, final Class targetClass) {
096:                if (logger.isDebugEnabled()) {
097:                    logger.debug("decorate(List list = " + list
098:                            + ", Class targetClass = " + targetClass
099:                            + ") - start");
100:                }
101:
102:                List returnList = new VeryLazyList(list, targetClass,
103:                        new FieldValueConvertor());
104:                if (logger.isDebugEnabled()) {
105:                    logger
106:                            .debug("decorate(List, Class) - end - return value = "
107:                                    + returnList);
108:                }
109:                return returnList;
110:            }
111:
112:            /**
113:             * Create a vary lazy list.
114:             *
115:             * @param list
116:             * <copyDoc>Refer to {@link List#set}.</copyDoc>
117:             * @param targetClass The class of object you want to add to the list.
118:             * @param convertor Used to create objects of the chosen class.
119:             * @return a new very lazy list.
120:             */
121:            public static List decorate(final List list,
122:                    final Class targetClass, final FieldValueConvertor convertor) {
123:                if (logger.isDebugEnabled()) {
124:                    logger.debug("decorate(List list = " + list
125:                            + ", Class targetClass = " + targetClass
126:                            + ", FieldValueConvertor convertor = " + convertor
127:                            + ") - start");
128:                }
129:
130:                List returnList = new VeryLazyList(list, targetClass, convertor);
131:                if (logger.isDebugEnabled()) {
132:                    logger.debug("decorate - end - return value = "
133:                            + returnList);
134:                }
135:                return returnList;
136:            }
137:
138:            /**
139:             * <copyDoc>Refer to {@link #decorate(List, Class, FieldValueConvertor)}.
140:             * </copyDoc>
141:             */
142:            private FieldValueConvertor convertor;
143:            /**
144:             * <copyDoc>Refer to {@link #decorate(List, Class, FieldValueConvertor)}.
145:             * </copyDoc>
146:             */
147:            private Class targetClass;
148:
149:            /**
150:             * Calls super constructor directly.
151:             *
152:             * @param listParam
153:             * <copyDoc>Refer to {@link List#set}.</copyDoc>
154:             * @param targetClassParam
155:             * <copyDoc>Refer to {@link #decorate(List, Class, FieldValueConvertor)}.
156:             * </copyDoc>
157:             * @param convertorParam
158:             * <copyDoc>Refer to {@link #decorate(List, Class, FieldValueConvertor)}.
159:             * </copyDoc>
160:             */
161:            protected VeryLazyList(final List listParam,
162:                    final Class targetClassParam,
163:                    final FieldValueConvertor convertorParam) {
164:                super (listParam, PrototypeFactory.getInstance(convertorParam
165:                        .convertFromString(targetClassParam, "")));
166:                this .convertor = convertorParam;
167:                this .targetClass = targetClassParam;
168:            }
169:
170:            /**
171:             * Overridden to read the object's string value and convert it before adding
172:             * to the list.
173:             *
174:             * @param indexParam
175:             * <copyDoc>Refer to {@link List#set}.</copyDoc>
176:             * @param elementParam
177:             * <copyDoc>Refer to {@link List#set}.</copyDoc>
178:             * @return
179:             * <copyDoc>Refer to {@link List#set}.</copyDoc>
180:             */
181:            public synchronized Object set(final int indexParam,
182:                    final Object elementParam) {
183:                if (logger.isDebugEnabled()) {
184:                    logger.debug("set(int indexParam = " + indexParam
185:                            + ", Object elementParam = " + elementParam
186:                            + ") - start");
187:                }
188:
189:                while (indexParam >= this .size()) {
190:                    super .add(factory.create());
191:                }
192:                String convertFrom;
193:                if (elementParam instanceof  List) {
194:                    convertFrom = ((List) elementParam).get(0).toString();
195:                } else {
196:                    convertFrom = elementParam.toString();
197:                }
198:                Object object = convertor.convertFromString(targetClass,
199:                        convertFrom);
200:                Object returnObject = super .set(indexParam, object);
201:                if (logger.isDebugEnabled()) {
202:                    logger.debug("set(int, Object) - end - return value = "
203:                            + returnObject);
204:                }
205:                return returnObject;
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.