Source Code Cross Referenced for FilterImpl.java in  » Database-ORM » hibernate » org » hibernate » impl » 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 » Database ORM » hibernate » org.hibernate.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: FilterImpl.java 8754 2005-12-05 23:36:59Z steveebersole $
002:        package org.hibernate.impl;
003:
004:        import java.io.Serializable;
005:        import java.util.Arrays;
006:        import java.util.Collection;
007:        import java.util.HashMap;
008:        import java.util.Iterator;
009:        import java.util.Map;
010:
011:        import org.hibernate.Filter;
012:        import org.hibernate.HibernateException;
013:        import org.hibernate.engine.FilterDefinition;
014:        import org.hibernate.type.Type;
015:
016:        /**
017:         * Implementation of FilterImpl.  FilterImpl implements the user's
018:         * view into enabled dynamic filters, allowing them to set filter parameter values.
019:         *
020:         * @author Steve Ebersole
021:         */
022:        public class FilterImpl implements  Filter, Serializable {
023:            public static final String MARKER = "$FILTER_PLACEHOLDER$";
024:
025:            private transient FilterDefinition definition;
026:            private String filterName;
027:            private Map parameters = new HashMap();
028:
029:            void afterDeserialize(SessionFactoryImpl factory) {
030:                definition = factory.getFilterDefinition(filterName);
031:            }
032:
033:            /**
034:             * Constructs a new FilterImpl.
035:             *
036:             * @param configuration The filter's global configuration.
037:             */
038:            public FilterImpl(FilterDefinition configuration) {
039:                this .definition = configuration;
040:                filterName = definition.getFilterName();
041:            }
042:
043:            public FilterDefinition getFilterDefinition() {
044:                return definition;
045:            }
046:
047:            /**
048:             * Get the name of this filter.
049:             *
050:             * @return This filter's name.
051:             */
052:            public String getName() {
053:                return definition.getFilterName();
054:            }
055:
056:            public Map getParameters() {
057:                return parameters;
058:            }
059:
060:            /**
061:             * Set the named parameter's value for this filter.
062:             *
063:             * @param name The parameter's name.
064:             * @param value The value to be applied.
065:             * @return This FilterImpl instance (for method chaining).
066:             * @throws IllegalArgumentException Indicates that either the parameter was undefined or that the type
067:             * of the passed value did not match the configured type.
068:             */
069:            public Filter setParameter(String name, Object value)
070:                    throws IllegalArgumentException {
071:                // Make sure this is a defined parameter and check the incoming value type
072:                // TODO: what should be the actual exception type here?
073:                Type type = definition.getParameterType(name);
074:                if (type == null) {
075:                    throw new IllegalArgumentException(
076:                            "Undefined filter parameter [" + name + "]");
077:                }
078:                if (value != null
079:                        && !type.getReturnedClass().isAssignableFrom(
080:                                value.getClass())) {
081:                    throw new IllegalArgumentException(
082:                            "Incorrect type for parameter [" + name + "]");
083:                }
084:                parameters.put(name, value);
085:                return this ;
086:            }
087:
088:            /**
089:             * Set the named parameter's value list for this filter.  Used
090:             * in conjunction with IN-style filter criteria.
091:             *
092:             * @param name   The parameter's name.
093:             * @param values The values to be expanded into an SQL IN list.
094:             * @return This FilterImpl instance (for method chaining).
095:             */
096:            public Filter setParameterList(String name, Collection values)
097:                    throws HibernateException {
098:                // Make sure this is a defined parameter and check the incoming value type
099:                if (values == null) {
100:                    throw new IllegalArgumentException(
101:                            "Collection must be not null!");
102:                }
103:                Type type = definition.getParameterType(name);
104:                if (type == null) {
105:                    throw new HibernateException("Undefined filter parameter ["
106:                            + name + "]");
107:                }
108:                if (values.size() > 0) {
109:                    Class elementClass = values.iterator().next().getClass();
110:                    if (!type.getReturnedClass().isAssignableFrom(elementClass)) {
111:                        throw new HibernateException(
112:                                "Incorrect type for parameter [" + name + "]");
113:                    }
114:                }
115:                parameters.put(name, values);
116:                return this ;
117:            }
118:
119:            /**
120:             * Set the named parameter's value list for this filter.  Used
121:             * in conjunction with IN-style filter criteria.
122:             *
123:             * @param name The parameter's name.
124:             * @param values The values to be expanded into an SQL IN list.
125:             * @return This FilterImpl instance (for method chaining).
126:             */
127:            public Filter setParameterList(String name, Object[] values)
128:                    throws IllegalArgumentException {
129:                return setParameterList(name, Arrays.asList(values));
130:            }
131:
132:            /**
133:             * Get the value of the named parameter for the current filter.
134:             *
135:             * @param name The name of the parameter for which to return the value.
136:             * @return The value of the named parameter.
137:             */
138:            public Object getParameter(String name) {
139:                return parameters.get(name);
140:            }
141:
142:            /**
143:             * Perform validation of the filter state.  This is used to verify the
144:             * state of the filter after its enablement and before its use.
145:             *
146:             * @throws HibernateException If the state is not currently valid.
147:             */
148:            public void validate() throws HibernateException {
149:                // for each of the defined parameters, make sure its value
150:                // has been set
151:                Iterator itr = definition.getParameterNames().iterator();
152:                while (itr.hasNext()) {
153:                    final String parameterName = (String) itr.next();
154:                    if (parameters.get(parameterName) == null) {
155:                        throw new HibernateException("Filter [" + getName()
156:                                + "] parameter [" + parameterName
157:                                + "] value not set");
158:                    }
159:                }
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.