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


001:        /**
002:         * $Id: SetAttributeCommand.java,v 1.10 2005/11/07 17:40:17 cathywu Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.admin.cli.commands;
014:
015:        //CLI framework
016:        import com.sun.enterprise.cli.framework.*;
017:
018:        //JMX
019:        import javax.management.MBeanServerConnection;
020:        import javax.management.ObjectName;
021:        import javax.management.MBeanException;
022:        import javax.management.ReflectionException;
023:        import javax.management.MalformedObjectNameException;
024:        import javax.management.InstanceNotFoundException;
025:
026:        import com.sun.portal.admin.common.util.AdminUtil;
027:        import com.sun.portal.admin.common.PSMBeanException;
028:
029:        import java.util.Collections;
030:        import java.util.List;
031:        import java.util.Vector;
032:        import java.util.Iterator;
033:        import java.util.Map;
034:        import java.util.logging.Logger;
035:        import java.util.logging.Level;
036:
037:        import com.sun.portal.admin.common.AttrOptionConstants;
038:
039:        public class SetAttributeCommand extends GenericCommand {
040:            public void runCommand() throws CommandException,
041:                    CommandValidationException {
042:                if (!validateOptions()) {
043:                    throw new CommandValidationException(
044:                            getLocalizedString(ERROR_OPTION_VALIDATION_FAILED));
045:                }
046:
047:                String portalId = getOption(OPT_PORTAL_ID);
048:                if (portalId != null) {
049:                    validatePortalId();
050:                }
051:
052:                String operation = "";
053:
054:                try {
055:                    String component = getOption(AttrOptionConstants.OPT_COMPONENT);
056:                    List values = null;
057:                    Vector v = getOperands();
058:                    if (v == null || v.isEmpty()) {
059:                        values = Collections.EMPTY_LIST;
060:                    } else {
061:                        values = getMultiValueFromString((String) v
062:                                .firstElement());
063:                    }
064:
065:                    validateSetOptions(values, getOptions(), component);
066:
067:                    MBeanServerConnection mbsc = getMBeanServerConnection(
068:                            getUserId(), getPassword(), getHost());
069:
070:                    ObjectName objectName = portalId == null ? AdminUtil
071:                            .getPortalDomainMBeanObjectName(getDomainId())
072:                            : AdminUtil.getPortalMBeanObjectName(getDomainId(),
073:                                    portalId);
074:
075:                    Map optMap = getOptions();
076:                    //Process the options to convert the add and remove option values
077:                    //from a single string to multivalued List
078:                    //process add if it exists
079:                    if (optMap.containsKey(AttrOptionConstants.OPT_ADD)) {
080:                        List optValues = getMultiValueOption(AttrOptionConstants.OPT_ADD);
081:                        //remove the original key-value since it is key-string pair
082:                        optMap.remove(AttrOptionConstants.OPT_ADD);
083:                        //then put the new key-list pair into the map
084:                        optMap.put(AttrOptionConstants.OPT_ADD, optValues);
085:                    }
086:                    //process remove if it exists            
087:                    if (optMap.containsKey(AttrOptionConstants.OPT_REMOVE)) {
088:                        List optValues = getMultiValueOption(AttrOptionConstants.OPT_REMOVE);
089:                        optMap.remove(AttrOptionConstants.OPT_REMOVE);
090:                        optMap.put(AttrOptionConstants.OPT_REMOVE, optValues);
091:                    }
092:
093:                    optMap.put("operation", "set");
094:                    // Setting the params and signature
095:                    Object[] params = { values, optMap };
096:                    String[] signature = { "java.util.List", "java.util.Map" };
097:                    operation = "setAttribute";
098:
099:                    mbsc.invoke(objectName, operation, params, signature);
100:
101:                } catch (InstanceNotFoundException ie) {
102:                    logger.log(Level.SEVERE, "PSALI_CSPACC0005", ie);
103:                    throw new CommandException(getLocalizedString(
104:                            ERROR_MBEAN_INSTANCE_NOT_FOUND,
105:                            new Object[] { operation }), ie);
106:                } catch (MBeanException me) {
107:                    logger.log(Level.SEVERE, "PSALI_CSPACC0006", me);
108:                    boolean psmbe = me.getCause() instanceof  PSMBeanException;
109:                    if (getBooleanOption(OPT_DEBUG)) {
110:                        if (psmbe) {
111:                            String dbgMsg = me.getCause().getMessage();
112:                            if (dbgMsg != null) {
113:                                CLILogger.getInstance().printMessage(dbgMsg);
114:                            }
115:                        }
116:                    }
117:                    if (psmbe) {
118:                        throw new CommandException(
119:                                getLocalizedString(((PSMBeanException) me
120:                                        .getCause()).getErrorKey()), me);
121:                    } else {
122:                        throw new CommandException(
123:                                getLocalizedString(ERROR_JMX_INVOKE), me);
124:                    }
125:                } catch (ReflectionException re) {
126:                    logger.log(Level.SEVERE, "PSALI_CSPACC0007", re);
127:                    throw new CommandException(
128:                            getLocalizedString(ERROR_JMX_INVOKE), re);
129:                } catch (CommandException ce) {
130:                    logger.log(Level.SEVERE, "PSALI_CSPACC0008", ce);
131:                    throw ce;
132:                } catch (CommandValidationException cve) {
133:                    logger.log(Level.SEVERE, "PSALI_CSPACC0013", cve);
134:                    throw cve;
135:                } catch (Exception ex) {
136:                    logger.log(Level.SEVERE, "PSALI_CSPACC0010", ex);
137:                    throw new CommandException(
138:                            getLocalizedString(COMMAND_FAILED), ex);
139:                } finally {
140:                    closeMBeanServerConnection();
141:                }
142:            }
143:
144:            private void validateSetOptions(List values, Map optionsMap,
145:                    String component) throws CommandValidationException {
146:                validateBasicOptions(optionsMap);
147:                validateBasicSetOptions(values, optionsMap);
148:                if ("desktop".equals(component)) {
149:                    validateDesktopOptions(optionsMap);
150:                } else if ("subscriptions".equals(component)) {
151:                    validateSubscriptionsOptions(optionsMap);
152:                }
153:                //Component owners to add more calls here as required
154:
155:            }
156:
157:            private void validateBasicOptions(Map optionsMap)
158:                    throws CommandValidationException {
159:                //validate the basic options
160:                boolean global = Boolean
161:                        .valueOf(
162:                                (String) optionsMap
163:                                        .get(AttrOptionConstants.OPT_GLOBAL))
164:                        .booleanValue();
165:                boolean org = Boolean.valueOf(
166:                        (String) optionsMap.get(AttrOptionConstants.OPT_ORG))
167:                        .booleanValue();
168:                boolean dn = optionsMap.containsKey(AttrOptionConstants.OPT_DN);
169:                if (global) {
170:                    //global is not allowed with org and dn options
171:                    if (org || dn) {
172:                        throw new CommandValidationException(
173:                                getLocalizedString("error.psadmin.validation.combination.1"));
174:                    }
175:                }
176:            }
177:
178:            private void validateBasicSetOptions(List values, Map optionsMap)
179:                    throws CommandValidationException {
180:                boolean inherit = Boolean.valueOf(
181:                        (String) optionsMap
182:                                .get(AttrOptionConstants.OPT_INHERIT))
183:                        .booleanValue();
184:                boolean add = optionsMap
185:                        .containsKey(AttrOptionConstants.OPT_ADD);
186:                boolean remove = optionsMap
187:                        .containsKey(AttrOptionConstants.OPT_REMOVE);
188:                boolean dn = optionsMap.containsKey(AttrOptionConstants.OPT_DN);
189:
190:                //The following logic can be simplified by not testing everything
191:                //in every if. Instead the tests can grow shorter as execution
192:                //falls thru the ifs. But none of the tests are very expensive
193:                //and this way these can be separated out easily later, if needed.
194:                if (inherit) {
195:                    //if inherit is true, then all others are invalid
196:                    if (add || remove || values.size() != 0) {
197:                        //inherit is not allowed with other options or operand
198:                        throw new CommandValidationException(
199:                                getLocalizedString("error.psadmin.validation.combination.2"));
200:                    }
201:                    if (!dn) {
202:                        //dn must be specified with inherit
203:                        throw new CommandValidationException(
204:                                getLocalizedString("error.psadmin.validation.combination.6"));
205:                    }
206:                } else if (add || remove) {
207:                    //if add is specified, then only remove is valid
208:                    //if remove is specified, then only add is valid
209:                    //if add and remove are given, then all others are invalid
210:                    if (inherit || !values.isEmpty()) {
211:                        //add/remove is not allowed with other options or operand
212:                        throw new CommandValidationException(
213:                                getLocalizedString("error.psadmin.validation.combination.3"));
214:                    }
215:                } else if (values.size() == 1) {
216:                    //if values are given as operand then, all others are invalid
217:                    if (inherit || add || remove) {
218:                        //operand is not allowed with other options
219:                        throw new CommandValidationException(
220:                                getLocalizedString("error.psadmin.validation.combination.4"));
221:                    }
222:                } else if (values.isEmpty()) {
223:                    //if neither any options nor values, then its invalid
224:                    if (!inherit && !add && !remove) {
225:                        //neither options nor operands specified
226:                        throw new CommandValidationException(
227:                                getLocalizedString("error.psadmin.validation.combination.5"));
228:                    }
229:                }
230:            }
231:
232:            private void validateDesktopOptions(Map map)
233:                    throws CommandValidationException {
234:
235:                String portalId = getOption(OPT_PORTAL_ID);
236:
237:                if (portalId == null) {
238:                    throw new CommandValidationException(
239:                            getLocalizedString("error.psadmin.portalid.not.specified"));
240:                }
241:
242:                //Following check is required if we have org as valid option for cli
243:                boolean org = Boolean.valueOf(
244:                        (String) map.get(AttrOptionConstants.OPT_ORG))
245:                        .booleanValue();
246:                if (org) {
247:                    throw new CommandValidationException(
248:                            getLocalizedString("error.psadmin.org.option.not.valid.for.desktop"));
249:                }
250:
251:            }
252:
253:            private void validateSubscriptionsOptions(Map map)
254:                    throws CommandValidationException {
255:
256:                String portalId = getOption(OPT_PORTAL_ID);
257:
258:                if (portalId == null) {
259:                    throw new CommandValidationException(
260:                            getLocalizedString("error.psadmin.portalid.not.specified"));
261:                }
262:            }
263:
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.