001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Admin/Sources/es/udc/mypersonalizer/admin/http/controller/actions/prototypes/ShowAllServicesAction.java,v 1.1.1.1 2004/03/25 12:08:38 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:38 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.admin.http.controller.actions.prototypes;
042:
043: import java.util.Iterator;
044: import java.util.Collection;
045: import java.util.ArrayList;
046:
047: import javax.servlet.http.HttpServletRequest;
048: import javax.servlet.http.HttpServletResponse;
049:
050: import org.apache.struts.action.ActionMapping;
051: import org.apache.struts.action.ActionForm;
052: import org.apache.struts.action.ActionForward;
053: import org.apache.struts.util.MessageResources;
054:
055: import es.udc.mypersonalizer.kernel.conventions.ServiceConventions;
056: import es.udc.mypersonalizer.kernel.controller.actions.DefaultAction;
057:
058: import es.udc.mypersonalizer.admin.http.controller.actions.propertyeditor.interfaces.PropertyEditorConfigurationRegistry;
059: import es.udc.mypersonalizer.admin.http.controller.actions.propertyeditor.interfaces.PropertyEditorConfiguration;
060: import es.udc.mypersonalizer.admin.http.controller.actions.prototypes.propertyeditor.ServicePropertyAccessStrategy;
061: import es.udc.mypersonalizer.admin.http.controller.actions.prototypes.propertyeditor.ServiceButtonsStateAccessStrategy;
062: import es.udc.mypersonalizer.admin.http.controller.actions.prototypes.util.ServicePrototypeSessionManager;
063: import es.udc.mypersonalizer.admin.http.controller.actions.prototypes.util.PrototypesGlobalData;
064: import es.udc.mypersonalizer.admin.http.controller.actions.prototypes.util.ServicePrototypeStatus;
065: import es.udc.mypersonalizer.admin.http.view.viewobjects.prototypes.ViewPrototypeStatus;
066:
067: /**
068: * This action retrieves all services and their prototypes status (if they
069: * exist). It adds to the request two attributes: (1) "prototypesStatus":
070: * a collection of {@link ServicePrototypeStatus} and (2)
071: * "serviceButtonsStateId": a <code>String</code> with value
072: * {@link ServiceConventions#SERVICE_BUTTONS_STATE_SERVICE_IDENTIFIER}.
073: *
074: * This class also registers in its static block the prototypes tool property
075: * editor configuration.
076: *
077: * @author Abel Iago Toral Quiroga
078: * @author Fernando Bellas
079: * @since 1.0
080: */
081: public class ShowAllServicesAction extends DefaultAction {
082:
083: /* Register the property editor configurations for the prototypes tool */
084: static {
085:
086: /* Register the configuration for the prototype property */
087: PropertyEditorConfiguration prototypePropertyConfiguration = new PropertyEditorConfiguration(
088: new ServicePropertyAccessStrategy(),
089: PrototypesGlobalData.PROPERTY_EDITOR_EXIT_URL,
090: false,
091: PrototypesGlobalData.PROPERTY_EDITOR_EXIT_MESSAGE_IDENTIFIER);
092: PropertyEditorConfigurationRegistry
093: .registerConfiguration(
094: PrototypesGlobalData.PROPERTY_EDITOR_PROTOTYPE_CONFIGURATION_IDENTIFIER,
095: prototypePropertyConfiguration);
096:
097: /* Register the configuration for the service buttons state property */
098: PropertyEditorConfiguration buttonsStatePropertyConfiguration = new PropertyEditorConfiguration(
099: new ServiceButtonsStateAccessStrategy(),
100: PrototypesGlobalData.PROPERTY_EDITOR_EXIT_URL,
101: false,
102: PrototypesGlobalData.PROPERTY_EDITOR_EXIT_MESSAGE_IDENTIFIER);
103: PropertyEditorConfigurationRegistry
104: .registerConfiguration(
105: PrototypesGlobalData.PROPERTY_EDITOR_BUTTONS_STATE_CONFIGURATION_IDENTIFIER,
106: buttonsStatePropertyConfiguration);
107: }
108:
109: protected ActionForward doExecute(ActionMapping mapping,
110: ActionForm form, HttpServletRequest request,
111: HttpServletResponse response) throws Exception {
112:
113: /* Get all service prototype status */
114: Iterator iterator = ServicePrototypeSessionManager
115: .findAllServicePrototypesStatus(request).iterator();
116:
117: /* Create a view-object with all services identifiers, their
118: prototypes status information and the possible actions */
119: Collection prototypesStatusList = new ArrayList();
120: while (iterator.hasNext()) {
121: ServicePrototypeStatus prototypeStatus = (ServicePrototypeStatus) iterator
122: .next();
123:
124: String statusAsString = statusToString(
125: getResources(request), prototypeStatus.getStatus());
126:
127: ViewPrototypeStatus viewPrototypeStatus = new ViewPrototypeStatus(
128: prototypeStatus.getPrototypeIdentifier(),
129: statusAsString, prototypeStatus.getPrototype()
130: .getServiceProperty() != null,
131: prototypeStatus.getPrototype()
132: .getServiceButtonsStateProperty() != null);
133:
134: prototypesStatusList.add(viewPrototypeStatus);
135: }
136:
137: /* Add objects to the request and forward */
138: request.setAttribute("prototypesStatus", prototypesStatusList);
139: request
140: .setAttribute(
141: "serviceButtonsStateId",
142: ServiceConventions.SERVICE_BUTTONS_STATE_SERVICE_IDENTIFIER);
143:
144: return mapping.findForward("ShowAllServicesJSP");
145: }
146:
147: /**
148: * Converts a prototype status in a String describing the status for the
149: * JSP page.
150: * @param resources To have access to the messages.
151: * @param status a prototype status.
152: * @return A string representation of the prototype status.
153: */
154: private String statusToString(MessageResources resources, int status) {
155:
156: if (status == ServicePrototypeStatus.MODIFIED) {
157: return resources
158: .getMessage("Prototypes.PrototypeStatus.modified");
159: } else if (status == ServicePrototypeStatus.NOT_MODIFIED) {
160: return resources
161: .getMessage("Prototypes.PrototypeStatus.notModified");
162: } else {
163: return resources
164: .getMessage("Prototypes.PrototypeStatus.unknown");
165: }
166: }
167: }
|