Source Code Cross Referenced for PredefinedRepliesMobileAppAttributeHandler.java in  » Portal » Open-Portal » com » sun » portal » wireless » admin » 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 » Portal » Open Portal » com.sun.portal.wireless.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Mar 17, 2005
003:         */
004:        package com.sun.portal.wireless.admin;
005:
006:        import java.util.List;
007:        import java.util.Map;
008:        import java.util.HashMap;
009:        import java.util.ArrayList;
010:        import java.util.Iterator;
011:
012:        import com.sun.portal.admin.common.PSMBeanException;
013:        import com.sun.portal.admin.common.AttrOptionConstants;
014:
015:        /**
016:         * Attribute handler for predefinedReplies
017:         * 
018:         * @author ashwin.mathew@sun.com
019:         */
020:        public class PredefinedRepliesMobileAppAttributeHandler extends
021:                DefaultMobileAppAttributeHandler {
022:
023:            // The values should be of the form "presetN=<value>".
024:            private static final String PRESET = "preset";
025:            private static final char EQUALS = '=';
026:            private static final int INDEX_EQUALS = 7;
027:            private static final int INDEX_NUMBER = 6;
028:
029:            /**
030:             * @param service
031:             * @param attributeName
032:             * @param userFriendlyName
033:             * @param scope
034:             * @param type
035:             * @param privilege
036:             */
037:            protected PredefinedRepliesMobileAppAttributeHandler(
038:                    String service, String attributeName,
039:                    String userFriendlyName, int scope, int type,
040:                    int actualType, int privilege) {
041:                super (service, attributeName, userFriendlyName, scope, type,
042:                        actualType, privilege);
043:            }
044:
045:            public boolean requiresOldValues() {
046:                return true;
047:            }
048:
049:            /* (non-Javadoc)
050:             * @see com.sun.portal.wireless.admin.MobileAppAttributeHandler#validate(java.util.List, java.util.Map)
051:             */
052:            public void validate(List values, Map optionsMap)
053:                    throws PSMBeanException {
054:                if (values == null || optionsMap == null) {
055:                    // It's a get no validation required
056:                    return;
057:                }
058:
059:                Map valuesMap = validatePredefinedReplies(values);
060:
061:                Map addValuesMap = null;
062:                Map removeValuesMap = null;
063:
064:                List addValues = (List) optionsMap
065:                        .get(AttrOptionConstants.OPT_ADD);
066:                if (addValues != null) {
067:                    addValuesMap = validatePredefinedReplies(addValues);
068:                }
069:
070:                List removeValues = (List) optionsMap
071:                        .get(AttrOptionConstants.OPT_REMOVE);
072:                if (removeValues != null) {
073:                    removeValuesMap = validatePredefinedReplies(removeValues);
074:                }
075:
076:                List outputList = null;
077:
078:                List oldValues = (List) optionsMap
079:                        .get(AbstractMobileGetSetAttributeHandler.KEY_OLD_VALUES);
080:                // No need to do this if the complete value list is being replaced by values
081:                if (oldValues != null
082:                        && (addValues != null || removeValues != null)) {
083:                    outputList = new ArrayList();
084:
085:                    // Copy oldValues to a HashMap to make processing easier
086:                    Map oldValuesMap = new HashMap();
087:                    for (int i = 0; i < oldValues.size(); i++) {
088:                        String value = (String) oldValues.get(i);
089:                        String key = value.substring(0, INDEX_EQUALS);
090:                        String predefinedReply = value
091:                                .substring(INDEX_EQUALS + 1);
092:                        oldValuesMap.put(key, predefinedReply);
093:                    }
094:
095:                    // Replace keys in oldValues to empty for keys in removeValues
096:                    if (removeValuesMap != null) {
097:                        Iterator removeKeys = removeValuesMap.keySet()
098:                                .iterator();
099:                        while (removeKeys.hasNext()) {
100:                            String key = (String) removeKeys.next();
101:                            oldValuesMap.put(key, null);
102:                        }
103:                    }
104:
105:                    // Replace keys in oldValues with those from addValues
106:                    if (addValuesMap != null) {
107:                        oldValuesMap.putAll(addValuesMap);
108:                    }
109:
110:                    // Remove addValues and removeValues from optionsMap
111:                    optionsMap.remove(AttrOptionConstants.OPT_ADD);
112:                    optionsMap.remove(AttrOptionConstants.OPT_REMOVE);
113:
114:                    outputList = getOutputList(oldValuesMap);
115:                } else {
116:                    outputList = getOutputList(valuesMap);
117:                }
118:
119:                optionsMap
120:                        .put(
121:                                AbstractMobileGetSetAttributeHandler.KEY_OVERRIDE_VALUES,
122:                                outputList);
123:            }
124:
125:            private List getOutputList(Map valuesMap) {
126:                List outputList = new ArrayList();
127:
128:                // Array to make sure that all presetN entries are present
129:                boolean[] isPresent = new boolean[10];
130:
131:                Iterator keys = valuesMap.keySet().iterator();
132:                while (keys.hasNext()) {
133:                    String key = (String) keys.next();
134:                    String predefinedReply = (String) valuesMap.get(key);
135:                    if (predefinedReply == null) {
136:                        predefinedReply = "";
137:                    }
138:
139:                    String element = key + EQUALS + predefinedReply;
140:
141:                    outputList.add(element);
142:
143:                    int presetNum = Integer.parseInt(key
144:                            .substring(INDEX_NUMBER));
145:                    isPresent[presetNum] = true;
146:                }
147:
148:                // Values are from 1 to 9
149:                for (int i = 1; i < isPresent.length; i++) {
150:                    if (!isPresent[i]) {
151:                        outputList.add(PRESET + i + EQUALS);
152:                    }
153:                }
154:
155:                return outputList;
156:            }
157:
158:            private Map validatePredefinedReplies(List values)
159:                    throws PSMBeanException {
160:                HashMap valuesMap = new HashMap();
161:
162:                for (int i = 0; i < values.size(); i++) {
163:                    String value = (String) values.get(i);
164:
165:                    if (!value.startsWith(PRESET)) {
166:                        throw new PSMBeanException(
167:                                "error.psadmin.predefinedReplies.format.incorrect");
168:                    }
169:
170:                    try {
171:                        Integer.parseInt(value.substring(INDEX_NUMBER,
172:                                INDEX_NUMBER + 1));
173:                    } catch (NumberFormatException e) {
174:                        throw new PSMBeanException(
175:                                "error.psadmin.predefinedReplies.format.incorrect");
176:                    }
177:
178:                    if (value.length() >= INDEX_EQUALS + 1
179:                            && !(value.charAt(INDEX_EQUALS) == EQUALS)) {
180:                        throw new PSMBeanException(
181:                                "error.psadmin.predefinedReplies.format.incorrect");
182:                    }
183:
184:                    String key = value.substring(0, INDEX_EQUALS);
185:                    String predefinedReply = null;
186:                    if (value.length() >= INDEX_EQUALS + 1) {
187:                        predefinedReply = value.substring(INDEX_EQUALS + 1);
188:                    }
189:                    valuesMap.put(key, predefinedReply);
190:                }
191:
192:                return valuesMap;
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.