1 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 ; 27 28 32 public class DestinationFacade { 33 34 private String JMSDestination; 35 private String JMSDestinationType; 36 private BrokerFacade brokerFacade; 37 38 public DestinationFacade(BrokerFacade brokerFacade) { 39 this.brokerFacade = brokerFacade; 40 } 41 42 public String toString() { 43 return super.toString() + "[destination:" + JMSDestination + "; type=" + JMSDestinationType + "]"; 44 } 45 46 47 public void removeDestination() throws Exception { 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 { 60 if (isQueue()) { 61 getBrokerAdmin().addQueue(getValidDestination()); 62 } 63 else { 64 getBrokerAdmin().addTopic(getValidDestination()); 65 } 66 } 67 68 public BrokerViewMBean getBrokerAdmin() throws Exception { 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 getJMSDestination() { 86 return JMSDestination; 87 } 88 89 public void setJMSDestination(String destination) { 90 this.JMSDestination = destination; 91 } 92 93 public String getJMSDestinationType() { 94 return JMSDestinationType; 95 } 96 97 public void setJMSDestinationType(String 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 getValidDestination() { 107 if (JMSDestination == null) { 108 throw new IllegalArgumentException ("No JMSDestination parameter specified"); 109 } 110 return JMSDestination; 111 } 112 113 114 protected ModelAndView redirectToRequest(HttpServletRequest request) { 115 String view = "redirect:" + request.getRequestURI(); 116 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 getPhysicalDestinationName() { 126 return createDestination().getPhysicalName(); 127 } 128 } 129 | Popular Tags |