Home » geronimo-2.2-source-release » org.apache.geronimo.console.jmsmanager.renderers » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.console.jmsmanager.renderers;
   19   
   20   import java.io.IOException;
   21   import java.util.ArrayList;
   22   import java.util.Collections;
   23   import java.util.Iterator;
   24   import java.util.List;
   25   import java.util.Set;
   26   
   27   import javax.management.ObjectName;
   28   import javax.portlet.PortletException;
   29   import javax.portlet.RenderRequest;
   30   import javax.portlet.RenderResponse;
   31   import javax.jms.Destination;
   32   
   33   import org.slf4j.Logger;
   34   import org.slf4j.LoggerFactory;
   35   import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
   36   import org.apache.geronimo.console.jmsmanager.DestinationInfo;
   37   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   38   import org.apache.geronimo.kernel.DependencyManager;
   39   import org.apache.geronimo.kernel.Kernel;
   40   import org.apache.geronimo.kernel.KernelRegistry;
   41   import org.apache.geronimo.gbean.AbstractNameQuery;
   42   import org.apache.geronimo.gbean.AbstractName;
   43   
   44   public class ViewDestinationsRenderer extends AbstractJMSManager implements
   45           PortletRenderer {
   46   
   47       protected final Logger log = LoggerFactory.getLogger(getClass());
   48   
   49       public String render(RenderRequest request, RenderResponse response)
   50               throws PortletException, IOException {
   51   
   52           List destinationList = getDestinationList(request, response);
   53   
   54           request.setAttribute(DESTINATION_LIST, destinationList);
   55   
   56           return "/WEB-INF/view/jmsmanager/view.jsp";
   57       }
   58   
   59       public List getDestinationList(RenderRequest request,
   60               RenderResponse response) {
   61           Kernel kernel = KernelRegistry.getSingleKernel();
   62   
   63           Set destinations = kernel.listGBeans(new AbstractNameQuery(Destination.class.getName()));
   64           List destinationInfos = new ArrayList(destinations.size());
   65           DependencyManager dm = kernel.getDependencyManager();
   66           for (Iterator iterator = destinations.iterator(); iterator.hasNext();) {
   67               AbstractName destinationName = (AbstractName) iterator.next();
   68   
   69               try {
   70                   Class type;
   71                   try {
   72                       type = Class.forName((String) kernel.getAttribute(
   73                               destinationName, "adminObjectInterface"));
   74                   } catch (ClassCastException cce) {
   75                       type = (Class) kernel.getAttribute(destinationName,
   76                               "adminObjectInterface");
   77                   }
   78                   Set parents = dm.getParents(destinationName);
   79                   Iterator i = parents.iterator();
   80                   // If no parents this is a configuration we don't need those
   81                   // here.
   82                   if (!i.hasNext()) {
   83                       continue;
   84                   }
   85                   ObjectName parent = (ObjectName) i.next();
   86                   String adminObjectName = (String) destinationName.getName().get(NameFactory.J2EE_NAME);
   87                   if (adminObjectName.equals("MDBTransferBeanOutQueue")
   88                           || adminObjectName.equals("SendReceiveQueue")) {
   89                       continue;
   90                   }
   91                   String configURI = parent.getKeyProperty("name");
   92                   if (configURI.startsWith("\"")) {
   93                       configURI = configURI.substring(1);
   94                   }
   95                   if (configURI.endsWith("\"")) {
   96                       configURI = configURI.substring(0, configURI.length() - 1);
   97                   }
   98   
   99                   DestinationInfo info = new DestinationInfo(adminObjectName,
  100                           (String) kernel.getAttribute(destinationName, "PhysicalName"),
  101                           type,
  102                           (String) destinationName.getName().get(NameFactory.J2EE_APPLICATION),
  103                           (String) destinationName.getName().get(NameFactory.JCA_RESOURCE),
  104                           configURI);
  105                   destinationInfos.add(info);
  106               } catch (Exception e) {
  107                   log.error("Failed to get destinations list", e);
  108               }
  109           }
  110           Collections.sort(destinationInfos);
  111           return destinationInfos;
  112       }
  113   
  114   }

Home » geronimo-2.2-source-release » org.apache.geronimo.console.jmsmanager.renderers » [javadoc | source]