View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.rcp.unit;
17  
18  import java.io.File;
19  import java.io.InputStream;
20  import java.util.Dictionary;
21  
22  import org.osgi.framework.Bundle;
23  import org.osgi.framework.BundleContext;
24  import org.osgi.framework.BundleException;
25  import org.osgi.framework.BundleListener;
26  import org.osgi.framework.Filter;
27  import org.osgi.framework.FrameworkListener;
28  import org.osgi.framework.InvalidSyntaxException;
29  import org.osgi.framework.ServiceListener;
30  import org.osgi.framework.ServiceReference;
31  import org.osgi.framework.ServiceRegistration;
32  import org.seasar.uruma.util.AssertionUtil;
33  
34  /**
35   * テスト用の {@link BundleContext} オブジェクトです。<br />
36   * 
37   * @author y-komori
38   */
39  public class MockBundleContext implements BundleContext {
40      protected Bundle bundle;
41  
42      /**
43       * {@link MockBundleContext} を構築します。<br />
44       */
45      public MockBundleContext(final MockBundle bundle) {
46          AssertionUtil.assertNotNull("bundle", bundle);
47          this.bundle = bundle;
48      }
49  
50      public void addBundleListener(final BundleListener listener) {
51          // Do nothing.
52      }
53  
54      public void addFrameworkListener(final FrameworkListener listener) {
55          // Do nothing.
56      }
57  
58      public void addServiceListener(final ServiceListener listener) {
59          // Do nothing.
60      }
61  
62      public void addServiceListener(final ServiceListener listener,
63              final String filter) throws InvalidSyntaxException {
64          // Do nothing.
65      }
66  
67      public Filter createFilter(final String filter)
68              throws InvalidSyntaxException {
69          return null;
70      }
71  
72      public ServiceReference[] getAllServiceReferences(final String clazz,
73              final String filter) throws InvalidSyntaxException {
74          return null;
75      }
76  
77      public Bundle getBundle() {
78          return bundle;
79      }
80  
81      public Bundle getBundle(final long id) {
82          return bundle;
83      }
84  
85      public Bundle[] getBundles() {
86          return new Bundle[] { bundle };
87      }
88  
89      public File getDataFile(final String filename) {
90          return null;
91      }
92  
93      public String getProperty(final String key) {
94          return null;
95      }
96  
97      public Object getService(final ServiceReference reference) {
98          return null;
99      }
100 
101     public ServiceReference getServiceReference(final String clazz) {
102         return null;
103     }
104 
105     public ServiceReference[] getServiceReferences(final String clazz,
106             final String filter) throws InvalidSyntaxException {
107         return null;
108     }
109 
110     public Bundle installBundle(final String location) throws BundleException {
111         return null;
112     }
113 
114     public Bundle installBundle(final String location, final InputStream input)
115             throws BundleException {
116         // TODO 自動生成されたメソッド・スタブ
117         return null;
118     }
119 
120     @SuppressWarnings("unchecked")
121     public ServiceRegistration registerService(final String[] clazzes,
122             final Object service, final Dictionary properties) {
123         return null;
124     }
125 
126     @SuppressWarnings("unchecked")
127     public ServiceRegistration registerService(final String clazz,
128             final Object service, final Dictionary properties) {
129         return null;
130     }
131 
132     public void removeBundleListener(final BundleListener listener) {
133         // Do nothing.
134     }
135 
136     public void removeFrameworkListener(final FrameworkListener listener) {
137         // Do nothing.
138     }
139 
140     public void removeServiceListener(final ServiceListener listener) {
141         // Do nothing.
142     }
143 
144     public boolean ungetService(final ServiceReference reference) {
145         return false;
146     }
147 
148 }