Source Code Cross Referenced for DataGridStateFactory.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » databinding » datagrid » api » 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 beehive 1.0.2 src » org.apache.beehive.netui.databinding.datagrid.api 
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:         * $Header:$
018:         */
019:        package org.apache.beehive.netui.databinding.datagrid.api;
020:
021:        import java.util.HashMap;
022:        import javax.servlet.jsp.PageContext;
023:        import javax.servlet.jsp.JspContext;
024:        import javax.servlet.ServletRequest;
025:
026:        import org.apache.beehive.netui.util.Bundle;
027:
028:        /**
029:         * <p>
030:         * Factory class used to construct instances of {@link DataGridState} objects.  This
031:         * class is used by the data grid and other clients to obtain the state for a data grid
032:         * with a given name.
033:         * </p>
034:         * <p>
035:         * Data grid state information is scoped by a unique data grid String name.  This name
036:         * should be unique for a particular scope in a request.  For all factory methods that
037:         * take a data grid name as a parameter, the value of the <code>name</code> attribute
038:         * should match the value of the
039:         * {@link org.apache.beehive.netui.tags.databinding.datagrid.DataGrid#setName(String)}
040:         * attribute for the data grid whose state to lookup.
041:         * </p>
042:         */
043:        public final class DataGridStateFactory {
044:
045:            private static final String KEY = DataGridStateFactory.class
046:                    .getName()
047:                    + "REQUEST_KEY";
048:            private static final DataGridConfig DEFAULT_DATA_GRID_CONFIG = DataGridConfigFactory
049:                    .getInstance();
050:
051:            /**
052:             * Get an instance of a DataGridStateFactory given a {@link JspContext}.
053:             *
054:             * @param jspContext the current {@link JspContext}
055:             * @return an instance of the factory
056:             */
057:            public static final DataGridStateFactory getInstance(
058:                    JspContext jspContext) {
059:                assert jspContext instanceof  PageContext;
060:                return getInstance(((PageContext) jspContext).getRequest());
061:            }
062:
063:            /**
064:             * Get an instance of a DataGridStateFactory given a {@link ServletRequest}.
065:             *
066:             * @param request the current {@link ServletRequest}
067:             * @return an instance of the factory
068:             */
069:            public static final DataGridStateFactory getInstance(
070:                    ServletRequest request) {
071:                Object obj = request.getAttribute(KEY);
072:                if (obj != null) {
073:                    assert obj instanceof  DataGridStateFactory;
074:                    return (DataGridStateFactory) obj;
075:                } else {
076:                    DataGridStateFactory factory = new DataGridStateFactory(
077:                            request);
078:                    request.setAttribute(KEY, factory);
079:                    return factory;
080:                }
081:            }
082:
083:            private final ServletRequest _request;
084:            private final HashMap/*<String, DataGridStateCodec>*/_cache;
085:
086:            private DataGridStateFactory(ServletRequest request) {
087:                _request = request;
088:                _cache = new HashMap/*<String, DataGridStateCodec>*/();
089:            }
090:
091:            /**
092:             * <p>
093:             * Lookup a {@link DataGridState} object given a data grid identifier.
094:             * </p>
095:             * <p>
096:             * This method will use the default {@link DataGridConfig} object when returning a data grid specific
097:             * implementation of the {@link DataGridState} object.  In order to specify a {@link DataGridConfig},
098:             * the {@link DataGridStateFactory#getDataGridState(String, DataGridConfig)} can be supplied
099:             * with a specific data grid configuration.
100:             * </p>
101:             *
102:             * @param name the name of a data grid.
103:             * @return the {@link DataGridState} for the data grid with the given name
104:             */
105:            public final DataGridState getDataGridState(String name) {
106:                return getDataGridState(name, DEFAULT_DATA_GRID_CONFIG);
107:            }
108:
109:            /**
110:             * <p>
111:             * Lookup a {@link DataGridState} object given a data grid identifier and a specific
112:             * {@link DataGridConfig} object.
113:             * </p>
114:             *
115:             * @param name the name of the data grid
116:             * @param config the {@link DataGridConfig} object to use when creating the
117:             * grid's {@link DataGridState} object.
118:             * @return the data grid state object
119:             */
120:            public final DataGridState getDataGridState(String name,
121:                    DataGridConfig config) {
122:                if (config == null)
123:                    throw new IllegalArgumentException(
124:                            Bundle
125:                                    .getErrorString("DataGridStateFactory_nullDataGridConfig"));
126:
127:                DataGridStateCodec codec = lookupCodec(name, config);
128:                DataGridState state = codec.getDataGridState();
129:                return state;
130:            }
131:
132:            /**
133:             * <p>
134:             * Lookup a {@link DataGridURLBuilder} object given a data grid identifier.
135:             * </p>
136:             * <p>
137:             * This method will use the default {@link DataGridConfig} object when returning a data grid specific
138:             * implementation of the {@link DataGridURLBuilder} object.  In order to specify a {@link DataGridConfig},
139:             * the {@link DataGridStateFactory#getDataGridURLBuilder(String, DataGridConfig)} can be supplied
140:             * with a specific data grid configuration.
141:             * </p>
142:             *
143:             * @param name the name of the data grid
144:             * @return the {@link DataGridURLBuilder} for the data grid with the given name
145:             */
146:            public final DataGridURLBuilder getDataGridURLBuilder(String name) {
147:                return getDataGridURLBuilder(name, DEFAULT_DATA_GRID_CONFIG);
148:            }
149:
150:            /**
151:             * <p>
152:             * Lookup a {@link DataGridURLBuilder} object given a data grid identifier and a specific
153:             * {@link DataGridConfig} object.
154:             * </p>
155:             *
156:             * @param name the name of the data grid
157:             * @param config the {@link DataGridConfig} object to use when creating the
158:             * grid's {@link DataGridURLBuilder} object.
159:             * @return the URL builder for a data grid's state object
160:             */
161:            public final DataGridURLBuilder getDataGridURLBuilder(String name,
162:                    DataGridConfig config) {
163:                if (config == null)
164:                    throw new IllegalArgumentException(
165:                            Bundle
166:                                    .getErrorString("DataGridStateFactory_nullDataGridConfig"));
167:
168:                DataGridStateCodec codec = lookupCodec(name, config);
169:                DataGridURLBuilder builder = codec.getDataGridURLBuilder();
170:                return builder;
171:            }
172:
173:            /**
174:             * <p>
175:             * Convenience method that allows a {@link DataGridState} object from a client to
176:             * be attached to the factory.  This allows subsequent calls to retrieve this same {@link DataGridState}
177:             * instance.
178:             * </p>
179:             *
180:             * @param name the name of the data grid
181:             * @param state the {@link DataGridState} object to attach
182:             */
183:            public final void attachDataGridState(String name,
184:                    DataGridState state) {
185:                DataGridStateCodec codec = lookupCodec(name,
186:                        DEFAULT_DATA_GRID_CONFIG);
187:                codec.setDataGridState(state);
188:            }
189:
190:            private final DataGridStateCodec lookupCodec(String name,
191:                    DataGridConfig config) {
192:                DataGridStateCodec codec = null;
193:                if (_cache.containsKey(name))
194:                    codec = (DataGridStateCodec) _cache.get(name);
195:                else {
196:                    assert config != null;
197:                    codec = config.createStateCodec(_request, name);
198:                    _cache.put(name, codec);
199:                }
200:
201:                return codec;
202:            }
203:        }
www___.___j_a_v__a2_s__.c_om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.