Source Code Cross Referenced for DefaultMobileAppAttributeHandler.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:        package com.sun.portal.wireless.admin;
002:
003:        import java.util.Map;
004:        import java.util.List;
005:        import java.util.ArrayList;
006:        import java.math.BigInteger;
007:
008:        import com.sun.portal.admin.common.AttrOptionConstants;
009:        import com.sun.portal.admin.common.AttributeInfo;
010:        import com.sun.portal.admin.common.PSMBeanException;
011:
012:        /**
013:         * Default attribute handler.
014:         * 
015:         * @author ashwin.mathew@sun.com
016:         */
017:        public class DefaultMobileAppAttributeHandler implements 
018:                MobileAppAttributeHandler {
019:
020:            private String service;
021:
022:            private String attributeName;
023:
024:            private String userFriendlyName;
025:
026:            private int scope;
027:
028:            private int type;
029:
030:            // Type is the type declared in the schema.
031:            // Actual type is type we have to validate for.
032:            private int actualType;
033:
034:            private int privilege;
035:
036:            private static final String TRUE_VALUE = "true";
037:            private static final String FALSE_VALUE = "false";
038:
039:            private static final BigInteger MAX_INTEGER_VAL = new BigInteger(
040:                    String.valueOf(Integer.MAX_VALUE));
041:
042:            protected DefaultMobileAppAttributeHandler(String service,
043:                    String attributeName, String userFriendlyName, int scope,
044:                    int type, int actualType, int privilege) {
045:                this .service = service;
046:                this .attributeName = attributeName;
047:                this .userFriendlyName = userFriendlyName;
048:                this .scope = scope;
049:                this .type = type;
050:                this .actualType = actualType;
051:                this .privilege = privilege;
052:            }
053:
054:            public String getService() {
055:                return service;
056:            }
057:
058:            public String getAttributeName() {
059:                return attributeName;
060:            }
061:
062:            public String getUserFriendlyName() {
063:                return userFriendlyName;
064:            }
065:
066:            public int getScope() {
067:                return scope;
068:            }
069:
070:            public int getPrivilege() {
071:                return privilege;
072:            }
073:
074:            public int getType() {
075:                return type;
076:            }
077:
078:            // We need this to perform validations properly,
079:            // since many MA types are not indicative of the
080:            // types actually stored.
081:            public int getActualType() {
082:                return actualType;
083:            }
084:
085:            public boolean requiresOldValues() {
086:                return false;
087:            }
088:
089:            // Default implementation, subclasses may override.
090:            public void validate(List values, Map optionsMap)
091:                    throws PSMBeanException {
092:                boolean isGlobal = Boolean
093:                        .valueOf(
094:                                (String) optionsMap
095:                                        .get(AttrOptionConstants.OPT_GLOBAL))
096:                        .booleanValue();
097:
098:                boolean isOrg = Boolean.valueOf(
099:                        (String) optionsMap.get(AttrOptionConstants.OPT_ORG))
100:                        .booleanValue();
101:
102:                String dn = (String) optionsMap.get(AttrOptionConstants.OPT_DN);
103:
104:                switch (scope) {
105:                case MobileAppAttributeHandler.SCOPE_GLOBAL: {
106:                    if (dn != null) {
107:                        throw new PSMBeanException(
108:                                "error.psadmin.attribute.not.dn.specific");
109:                    }
110:
111:                    if (isOrg) {
112:                        throw new PSMBeanException(
113:                                "error.psadmin.attribute.not.organization");
114:                    }
115:
116:                    break;
117:                }
118:                case MobileAppAttributeHandler.SCOPE_ORGANIZATION: {
119:                    if (isGlobal) {
120:                        throw new PSMBeanException(
121:                                "error.psadmin.attribute.not.global");
122:                    }
123:
124:                    if (dn == null) {
125:                        throw new PSMBeanException(
126:                                "error.psadmin.dn.is.required");
127:                    }
128:                    break;
129:                }
130:                case MobileAppAttributeHandler.SCOPE_USER: {
131:                    if (isGlobal) {
132:                        throw new PSMBeanException(
133:                                "error.psadmin.attribute.not.global");
134:                    }
135:
136:                    if (isOrg) {
137:                        throw new PSMBeanException(
138:                                "error.psadmin.attribute.not.organization");
139:                    }
140:
141:                    if (dn == null) {
142:                        throw new PSMBeanException(
143:                                "error.psadmin.dn.is.required");
144:                    }
145:                    break;
146:                }
147:                }
148:
149:                if (values != null
150:                        && getActualType() != AttributeInfo.LIST_NUMERIC
151:                        && getActualType() != AttributeInfo.LIST_STRING
152:                        && getActualType() != AttributeInfo.MULTIPLE_CHOICE_NUMERIC
153:                        && getActualType() != AttributeInfo.MULTIPLE_CHOICE_STRING
154:                        && getActualType() != AttributeInfo.UNKOWN_TYPE) {
155:                    validateSingleValueAttribute(values, optionsMap,
156:                            getActualType());
157:                }
158:            }
159:
160:            /**
161:             * This method does following validations
162:             * 1) add/remove options are not allowed for single valued attribute
163:             * 2) boolean attribute can have only true/fase as their values
164:             * 3) numeric attribute can have only numeric value
165:             * @param values
166:             * @param optionsMap
167:             * @param attributeType
168:             * @throws PSMBeanException
169:             */
170:            private void validateSingleValueAttribute(List values,
171:                    Map optionsMap, int attributeType) throws PSMBeanException {
172:                List addValues = (List) optionsMap
173:                        .get(AttrOptionConstants.OPT_ADD);
174:                List removeValues = (List) optionsMap
175:                        .get(AttrOptionConstants.OPT_REMOVE);
176:
177:                if (addValues != null || removeValues != null
178:                        || values.size() != 1) {
179:                    throw new PSMBeanException(
180:                            "error.psadmin.attribute.is.single.valued");
181:                }
182:
183:                String valueStr = ((String) values.get(0)).trim();
184:
185:                switch (attributeType) {
186:                case AttributeInfo.SINGLE_BOOLEAN: {
187:                    if (!(valueStr.equalsIgnoreCase(TRUE_VALUE) || valueStr
188:                            .equalsIgnoreCase(FALSE_VALUE))) {
189:                        throw new PSMBeanException(
190:                                "error.psadmin.attribute.is.boolean");
191:                    }
192:                    break;
193:                }
194:                case AttributeInfo.SINGLE_NUMERIC: {
195:                    BigInteger valueBigInt = new BigInteger(valueStr);
196:                    if (valueBigInt.compareTo(MAX_INTEGER_VAL) > 0) {
197:                        throw new PSMBeanException(
198:                                "error.psadmin.attribute.number.too.large");
199:                    } else if (valueBigInt.compareTo(BigInteger.ZERO) <= 0) {
200:                        throw new PSMBeanException(
201:                                "error.psadmin.attribute.number.too.small");
202:                    }
203:
204:                    try {
205:                        int valueInt = Integer.parseInt(valueStr);
206:
207:                        // This will take care of any leading 0's
208:                        values.set(0, String.valueOf(valueInt));
209:                    } catch (NumberFormatException e) {
210:                        throw new PSMBeanException(
211:                                "error.psadmin.attribute.is.number");
212:                    }
213:                    break;
214:                }
215:                }
216:            }
217:
218:            // Default implementation, subclasses may override.
219:            public List processGetValue(List values) throws PSMBeanException {
220:                return values;
221:            }
222:
223:            // Default implementation, subclasses may override.
224:            public List processSetValue(List values) throws PSMBeanException {
225:                return values;
226:            }
227:
228:            public final List getAttributeInfoList() {
229:                ArrayList infoList = new ArrayList();
230:
231:                // Not setting these for now, may support later
232:                String desc = null;
233:                String exampleKey = null;
234:
235:                // Note the use of actualType rather than type.
236:                // If type were to be used, users would get confused
237:                // by the validations, which function based on actualType.
238:                infoList.add(new Integer(getActualType()));
239:                infoList.add(desc);
240:                infoList.add(new Integer(getPrivilege()));
241:                infoList.add(exampleKey);
242:
243:                return infoList;
244:            }
245:
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.