KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > web > DestinationFacade


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.web;
19
20 import org.apache.activemq.broker.jmx.BrokerViewMBean;
21 import org.apache.activemq.command.ActiveMQDestination;
22 import org.apache.activemq.command.ActiveMQQueue;
23 import org.apache.activemq.command.ActiveMQTopic;
24 import org.springframework.web.servlet.ModelAndView;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 /**
29  *
30  * @version $Revision: 516117 $
31  */

32 public class DestinationFacade {
33
34     private String JavaDoc JMSDestination;
35     private String JavaDoc JMSDestinationType;
36     private BrokerFacade brokerFacade;
37
38     public DestinationFacade(BrokerFacade brokerFacade) {
39         this.brokerFacade = brokerFacade;
40     }
41
42     public String JavaDoc toString() {
43         return super.toString() + "[destination:" + JMSDestination + "; type=" + JMSDestinationType + "]";
44     }
45
46
47     // Operations
48
// -------------------------------------------------------------------------
49
public void removeDestination() throws Exception JavaDoc {
50         getValidDestination();
51         if (isQueue()) {
52             getBrokerAdmin().removeQueue(getJMSDestination());
53         }
54         else {
55             getBrokerAdmin().removeTopic(getJMSDestination());
56         }
57     }
58
59     public void addDestination() throws Exception JavaDoc {
60         if (isQueue()) {
61             getBrokerAdmin().addQueue(getValidDestination());
62         }
63         else {
64             getBrokerAdmin().addTopic(getValidDestination());
65         }
66     }
67     
68     // Properties
69
// -------------------------------------------------------------------------
70
public BrokerViewMBean getBrokerAdmin() throws Exception JavaDoc {
71         return brokerFacade.getBrokerAdmin();
72     }
73
74     public BrokerFacade getBrokerFacade() {
75         return brokerFacade;
76     }
77
78     public boolean isQueue() {
79         if (JMSDestinationType != null && JMSDestinationType.equalsIgnoreCase("topic")) {
80             return false;
81         }
82         return true;
83     }
84
85     public String JavaDoc getJMSDestination() {
86         return JMSDestination;
87     }
88
89     public void setJMSDestination(String JavaDoc destination) {
90         this.JMSDestination = destination;
91     }
92
93     public String JavaDoc getJMSDestinationType() {
94         return JMSDestinationType;
95     }
96
97     public void setJMSDestinationType(String JavaDoc type) {
98         this.JMSDestinationType = type;
99     }
100
101     protected ActiveMQDestination createDestination() {
102         byte destinationType = isQueue() ? ActiveMQDestination.QUEUE_TYPE : ActiveMQDestination.TOPIC_TYPE;
103         return ActiveMQDestination.createDestination(getValidDestination(), destinationType);
104     }
105
106     protected String JavaDoc getValidDestination() {
107         if (JMSDestination == null) {
108             throw new IllegalArgumentException JavaDoc("No JMSDestination parameter specified");
109         }
110         return JMSDestination;
111     }
112
113
114     protected ModelAndView redirectToRequest(HttpServletRequest JavaDoc request) {
115         String JavaDoc view = "redirect:" + request.getRequestURI();
116 // System.out.println("Redirecting to: " + view);
117
return new ModelAndView(view);
118     }
119
120
121     protected ModelAndView redirectToBrowseView() {
122         return new ModelAndView("redirect:" + (isQueue() ? "queues.jsp" : "topics.jsp"));
123     }
124
125     protected String JavaDoc getPhysicalDestinationName() {
126         return createDestination().getPhysicalName();
127     }
128 }
129
Popular Tags