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