KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > messagedriven > mock > JmsMockProviderAdapter


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.messagedriven.mock;
23
24 import java.util.Properties JavaDoc;
25
26 import javax.naming.Context JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28
29 import org.jboss.jms.jndi.JMSProviderAdapter;
30 import org.w3c.dom.Document JavaDoc;
31 import org.w3c.dom.Element JavaDoc;
32 import org.w3c.dom.Node JavaDoc;
33 import org.w3c.dom.NodeList JavaDoc;
34
35 /**
36  * A MockJMSProviderAdapter.
37  *
38  * @author <a HREF="weston.price@jboss.com">Weston Price</a>
39  * @version $Revision: 44980 $
40  */

41 public class JmsMockProviderAdapter implements JMSProviderAdapter, JmsMockObject
42 {
43    private static final String JavaDoc DEFAULT_URL = "org/jboss/test/messagedriven/mock/mock-provider-adapter.xml";
44    
45    private String JavaDoc name;
46    private String JavaDoc factoryRef;
47    private String JavaDoc queueFactoryRef;
48    private String JavaDoc topicFactoryRef;
49    
50    
51    //TODO create mock provider adapter xml file.
52
public String JavaDoc getFactoryRef()
53    {
54       return this.factoryRef;
55    }
56
57    public Context JavaDoc getInitialContext() throws NamingException JavaDoc
58    {
59      return null;
60      
61    }
62
63    public String JavaDoc getName()
64    {
65       return this.name;
66    }
67
68    public Properties JavaDoc getProperties()
69    {
70       // TODO Auto-generated method stub
71
return null;
72    }
73
74    public String JavaDoc getQueueFactoryRef()
75    {
76       // TODO Auto-generated method stub
77
return this.queueFactoryRef;
78    }
79
80    public String JavaDoc getTopicFactoryRef()
81    {
82       // TODO Auto-generated method stub
83
return this.topicFactoryRef;
84    }
85
86    public void setFactoryRef(String JavaDoc newFactoryRef)
87    {
88       this.factoryRef = newFactoryRef;
89
90    }
91
92    public void setName(String JavaDoc name)
93    {
94       this.name = name;
95    }
96
97    public void setProperties(Properties JavaDoc properties)
98    {
99       // TODO Auto-generated method stub
100

101    }
102
103    public void setQueueFactoryRef(String JavaDoc newQueueFactoryRef)
104    {
105       this.queueFactoryRef = newQueueFactoryRef;
106       
107    }
108
109    public void setTopicFactoryRef(String JavaDoc newTopicFactoryRef)
110    {
111       this.topicFactoryRef = newTopicFactoryRef;
112    }
113    
114    public void load(final String JavaDoc xml)
115    {
116       
117       Document JavaDoc doc = JmsMockObjectHelper.getDocument(xml);
118       
119       final NodeList JavaDoc nl = doc.getDocumentElement().getChildNodes();
120       
121       for(int i = 0; i < nl.getLength(); i++){
122          
123          Node JavaDoc node = (Node JavaDoc)nl.item(i);
124          
125          if(node.getNodeType() == Node.ELEMENT_NODE){
126                
127             Element JavaDoc elem = (Element JavaDoc)node;
128             String JavaDoc nodeName = elem.getNodeName();
129             
130             NodeList JavaDoc childNodes = elem.getChildNodes();
131             
132             for(int j = 0; j < childNodes.getLength(); j++){
133                
134                Node JavaDoc child = (Node JavaDoc)childNodes.item(j);
135                if(child.getNodeType() == Node.TEXT_NODE){
136 // setValue(nodeName, child.getTextContent());
137

138                }
139             }
140             
141          }
142          
143       }
144       
145    }
146
147    public void load(Element JavaDoc xml)
148    {
149     
150    }
151
152    public void load()
153    {
154     
155       load(DEFAULT_URL);
156       
157    }
158    
159    public static void main(String JavaDoc[] args)
160    {
161       JmsMockProviderAdapter a = new JmsMockProviderAdapter();
162       a.load();
163       
164    }
165    
166    private void setValue(String JavaDoc name, String JavaDoc value){
167
168       if(name.equals("name")){
169          setName(value);
170
171       }else if(name.equals("factoryRef")){
172          
173          setFactoryRef(value);
174          
175       }else if(name.equals("queueFactoryRef")){
176          
177          setQueueFactoryRef(value);
178          
179       }else if(name.equals("topicFactoryRef")){
180          
181          setTopicFactoryRef(value);
182       }
183    
184    }
185
186
187 }
188
Popular Tags