KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > routing > mock > ComponentMock


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: ComponentMock.java 16:18:41 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

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 JavaDoc;
33 import javax.management.ObjectName JavaDoc;
34 import javax.xml.namespace.QName JavaDoc;
35
36 import org.w3c.dom.Document JavaDoc;
37 import org.w3c.dom.DocumentFragment JavaDoc;
38
39 /**
40  * Mock object of the Component
41  *
42  * @author ddesjardins - eBMWebsourcing
43  */

44 public class ComponentMock implements Component, ComponentLifeCycle {
45
46     private static final String JavaDoc ENDPOINT = "ClockEndpoint";
47
48     // private DeliveryChannel channel;
49

50     private static final String JavaDoc SERVICE = "ClockService";
51
52     private String JavaDoc state = "Shutdown";
53
54     private ComponentContext context;
55
56     private ServiceUnitManager serviceUnitManager;
57
58     @SuppressWarnings JavaDoc("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 JavaDoc getExtensionMBeanName() {
70         ObjectName JavaDoc objectName = null;
71         try {
72             objectName = new ObjectName JavaDoc("test@test:name=test");
73         } catch (MalformedObjectNameException JavaDoc e) {
74             // Do nothing
75
} catch (NullPointerException JavaDoc e) {
76             // Do nothing
77
}
78         return objectName;
79     }
80
81     public ComponentLifeCycle getLifeCycle() {
82         return this;
83     }
84
85     public Document JavaDoc 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 JavaDoc 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             // this.channel = this.context.getDeliveryChannel();
124
if (context != null) {
125                 endpointReference = this.context.activateEndpoint(new QName JavaDoc(
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 JavaDoc getState() {
138         return state;
139     }
140 }
141
Popular Tags