Source Code Cross Referenced for JbiQueryTask.java in  » ESB » open-esb » com » sun » jbi » ui » ant » 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 » com.sun.jbi.ui.ant 
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:         * @(#)JbiQueryTask.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.ui.ant;
030:
031:        import com.sun.jbi.ui.common.ServiceAssemblyInfo;
032:        import com.sun.jbi.ui.common.JBIComponentInfo;
033:        import com.sun.jbi.ui.common.ServiceUnitInfo;
034:        import java.io.PrintWriter;
035:        import java.io.StringWriter;
036:        import java.util.Iterator;
037:        import java.util.List;
038:        import org.apache.tools.ant.BuildException;
039:
040:        /** This class is a base class that has the helper methods the extended classes of the
041:         * query interface need to implement. All concreate query tasks extend directly from this
042:         * or from a derived class of this.
043:         *
044:         * @author Sun Microsystems, Inc.
045:         */
046:        public abstract class JbiQueryTask extends JbiTargetTask {
047:            /** query information for one or more objects **/
048:            protected static final int LIST_QUERY_RESULT_TYPE = 1;
049:            /** query information for a single object **/
050:            protected static final int SINGLE_QUERY_RESULT_TYPE = 2;
051:
052:            /** started state */
053:            protected static final String STARTED_STATE = "started";
054:            /** stopped state */
055:            protected static final String STOPPED_STATE = "stopped";
056:            /** shutdown state */
057:            protected static final String SHUTDOWN_STATE = "shutdown";
058:            /** unknown state */
059:            protected static final String UNKNOWN_STATE = "unknown";
060:            /** any state */
061:            protected static final String ANY_STATE = "any";
062:
063:            /** i18n text for installed state for shared libs */
064:            private static String sDisplayInstalledState = null;
065:            /** i18n text for started state */
066:            private static String sDisplayStartedState = null;
067:            /** i18n text for stopped state */
068:            private static String sDisplayStoppedState = null;
069:            /** i18n text for shutdown state */
070:            private static String sDisplayShutdownState = null;
071:            /** i18n text for unknown state */
072:            private static String sDisplayUnknownState = null;
073:
074:            /**
075:             * query result type. single or list.
076:             */
077:            private int mQueryResultType = LIST_QUERY_RESULT_TYPE;
078:
079:            /** Holds value of property xmlOutput. */
080:            private String mXmlOutput = null;
081:
082:            /**
083:             * base constructor.
084:             */
085:            public JbiQueryTask() {
086:                super ();
087:                initStateDisplayValues();
088:            }
089:
090:            /**
091:             * loads the i18n text for the states
092:             */
093:            private void initStateDisplayValues() {
094:
095:                if (sDisplayInstalledState == null) {
096:                    sDisplayInstalledState = getI18NBundle().getMessage(
097:                            "jbi.ui.ant.print.state.installed");
098:                }
099:
100:                if (sDisplayStartedState == null) {
101:                    sDisplayStartedState = getI18NBundle().getMessage(
102:                            "jbi.ui.ant.print.state.started");
103:                }
104:
105:                if (sDisplayStoppedState == null) {
106:                    sDisplayStoppedState = getI18NBundle().getMessage(
107:                            "jbi.ui.ant.print.state.stopped");
108:                }
109:
110:                if (sDisplayShutdownState == null) {
111:                    sDisplayShutdownState = getI18NBundle().getMessage(
112:                            "jbi.ui.ant.print.state.shutdown");
113:                }
114:
115:                if (sDisplayUnknownState == null) {
116:                    sDisplayUnknownState = getI18NBundle().getMessage(
117:                            "jbi.ui.ant.print.state.unknown");
118:                }
119:
120:            }
121:
122:            /** Getter for property XmlOutput.
123:             * @return Value of XmlOutput.
124:             */
125:            public String getXmlOutput() {
126:                return this .mXmlOutput;
127:            }
128:
129:            /**
130:             * Setter for property XmlOutput.
131:             * @param xmlOutput xml text.
132:             */
133:            public void setXmlOutput(String xmlOutput) {
134:                this .mXmlOutput = xmlOutput;
135:            }
136:
137:            /** Getter for property QueryType.
138:             * @return Value of QueryType.
139:             */
140:            protected int getQueryResultType() {
141:                return this .mQueryResultType;
142:            }
143:
144:            /** Setter for property QueryType to LIST_QUERY_RESULT_TYPE.
145:             *
146:             */
147:            protected void setListQueryResultType() {
148:                this .mQueryResultType = LIST_QUERY_RESULT_TYPE;
149:            }
150:
151:            /** Setter for property QueryType to SINGLE_QUERY_RESULT_TYPE.
152:             *
153:             */
154:            protected void setSingleQueryResultType() {
155:                this .mQueryResultType = SINGLE_QUERY_RESULT_TYPE;
156:            }
157:
158:            /**
159:             * returns i18n key
160:             * the i18n key
161:             * @return i18n key
162:             */
163:            protected abstract String getQueryResultHeaderI18NKey();
164:
165:            /**
166:             * returns i18n key
167:             * @return the i18n key
168:             */
169:            protected abstract String getQueryResultHeaderSeparatorI18NKey();
170:
171:            /**
172:             * returns i18n key
173:             * the i18n key
174:             * @return i18n key
175:             */
176:            protected abstract String getQueryResultPageSeparatorI18NKey();
177:
178:            /**
179:             * returns i18n key
180:             * @return the i18n key
181:             */
182:            protected abstract String getEmptyQueryResultI18NKey();
183:
184:            /**
185:             * returns i18n key
186:             * @return the i18n key
187:             */
188:            protected abstract String getEmptyQueryResultI18NMessage();
189:
190:            /**
191:             * converts the state to the display value
192:             * @return text for displaying the state
193:             * @param stateValue text representing the state .
194:             * @param compType component type in the JBIComponentInfo
195:             */
196:            private String toComponentInfoStateDisplayValue(String stateValue,
197:                    String compType) {
198:                String stateDisplay = this .sDisplayUnknownState;
199:
200:                if (STARTED_STATE.equalsIgnoreCase(stateValue)) {
201:                    stateDisplay = sDisplayStartedState;
202:                } else if (STOPPED_STATE.equalsIgnoreCase(stateValue)) {
203:                    stateDisplay = sDisplayStoppedState;
204:                } else if (SHUTDOWN_STATE.equalsIgnoreCase(stateValue)) {
205:                    if (JBIComponentInfo.SHARED_LIBRARY_TYPE
206:                            .equalsIgnoreCase(compType)) {
207:                        stateDisplay = sDisplayInstalledState;
208:                    } else {
209:                        stateDisplay = sDisplayShutdownState;
210:                    }
211:                } else {
212:                    stateDisplay = sDisplayUnknownState;
213:                }
214:
215:                return stateDisplay;
216:
217:            }
218:
219:            /**
220:             * converts to state
221:             * @param taskPropState value passed from task attribute state
222:             * @return state value
223:             */
224:            protected String toJbiComponentInfoState(String taskPropState) {
225:                String compInfoState = JBIComponentInfo.UNKNOWN_STATE;
226:
227:                if (taskPropState == null || taskPropState.length() == 0) {
228:                    return compInfoState;
229:                }
230:
231:                if (STARTED_STATE.equalsIgnoreCase(taskPropState)) {
232:                    compInfoState = JBIComponentInfo.STARTED_STATE;
233:                } else if (STOPPED_STATE.equalsIgnoreCase(taskPropState)) {
234:                    compInfoState = JBIComponentInfo.STOPPED_STATE;
235:                } else if (SHUTDOWN_STATE.equalsIgnoreCase(taskPropState)) {
236:                    compInfoState = JBIComponentInfo.SHUTDOWN_STATE;
237:                }
238:
239:                return compInfoState;
240:            }
241:
242:            /**
243:             * converts the state to the display value
244:             * @return text for displaying the state
245:             * @param stateValue text representing the state .
246:             */
247:            private String toServiceAssemblyInfoStateDisplayValue(
248:                    String stateValue) {
249:                String stateDisplay = this .sDisplayUnknownState;
250:
251:                if (STARTED_STATE.equalsIgnoreCase(stateValue)) {
252:                    stateDisplay = sDisplayStartedState;
253:                } else if (STOPPED_STATE.equalsIgnoreCase(stateValue)) {
254:                    stateDisplay = sDisplayStoppedState;
255:                } else if (SHUTDOWN_STATE.equalsIgnoreCase(stateValue)) {
256:                    stateDisplay = sDisplayShutdownState;
257:                } else {
258:                    stateDisplay = sDisplayUnknownState;
259:                }
260:
261:                return stateDisplay;
262:
263:            }
264:
265:            /**
266:             * converts the state to the display value
267:             * @return text for displaying the state
268:             * @param stateValue text representing the state .
269:             */
270:            private String toServiceUnitInfoStateDisplayValue(String stateValue) {
271:                String stateDisplay = this .sDisplayUnknownState;
272:
273:                if (STARTED_STATE.equalsIgnoreCase(stateValue)) {
274:                    stateDisplay = sDisplayStartedState;
275:                } else if (STOPPED_STATE.equalsIgnoreCase(stateValue)) {
276:                    stateDisplay = sDisplayStoppedState;
277:                } else if (SHUTDOWN_STATE.equalsIgnoreCase(stateValue)) {
278:                    stateDisplay = sDisplayShutdownState;
279:                } else {
280:                    stateDisplay = sDisplayUnknownState;
281:                }
282:
283:                return stateDisplay;
284:
285:            }
286:
287:            /**
288:             * converts to state
289:             * @param taskPropState value passed from task attribute state
290:             * @return state value
291:             */
292:            protected String toServiceAssemblyInfoState(String taskPropState) {
293:                String compInfoState = ServiceAssemblyInfo.UNKNOWN_STATE;
294:
295:                if (taskPropState == null || taskPropState.length() == 0) {
296:                    return compInfoState;
297:                }
298:
299:                if (STARTED_STATE.equalsIgnoreCase(taskPropState)) {
300:                    compInfoState = ServiceAssemblyInfo.STARTED_STATE;
301:                } else if (STOPPED_STATE.equalsIgnoreCase(taskPropState)) {
302:                    compInfoState = ServiceAssemblyInfo.STOPPED_STATE;
303:                } else if (SHUTDOWN_STATE.equalsIgnoreCase(taskPropState)) {
304:                    compInfoState = ServiceAssemblyInfo.SHUTDOWN_STATE;
305:                }
306:
307:                return compInfoState;
308:            }
309:
310:            /**
311:             * validates the state value
312:             * @param state value
313:             * @throws BuildException on invalid state value
314:             */
315:            protected void validateTaskPropertyForStateValue(String state)
316:                    throws BuildException {
317:
318:                if (state == null || state.length() == 0) {
319:                    // all sates
320:                    return;
321:                }
322:                String stateValue = state;
323:
324:                if (!(STARTED_STATE.equalsIgnoreCase(stateValue)
325:                        || STOPPED_STATE.equalsIgnoreCase(stateValue) || SHUTDOWN_STATE
326:                        .equalsIgnoreCase(stateValue))) {
327:                    throwTaskBuildException(
328:                            "jbi.ui.ant.task.error.invalid.state", state);
329:                }
330:
331:            }
332:
333:            /**
334:             * use to clear the xml output if set, to empty list before executing the
335:             * query. This way, failred query will have the xml output set to empty list.
336:             * @param xmlText xml text to set to the output xml property value
337:             */
338:            protected void initXmlOutput(String xmlText) {
339:                printResultsToXmlOutput(xmlText);
340:            }
341:
342:            /**
343:             * set the xmlResult as a value of the property from getXmlOutput
344:             * @param xmlResult results in xml text
345:             * @return true if the result is saved in the property else false.
346:             */
347:            protected boolean printResultsToXmlOutput(String xmlResult) {
348:                String xmlOutputProp = this .getXmlOutput();
349:                if (xmlOutputProp != null) {
350:                    this .getProject().setProperty(xmlOutputProp, xmlResult);
351:                    return true;
352:                } else {
353:                    return false;
354:                }
355:            }
356:
357:            /** prints result
358:             * @param aResult result to print
359:             */
360:            protected void printComponentQueryResults(String aResult) {
361:                if (printResultsToXmlOutput(aResult)) {
362:                    return;
363:                }
364:
365:                String header = getI18NBundle().getMessage(
366:                        getQueryResultHeaderI18NKey(), getValidTarget());
367:                String headerSeparator = getI18NBundle().getMessage(
368:                        getQueryResultHeaderSeparatorI18NKey());
369:                String pageSeparator = getI18NBundle().getMessage(
370:                        getQueryResultPageSeparatorI18NKey());
371:                String emptyResult = getEmptyQueryResultI18NMessage();
372:
373:                List list = JBIComponentInfo.readFromXmlText(aResult);
374:
375:                StringWriter stringWriter = new StringWriter();
376:                PrintWriter msgWriter = new PrintWriter(stringWriter);
377:
378:                msgWriter.println(headerSeparator);
379:                msgWriter.println(header);
380:                msgWriter.println(headerSeparator);
381:
382:                if (list.size() <= 0) {
383:                    msgWriter.println(emptyResult);
384:                    msgWriter.println(pageSeparator);
385:                } else {
386:                    for (Iterator itr = list.iterator(); itr.hasNext();) {
387:                        JBIComponentInfo info = (JBIComponentInfo) itr.next();
388:
389:                        String status = getI18NBundle().getMessage(
390:                                "jbi.ui.ant.print.comp.info.state",
391:                                toComponentInfoStateDisplayValue(info
392:                                        .getState(), info.getType()));
393:
394:                        String name = getI18NBundle().getMessage(
395:                                "jbi.ui.ant.print.comp.info.name",
396:                                info.getName());
397:
398:                        String desc = getI18NBundle().getMessage(
399:                                "jbi.ui.ant.print.comp.info.desc",
400:                                info.getDescription());
401:
402:                        msgWriter.println(name);
403:                        msgWriter.println(status);
404:                        msgWriter.println(desc);
405:                        msgWriter.println(pageSeparator);
406:                    }
407:                }
408:                msgWriter.close();
409:                printMessage(stringWriter.toString());
410:
411:            }
412:
413:            /** prints result
414:             * @param aResult result to print
415:             */
416:            protected void printDeploymentQueryResults(String aResult) {
417:
418:                if (printResultsToXmlOutput(aResult)) {
419:                    return;
420:                }
421:
422:                String header = getI18NBundle().getMessage(
423:                        getQueryResultHeaderI18NKey(), getValidTarget());
424:                String headerSeparator = getI18NBundle().getMessage(
425:                        getQueryResultHeaderSeparatorI18NKey());
426:                String pageSeparator = getI18NBundle().getMessage(
427:                        getQueryResultPageSeparatorI18NKey());
428:                String emptyResult = getEmptyQueryResultI18NMessage();
429:
430:                List list = ServiceAssemblyInfo
431:                        .readFromXmlTextWithProlog(aResult);
432:
433:                StringWriter stringWriter = new StringWriter();
434:                PrintWriter msgWriter = new PrintWriter(stringWriter);
435:
436:                msgWriter.println(headerSeparator);
437:                msgWriter.println(header);
438:                msgWriter.println(headerSeparator);
439:
440:                if (list.size() <= 0) {
441:                    msgWriter.println(emptyResult);
442:                    msgWriter.println(pageSeparator);
443:                } else {
444:                    for (Iterator itr = list.iterator(); itr.hasNext();) {
445:                        ServiceAssemblyInfo saInfo = (ServiceAssemblyInfo) itr
446:                                .next();
447:                        List suInfoList = saInfo.getServiceUnitInfoList();
448:
449:                        String saName = getI18NBundle().getMessage(
450:                                "jbi.ui.ant.print.sasm.info.name",
451:                                saInfo.getName());
452:
453:                        String saState = getI18NBundle().getMessage(
454:                                "jbi.ui.ant.print.sasm.info.state",
455:                                toServiceAssemblyInfoStateDisplayValue(saInfo
456:                                        .getState()));
457:
458:                        String saDesc = getI18NBundle().getMessage(
459:                                "jbi.ui.ant.print.sasm.info.desc",
460:                                saInfo.getDescription());
461:
462:                        String suInfoListDesc = getI18NBundle().getMessage(
463:                                "jbi.ui.ant.print.sasm.info.sunit.list.size",
464:                                Integer.toString(suInfoList.size()));
465:
466:                        msgWriter.println(saName);
467:                        msgWriter.println(saState);
468:                        msgWriter.println(saDesc);
469:                        msgWriter.println(suInfoListDesc);
470:
471:                        for (Iterator suItr = suInfoList.iterator(); suItr
472:                                .hasNext();) {
473:                            ServiceUnitInfo suInfo = (ServiceUnitInfo) suItr
474:                                    .next();
475:
476:                            String suState = getI18NBundle().getMessage(
477:                                    "jbi.ui.ant.print.sunit.info.state",
478:                                    toServiceUnitInfoStateDisplayValue(suInfo
479:                                            .getState()));
480:
481:                            String deployedOn = getI18NBundle().getMessage(
482:                                    "jbi.ui.ant.print.sunit.info.deployed.on",
483:                                    suInfo.getDeployedOn());
484:
485:                            String suName = getI18NBundle().getMessage(
486:                                    "jbi.ui.ant.print.sunit.info.name",
487:                                    suInfo.getName());
488:
489:                            String suDesc = getI18NBundle().getMessage(
490:                                    "jbi.ui.ant.print.sunit.info.desc",
491:                                    suInfo.getDescription());
492:
493:                            msgWriter.println(suName);
494:                            msgWriter.println(suState);
495:                            msgWriter.println(deployedOn);
496:                            msgWriter.println(suDesc);
497:                        }
498:
499:                        msgWriter.println(pageSeparator);
500:                    }
501:                }
502:
503:                msgWriter.close();
504:                printMessage(stringWriter.toString());
505:
506:            }
507:
508:            /**
509:             * This class is a base class for the component query tasks ( list-bindings and
510:             * list-engines) that has the common attributes
511:             */
512:            public static abstract class JbiComponentQueryTask extends
513:                    JbiQueryTask {
514:                /**
515:                 * Holds value of property component state.
516:                 */
517:                private String mState;
518:
519:                /**
520:                 * Holds value of property shared library name.
521:                 */
522:                private String mSharedLibraryName;
523:
524:                /**
525:                 * Holds value of property service assembly name.
526:                 */
527:                private String mServiceAssemblyName;
528:
529:                /**
530:                 * constructor
531:                 */
532:                public JbiComponentQueryTask() {
533:                    super ();
534:                }
535:
536:                /**
537:                 * Getter for property state.
538:                 * @return Value of property state.
539:                 */
540:                public String getState() {
541:                    return this .mState;
542:                }
543:
544:                /**
545:                 * Setter for property state.
546:                 * @param state New value of property state.
547:                 */
548:                public void setState(String state) {
549:                    this .mState = state;
550:                }
551:
552:                /**
553:                 * Getter for property sharedLibraryName.
554:                 * @return Value of property sharedLibraryName.
555:                 */
556:                public String getSharedLibraryName() {
557:                    return this .mSharedLibraryName;
558:                }
559:
560:                /**
561:                 * Setter for property sharedLibraryName.
562:                 * @param sharedLibraryName shared Library Name
563:                 */
564:                public void setSharedLibraryName(String sharedLibraryName) {
565:                    this .mSharedLibraryName = sharedLibraryName;
566:                }
567:
568:                /**
569:                 * Getter for property serviceAssemblyName.
570:                 * @return Value of property serviceAssemblyName.
571:                 */
572:                public String getServiceAssemblyName() {
573:                    return this .mServiceAssemblyName;
574:                }
575:
576:                /**
577:                 * Setter for property serviceAssemblyName.
578:                 * @param serviceAssemblyName New value of property serviceAssemblyName.
579:                 */
580:                public void setServiceAssemblyName(String serviceAssemblyName) {
581:                    this.mServiceAssemblyName = serviceAssemblyName;
582:                }
583:            }
584:
585:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.