Source Code Cross Referenced for TaskAdmin.java in  » ESB » wso2-esb » org » wso2 » esb » services » 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 » wso2 esb » org.wso2.esb.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.wso2.esb.services;
018:
019:        import org.apache.axiom.om.OMAttribute;
020:        import org.apache.axiom.om.OMElement;
021:        import org.apache.axiom.om.xpath.AXIOMXPath;
022:        import org.apache.axis2.AxisFault;
023:        import org.apache.commons.logging.Log;
024:        import org.apache.commons.logging.LogFactory;
025:        import org.apache.synapse.Startup;
026:        import org.apache.synapse.SynapseConstants;
027:        import org.apache.synapse.SynapseException;
028:        import org.apache.synapse.config.SynapseConfiguration;
029:        import org.apache.synapse.config.xml.StartupFinder;
030:        import org.apache.synapse.core.SynapseEnvironment;
031:        import org.apache.synapse.startup.quartz.SimpleQuartz;
032:        import org.apache.synapse.startup.quartz.SimpleQuartzFactory;
033:        import org.jaxen.JaxenException;
034:        import org.wso2.esb.services.tos.TaskData;
035:
036:        import javax.xml.namespace.QName;
037:        import java.util.ArrayList;
038:        import java.util.Collections;
039:        import java.util.Comparator;
040:        import java.util.List;
041:
042:        /**
043:         * 
044:         */
045:        public class TaskAdmin extends AbstractESBAdmin {
046:
047:            private Log log = LogFactory.getLog(TaskAdmin.class);
048:
049:            /**
050:             * Gives the list of Tasks in the SynapseConfiguration as a TaskData transfer objects
051:             * 
052:             * @return Array of TaskData objects
053:             * @throws AxisFault if any error occured in reading the contents from the
054:             *                      SynapseConfiguration
055:             */
056:            public TaskData[] taskData() throws AxisFault {
057:                SynapseConfiguration synCfg = getSynapseConfiguration();
058:                ArrayList<TaskData> taskData = new ArrayList<TaskData>();
059:                // for the moment we only have tasks
060:                for (Object obj : synCfg.getStartups()) {
061:                    if (obj instanceof  SimpleQuartz) {
062:                        TaskData td = new TaskData();
063:                        SimpleQuartz q = (SimpleQuartz) obj;
064:                        td.setName(q.getName());
065:                        td.setClazz(q.getJobClass());
066:                        td.setEnableStatistics(false);
067:                        td.setEnableTracing(false);
068:                        taskData.add(td);
069:                    }
070:                }
071:
072:                Collections.sort(taskData, new Comparator() {
073:                    public int compare(Object o1, Object o2) {
074:                        return ((TaskData) o1).getName().compareToIgnoreCase(
075:                                ((TaskData) o2).getName());
076:                    }
077:                });
078:
079:                return taskData.toArray(new TaskData[taskData.size()]);
080:            }
081:
082:            /**
083:             * Deletes the task with the given name from SynapseConfiguration
084:             *
085:             * @param taskName - Name of the task to delete
086:             * @throws AxisFault if the Task described by the given name doesnt
087:             *                   exists in the Synapse Configuration
088:             */
089:            public void deleteTask(String taskName) throws AxisFault {
090:                try {
091:                    log.debug("Deleting task : " + taskName);
092:
093:                    SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
094:                    Startup st = synapseConfiguration.getStartup(taskName);
095:                    if (st != null) {
096:                        st.destroy();
097:                    }
098:                    synapseConfiguration.removeStartup(taskName);
099:                    log.info("Deleted task : " + taskName
100:                            + " from the configuration");
101:                } catch (SynapseException syne) {
102:                    handleFault(log, "Error removing sequence : " + taskName,
103:                            syne);
104:                }
105:            }
106:
107:            /**
108:             * Returns the OMelement representation of the task given by task name
109:             *
110:             * @param taskName - name of the sequence to get
111:             * @return OMElement representing the Task of the given task name
112:             * @throws AxisFault if any error occured while getting the data from the
113:             *                   SynapseConfiguration
114:             */
115:            public OMElement getTask(String taskName) throws AxisFault {
116:                SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
117:                try {
118:                    if (synapseConfiguration.getStartup(taskName) != null) {
119:                        OMElement taskElement = StartupFinder.getInstance()
120:                                .serializeStartup(
121:                                        null,
122:                                        synapseConfiguration
123:                                                .getStartup(taskName));
124:
125:                        AXIOMXPath xPathLast = new AXIOMXPath("//syn:property");
126:                        xPathLast.addNamespace("syn",
127:                                SynapseConstants.SYNAPSE_NAMESPACE);
128:                        List<OMElement> selectNodes = xPathLast
129:                                .selectNodes(taskElement);
130:
131:                        for (OMElement selectedNode : selectNodes) {
132:                            OMAttribute attributeValue = selectedNode
133:                                    .getAttribute(new QName("value"));
134:                            if (attributeValue == null) {
135:                                OMElement firstElement = selectedNode
136:                                        .getFirstElement();
137:                                selectedNode.setText(firstElement.toString());
138:                                firstElement.detach();
139:                            }
140:
141:                        }
142:
143:                        return taskElement;
144:                    } else {
145:                        handleFault(log, "Task with the name " + taskName
146:                                + " does not exist", null);
147:                    }
148:                } catch (SynapseException syne) {
149:                    handleFault(log, "Unable to get the task : " + taskName,
150:                            syne);
151:                } catch (JaxenException e) {
152:                    handleFault(log, "Unable to get the task : " + taskName, e);
153:                }
154:                return null;
155:            }
156:
157:            public void addTask(OMElement taskElement) throws AxisFault {
158:
159:                SimpleQuartzFactory fac = new SimpleQuartzFactory();
160:                Startup st = fac.createStartup(taskElement.getFirstElement());
161:                getSynapseConfiguration().addStartup(st);
162:                Object o = getAxisConfig().getParameter(
163:                        SynapseConstants.SYNAPSE_ENV).getValue();
164:                if (o instanceof  SynapseEnvironment) {
165:                    st.init((SynapseEnvironment) o);
166:                } else {
167:                    handleFault(
168:                            log,
169:                            "Can not initialize the task. Task is added but not scheduled.",
170:                            null);
171:                }
172:            }
173:
174:            public void editTask(OMElement taskElement) throws AxisFault {
175:
176:                SimpleQuartzFactory fac = new SimpleQuartzFactory();
177:                Startup st = fac.createStartup(taskElement.getFirstElement());
178:                deleteTask(st.getName());
179:                getSynapseConfiguration().addStartup(st);
180:                Object o = getAxisConfig().getParameter(
181:                        SynapseConstants.SYNAPSE_ENV).getValue();
182:                if (o instanceof  SynapseEnvironment) {
183:                    st.init((SynapseEnvironment) o);
184:                } else {
185:                    handleFault(
186:                            log,
187:                            "Can not initialize the task. Task is added but not scheduled.",
188:                            null);
189:                }
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.