Source Code Cross Referenced for FactoryUtils.java in  » Library » Apache-common-Collections » org » apache » commons » collections » 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 » Library » Apache common Collections » org.apache.commons.collections 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2002-2004 The Apache Software Foundation
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.apache.commons.collections;
017:
018:        import org.apache.commons.collections.functors.ConstantFactory;
019:        import org.apache.commons.collections.functors.InstantiateFactory;
020:        import org.apache.commons.collections.functors.ExceptionFactory;
021:        import org.apache.commons.collections.functors.PrototypeFactory;
022:
023:        /**
024:         * <code>FactoryUtils</code> provides reference implementations and utilities
025:         * for the Factory functor interface. The supplied factories are:
026:         * <ul>
027:         * <li>Prototype - clones a specified object
028:         * <li>Reflection - creates objects using reflection
029:         * <li>Constant - always returns the same object
030:         * <li>Null - always returns null
031:         * <li>Exception - always throws an exception
032:         * </ul>
033:         * All the supplied factories are Serializable.
034:         * 
035:         * @since Commons Collections 3.0
036:         * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
037:         *
038:         * @author Stephen Colebourne
039:         */
040:        public class FactoryUtils {
041:
042:            /**
043:             * This class is not normally instantiated.
044:             */
045:            public FactoryUtils() {
046:                super ();
047:            }
048:
049:            /**
050:             * Gets a Factory that always throws an exception.
051:             * This could be useful during testing as a placeholder.
052:             *
053:             * @see org.apache.commons.collections.functors.ExceptionFactory
054:             * 
055:             * @return the factory
056:             */
057:            public static Factory exceptionFactory() {
058:                return ExceptionFactory.INSTANCE;
059:            }
060:
061:            /**
062:             * Gets a Factory that will return null each time the factory is used.
063:             * This could be useful during testing as a placeholder.
064:             *
065:             * @see org.apache.commons.collections.functors.ConstantFactory
066:             * 
067:             * @return the factory
068:             */
069:            public static Factory nullFactory() {
070:                return ConstantFactory.NULL_INSTANCE;
071:            }
072:
073:            /**
074:             * Creates a Factory that will return the same object each time the factory
075:             * is used. No check is made that the object is immutable. In general, only
076:             * immutable objects should use the constant factory. Mutable objects should
077:             * use the prototype factory.
078:             *
079:             * @see org.apache.commons.collections.functors.ConstantFactory
080:             * 
081:             * @param constantToReturn  the constant object to return each time in the factory
082:             * @return the <code>constant</code> factory.
083:             */
084:            public static Factory constantFactory(Object constantToReturn) {
085:                return ConstantFactory.getInstance(constantToReturn);
086:            }
087:
088:            /**
089:             * Creates a Factory that will return a clone of the same prototype object
090:             * each time the factory is used. The prototype will be cloned using one of these
091:             * techniques (in order):
092:             * <ul>
093:             * <li>public clone method
094:             * <li>public copy constructor
095:             * <li>serialization clone
096:             * <ul>
097:             *
098:             * @see org.apache.commons.collections.functors.PrototypeFactory
099:             * 
100:             * @param prototype  the object to clone each time in the factory
101:             * @return the <code>prototype</code> factory
102:             * @throws IllegalArgumentException if the prototype is null
103:             * @throws IllegalArgumentException if the prototype cannot be cloned
104:             */
105:            public static Factory prototypeFactory(Object prototype) {
106:                return PrototypeFactory.getInstance(prototype);
107:            }
108:
109:            /**
110:             * Creates a Factory that can create objects of a specific type using
111:             * a no-args constructor.
112:             *
113:             * @see org.apache.commons.collections.functors.InstantiateFactory
114:             * 
115:             * @param classToInstantiate  the Class to instantiate each time in the factory
116:             * @return the <code>reflection</code> factory
117:             * @throws IllegalArgumentException if the classToInstantiate is null
118:             */
119:            public static Factory instantiateFactory(Class classToInstantiate) {
120:                return InstantiateFactory.getInstance(classToInstantiate, null,
121:                        null);
122:            }
123:
124:            /**
125:             * Creates a Factory that can create objects of a specific type using
126:             * the arguments specified to this method.
127:             *
128:             * @see org.apache.commons.collections.functors.InstantiateFactory
129:             * 
130:             * @param classToInstantiate  the Class to instantiate each time in the factory
131:             * @param paramTypes  parameter types for the constructor, can be null
132:             * @param args  the arguments to pass to the constructor, can be null
133:             * @return the <code>reflection</code> factory
134:             * @throws IllegalArgumentException if the classToInstantiate is null
135:             * @throws IllegalArgumentException if the paramTypes and args don't match
136:             * @throws IllegalArgumentException if the constructor doesn't exist
137:             */
138:            public static Factory instantiateFactory(Class classToInstantiate,
139:                    Class[] paramTypes, Object[] args) {
140:                return InstantiateFactory.getInstance(classToInstantiate,
141:                        paramTypes, args);
142:            }
143:
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.