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


001:        /*
002:         * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.admin.cli.commands.logging;
006:
007:        import com.sun.enterprise.cli.framework.CommandException;
008:        import com.sun.enterprise.cli.framework.CommandValidationException;
009:        import com.sun.portal.admin.cli.commands.AdminBaseCommand;
010:        import com.sun.portal.log.common.LoggersList;
011:
012:        import javax.management.MBeanException;
013:        import java.util.LinkedList;
014:
015:        public abstract class LoggingBaseCommand extends AdminBaseCommand {
016:
017:            protected static final String LINE_SEPARATOR = System
018:                    .getProperty("line.separator");
019:
020:            protected static final String LOGGING_PREFIX = "logging.";
021:
022:            protected static final String SUCCESS = "success";
023:            protected static final String ERROR = "error";
024:            protected static final String WARNING = "warning";
025:
026:            // Options common to logging
027:            protected static final String OPT_NAME = "name";
028:            protected static final String OPT_LEVEL = "level";
029:            protected static final String OPT_COMPONENT = "component";
030:
031:            // Options for "component"
032:            // Options like portal, instance, searchserver is defined in AdminCLIConstants
033:            private static final String OPT_SRA_INSTANCE = "sra-instance";
034:
035:            // Error suffixes
036:            protected static final String INSTANCE_NOT_FOUND_EXCEPTION = "instance.not.found.exception";
037:            protected static final String INVALID_COMPONENT = "invalid.component";
038:            protected static final String INVALID_LEVEL = "invalid.level";
039:            protected static final String INVALID_LOGGER = "invalid.logger";
040:            protected static final String REQUIRED_PORTAL_INSTANCE = "required.portal.instance";
041:            protected static final String INVALID_PORTAL_INSTANCE = "invalid.portal.instance";
042:            protected static final String REQUIRED_SEARCH_SERVER = "required.search.server";
043:            protected static final String INVALID_SEARCH_SERVER = "invalid.search.server";
044:            protected static final String REQUIRED_INSTANCE_NAME = "required.instance.name";
045:            protected static final String INVALID_INSTANCE_NAME = "invalid.instance.name";
046:
047:            // Object Name registered in Portal MBean server
048:            protected static final String PORTAL_LOG_OBJECT_NAME = "PortalDomain.PortalLogConfigurator";
049:
050:            protected LinkedList getPath() {
051:                LinkedList path = new LinkedList();
052:                path.addFirst(getDomainId());
053:                path.addFirst("portalLogConfigurator");
054:                return path;
055:            }
056:
057:            protected String getComponent() {
058:                return getOption(OPT_COMPONENT);
059:            }
060:
061:            protected String getComponentId() {
062:                // componentId is valid only for portal and search
063:                String component = getComponent();
064:                if (component.equals(LoggersList.COMPONENT_PORTAL_INSTANCE)) {
065:                    return getPortalId();
066:
067:                } else if (component
068:                        .equals(LoggersList.COMPONENT_SEARCH_INSTANCE)) {
069:                    return getSearchServerId();
070:
071:                } else {
072:                    return component;
073:                }
074:            }
075:
076:            protected String getInstance() {
077:                // instance is valid only for portal and sra
078:                String component = getComponent();
079:                if (component.equals(LoggersList.COMPONENT_PORTAL_INSTANCE)) {
080:                    return getInstanceId();
081:
082:                } else if (component.equals(LoggersList.COMPONENT_GW_INSTANCE)
083:                        || component.equals(LoggersList.COMPONENT_NLP_INSTANCE)
084:                        || component.equals(LoggersList.COMPONENT_RWP_INSTANCE)) {
085:                    return getSRAInstance();
086:
087:                } else {
088:                    return component;
089:                }
090:            }
091:
092:            protected String getSRAInstance() {
093:                return getOption(OPT_SRA_INSTANCE);
094:            }
095:
096:            protected String getLoggerName() {
097:                return getOption(OPT_NAME);
098:            }
099:
100:            protected String getLevel() {
101:                return getOption(OPT_LEVEL);
102:            }
103:
104:            protected boolean isVerbose() {
105:                return getBooleanOption(OPT_VERBOSE);
106:            }
107:
108:            public boolean validateOptions() throws CommandValidationException {
109:                if (super .validateOptions()) {
110:                    String component = getComponent();
111:                    if (component.equals(LoggersList.COMPONENT_PORTAL_INSTANCE)) {
112:
113:                        checkPortalInstance(component, true);
114:                        checkSearchServer(component, false);
115:                        checkSRAInstance(component, false);
116:
117:                    } else if (component
118:                            .equals(LoggersList.COMPONENT_SEARCH_INSTANCE)) {
119:
120:                        checkSearchServer(component, true);
121:                        checkPortalInstance(component, false);
122:                        checkSRAInstance(component, false);
123:
124:                    } else if (component
125:                            .equals(LoggersList.COMPONENT_GW_INSTANCE)
126:                            || component
127:                                    .equals(LoggersList.COMPONENT_NLP_INSTANCE)
128:                            || component
129:                                    .equals(LoggersList.COMPONENT_RWP_INSTANCE)) {
130:
131:                        checkSRAInstance(component, true);
132:                        checkPortalInstance(component, false);
133:                        checkSearchServer(component, false);
134:
135:                    } else if (component
136:                            .equals(LoggersList.COMPONENT_PAS_INSTANCE)) {
137:
138:                        checkPortalInstance(component, false);
139:                        checkSearchServer(component, false);
140:                        checkSRAInstance(component, false);
141:                    } else {
142:                        StringBuffer validComponentList = new StringBuffer(
143:                                " Valid component names are ");
144:                        validComponentList
145:                                .append(LoggersList.COMPONENT_PORTAL_INSTANCE);
146:                        validComponentList.append(",");
147:                        validComponentList
148:                                .append(LoggersList.COMPONENT_SEARCH_INSTANCE);
149:                        validComponentList.append(",");
150:                        validComponentList
151:                                .append(LoggersList.COMPONENT_PAS_INSTANCE);
152:                        validComponentList.append(",");
153:                        validComponentList
154:                                .append(LoggersList.COMPONENT_GW_INSTANCE);
155:                        validComponentList.append(",");
156:                        validComponentList
157:                                .append(LoggersList.COMPONENT_NLP_INSTANCE);
158:                        validComponentList.append(",");
159:                        validComponentList
160:                                .append(LoggersList.COMPONENT_RWP_INSTANCE);
161:                        throw new CommandValidationException(
162:                                getLocalizedString(LOGGING_PREFIX
163:                                        + INVALID_COMPONENT, new Object[] {
164:                                        component, validComponentList }));
165:                    }
166:                }
167:                return true;
168:            }
169:
170:            private void checkPortalInstance(String component, boolean required)
171:                    throws CommandValidationException {
172:                String portalId = getPortalId(); // Returns "" if not present
173:                String instanceId = getInstanceId(); // Returns "" if not present
174:                if (portalId == null) // prudency check
175:                    portalId = "";
176:                if (instanceId == null) // prudency check
177:                    instanceId = "";
178:
179:                if (required) {
180:                    if (portalId.equals("") || instanceId.equals("")) {
181:                        throw new CommandValidationException(
182:                                getLocalizedString(LOGGING_PREFIX
183:                                        + REQUIRED_PORTAL_INSTANCE,
184:                                        new Object[] { component }));
185:                    }
186:                } else {
187:                    if (!portalId.equals("") || !instanceId.equals("")) {
188:                        throw new CommandValidationException(
189:                                getLocalizedString(LOGGING_PREFIX
190:                                        + INVALID_PORTAL_INSTANCE,
191:                                        new Object[] { component }));
192:                    }
193:                }
194:            }
195:
196:            private void checkSearchServer(String component, boolean required)
197:                    throws CommandValidationException {
198:                String searchserverId = getSearchServerId(); // Returns "" if not present
199:                if (searchserverId == null) // prudency check
200:                    searchserverId = "";
201:
202:                if (required) {
203:                    if (searchserverId.equals("")) {
204:                        throw new CommandValidationException(
205:                                getLocalizedString(LOGGING_PREFIX
206:                                        + REQUIRED_SEARCH_SERVER,
207:                                        new Object[] { component }));
208:                    }
209:                } else {
210:                    if (!searchserverId.equals("")) {
211:                        throw new CommandValidationException(
212:                                getLocalizedString(LOGGING_PREFIX
213:                                        + INVALID_SEARCH_SERVER,
214:                                        new Object[] { component }));
215:                    }
216:                }
217:            }
218:
219:            private void checkSRAInstance(String component, boolean required)
220:                    throws CommandValidationException {
221:                String instanceName = getSRAInstance(); // Returns "" if not present
222:                if (instanceName == null) // prudency check
223:                    instanceName = "";
224:
225:                if (required) {
226:                    if (instanceName.equals("")) {
227:                        throw new CommandValidationException(
228:                                getLocalizedString(LOGGING_PREFIX
229:                                        + REQUIRED_INSTANCE_NAME,
230:                                        new Object[] { component }));
231:                    }
232:                } else {
233:                    if (!instanceName.equals("")) {
234:                        throw new CommandValidationException(
235:                                getLocalizedString(LOGGING_PREFIX
236:                                        + INVALID_INSTANCE_NAME,
237:                                        new Object[] { component }));
238:                    }
239:                }
240:            }
241:
242:            protected String getCauseMessages(Exception e) {
243:                StringBuffer sb = new StringBuffer(e.getLocalizedMessage());
244:                Throwable t = e.getCause();
245:                while (t != null) {
246:                    sb.append(LINE_SEPARATOR).append("\t").append(
247:                            t.getLocalizedMessage());
248:                    t = t.getCause();
249:                }
250:
251:                return sb.toString();
252:            }
253:
254:            protected void throwError(MBeanException me)
255:                    throws CommandException {
256:                Exception e = (Exception) me.getTargetException();
257:                throw new CommandException(getLocalizedString(LOGGING_PREFIX
258:                        + ERROR, new Object[] { getCauseMessages(e) }));
259:            }
260:        }
w_w___w.ja___v_a_2_s___._c___om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.