001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.console.configcreator;
017:
018: import java.io.IOException;
019: import java.util.HashSet;
020: import java.util.List;
021:
022: import javax.portlet.ActionRequest;
023: import javax.portlet.ActionResponse;
024: import javax.portlet.PortletException;
025: import javax.portlet.RenderRequest;
026: import javax.portlet.RenderResponse;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.apache.geronimo.console.MultiPageModel;
031:
032: /**
033: * A handler for ...
034: *
035: * @version $Rev: 585954 $ $Date: 2007-10-18 06:09:12 -0700 (Thu, 18 Oct 2007) $
036: */
037: public class ReferencesHandler extends AbstractHandler {
038: private static final Log log = LogFactory
039: .getLog(ReferencesHandler.class);
040:
041: public ReferencesHandler() {
042: super (REFERENCES_MODE,
043: "/WEB-INF/view/configcreator/references.jsp");
044: }
045:
046: public String actionBeforeView(ActionRequest request,
047: ActionResponse response, MultiPageModel model)
048: throws PortletException, IOException {
049: return getMode();
050: }
051:
052: public void renderView(RenderRequest request,
053: RenderResponse response, MultiPageModel model)
054: throws PortletException, IOException {
055: WARConfigData data = getSessionData(request);
056: request.setAttribute(DATA_PARAMETER, data);
057: request.setAttribute(DEPLOYED_EJBS_PARAMETER, JSR77_Util
058: .getDeployedEJBs(request));
059: request.setAttribute(DEPLOYED_JDBC_CONNECTION_POOLS_PARAMETER,
060: JSR77_Util.getJDBCConnectionPools(request));
061: request.setAttribute(
062: DEPLOYED_JMS_CONNECTION_FACTORIES_PARAMETER, JSR77_Util
063: .getJMSConnectionFactories(request));
064: request.setAttribute(DEPLOYED_JMS_DESTINATIONS_PARAMETER,
065: JSR77_Util.getJMSDestinations(request));
066: request.setAttribute(DEPLOYED_JAVAMAIL_SESSIONS_PARAMETER,
067: JSR77_Util.getJavaMailSessions(request));
068: }
069:
070: public String actionAfterView(ActionRequest request,
071: ActionResponse response, MultiPageModel model)
072: throws PortletException, IOException {
073: WARConfigData data = getSessionData(request);
074: data.readReferencesData(request);
075: HashSet dependenciesSet = new HashSet();
076: if (processRefs(data.getEjbRefs(), dependenciesSet)
077: && processRefs(data.getEjbLocalRefs(), dependenciesSet)
078: && processRefs(data.getJdbcPoolRefs(), dependenciesSet)
079: && processRefs(data.getJavaMailSessionRefs(),
080: dependenciesSet)
081: && processRefs(data.getJmsConnectionFactoryRefs(),
082: dependenciesSet)
083: && processRefs(data.getJmsDestinationRefs(),
084: dependenciesSet)) {
085: data.getDependencies().clear();
086: data.getDependencies().addAll(dependenciesSet);
087: if (data.getSecurity() != null) {
088: return SECURITY_MODE + "-before";
089: }
090: return DEPENDENCIES_MODE + "-before";
091: }
092: data.setReferenceNotResolved(true);
093: return getMode() + "-before";
094: }
095:
096: private boolean processRefs(List refList, HashSet dependenciesSet) {
097: for (int i = 0; i < refList.size(); i++) {
098: ReferenceData referenceData = (ReferenceData) refList
099: .get(i);
100: String referenceLink = referenceData.getRefLink();
101: if (referenceLink == null || referenceLink.length() <= 0) {
102: return false;
103: }
104: dependenciesSet.add(JSR88_Util
105: .getDependencyString(referenceLink));
106: }
107: return true;
108: }
109: }
|