Source Code Cross Referenced for TestVerifier.java in  » ESB » open-esb » java4ant » 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 » ESB » open esb » java4ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)TestVerifier.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package java4ant;
030:
031:        import java.util.Iterator;
032:        import java.util.Set;
033:
034:        import javax.management.MBeanServerConnection;
035:        import javax.management.remote.JMXConnector;
036:        import javax.management.remote.JMXConnectorFactory;
037:        import javax.management.remote.JMXServiceURL;
038:        import javax.management.ObjectName;
039:
040:        import javax.management.openmbean.ArrayType;
041:        import javax.management.openmbean.CompositeData;
042:        import javax.management.openmbean.CompositeDataSupport;
043:        import javax.management.openmbean.CompositeType;
044:        import javax.management.openmbean.OpenType;
045:        import javax.management.openmbean.OpenDataException;
046:        import javax.management.openmbean.SimpleType;
047:        import javax.management.openmbean.TabularData;
048:
049:        /**
050:         * This class is used to test Application Verifier.
051:         */
052:        public class TestVerifier {
053:            /**  MBean Server Connection */
054:            private MBeanServerConnection mbns;
055:
056:            /** Result Prefix */
057:            private static final String RESULT_PREFIX = "##### Result of ";
058:
059:            /** system properties used by this class */
060:            private static final String USER = "jmx.user";
061:            private static final String PASSWORD = "jmx.password";
062:            private static final String PROVIDER = "jmx.provider";
063:
064:            private static final String APPLICATION_URL = "application_url";
065:            private static final String TARGET = "target";
066:            private static final String GENERATE_TEMPLATES = "generate_templates";
067:            private static final String TEMPLATE_DIR = "template_dir";
068:            private static final String INCLUDE_DEPLOY_COMMAND = "include_deploy_command";
069:            private static final String APPLICATION_NAME = "application_name";
070:            private static final String CONFIG_DIR = "config_dir";
071:
072:            /**
073:             * Initialize connection to MBean Server
074:             */
075:            public void initMBeanServerConnection() throws Exception {
076:                java.util.Map<String, String[]> env = new java.util.HashMap();
077:                String user = System.getProperty(USER);
078:                String pass = System.getProperty(PASSWORD);
079:                String[] credentials = new String[] { user, pass };
080:                env.put("jmx.remote.credentials", credentials);
081:
082:                String jmxProvider = System.getProperty(PROVIDER);
083:
084:                JMXConnector connector = JMXConnectorFactory.connect(
085:                        new JMXServiceURL(jmxProvider), env);
086:
087:                mbns = connector.getMBeanServerConnection();
088:            }
089:
090:            /**
091:             * Verify Application
092:             */
093:
094:            public CompositeData verifyApplication() throws Exception {
095:                String info = "com.sun.jbi:ServiceName=JbiReferenceAdminUiService,ComponentType=System";
096:                return (CompositeData) mbns
097:                        .invoke(
098:                                new ObjectName(info),
099:                                "verifyApplication",
100:                                new Object[] {
101:                                        System.getProperty(APPLICATION_URL),
102:                                        System.getProperty(TARGET),
103:                                        Boolean
104:                                                .getBoolean(System
105:                                                        .getProperty(GENERATE_TEMPLATES)),
106:                                        System.getProperty(TEMPLATE_DIR),
107:                                        Boolean
108:                                                .getBoolean(System
109:                                                        .getProperty(INCLUDE_DEPLOY_COMMAND)) },
110:                                new String[] { "java.lang.String",
111:                                        "java.lang.String", "boolean",
112:                                        "java.lang.String", "boolean" });
113:
114:            }
115:
116:            /**
117:             * parse and print the verifier report
118:             */
119:            public void printVerifierReport(CompositeData verifierReport) {
120:                String[] attributeNames = { "ServiceAssemblyName",
121:                        "ServiceAssemblyDescription", "NumServiceUnits",
122:                        "AllComponentsInstalled", "MissingComponentsList",
123:                        "EndpointInfo", "TemplateZIPID", };
124:
125:                String[] endpointNames = { "EndpointName", "ServiceUnitName",
126:                        "ComponentName", "Status",
127:                        "MissingApplicationVariables",
128:                        "MissingApplicationConfigurations" };
129:                Object[] reportValues = verifierReport.getAll(attributeNames);
130:
131:                String saName = (String) reportValues[0];
132:                String saDesc = (String) reportValues[1];
133:                int numSUs = ((Integer) reportValues[2]).intValue();
134:                boolean allComponentsInstalled = ((Boolean) reportValues[3])
135:                        .booleanValue();
136:                String[] missingComponents = (String[]) reportValues[4];
137:                CompositeData[] endpointInfo = (CompositeData[]) reportValues[5];
138:                String templateZipID = (String) reportValues[6];
139:
140:                System.out.println("Service Assembly Information");
141:                System.out.println("-----------------------------");
142:                System.out.println("Name: " + saName);
143:                System.out.println("Service Units: " + numSUs);
144:                System.out.println("Description: " + saDesc);
145:
146:                if (!allComponentsInstalled) {
147:                    StringBuffer missingCompString = new StringBuffer();
148:                    for (int i = 0; i < missingComponents.length; i++) {
149:                        missingCompString.append(" " + missingComponents[i]);
150:                    }
151:                    System.out
152:                            .println("The following components are not installed:"
153:                                    + missingCompString.toString());
154:                }
155:                System.out.println();
156:                for (int i = 0; i < endpointInfo.length; i++) {
157:                    System.out.println("Endpoint Configuration");
158:                    System.out.println("-----------------------");
159:
160:                    Object[] endpointValues = endpointInfo[i]
161:                            .getAll(endpointNames);
162:                    System.out.println("Name: " + (String) endpointValues[0]);
163:                    System.out.println("Service Unit: "
164:                            + (String) endpointValues[1]);
165:                    System.out.println("Component: "
166:                            + (String) endpointValues[2]);
167:                    System.out.println("Status: " + (String) endpointValues[3]);
168:
169:                    String[] appVars = (String[]) endpointValues[4];
170:                    if (appVars != null && appVars.length > 0) {
171:                        System.out.println("Missing Application Variables ");
172:                        for (int j = 0; j < appVars.length; j++) {
173:                            System.out.print("\t" + appVars[j]);
174:                        }
175:                        System.out.println();
176:                    }
177:
178:                    String[] appConfigs = (String[]) endpointValues[5];
179:                    if (appConfigs != null && appConfigs.length > 0) {
180:                        System.out
181:                                .println("Missing Application Configurations ");
182:                        for (int j = 0; j < appConfigs.length; j++) {
183:                            System.out.print("\t" + appConfigs[j]);
184:                        }
185:                        System.out.println();
186:                    }
187:
188:                }
189:
190:                //JavaEEVerificationReport is optional element
191:                if (verifierReport.containsKey("JavaEEVerificationReport")) {
192:                    CompositeData[] javaEEVerifierReports = (CompositeData[]) verifierReport
193:                            .get("JavaEEVerificationReport");
194:
195:                    if (javaEEVerifierReports != null
196:                            && javaEEVerifierReports.length > 0) {
197:                        System.out.println();
198:                        System.out.println("JavaEE Verifier Reports");
199:                        System.out.println("-----------------------");
200:                    }
201:                    for (int i = 0; i < javaEEVerifierReports.length; i++) {
202:                        System.out.println("Service Unit Name: "
203:                                + javaEEVerifierReports[i]
204:                                        .get("ServiceUnitName"));
205:                        TabularData reportTable = (TabularData) javaEEVerifierReports[i]
206:                                .get("JavaEEVerifierReport");
207:                        Set rows = reportTable.keySet();
208:                        for (Object row : rows) {
209:                            Object[] key = ((java.util.List) row).toArray();
210:                            CompositeData compData = reportTable.get(key);
211:                            System.out.println();
212:                            printCompositeData(compData, 0);
213:                        }
214:
215:                    }
216:                }
217:
218:            }
219:
220:            /**
221:             * parse and print the report
222:             */
223:            public void printCompositeData(TabularData statsReport) {
224:                Set names = statsReport.keySet();
225:                for (Object name : names) {
226:                    Object[] key = ((java.util.List) name).toArray();
227:                    CompositeData compData = statsReport.get(key);
228:                    System.out.println();
229:                    printCompositeData(compData, 1);
230:                }
231:            }
232:
233:            /**
234:             * parse and print the report
235:             */
236:            protected void printCompositeData(CompositeData compData,
237:                    int recursiveLevel) {
238:
239:                String tabT = "";
240:                for (int i = 0; i < recursiveLevel; ++i) {
241:                    tabT = tabT + "\t";
242:                }
243:                recursiveLevel++;
244:
245:                CompositeType compType = compData.getCompositeType();
246:                Iterator itr = compType.keySet().iterator();
247:                while (itr.hasNext()) {
248:                    String keyName = (String) itr.next();
249:                    OpenType openType = compType.getType(keyName);
250:                    Object itemValue = compData.get(keyName);
251:                    String className = null;
252:                    if (itemValue != null) {
253:                        className = itemValue.getClass().getName();
254:                    }
255:
256:                    if (openType.isArray()) {
257:                        System.out.println(tabT + keyName + ":");
258:                        if ((openType.getTypeName() != null)
259:                                && (openType.getTypeName().compareTo(
260:                                        "[Ljava.lang.String;") == 0)) {
261:                            String[] strArray = (String[]) compData
262:                                    .get(keyName);
263:                            for (int i = 0; i < strArray.length; ++i) {
264:                                System.out.println(tabT + "\t" + strArray[i]);
265:                            }
266:                        } else if ((openType.getTypeName() != null)
267:                                && (openType
268:                                        .getTypeName()
269:                                        .compareTo(
270:                                                "[Ljavax.management.openmbean.CompositeData;") == 0)) {
271:                            CompositeData[] compDataArray = (CompositeData[]) compData
272:                                    .get(keyName);
273:                            for (int i = 0; i < compDataArray.length; ++i) {
274:                                printCompositeData(compDataArray[i],
275:                                        recursiveLevel);
276:                            }
277:                        }
278:
279:                    } else {
280:
281:                        if (className != null
282:                                && (className
283:                                        .equals("javax.management.openmbean.CompositeDataSupport") || className
284:                                        .equals("javax.management.openmbean.CompositeData"))) {
285:                            printCompositeData((CompositeData) compData
286:                                    .get(keyName), recursiveLevel);
287:                        } else if (className != null
288:                                && (className
289:                                        .equals("javax.management.openmbean.TabularDataSupport") || className
290:                                        .equals("javax.management.openmbean.TabularData"))) {
291:                            printCompositeData((TabularData) compData
292:                                    .get(keyName));
293:                        } else {
294:                            System.out.println(tabT + keyName + "="
295:                                    + compData.get(keyName));
296:                        }
297:                    }
298:                }
299:
300:            }
301:
302:            /**
303:             * Export Application Configuration
304:             */
305:            public String exportApplication() throws Exception {
306:                String info = "com.sun.jbi:ServiceName=JbiReferenceAdminUiService,ComponentType=System";
307:                return (String) mbns.invoke(new ObjectName(info),
308:                        "exportApplicationConfiguration", new Object[] {
309:                                System.getProperty(APPLICATION_NAME),
310:                                System.getProperty(CONFIG_DIR),
311:                                System.getProperty(TARGET), }, new String[] {
312:                                "java.lang.String", "java.lang.String",
313:                                "java.lang.String" });
314:
315:            }
316:
317:            /**
318:             * The main method
319:             */
320:            public static void main(String[] params) throws Exception {
321:
322:                TestVerifier testVerifier = new TestVerifier();
323:                testVerifier.initMBeanServerConnection();
324:                if (params.length == 0) {
325:                    throw new Exception("Usage: TestVerifier verify|export");
326:                }
327:                if (params[0].equals("verify")) {
328:                    testVerifier.printVerifierReport(testVerifier
329:                            .verifyApplication());
330:                } else {
331:                    testVerifier.exportApplication();
332:                }
333:
334:            }
335:
336:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.