KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > jmsmanager > renderers > ViewDestinationsRenderer


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 JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import javax.management.ObjectName JavaDoc;
28 import javax.portlet.PortletException;
29 import javax.portlet.RenderRequest;
30 import javax.portlet.RenderResponse;
31 import javax.jms.Destination JavaDoc;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
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 static Log log = LogFactory
48             .getLog(ViewDestinationsRenderer.class);
49
50     public String JavaDoc render(RenderRequest request, RenderResponse response)
51             throws PortletException, IOException JavaDoc {
52
53         List JavaDoc destinationList = getDestinationList(request, response);
54
55         request.setAttribute(DESTINATION_LIST, destinationList);
56
57         return "/WEB-INF/view/jmsmanager/view.jsp";
58     }
59
60     public List JavaDoc getDestinationList(RenderRequest request,
61             RenderResponse response) {
62         Kernel kernel = KernelRegistry.getSingleKernel();
63
64         Set JavaDoc destinations = kernel.listGBeans(new AbstractNameQuery(Destination JavaDoc.class.getName()));
65         List JavaDoc destinationInfos = new ArrayList JavaDoc(destinations.size());
66         DependencyManager dm = kernel.getDependencyManager();
67         for (Iterator JavaDoc iterator = destinations.iterator(); iterator.hasNext();) {
68             AbstractName destinationName = (AbstractName) iterator.next();
69
70             try {
71                 Class JavaDoc type;
72                 try {
73                     type = Class.forName((String JavaDoc) kernel.getAttribute(
74                             destinationName, "adminObjectInterface"));
75                 } catch (ClassCastException JavaDoc cce) {
76                     type = (Class JavaDoc) kernel.getAttribute(destinationName,
77                             "adminObjectInterface");
78                 }
79                 Set JavaDoc parents = dm.getParents(destinationName);
80                 Iterator JavaDoc i = parents.iterator();
81                 // If no parents this is a configuration we don't need those
82
// here.
83
if (!i.hasNext()) {
84                     continue;
85                 }
86                 ObjectName JavaDoc parent = (ObjectName JavaDoc) i.next();
87                 String JavaDoc adminObjectName = (String JavaDoc) destinationName.getName().get(NameFactory.J2EE_NAME);
88                 if (adminObjectName.equals("MDBTransferBeanOutQueue")
89                         || adminObjectName.equals("SendReceiveQueue")) {
90                     continue;
91                 }
92                 String JavaDoc configURI = parent.getKeyProperty("name");
93                 if (configURI.startsWith("\"")) {
94                     configURI = configURI.substring(1);
95                 }
96                 if (configURI.endsWith("\"")) {
97                     configURI = configURI.substring(0, configURI.length() - 1);
98                 }
99
100                 DestinationInfo info = new DestinationInfo(adminObjectName,
101                         (String JavaDoc) kernel.getAttribute(destinationName, "PhysicalName"),
102                         type,
103                         (String JavaDoc) destinationName.getName().get(NameFactory.J2EE_APPLICATION),
104                         (String JavaDoc) destinationName.getName().get(NameFactory.JCA_RESOURCE),
105                         configURI);
106                 destinationInfos.add(info);
107             } catch (Exception JavaDoc e) {
108                 log.error(e);
109             }
110         }
111         Collections.sort(destinationInfos);
112         return destinationInfos;
113     }
114
115 }
116
Popular Tags