Source Code Cross Referenced for JMSConnectorPortlet.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » console » jmsmanager » server » 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 » EJB Server geronimo » plugins » org.apache.geronimo.console.jmsmanager.server 
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:         */package org.apache.geronimo.console.jmsmanager.server;
017:
018:        import java.io.IOException;
019:        import java.util.Arrays;
020:        import java.util.List;
021:        import java.util.ArrayList;
022:        import java.net.URI;
023:
024:        import javax.portlet.PortletRequestDispatcher;
025:        import javax.portlet.ActionRequest;
026:        import javax.portlet.ActionResponse;
027:        import javax.portlet.PortletException;
028:        import javax.portlet.RenderRequest;
029:        import javax.portlet.RenderResponse;
030:        import javax.portlet.WindowState;
031:        import javax.portlet.PortletConfig;
032:        import javax.portlet.PortletContext;
033:        import org.apache.geronimo.console.util.PortletManager;
034:        import org.apache.geronimo.kernel.proxy.GeronimoManagedBean;
035:        import org.apache.geronimo.management.geronimo.JMSConnector;
036:        import org.apache.geronimo.management.geronimo.JMSManager;
037:        import org.apache.geronimo.management.geronimo.JMSBroker;
038:        import org.apache.geronimo.gbean.AbstractName;
039:        import org.apache.commons.logging.Log;
040:        import org.apache.commons.logging.LogFactory;
041:
042:        /**
043:         * List, edit, add, remove JMS network connectors
044:         *
045:         * @version $Rev: 560997 $ $Date: 2007-07-30 07:27:33 -0700 (Mon, 30 Jul 2007) $
046:         */
047:        public class JMSConnectorPortlet extends BaseJMSPortlet {
048:            private final static Log log = LogFactory
049:                    .getLog(JMSConnectorPortlet.class);
050:
051:            private PortletRequestDispatcher normalView;
052:
053:            private PortletRequestDispatcher maximizedView;
054:
055:            private PortletRequestDispatcher helpView;
056:
057:            protected PortletRequestDispatcher editView;
058:
059:            public void processAction(ActionRequest actionRequest,
060:                    ActionResponse actionResponse) throws PortletException,
061:                    IOException {
062:                try {
063:                    String mode = actionRequest.getParameter("mode");
064:                    String connectorURI = actionRequest
065:                            .getParameter("connectorURI");
066:                    String brokerURI = actionRequest.getParameter("brokerURI");
067:                    JMSManager manager = PortletManager.getCurrentServer(
068:                            actionRequest).getJMSManagers()[0]; //todo: handle multiple
069:                    if (mode.equals("new")) {
070:                        // User selected to add a new connector, need to show criteria portlet
071:                        actionResponse.setRenderParameter("mode", "new");
072:                        String protocol = actionRequest
073:                                .getParameter("protocol");
074:                        actionResponse.setRenderParameter("protocol", protocol);
075:                        actionResponse.setRenderParameter("brokerURI",
076:                                brokerURI);
077:                    } else if (mode.equals("add")) { // User just submitted the form to add a new connector
078:                        // Get submitted values
079:                        //todo: lots of validation
080:                        String protocol = actionRequest
081:                                .getParameter("protocol");
082:                        String host = actionRequest.getParameter("host");
083:                        int port = Integer.parseInt(actionRequest
084:                                .getParameter("port"));
085:                        String name = actionRequest.getParameter("name");
086:                        AbstractName brokerAbstractName = new AbstractName(URI
087:                                .create(brokerURI));
088:                        // Create and configure the connector
089:                        JMSConnector connector = PortletManager
090:                                .createJMSConnector(actionRequest, manager,
091:                                        brokerAbstractName, name, protocol,
092:                                        host, port);
093:                        // Start the connector
094:                        try {
095:                            ((GeronimoManagedBean) connector).startRecursive();
096:                        } catch (Exception e) {
097:                            log.error("Unable to start connector", e); //todo: get into rendered page somehow?
098:                        }
099:                        actionResponse.setRenderParameter("mode", "list");
100:                    } else if (mode.equals("save")) { // User just submitted the form to update a connector
101:                        // Get submitted values
102:                        //todo: lots of validation
103:                        String host = actionRequest.getParameter("host");
104:                        int port = Integer.parseInt(actionRequest
105:                                .getParameter("port"));
106:                        // Identify and update the connector
107:                        AbstractName connectorAbstractName = new AbstractName(
108:                                URI.create(connectorURI));
109:                        JMSConnector connector = (JMSConnector) PortletManager
110:                                .getManagedBean(actionRequest,
111:                                        connectorAbstractName);
112:                        if (connector != null) {
113:                            connector.setHost(host);
114:                            connector.setPort(port);
115:                        }
116:                        actionResponse.setRenderParameter("mode", "list");
117:                    } else if (mode.equals("start")) {
118:                        AbstractName connectorAbstractName = new AbstractName(
119:                                URI.create(connectorURI));
120:                        try {
121:                            PortletManager.getManagedBean(actionRequest,
122:                                    connectorAbstractName).startRecursive();
123:                        } catch (Exception e) {
124:                            throw new PortletException(e);
125:                        }
126:                        actionResponse.setRenderParameter("mode", "list");
127:                    } else if (mode.equals("stop")) {
128:                        AbstractName connectorAbstractName = new AbstractName(
129:                                URI.create(connectorURI));
130:                        try {
131:                            PortletManager.getManagedBean(actionRequest,
132:                                    connectorAbstractName).stop();
133:                        } catch (Exception e) {
134:                            throw new PortletException(e);
135:                        }
136:                        actionResponse.setRenderParameter("mode", "list");
137:                    } else if (mode.equals("edit")) {
138:                        actionResponse.setRenderParameter("connectorURI",
139:                                connectorURI);
140:                        actionResponse.setRenderParameter("brokerURI",
141:                                brokerURI);
142:                        actionResponse.setRenderParameter("mode", "edit");
143:                    } else if (mode.equals("delete")) {
144:                        AbstractName connectorAbstractName = new AbstractName(
145:                                URI.create(connectorURI));
146:                        manager.removeConnector(connectorAbstractName);
147:                        actionResponse.setRenderParameter("mode", "list");
148:                    }
149:                } catch (Throwable e) {
150:                    log.error("Unable to process portlet action", e);
151:                    if (e instanceof  PortletException) {
152:                        throw (PortletException) e;
153:                    }
154:                }
155:            }
156:
157:            protected void doView(RenderRequest renderRequest,
158:                    RenderResponse renderResponse) throws IOException,
159:                    PortletException {
160:                if (WindowState.MINIMIZED
161:                        .equals(renderRequest.getWindowState())) {
162:                    return;
163:                }
164:
165:                try {
166:                    String mode = renderRequest.getParameter("mode");
167:                    if (mode == null || mode.equals("")) {
168:                        mode = "list";
169:                    }
170:                    JMSManager manager = PortletManager.getCurrentServer(
171:                            renderRequest).getJMSManagers()[0]; //todo: handle multiple
172:
173:                    if (mode.equals("new")) {
174:                        String brokerURI = renderRequest
175:                                .getParameter("brokerURI");
176:                        String protocol = renderRequest
177:                                .getParameter("protocol");
178:                        renderRequest.setAttribute("protocol", protocol);
179:                        renderRequest.setAttribute("brokerURI", brokerURI);
180:                        renderRequest.setAttribute("brokerName",
181:                                new AbstractName(URI.create(brokerURI))
182:                                        .getName().get("name").toString());
183:                        renderRequest.setAttribute("mode", "add");
184:                        editView.include(renderRequest, renderResponse);
185:                    } else if (mode.equals("edit")) {
186:                        String brokerURI = renderRequest
187:                                .getParameter("brokerURI");
188:                        String connectorURI = renderRequest
189:                                .getParameter("connectorURI");
190:                        JMSConnector connector = (JMSConnector) PortletManager
191:                                .getManagedBean(renderRequest,
192:                                        new AbstractName(URI
193:                                                .create(connectorURI)));
194:                        if (connector == null) {
195:                            doList(renderRequest, manager, renderResponse);
196:                        } else {
197:                            renderRequest.setAttribute("connectorURI",
198:                                    connectorURI);
199:                            renderRequest.setAttribute("brokerName",
200:                                    new AbstractName(URI.create(brokerURI))
201:                                            .getName().get("name").toString());
202:                            renderRequest.setAttribute("connectorName",
203:                                    new AbstractName(URI.create(connectorURI))
204:                                            .getName().get("name").toString());
205:                            renderRequest.setAttribute("protocol", connector
206:                                    .getProtocol());
207:                            renderRequest.setAttribute("port", new Integer(
208:                                    connector.getPort()));
209:                            renderRequest.setAttribute("host", connector
210:                                    .getHost());
211:                            renderRequest.setAttribute("mode", "save");
212:                            editView.include(renderRequest, renderResponse);
213:                        }
214:                    } else if (mode.equals("list")) {
215:                        doList(renderRequest, manager, renderResponse);
216:                    }
217:                } catch (Throwable e) {
218:                    log.error("Unable to render portlet", e);
219:                }
220:            }
221:
222:            private void doList(RenderRequest renderRequest,
223:                    JMSManager manager, RenderResponse renderResponse)
224:                    throws PortletException, IOException {
225:                List beans = new ArrayList();
226:                JMSBroker[] brokers = (JMSBroker[]) manager.getContainers();
227:                for (int i = 0; i < brokers.length; i++) {
228:                    JMSBroker broker = brokers[i];
229:                    AbstractName brokerAbstractName = PortletManager
230:                            .getNameFor(renderRequest, broker);
231:                    JMSConnector[] connectors = (JMSConnector[]) manager
232:                            .getConnectorsForContainer(broker);
233:                    for (int j = 0; j < connectors.length; j++) {
234:                        JMSConnector connector = connectors[j];
235:                        AbstractName connectorAbstractName = PortletManager
236:                                .getNameFor(renderRequest, connector);
237:                        String brokerName = brokerAbstractName.getName().get(
238:                                "name").toString();
239:                        String connectorName = connectorAbstractName.getName()
240:                                .get("name").toString();
241:                        ConnectorWrapper info = new ConnectorWrapper(
242:                                brokerName, brokerAbstractName.toString(),
243:                                connectorName,
244:                                connectorAbstractName.toString(), connector);
245:                        beans.add(info);
246:                    }
247:                }
248:                renderRequest.setAttribute("brokers", getBrokerList(
249:                        renderRequest, manager));
250:                renderRequest.setAttribute("connectors", beans);
251:                ArrayList protocols = new ArrayList(Arrays.asList(manager
252:                        .getSupportedProtocols()));
253:                protocols.remove("peer"); // add operation not supported for peer protocol
254:                protocols.remove("failover"); // add operation not supported for failover protocol
255:                renderRequest.setAttribute("protocols", protocols);
256:
257:                if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
258:                    normalView.include(renderRequest, renderResponse);
259:                } else {
260:                    maximizedView.include(renderRequest, renderResponse);
261:                }
262:            }
263:
264:            protected void doHelp(RenderRequest renderRequest,
265:                    RenderResponse renderResponse) throws PortletException,
266:                    IOException {
267:                helpView.include(renderRequest, renderResponse);
268:            }
269:
270:            public void init(PortletConfig portletConfig)
271:                    throws PortletException {
272:                super .init(portletConfig);
273:                PortletContext pc = portletConfig.getPortletContext();
274:                normalView = pc
275:                        .getRequestDispatcher("/WEB-INF/view/jmsmanager/server/connector/normal.jsp");
276:                maximizedView = pc
277:                        .getRequestDispatcher("/WEB-INF/view/jmsmanager/server/connector/maximized.jsp");
278:                helpView = pc
279:                        .getRequestDispatcher("/WEB-INF/view/jmsmanager/server/connector/help.jsp");
280:                editView = pc
281:                        .getRequestDispatcher("/WEB-INF/view/jmsmanager/server/connector/editGeneric.jsp");
282:            }
283:
284:            public void destroy() {
285:                helpView = null;
286:                editView = null;
287:                normalView = null;
288:                maximizedView = null;
289:                super .destroy();
290:            }
291:
292:            public static boolean isValid(String s) {
293:                return s != null && !s.equals("");
294:            }
295:
296:            public static class ConnectorWrapper {
297:                private String brokerName;
298:                private String brokerURI;
299:                private String connectorName;
300:                private String connectorURI;
301:                private JMSConnector connector;
302:
303:                public ConnectorWrapper(String brokerName, String brokerURI,
304:                        String connectorName, String connectorURI,
305:                        JMSConnector connector) {
306:                    this .brokerName = brokerName;
307:                    this .brokerURI = brokerURI;
308:                    this .connectorName = connectorName;
309:                    this .connectorURI = connectorURI;
310:                    this .connector = connector;
311:                }
312:
313:                public String getBrokerName() {
314:                    return brokerName;
315:                }
316:
317:                public String getConnectorName() {
318:                    return connectorName;
319:                }
320:
321:                public JMSConnector getConnector() {
322:                    return connector;
323:                }
324:
325:                public String getBrokerURI() {
326:                    return brokerURI;
327:                }
328:
329:                public String getConnectorURI() {
330:                    return connectorURI;
331:                }
332:            }
333:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.