1 16 17 18 package org.apache.webapp.admin.context; 19 20 import java.io.IOException ; 21 import java.util.Collections ; 22 import java.util.Iterator ; 23 import java.util.Locale ; 24 import java.util.ArrayList ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 import javax.servlet.http.HttpSession ; 29 import org.apache.struts.action.Action; 30 import org.apache.struts.action.ActionForm; 31 import org.apache.struts.action.ActionForward; 32 import org.apache.struts.action.ActionMapping; 33 34 import javax.management.MBeanServer ; 35 import javax.management.ObjectName ; 36 import org.apache.struts.util.MessageResources; 37 38 import org.apache.webapp.admin.ApplicationServlet; 39 40 46 47 public class DeleteContextAction extends Action { 48 49 50 53 private MBeanServer mBServer = null; 54 55 56 58 73 public ActionForward execute(ActionMapping mapping, 74 ActionForm form, 75 HttpServletRequest request, 76 HttpServletResponse response) 77 throws IOException , ServletException { 78 79 80 HttpSession session = request.getSession(); 82 Locale locale = getLocale(request); 83 MessageResources resources = getResources(request); 84 85 try { 87 mBServer = ((ApplicationServlet) getServlet()).getServer(); 88 } catch (Throwable t) { 89 throw new ServletException 90 ("Cannot acquire MBeanServer reference", t); 91 } 92 93 String patternObject = null; 96 97 ContextsForm contextsForm = new ContextsForm(); 100 String select = request.getParameter("select"); 101 if (select != null) { 102 String contexts[] = new String [1]; 103 contexts[0] = select; 104 contextsForm.setContexts(contexts); 105 patternObject = select; 106 } 107 request.setAttribute("contextsForm", contextsForm); 108 109 String parent = request.getParameter("parent"); 111 if (parent != null) { 112 patternObject = parent; 113 } 114 115 ArrayList list = new ArrayList (); 117 try { 118 ObjectName poname = new ObjectName (patternObject); 119 String domain = poname.getDomain(); 120 StringBuffer sb = new StringBuffer (domain); 121 sb.append(":j2eeType=WebModule,*"); 122 ObjectName search = new ObjectName (sb.toString()); 123 Iterator items = 125 mBServer.queryNames(search, null).iterator(); 126 String item = null; 127 String host = poname.getKeyProperty("host"); 128 if (host==null) { 129 String name = poname.getKeyProperty("name"); 130 if ((name != null) && (name.length() > 0)) { 131 name = name.substring(2); 132 int i = name.indexOf("/"); 133 host = name.substring(0,i); 134 } 135 } 136 String hostPrefix = "//"+host; 137 String hostAttr = null; 138 while (items.hasNext()) { 139 item = items.next().toString(); 140 ObjectName oname = new ObjectName (item); 141 hostAttr = oname.getKeyProperty("name"); 142 if (hostAttr.startsWith(hostPrefix)) { 143 list.add(item); 144 } 145 } 146 } catch (Exception e) { 147 getServlet().log 148 (resources.getMessage(locale, "users.error.select")); 149 response.sendError 150 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 151 resources.getMessage(locale, "users.error.select")); 152 return (null); 153 } 154 Collections.sort(list); 155 request.setAttribute("contextsList", list); 156 157 return (mapping.findForward("Contexts")); 159 160 } 161 162 } 163 | Popular Tags |