Source Code Cross Referenced for ParamHelper.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » 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 » Library » Apache beehive 1.0.2 src » org.apache.beehive.netui.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:         * $Header:$
018:         */
019:        package org.apache.beehive.netui.util;
020:
021:        import java.util.Map;
022:        import java.util.List;
023:        import java.lang.reflect.Array;
024:        import org.apache.beehive.netui.util.logging.Logger;
025:
026:        /**
027:         * This class is used by NetUI tags that use parameters.
028:         */
029:        public class ParamHelper {
030:            private static final Logger logger = Logger
031:                    .getInstance(ParamHelper.class);
032:
033:            /**
034:             * Add a new parameter or update an existing parameter's list of values.
035:             * <p/>
036:             * <em>Implementation Note:</em> in the case that a Map was provided for
037:             * the <code>value</code> parameter, the this returns without doing
038:             * anything; in any other case, params is updated (even in
039:             * <code>value</code> is null).
040:             * </p>
041:             * <p/>
042:             * If value is some object (not an array or list), the string
043:             * representation of that object is added as a value for name.  If the
044:             * value is a list (or array) of objects, then the string representation
045:             * of each element is added as a value for name.  When there are multiple
046:             * values for a name, then an array of Strings is used in Map.
047:             * </p>
048:             *
049:             * @param params an existing Map of names and values to update
050:             * @param name   the name of the parameter to add or update
051:             * @param value  an item or list of items to put into the map
052:             * @throws IllegalArgumentException in the case that either the params
053:             *                                  <p/>
054:             *                                  or name given was null
055:             */
056:            public static void addParam(Map params, String name, Object value) {
057:
058:                if (params == null)
059:                    throw new IllegalArgumentException(
060:                            "Parameter map cannot be null");
061:                if (name == null)
062:                    throw new IllegalArgumentException(
063:                            "Parameter name cannot be null");
064:
065:                if (value instanceof  Map) {
066:                    logger
067:                            .warn(Bundle.getString("Tags_BadParameterType",
068:                                    name));
069:                    return;
070:                }
071:
072:                if (value == null)
073:                    value = "";
074:
075:                // check to see if we are adding a new element
076:                //      or if this is an existing element
077:                Object o = params.get(name);
078:                int length = 0;
079:
080:                if (o != null) {
081:                    assert (o instanceof  String || o instanceof  String[]);
082:
083:                    if (o.getClass().isArray()) {
084:                        length = Array.getLength(o);
085:                    } else {
086:                        length++;
087:                    }
088:                }
089:
090:                // check how much size the output needs to be
091:                if (value.getClass().isArray()) {
092:                    length += Array.getLength(value);
093:                } else if (value instanceof  List) {
094:                    length += ((List) value).size();
095:                } else {
096:                    length++;
097:                }
098:
099:                if (length == 0)
100:                    return;
101:
102:                //System.err.println("Number of vaues:" + length);
103:                // if there is only a single value push it to the parameter table
104:                if (length == 1) {
105:                    if (value.getClass().isArray()) {
106:                        Object val = Array.get(value, 0);
107:                        if (val != null)
108:                            params.put(name, val.toString());
109:                        else
110:                            params.put(name, "");
111:                    } else if (value instanceof  List) {
112:                        List list = (List) value;
113:                        Object val = list.get(0);
114:                        if (val != null)
115:                            params.put(name, val.toString());
116:                        else
117:                            params.put(name, "");
118:                    } else
119:                        params.put(name, value.toString());
120:                    return;
121:                }
122:
123:                // allocate the string for the multiple values
124:                String[] values = new String[length];
125:                int offset = 0;
126:
127:                // if we had old values, push them to the new array
128:                if (o != null) {
129:                    if (o.getClass().isArray()) {
130:                        String[] obs = (String[]) o;
131:                        for (; offset < obs.length; offset++) {
132:                            values[offset] = obs[offset];
133:                        }
134:                    } else {
135:                        values[0] = o.toString();
136:                        offset = 1;
137:                    }
138:                }
139:
140:                // now move the new values to the array starting at the offset
141:                // position
142:                if (value.getClass().isArray()) {
143:                    //need to convert this array into a String[]
144:                    int size = Array.getLength(value);
145:                    for (int i = 0; i < size; i++) {
146:                        Object val = Array.get(value, i);
147:                        if (val != null)
148:                            values[i + offset] = val.toString();
149:                        else
150:                            values[i + offset] = "";
151:                    }
152:                } else if (value instanceof  List) {
153:                    List list = (List) value;
154:                    int size = list.size();
155:                    for (int i = 0; i < size; i++) {
156:                        if (list.get(i) != null)
157:                            values[i + offset] = list.get(i).toString();
158:                        else
159:                            values[i + offset] = "";
160:                    }
161:                } else {
162:                    values[offset] = value.toString();
163:                }
164:                // store the new values array
165:                params.put(name, values);
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.