Source Code Cross Referenced for DispatchUtils.java in  » Build » ANT » org » apache » tools » ant » dispatch » 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 » Build » ANT » org.apache.tools.ant.dispatch 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.tools.ant.dispatch;
019:
020:        import org.apache.tools.ant.BuildException;
021:        import org.apache.tools.ant.UnknownElement;
022:        import org.apache.tools.ant.Task;
023:
024:        import java.lang.reflect.InvocationTargetException;
025:        import java.lang.reflect.Method;
026:
027:        /**
028:         * Determines and Executes the action method for the task.
029:         */
030:        public class DispatchUtils {
031:            /**
032:             * Determines and Executes the action method for the task.
033:             * @param task the task to execute.
034:             * @throws BuildException on error.
035:             */
036:            public static final void execute(Object task) throws BuildException {
037:                String methodName = "execute";
038:                Dispatchable dispatchable = null;
039:                try {
040:                    if (task instanceof  Dispatchable) {
041:                        dispatchable = (Dispatchable) task;
042:                    } else if (task instanceof  UnknownElement) {
043:                        UnknownElement ue = (UnknownElement) task;
044:                        Object realThing = ue.getRealThing();
045:                        if (realThing != null
046:                                && realThing instanceof  Dispatchable
047:                                && realThing instanceof  Task) {
048:                            dispatchable = (Dispatchable) realThing;
049:                        }
050:                    }
051:                    if (dispatchable != null) {
052:                        String mName = null;
053:                        try {
054:                            final String name = dispatchable
055:                                    .getActionParameterName();
056:                            if (name != null && name.trim().length() > 0) {
057:                                mName = "get"
058:                                        + name.trim().substring(0, 1)
059:                                                .toUpperCase();
060:                                if (name.length() > 1) {
061:                                    mName += name.substring(1);
062:                                }
063:                                final Class c = dispatchable.getClass();
064:                                final Method actionM = c.getMethod(mName,
065:                                        new Class[0]);
066:                                if (actionM != null) {
067:                                    final Object o = actionM.invoke(
068:                                            dispatchable, (Object[]) null);
069:                                    if (o != null) {
070:                                        final String s = o.toString();
071:                                        if (s != null && s.trim().length() > 0) {
072:                                            methodName = s.trim();
073:                                            Method executeM = null;
074:                                            executeM = dispatchable.getClass()
075:                                                    .getMethod(methodName,
076:                                                            new Class[0]);
077:                                            if (executeM == null) {
078:                                                throw new BuildException(
079:                                                        "No public "
080:                                                                + methodName
081:                                                                + "() in "
082:                                                                + dispatchable
083:                                                                        .getClass());
084:                                            }
085:                                            executeM.invoke(dispatchable,
086:                                                    (Object[]) null);
087:                                            if (task instanceof  UnknownElement) {
088:                                                ((UnknownElement) task)
089:                                                        .setRealThing(null);
090:                                            }
091:                                        } else {
092:                                            throw new BuildException(
093:                                                    "Dispatchable Task attribute '"
094:                                                            + name.trim()
095:                                                            + "' not set or value is empty.");
096:                                        }
097:                                    } else {
098:                                        throw new BuildException(
099:                                                "Dispatchable Task attribute '"
100:                                                        + name.trim()
101:                                                        + "' not set or value is empty.");
102:                                    }
103:                                }
104:                            } else {
105:                                throw new BuildException(
106:                                        "Action Parameter Name must not be empty for Dispatchable Task.");
107:                            }
108:                        } catch (NoSuchMethodException nsme) {
109:                            throw new BuildException("No public " + mName
110:                                    + "() in " + task.getClass());
111:                        }
112:                    } else {
113:                        Method executeM = null;
114:                        executeM = task.getClass().getMethod(methodName,
115:                                new Class[0]);
116:                        if (executeM == null) {
117:                            throw new BuildException("No public " + methodName
118:                                    + "() in " + task.getClass());
119:                        }
120:                        executeM.invoke(task, (Object[]) null);
121:                        if (task instanceof  UnknownElement) {
122:                            ((UnknownElement) task).setRealThing(null);
123:                        }
124:                    }
125:                } catch (InvocationTargetException ie) {
126:                    Throwable t = ie.getTargetException();
127:                    if (t instanceof  BuildException) {
128:                        throw ((BuildException) t);
129:                    } else {
130:                        throw new BuildException(t);
131:                    }
132:                } catch (NoSuchMethodException e) {
133:                    throw new BuildException(e);
134:                } catch (IllegalAccessException e) {
135:                    throw new BuildException(e);
136:                }
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.