KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Field JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Enumeration JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.jms.Connection JavaDoc;
27 import javax.jms.ConnectionFactory JavaDoc;
28 import javax.jms.Destination JavaDoc;
29 import javax.jms.Queue JavaDoc;
30 import javax.jms.QueueBrowser JavaDoc;
31 import javax.jms.Session JavaDoc;
32 import javax.management.ObjectName JavaDoc;
33 import javax.portlet.PortletException;
34 import javax.portlet.RenderRequest;
35 import javax.portlet.RenderResponse;
36
37 //import org.activemq.service.DeadLetterPolicy;
38
import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
39 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
40 import org.apache.geronimo.gbean.AbstractName;
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44 public class ViewDLQRenderer extends AbstractJMSManager implements PortletRenderer {
45
46     private static final Log log = LogFactory.getLog(ViewDLQRenderer.class);
47
48     private Destination JavaDoc dlq = null;
49
50     private QueueBrowser JavaDoc dlqBrowser = null;
51
52     private Connection JavaDoc connection = null;
53
54     private Session JavaDoc session = null;
55
56     private String JavaDoc dlqName;
57
58     public ViewDLQRenderer() {
59     }
60
61     public void setup(RenderRequest request, RenderResponse response) {
62         /*
63         String destinationApplicationName = request
64                 .getParameter("destinationApplicationName");
65         String destinationModuleName = request
66                 .getParameter("destinationModuleName");
67         String destinationName = request.getParameter("destinationName");
68
69         try {
70             //TODO configid disabled
71             AbstractName adminObjectName = null;//NameFactory.getComponentName(null,
72 // null, destinationApplicationName, NameFactory.JCA_RESOURCE,
73 // destinationModuleName, destinationName, null, baseContext);
74             Destination destination = (Destination) kernel.invoke(adminObjectName,
75                     "$getResource");
76             ConnectionFactory connectionFactory = (ConnectionFactory) kernel
77                     .invoke(JCA_MANAGED_CONNECTION_FACTORY_NAME,
78                             "$getResource");
79             connection = connectionFactory.createConnection();
80             session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
81
82             DeadLetterPolicy dlp = new DeadLetterPolicy();
83
84             //dlqName =
85             // dlp.getDeadLetterNameFromDestination((ActiveMQDestination)
86             // destination);
87             // This is a hack to get around the fact that the code commented
88             // above throws a ClassCastException due to ClassLoader weirdness.
89             Field f = dlp.getClass().getDeclaredField(
90                     "deadLetterPerDestinationName");
91             f.setAccessible(true);
92             boolean deadLetterPerDestinationName = f.getBoolean(dlp);
93             f = dlp.getClass().getDeclaredField("deadLetterPrefix");
94             f.setAccessible(true);
95             String deadLetterPrefix = "" + f.get(dlp);
96             if (deadLetterPerDestinationName) {
97                 dlqName = deadLetterPrefix
98                         + destination.getClass().getMethod("getPhysicalName",
99                                 null).invoke(destination, null);
100             } else {
101                 dlqName = deadLetterPrefix + deadLetterPrefix;
102             }
103
104             dlq = session.createQueue(dlqName);
105             dlqBrowser = session.createBrowser((Queue) dlq);
106
107             connection.start();
108
109         } catch (Exception e) {
110             log.error(e.getMessage(), e);
111         }
112         */

113     }
114
115     public List JavaDoc getDLQContents(QueueBrowser JavaDoc qb) {
116
117         List JavaDoc list = new ArrayList JavaDoc();
118
119         try {
120             for (Enumeration JavaDoc e = qb.getEnumeration(); e.hasMoreElements();) {
121                 Object JavaDoc o = e.nextElement();
122                 list.add(o);
123             }
124
125             connection.stop();
126             dlqBrowser.close();
127             session.close();
128             connection.close();
129
130         } catch (Exception JavaDoc e) {
131             log.error(e.getMessage(), e);
132         }
133
134         return list;
135     }
136
137     public String JavaDoc render(RenderRequest request, RenderResponse response)
138             throws PortletException, IOException JavaDoc {
139
140         setup(request, response);
141         List JavaDoc dlqContents = getDLQContents(dlqBrowser);
142         request.setAttribute("dlqcontents", dlqContents);
143         request.setAttribute("dlqname", dlqName);
144
145         return "/WEB-INF/view/jmsmanager/viewDLQ.jsp";
146     }
147
148 }
149
Popular Tags