1 22 package org.objectweb.petals.jbi.routing.mock; 23 24 import javax.jbi.JBIException; 25 import javax.jbi.component.Component; 26 import javax.jbi.component.ComponentContext; 27 import javax.jbi.component.ComponentLifeCycle; 28 import javax.jbi.component.ServiceUnitManager; 29 import javax.jbi.messaging.MessageExchange; 30 import javax.jbi.messaging.MessagingException; 31 import javax.jbi.servicedesc.ServiceEndpoint; 32 import javax.management.MalformedObjectNameException ; 33 import javax.management.ObjectName ; 34 import javax.xml.namespace.QName ; 35 36 import org.w3c.dom.Document ; 37 import org.w3c.dom.DocumentFragment ; 38 39 44 public class ComponentMock implements Component, ComponentLifeCycle { 45 46 private static final String ENDPOINT = "ClockEndpoint"; 47 48 50 private static final String SERVICE = "ClockService"; 51 52 private String state = "Shutdown"; 53 54 private ComponentContext context; 55 56 private ServiceUnitManager serviceUnitManager; 57 58 @SuppressWarnings ("unused") 59 private ServiceEndpoint endpointReference; 60 61 public ComponentContext getContext() { 62 return context; 63 } 64 65 public ServiceEndpoint getEndpointReference() { 66 return endpointReference; 67 } 68 69 public ObjectName getExtensionMBeanName() { 70 ObjectName objectName = null; 71 try { 72 objectName = new ObjectName ("test@test:name=test"); 73 } catch (MalformedObjectNameException e) { 74 } catch (NullPointerException e) { 76 } 78 return objectName; 79 } 80 81 public ComponentLifeCycle getLifeCycle() { 82 return this; 83 } 84 85 public Document getServiceDescription(ServiceEndpoint arg0) { 86 return null; 87 } 88 89 public ServiceUnitManager getServiceUnitManager() { 90 return serviceUnitManager; 91 } 92 93 public void setServiceUnitManager(ServiceUnitManager serviceUnitManager) { 94 this.serviceUnitManager = serviceUnitManager; 95 } 96 97 public void init(ComponentContext context) throws JBIException { 98 this.context = context; 99 } 100 101 public boolean isExchangeWithConsumerOkay(ServiceEndpoint arg0, 102 MessageExchange arg1) { 103 return true; 104 } 105 106 public boolean isExchangeWithProviderOkay(ServiceEndpoint arg0, 107 MessageExchange arg1) { 108 return true; 109 } 110 111 public ServiceEndpoint resolveEndpointReference(DocumentFragment arg0) { 112 ServiceEndpoint result = null; 113 return result; 114 } 115 116 public void shutDown() throws JBIException { 117 state = "Shutdown"; 118 } 119 120 public void start() throws JBIException { 121 state = "Started"; 122 try { 123 if (context != null) { 125 endpointReference = this.context.activateEndpoint(new QName ( 126 SERVICE), ENDPOINT); 127 } 128 } catch (MessagingException e) { 129 throw new JBIException(e); 130 } 131 } 132 133 public void stop() throws JBIException { 134 state = "Stopped"; 135 } 136 137 public String getState() { 138 return state; 139 } 140 } 141 | Popular Tags |