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.jmsmanager.renderers;
017:
018: import java.io.IOException;
019: import java.util.ArrayList;
020: import java.util.Collections;
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.Set;
024:
025: import javax.management.ObjectName;
026: import javax.portlet.PortletException;
027: import javax.portlet.RenderRequest;
028: import javax.portlet.RenderResponse;
029: import javax.jms.Destination;
030:
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033: import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
034: import org.apache.geronimo.console.jmsmanager.DestinationInfo;
035: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
036: import org.apache.geronimo.kernel.DependencyManager;
037: import org.apache.geronimo.kernel.Kernel;
038: import org.apache.geronimo.kernel.KernelRegistry;
039: import org.apache.geronimo.gbean.AbstractNameQuery;
040: import org.apache.geronimo.gbean.AbstractName;
041:
042: public class ViewDestinationsRenderer extends AbstractJMSManager
043: implements PortletRenderer {
044:
045: protected static Log log = LogFactory
046: .getLog(ViewDestinationsRenderer.class);
047:
048: public String render(RenderRequest request, RenderResponse response)
049: throws PortletException, IOException {
050:
051: List destinationList = getDestinationList(request, response);
052:
053: request.setAttribute(DESTINATION_LIST, destinationList);
054:
055: return "/WEB-INF/view/jmsmanager/view.jsp";
056: }
057:
058: public List getDestinationList(RenderRequest request,
059: RenderResponse response) {
060: Kernel kernel = KernelRegistry.getSingleKernel();
061:
062: Set destinations = kernel.listGBeans(new AbstractNameQuery(
063: Destination.class.getName()));
064: List destinationInfos = new ArrayList(destinations.size());
065: DependencyManager dm = kernel.getDependencyManager();
066: for (Iterator iterator = destinations.iterator(); iterator
067: .hasNext();) {
068: AbstractName destinationName = (AbstractName) iterator
069: .next();
070:
071: try {
072: Class type;
073: try {
074: type = Class.forName((String) kernel.getAttribute(
075: destinationName, "adminObjectInterface"));
076: } catch (ClassCastException cce) {
077: type = (Class) kernel.getAttribute(destinationName,
078: "adminObjectInterface");
079: }
080: Set parents = dm.getParents(destinationName);
081: Iterator i = parents.iterator();
082: // If no parents this is a configuration we don't need those
083: // here.
084: if (!i.hasNext()) {
085: continue;
086: }
087: ObjectName parent = (ObjectName) i.next();
088: String adminObjectName = (String) destinationName
089: .getName().get(NameFactory.J2EE_NAME);
090: if (adminObjectName.equals("MDBTransferBeanOutQueue")
091: || adminObjectName.equals("SendReceiveQueue")) {
092: continue;
093: }
094: String configURI = parent.getKeyProperty("name");
095: if (configURI.startsWith("\"")) {
096: configURI = configURI.substring(1);
097: }
098: if (configURI.endsWith("\"")) {
099: configURI = configURI.substring(0, configURI
100: .length() - 1);
101: }
102:
103: DestinationInfo info = new DestinationInfo(
104: adminObjectName, (String) kernel.getAttribute(
105: destinationName, "PhysicalName"), type,
106: (String) destinationName.getName().get(
107: NameFactory.J2EE_APPLICATION),
108: (String) destinationName.getName().get(
109: NameFactory.JCA_RESOURCE), configURI);
110: destinationInfos.add(info);
111: } catch (Exception e) {
112: log.error(e);
113: }
114: }
115: Collections.sort(destinationInfos);
116: return destinationInfos;
117: }
118:
119: }
|