001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
011: * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
012: * language governing permissions and limitations under the License.
013: */
014: package edu.iu.uis.eden.messaging.web;
015:
016: import java.io.IOException;
017: import java.util.ArrayList;
018: import java.util.List;
019: import java.util.Map;
020:
021: import javax.servlet.ServletException;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024: import javax.xml.namespace.QName;
025:
026: import org.apache.struts.action.ActionForm;
027: import org.apache.struts.action.ActionForward;
028: import org.apache.struts.action.ActionMapping;
029: import org.apache.struts.action.ActionMessages;
030: import org.kuali.bus.services.KSBServiceLocator;
031: import org.kuali.rice.RiceConstants;
032: import org.kuali.rice.core.Core;
033: import org.kuali.rice.util.RiceUtilities;
034:
035: import edu.iu.uis.eden.messaging.RemoteResourceServiceLocator;
036: import edu.iu.uis.eden.messaging.RemotedServiceHolder;
037: import edu.iu.uis.eden.messaging.RemotedServiceRegistry;
038: import edu.iu.uis.eden.messaging.ServerSideRemotedServiceHolder;
039: import edu.iu.uis.eden.messaging.ServiceInfo;
040: import edu.iu.uis.eden.messaging.resourceloading.KSBResourceLoaderFactory;
041: import edu.iu.uis.eden.web.WorkflowAction;
042:
043: /**
044: * Struts action for interacting with the queue of messages.
045: *
046: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
047: */
048: public class ServiceRegistryAction extends WorkflowAction {
049:
050: public ActionForward start(ActionMapping mapping, ActionForm form,
051: HttpServletRequest request, HttpServletResponse response)
052: throws IOException, ServletException {
053: return mapping.findForward("basic");
054: }
055:
056: public ActionForward refreshServiceRegistry(ActionMapping mapping,
057: ActionForm form, HttpServletRequest request,
058: HttpServletResponse response) throws IOException,
059: ServletException {
060: // TODO is this what really constitutes a "refresh" of the service registry?
061: KSBServiceLocator.getServiceDeployer().refresh();
062: KSBResourceLoaderFactory.getRemoteResourceLocator().refresh();
063: return mapping.findForward("basic");
064: }
065:
066: public ActionMessages establishRequiredState(
067: HttpServletRequest request, ActionForm actionForm)
068: throws Exception {
069: ServiceRegistryForm form = (ServiceRegistryForm) actionForm;
070: form.setMyIpAddress(RiceUtilities.getIpNumber());
071: form.setMyMessageEntity(Core.getCurrentContextConfig()
072: .getProperty(RiceConstants.MESSAGE_ENTITY));
073: form.setDevMode(Core.getCurrentContextConfig().getDevMode());
074: RemotedServiceRegistry registry = KSBServiceLocator
075: .getServiceDeployer();
076: RemoteResourceServiceLocator remoteLocator = KSBResourceLoaderFactory
077: .getRemoteResourceLocator();
078: form.setPublishedServices(getPublishedServices(registry));
079: form
080: .setPublishedTempServices(getPublishedTempServices(registry));
081: form
082: .setGlobalRegistryServices(getGlobalRegistryServices(remoteLocator));
083:
084: return null;
085: }
086:
087: private List<ServiceInfo> getPublishedServices(
088: RemotedServiceRegistry registry) {
089: Map<QName, ServerSideRemotedServiceHolder> publishedServiceHolders = registry
090: .getPublishedServices();
091: List<ServiceInfo> publishedServices = new ArrayList<ServiceInfo>();
092: for (ServerSideRemotedServiceHolder holder : publishedServiceHolders
093: .values()) {
094: publishedServices.add(holder.getServiceInfo());
095: }
096: return publishedServices;
097: }
098:
099: private List<ServiceInfo> getPublishedTempServices(
100: RemotedServiceRegistry registry) {
101: Map<QName, ServerSideRemotedServiceHolder> publishedTempServiceHolders = registry
102: .getPublishedTempServices();
103: List<ServiceInfo> publishedTempServices = new ArrayList<ServiceInfo>();
104: for (ServerSideRemotedServiceHolder holder : publishedTempServiceHolders
105: .values()) {
106: publishedTempServices.add(holder.getServiceInfo());
107: }
108: return publishedTempServices;
109: }
110:
111: private List<ServiceInfo> getGlobalRegistryServices(
112: RemoteResourceServiceLocator remoteLocator) {
113: Map<QName, List<RemotedServiceHolder>> clients = remoteLocator
114: .getClients();
115: List<ServiceInfo> globalRegistryServices = new ArrayList<ServiceInfo>();
116: for (List<RemotedServiceHolder> client : clients.values()) {
117: for (RemotedServiceHolder holder : client) {
118: globalRegistryServices.add(holder.getServiceInfo());
119: }
120: }
121: return globalRegistryServices;
122: }
123:
124: }
|