Source Code Cross Referenced for EditEarAction.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » webapp » jonasadmin » service » container » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.webapp.jonasadmin.service.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: EditEarAction.java 9680 2006-10-06 12:08:33Z danesa $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.webapp.jonasadmin.service.container;
025:
026:        import java.io.IOException;
027:        import java.net.URL;
028:        import java.util.ArrayList;
029:        import java.util.Iterator;
030:
031:        import javax.management.MalformedObjectNameException;
032:        import javax.management.ObjectName;
033:        import javax.servlet.ServletException;
034:        import javax.servlet.http.HttpServletRequest;
035:        import javax.servlet.http.HttpServletResponse;
036:
037:        import org.apache.struts.action.ActionForm;
038:        import org.apache.struts.action.ActionForward;
039:        import org.apache.struts.action.ActionMapping;
040:        import org.objectweb.jonas.container.EJBServiceImpl;
041:        import org.objectweb.jonas.jmx.J2eeObjectName;
042:        import org.objectweb.jonas.jmx.JonasManagementRepr;
043:        import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
044:        import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
045:        import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
046:        import org.objectweb.jonas.webapp.jonasadmin.common.ModuleItem;
047:
048:        /**
049:         * @author Michel-Ange ANTON
050:         * @author Adriana Danes
051:         */
052:
053:        public class EditEarAction extends JonasBaseAction {
054:
055:            //	--------------------------------------------------------- Public Methods
056:            /**
057:             * Used to initialize the name variable of a ModuleItem when we could not
058:             * identify the J2EEModule corresponding to a given URL which containes such
059:             * a module contained in a given ear.
060:             * This situation can arrive only with WebModules (in this case the MBeans and
061:             * their ObjectNames are created by CATALINA, not by JOnAS).
062:             */
063:            private static String NONAME = "";
064:
065:            public ActionForward executeAction(ActionMapping pMapping,
066:                    ActionForm pForm, HttpServletRequest pRequest,
067:                    HttpServletResponse pResponse) throws IOException,
068:                    ServletException {
069:
070:                // Selected ear
071:                String sObjectName = pRequest.getParameter("select");
072:
073:                ObjectName oObjectName = null;
074:                String domainName = null;
075:                String serverName = null;
076:                String appName = null;
077:
078:                // Form used
079:                EarForm oForm = null;
080:                if (sObjectName != null) {
081:                    String sPath = null;
082:                    try {
083:                        // Recreate ObjectName
084:                        oObjectName = ObjectName.getInstance(sObjectName);
085:                        domainName = oObjectName.getDomain();
086:                        serverName = oObjectName.getKeyProperty("J2EEServer");
087:                        appName = oObjectName.getKeyProperty("name");
088:                        // Build a new form
089:                        oForm = new EarForm();
090:                        oForm.reset(pMapping, pRequest);
091:                        m_Session.setAttribute("earForm", oForm);
092:                        URL earUrl = (java.net.URL) JonasManagementRepr
093:                                .getAttribute(oObjectName, "earUrl", serverName);
094:                        sPath = earUrl.toString();
095:                        //oForm.setPath(sPath);
096:                        oForm.setFilename(JonasAdminJmx.extractFilename(sPath));
097:                        //oForm.setObjectName(sObjectName);
098:                        //oForm.setModuleName(appName);
099:                    } catch (Throwable t) {
100:                        addGlobalError(t);
101:                        saveErrors(pRequest, m_Errors);
102:                        return (pMapping.findForward("Global Error"));
103:                    }
104:                } else {
105:                    // Used last form in session
106:                    oForm = (EarForm) m_Session.getAttribute("earForm");
107:                }
108:
109:                // Force the node selected in tree
110:                m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
111:                        + WhereAreYou.NODE_SEPARATOR + "services"
112:                        + WhereAreYou.NODE_SEPARATOR + "ear"
113:                        + WhereAreYou.NODE_SEPARATOR + oForm.getFilename(),
114:                        true);
115:
116:                // Populate
117:                try {
118:                    if (oObjectName != null) {
119:                        oForm
120:                                .setEarPath((URL) JonasManagementRepr
121:                                        .getAttribute(oObjectName, "earUrl",
122:                                                serverName));
123:                        oForm.setXmlDeploymentDescriptor(getStringAttribute(
124:                                oObjectName, "deploymentDescriptor"));
125:
126:                        // Use wars management attribute to construct the EarForm.wars ModuleItem list
127:                        // This allows using OBJECT_NAME in JSP link parameter 'on' (see earWars.jsp)
128:                        URL[] warPaths = (URL[]) JonasManagementRepr
129:                                .getAttribute(oObjectName, "wars", serverName);
130:                        String[] webModuleObjectNames = (String[]) JonasManagementRepr
131:                                .getAttribute(oObjectName, "webModules",
132:                                        serverName);
133:                        String[] arrayPathContext = getPathContexts(webModuleObjectNames);
134:                        ArrayList wars = new ArrayList();
135:                        for (int i = 0; i < warPaths.length; i++) {
136:                            URL warPath = warPaths[i];
137:                            String path = warPath.getPath();
138:                            // Looking for a possible association between the URL and the WebModule ObjectNames
139:                            // This will correctly work if the file names used to pack the wars are not dummy names
140:                            // but significant names allowing to distinguish the wars in case we have more than one
141:                            // in a ear.
142:                            int index = getWebModuleIndex(warPath,
143:                                    webModuleObjectNames, serverName);
144:                            ModuleItem it = null;
145:                            if (index > -1) {
146:                                // Could found an association between the URL and an MBean ObjectName
147:                                // There is a risc that the association is not correct
148:                                it = new ModuleItem(arrayPathContext[index],
149:                                        webModuleObjectNames[index], path);
150:                            } else {
151:                                // Could not found an association between the URL and an MBean ObjectName
152:                                it = new ModuleItem(NONAME, NONAME, path);
153:                            }
154:                            wars.add(it);
155:                        }
156:                        oForm.setWars(wars);
157:
158:                        // Use ejbJars management attribute to construct the EarForm.ejbjars ModuleItem list
159:                        // This allows using OBJECT_NAME in JSP link parameter 'select' (see earJars.jsp)
160:                        URL[] jarPaths = (URL[]) JonasManagementRepr
161:                                .getAttribute(oObjectName, "ejbJars",
162:                                        serverName);
163:                        ArrayList ejbJars = new ArrayList();
164:                        for (int i = 0; i < jarPaths.length; i++) {
165:                            URL jarPath = jarPaths[i];
166:                            String path = jarPath.getPath();
167:                            String name = EJBServiceImpl
168:                                    .buildEJBModuleName(jarPath);
169:                            ObjectName moduleObjectName = J2eeObjectName
170:                                    .getEJBModule(domainName, serverName,
171:                                            appName, name);
172:                            String objectName = moduleObjectName.toString();
173:                            ModuleItem it = new ModuleItem(name, objectName,
174:                                    path);
175:                            ejbJars.add(it);
176:                        }
177:                        oForm.setEjbjars(ejbJars);
178:
179:                        // Keep URL list in EarForm for the moment, as did not made changes yet in order to replace
180:                        // file paths with OBJECT_NAME in the case of ResourceAdapterModules
181:                        //oForm.setListRars((URL[]) JonasManagementRepr.getAttribute(oObjectName, "rars"));
182:                        URL[] rarPaths = (URL[]) JonasManagementRepr
183:                                .getAttribute(oObjectName, "rars", serverName);
184:                        ArrayList rars = new ArrayList();
185:                        for (int i = 0; i < rarPaths.length; i++) {
186:                            URL rarPath = rarPaths[i];
187:                            String path = rarPath.getPath();
188:                            ObjectName resourceAdapterObjectNames = J2eeObjectName
189:                                    .getResourceAdapters(domainName, appName,
190:                                            serverName);
191:                            Iterator itNames = JonasManagementRepr.queryNames(
192:                                    resourceAdapterObjectNames, serverName)
193:                                    .iterator();
194:                            ModuleItem it = null;
195:                            while (itNames.hasNext()) {
196:                                ObjectName resourceAdapterObjectName = (ObjectName) itNames
197:                                        .next();
198:                                String raFileName = (String) JonasManagementRepr
199:                                        .getAttribute(
200:                                                resourceAdapterObjectName,
201:                                                "fileName", serverName);
202:                                if (raFileName.equals(path)) {
203:                                    // found the ResourceAdapater
204:                                    String objectName = resourceAdapterObjectName
205:                                            .toString();
206:                                    it = new ModuleItem(
207:                                            resourceAdapterObjectName
208:                                                    .getKeyProperty("name"),
209:                                            objectName, path);
210:                                    rars.add(it);
211:                                }
212:                            }
213:                        }
214:                        oForm.setRars(rars);
215:                    }
216:                } catch (Throwable t) {
217:                    addGlobalError(t);
218:                    saveErrors(pRequest, m_Errors);
219:                    return (pMapping.findForward("Global Error"));
220:                }
221:                // Forward to the jsp.
222:                return (pMapping.findForward("Ear"));
223:            }
224:
225:            /**
226:             * Construct an array of Strings having the same size as the webModuleObjectNames array,
227:             * where each String represents the pathContext part of the name key property of the
228:             * corresponding OBJECT_NAME (same index in the 2 arrays).
229:             * Note that the structure of the name key property of ObjectNames created by Catalina
230:             * for WebModules is:
231:             * //host/pathContext
232:             * @param webModuleObjectNames array of OBJECT_NAMES corresponding to WebModule MBeans
233:             * @return array of pathContexts
234:             */
235:            private String[] getPathContexts(String[] webModuleObjectNames) {
236:                int nbNames = webModuleObjectNames.length;
237:                String[] ret = new String[nbNames];
238:                for (int i = 0; i < nbNames; i++) {
239:                    ObjectName oObjectName = null;
240:                    try {
241:                        oObjectName = ObjectName
242:                                .getInstance(webModuleObjectNames[i]);
243:                    } catch (MalformedObjectNameException e) {
244:                        ret[i] = null;
245:                    }
246:                    String nameKeyProp = oObjectName.getKeyProperty("name");
247:                    ret[i] = WebAppItem.extractLabelPathContext(nameKeyProp,
248:                            m_WhereAreYou.getCurrentCatalinaDefaultHostName());
249:                }
250:                return ret;
251:            }
252:
253:            /**
254:             * Look for the occurence of a String in arrayPathContext in the war URL.
255:             * If found (index > -1) we suppose that this is the name used to construct
256:             * the OBJECT_NAME of the MBean associated to the war.
257:             * @param warPath the URL of a war contained in the current ear
258:             * @param webModuleObjectNames array of WebModule MBean OBJECT_NAMEs which are
259:             * associated to wars contained in the current ear.
260:             * @return -1 if no association could be made, > -1 if an association was found
261:             */
262:            private int getWebModuleIndex(URL warPath,
263:                    String[] webModuleObjectNames, String serverName) {
264:                // In Jetty, JSR77 is not fully compliant yet.
265:                // So, should return -1 as warURL is not in the MBean.
266:                // link to bug #303876
267:                if (m_WhereAreYou != null && m_WhereAreYou.isJettyServer()) {
268:                    return -1;
269:                }
270:                int index = -1;
271:                for (int i = 0; i < webModuleObjectNames.length; i++) {
272:                    ObjectName webModuleObjectName = null;
273:                    try {
274:                        webModuleObjectName = ObjectName
275:                                .getInstance(webModuleObjectNames[i]);
276:                    } catch (MalformedObjectNameException e) {
277:                        return -1;
278:                    }
279:                    URL webModuleWarPath = (URL) JonasManagementRepr
280:                            .getAttribute(webModuleObjectName, "warURL",
281:                                    serverName);
282:                    if (warPath.equals(webModuleWarPath)) {
283:                        index = i;
284:                        break;
285:                    }
286:                }
287:                return index;
288:            }
289:        }
w___w___w._j___a__va__2_s.___c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.