You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by am...@apache.org on 2002/06/13 20:34:33 UTC

cvs commit: jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources DeleteResourceLinksAction.java ListResourceLinksAction.java ResourceLinkForm.java ResourceLinksForm.java SaveResourceLinkAction.java SetUpResourceLinkAction.java

amyroh      2002/06/13 11:34:33

  Added:       webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources
                        DeleteResourceLinksAction.java
                        ListResourceLinksAction.java ResourceLinkForm.java
                        ResourceLinksForm.java SaveResourceLinkAction.java
                        SetUpResourceLinkAction.java
  Log:
  Add incomplete Context Resource Link support in admin tool.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/DeleteResourceLinksAction.java
  
  Index: DeleteResourceLinksAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/DeleteResourceLinksAction.java,v 1.1 2002/06/13 18:34:32 amyroh Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/13 18:34:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-envEntry documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.webapp.admin.resources;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.Locale;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import javax.management.Attribute;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.JMException;
  import javax.management.MBeanAttributeInfo;
  import javax.management.MBeanOperationInfo;
  import javax.management.MBeanInfo;
  import org.apache.struts.util.MessageResources;
  import org.apache.webapp.admin.ApplicationServlet;
  
  
  /**
   * <p>Implementation of <strong>Action</strong> that deletes the
   * specified set of resource links entries.</p>
   *
   * @author Amy Roh
   * @version $Revision: 1.1 $ $Date: 2002/06/13 18:34:32 $
   * @since 4.1
   */
  
  public final class DeleteResourceLinksAction extends Action {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The MBeanServer we will be interacting with.
       */
      private MBeanServer mserver = null;
  
  
      /**
       * The MessageResources we will be retrieving messages from.
       */
      private MessageResources resources = null;
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process the specified HTTP request, and create the corresponding HTTP
       * response (or forward to another web component that will create it).
       * Return an <code>ActionForward</code> instance describing where and how
       * control should be forwarded, or <code>null</code> if the response has
       * already been completed.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
          throws IOException, ServletException {
  
          // Look up the components we will be using as needed
          if (mserver == null) {
              mserver = ((ApplicationServlet) getServlet()).getServer();
          }
          if (resources == null) {
              resources = getServlet().getResources();
          }
          HttpSession session = request.getSession();
          Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
  
          // Has this transaction been cancelled?
          if (isCancelled(request)) {
              return (mapping.findForward("List Resource Links Setup"));
          }
  
          // Check the transaction token
          if (!isTokenValid(request)) {
              response.sendError
                  (HttpServletResponse.SC_BAD_REQUEST,
                   resources.getMessage(locale, "users.error.token"));
              return (null);
          }
  
          // Perform any extra validation that is required
          ResourceLinksForm resourceLinksForm = (ResourceLinksForm) form;
          String resourceLinks[] = resourceLinksForm.getResourceLinks();
          if (resourceLinks == null) {
              resourceLinks = new String[0];
          }
  
          // Perform "Delete Resource Link" transactions as required
          try {
  
              // Construct the MBean Name for the naming source
              ObjectName dname = new ObjectName(ResourceUtils.NAMINGRESOURCES_TYPE);
  
              String signature[] = new String[1];
              signature[0] = "java.lang.String";
              Object params[] = new String[1];
  
              for (int i = 0; i < resourceLinks.length; i++) {
                  ObjectName oname = new ObjectName(resourceLinks[i]);
                  params[0] = oname.getKeyProperty("name");
                  mserver.invoke(dname, "removeResource",
                                 params, signature);
              }
  
          } catch (Throwable t) {
  
              getServlet().log
                  (resources.getMessage(locale, "users.error.invoke",
                                        "removeResource"), t);
              response.sendError
                  (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                   resources.getMessage(locale, "users.error.invoke",
                                        "removeResource"));
              return (null);
  
          }
  
          // Proceed to the list envEntrys screen
          return (mapping.findForward("Resource Links List Setup"));
  
      }
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/ListResourceLinksAction.java
  
  Index: ListResourceLinksAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/ListResourceLinksAction.java,v 1.1 2002/06/13 18:34:32 amyroh Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/13 18:34:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.webapp.admin.resources;
  
  
  import java.io.IOException;
  import java.net.URLDecoder;
  import java.util.Locale;
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import org.apache.struts.util.MessageResources;
  import org.apache.webapp.admin.ApplicationServlet;
  
  
  /**
   * <p>Retrieve the set of MBean names for all currently defined resource links,
   * and expose them in a request attribute named "resourceLinksForm".  This action
   * requires the following request parameters to be set:</p>
   * <ul>
   * <li><strong>forward</strong> - Global forward to which we should
   *     go after stashing the resourceLinks list.</li>
   * </ul>
   *
   * @author Amy Roh
   * @version $Revision: 1.1 $ $Date: 2002/06/13 18:34:32 $
   * @since 4.1
   */
  
  public class ListResourceLinksAction extends Action {
  
      // ----------------------------------------------------- Instance Variables
  
      /**
       * The MBeanServer we will be interacting with.
       */
      private MBeanServer mserver = null;
  
  
      /**
       * The MessageResources we will be retrieving messages from.
       */
      private MessageResources resources = null;
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process the specified HTTP request, and create the corresponding HTTP
       * response (or forward to another web component that will create it).
       * Return an <code>ActionForward</code> instance describing where and how
       * control should be forwarded, or <code>null</code> if the response has
       * already been completed.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
          throws IOException, ServletException {
  
  
          // Look up the components we will be using as needed
          if (mserver == null) {
              mserver = ((ApplicationServlet) getServlet()).getServer();
          }
          if (resources == null) {
              resources = getServlet().getResources();
          }
          HttpSession session = request.getSession();
          Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
          
          String parent = request.getParameter("parent");
          String parentType = request.getParameter("parentType");
          if (parent != null) {
              parent = URLDecoder.decode(parent);
          }
          if (parentType != null) {
              parentType = URLDecoder.decode(parentType);
          }
          // Create a form bean containing the requested MBean Names
          ResourceLinksForm resourceLinksForm = null;
          try {
                resourceLinksForm = 
                ResourceUtils.getResourceLinksForm(mserver, parent, parentType);
          } catch (Exception e) {
              getServlet().log(resources.getMessage
                               (locale,
                                "users.error.attribute.get", "resources"), e);
              response.sendError
                  (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                   resources.getMessage
                   (locale, "users.error.attribute.get", "resources"));
          }
  
          // Stash the results in request scope
          request.setAttribute("resourceLinksForm", resourceLinksForm);
          saveToken(request);
          String forward =
              URLDecoder.decode(request.getParameter("forward"));
          
          return (mapping.findForward(forward));
      }
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/ResourceLinkForm.java
  
  Index: ResourceLinkForm.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/ResourceLinkForm.java,v 1.1 2002/06/13 18:34:32 amyroh Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/13 18:34:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.webapp.admin.resources;
  
  import java.util.List;
  import java.util.ArrayList;
  
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  import org.apache.webapp.admin.LabelValueBean;
  
  /**
   * Form bean for the individual resource link page.
   *
   * @author Amy Roh
   * @version $Revision: 1.1 $ $Date: 2002/06/13 18:34:32 $
   * @since 4.1
   */
  
  public final class ResourceLinkForm extends BaseForm {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The name of the resource link.
       */
      private String name = null;
  
      public String getName() {
          return (this.name);
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      /**
       * The global name of the resource link.
       */
      private String global = null;
  
      public String getGlobal() {
          return (this.global);
      }
  
      public void setGlobal(String global) {
          this.global = global;
      }
      
      /**
       * The object name of the parent of this resource link.
       */
      private String parentObjectName = null;
      
      /**
       * Return the parent object name of the Logger this bean refers to.
       */
      public String getParentObjectName() {
          return this.parentObjectName;
      }
  
      /**
       * Set the parent object name of the Logger this bean refers to.
       */
      public void setParentObjectName(String parentObjectName) {
          this.parentObjectName = parentObjectName;
      }
      
      /**
       * The type of the resource link.
       */
      private String type = null;
  
      public String getType() {
          return (this.type);
      }
  
      public void setType(String type) {
          this.type = type;
      }
  
      // --------------------------------------------------------- Public Methods
  
      /**
       * Reset all properties to their default values.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      public void reset(ActionMapping mapping, HttpServletRequest request) {
  
          super.reset(mapping, request);
          name = null;
          global = null;
          type = null;
      }
  
      /**
       * Validate the properties that have been set from this HTTP request,
       * and return an <code>ActionErrors</code> object that encapsulates any
       * validation errors that have been found.  If no errors are found, return
       * <code>null</code> or an <code>ActionErrors</code> object with no
       * recorded error messages.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      
      private ActionErrors errors = null;
      
      public ActionErrors validate(ActionMapping mapping,
      HttpServletRequest request) {
          errors = new ActionErrors();
  
          String submit = request.getParameter("submit");
  
          if (submit != null) {
  
              // name is a required field
              if ((name == null) || (name.length() < 1)) {
                  errors.add("name",
                             new ActionError("resources.error.name.required"));
              }
  
              // global is a required field
              if (( global == null) || (global.length() < 1)) {
                  errors.add("global",
                             new ActionError("resources.error.global.required"));
              }
              
              // type is a required field
              if ((type == null) || (type.length() < 1)) {
                  errors.add("type",
                             new ActionError("resources.error.type.required"));
              }
              
           }
  
          return (errors);
  
      }
   
      
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/ResourceLinksForm.java
  
  Index: ResourceLinksForm.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/ResourceLinksForm.java,v 1.1 2002/06/13 18:34:33 amyroh Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/13 18:34:33 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.webapp.admin.resources;
  
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  
  
  /**
   * Form bean for the delete resource links page.
   *
   * @author Amy Roh
   * @version $Revision: 1.1 $ $Date: 2002/06/13 18:34:33 $
   * @since 4.1
   */
  
  public final class ResourceLinksForm extends BaseForm {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The object names of the specified resource links.
       */
      private String resourceLinks[] = null;
  
      public String[] getResourceLinks() {
          return (this.resourceLinks);
      }
  
      public void setResourceLinks(String resourceLinks[]) {
          this.resourceLinks = resourceLinks;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Reset all properties to their default values.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      public void reset(ActionMapping mapping, HttpServletRequest request) {
  
          super.reset(mapping, request);
          this.resourceLinks = null;
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/SaveResourceLinkAction.java
  
  Index: SaveResourceLinkAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/SaveResourceLinkAction.java,v 1.1 2002/06/13 18:34:33 amyroh Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/13 18:34:33 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.webapp.admin.resources;
  
  import java.io.IOException;
  import java.net.URLDecoder;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.Locale;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import javax.management.Attribute;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.JMException;
  import javax.management.MBeanAttributeInfo;
  import javax.management.MBeanOperationInfo;
  import javax.management.MBeanInfo;
  import org.apache.struts.util.MessageResources;
  import org.apache.webapp.admin.ApplicationServlet;
  
  
  /**
   * <p>Implementation of <strong>Action</strong> that saves a new or
   * updated resource link entry.</p>
   *
   * @author Amy Roh
   * @version $Revision: 1.1 $ $Date: 2002/06/13 18:34:33 $
   * @since 4.1
   */
  
  public final class SaveResourceLinkAction extends Action {
  
  
      // ----------------------------------------------------- Instance Variables
  
      /**
       * The MessageResources we will be retrieving messages from.
       */
      private MessageResources resources = null;
  
  
      /**
       * The MBeanServer we will be interacting with.
       */
      private MBeanServer mserver = null;
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process the specified HTTP request, and create the corresponding HTTP
       * response (or forward to another web component that will create it).
       * Return an <code>ActionForward</code> instance describing where and how
       * control should be forwarded, or <code>null</code> if the response has
       * already been completed.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
          throws IOException, ServletException {
  
          // Look up the components we will be using as needed
          if (mserver == null) {
              mserver = ((ApplicationServlet) getServlet()).getServer();
          }
          if (resources == null) {
              resources = getServlet().getResources();
          }
          HttpSession session = request.getSession();
          Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
  
          // Has this transaction been cancelled?
          if (isCancelled(request)) {
              return (mapping.findForward("List ResourceLinks Setup"));
          }
  
          // Check the transaction token
          if (!isTokenValid(request)) {
              response.sendError
                  (HttpServletResponse.SC_BAD_REQUEST,
                   resources.getMessage(locale, "users.error.token"));
              return (null);
          }
  
          // Perform any extra validation that is required
          ResourceLinkForm resourceLinkForm = (ResourceLinkForm) form;
          String objectName = resourceLinkForm.getObjectName();
       
          // Perform an "Add ResourceLink" transaction
          if (objectName == null) {
  
              String signature[] = new String[2];
              signature[0] = "java.lang.String";
              signature[1] = "java.lang.String";
  
              Object params[] = new Object[2];
              params[0] = resourceLinkForm.getName();
              
              // fix the type later ----- 
              //params[1] = ResourceUtils.DATASOURCE_CLASS;   
              params[1] = resourceLinkForm.getType();   
             
              ObjectName oname = null;
  
              try {
  
                  // Construct the MBean Name for the naming source
                  oname = new ObjectName(ResourceUtils.NAMINGRESOURCES_TYPE);
  
                  // Create the new object and associated MBean
                  objectName = (String) mserver.invoke(oname, "addResourceLink",
                                                       params, signature);
                                       
              } catch (Exception e) {
  
                  getServlet().log
                      (resources.getMessage(locale, "users.error.invoke",
                                            "addResource"), e);
                  response.sendError
                      (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                       resources.getMessage(locale, "users.error.invoke",
                                            "addResource"));
                  return (null);
              }
  
          }
          
          // Perform an "Update User database" transaction
          String attribute = null;
          try {
              
              ObjectName oname = new ObjectName(objectName);
  
              attribute = "name";
              mserver.setAttribute
                  (oname,
                   new Attribute(attribute, resourceLinkForm.getName()));
              attribute = "global";
              mserver.setAttribute
                  (oname,
                   new Attribute(attribute, resourceLinkForm.getGlobal()));
              attribute = "type";
              mserver.setAttribute
                  (oname,
                   new Attribute(attribute, resourceLinkForm.getType()));
              
  
          } catch (Exception e) {
  
              getServlet().log
                  (resources.getMessage(locale, "users.error.set.attribute",
                                        attribute), e);
              response.sendError
                  (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                   resources.getMessage(locale, "users.error.set.attribute",
                                        attribute));
              return (null);
  
          }
          
          // Proceed to the list entries screen
          return (mapping.findForward("ResourceLinks List Setup"));
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/SetUpResourceLinkAction.java
  
  Index: SetUpResourceLinkAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/SetUpResourceLinkAction.java,v 1.1 2002/06/13 18:34:33 amyroh Exp $
   * $Revision: 1.1 $
   * $Date: 2002/06/13 18:34:33 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-DataSource documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.webapp.admin.resources;
  
  import java.io.IOException;
  import java.net.URLDecoder;
  import java.util.Iterator;
  import java.util.Locale;
  import javax.management.Attribute;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.JMException;
  import javax.management.MBeanAttributeInfo;
  import javax.management.MBeanOperationInfo;
  import javax.management.MBeanInfo;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import org.apache.struts.util.MessageResources;
  import org.apache.webapp.admin.ApplicationServlet;
  
  
  /**
   * <p>Implementation of <strong>Action</strong> that sets up and stashes
   * a <code>ResourceLinkForm</code> bean in request scope.  The form bean will have
   * a null <code>objectName</code> property if this form represents a ResourceLink
   * being added, or a non-null value for an existing ResourceLink.</p>
   *
   * @author Amy Roh
   * @version $Revision: 1.1 $ $Date: 2002/06/13 18:34:33 $
   * @since 4.1
   */
  
  public final class SetUpResourceLinkAction extends Action {
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The MBeanServer we will be interacting with.
       */
      private MBeanServer mserver = null;
  
  
      /**
       * The MessageResources we will be retrieving messages from.
       */
      private MessageResources resources = null;
      
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process the specified HTTP request, and create the corresponding HTTP
       * response (or forward to another web component that will create it).
       * Return an <code>ActionForward</code> instance describing where and how
       * control should be forwarded, or <code>null</code> if the response has
       * already been completed.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
          throws IOException, ServletException {
  
          // Look up the components we will be using as needed
          if (mserver == null) {
              mserver = ((ApplicationServlet) getServlet()).getServer();
          }
          if (resources == null) {
              resources = getServlet().getResources();
          }
          HttpSession session = request.getSession();
          Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
  
          // Set up the form bean based on the creating or editing state
          String objectName = request.getParameter("objectName");
          
          ResourceLinkForm resourceLinkForm = new ResourceLinkForm();
          // fix type
          //resourceLinkForm.setType(ResourceUtils.DATASOURCE_CLASS);
  
          if (objectName == null) {
              resourceLinkForm.setNodeLabel
                  (resources.getMessage(locale, "resources.actions.resourcelk.create"));
              
          } else {
              resourceLinkForm.setNodeLabel
                  (resources.getMessage(locale, "resources.actions.resourcelk.edit"));
              resourceLinkForm.setObjectName(objectName);
              
              String attribute = null;
              try {
                  ObjectName oname = new ObjectName(objectName);
                  attribute = "name";
                  resourceLinkForm.setName
                      ((String) mserver.getAttribute(oname, attribute));
                  attribute = "global";
                  resourceLinkForm.setGlobal
                      ((String) mserver.getAttribute(oname, attribute));
                  attribute = "type";
                  resourceLinkForm.setType
                      ((String) mserver.getAttribute(oname, attribute));
                  
              } catch (Exception e) {
                  getServlet().log
                      (resources.getMessage(locale,
                          "users.error.attribute.get", attribute), e);
                  response.sendError
                      (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                       resources.getMessage
                           (locale, "users.error.attribute.get", attribute));
                  return (null);
              } 
          }
              
          // Stash the form bean and forward to the display page
          saveToken(request);
          request.setAttribute("resourceLinkForm", resourceLinkForm);
          return (mapping.findForward("ResourceLink"));
  
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>