| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| OSGiClassLoader |
|
| 2.0;2 |
| 1 | /* | |
| 2 | * Copyright 2005-2013 the original author or authors. | |
| 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, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | ||
| 17 | package org.dozer.osgi; | |
| 18 | ||
| 19 | import org.dozer.MappingException; | |
| 20 | import org.dozer.util.DozerClassLoader; | |
| 21 | import org.osgi.framework.BundleContext; | |
| 22 | ||
| 23 | import java.net.URL; | |
| 24 | ||
| 25 | /** | |
| 26 | * @author Dmitry Buzdin | |
| 27 | */ | |
| 28 | public final class OSGiClassLoader implements DozerClassLoader { | |
| 29 | ||
| 30 | private final BundleContext context; | |
| 31 | ||
| 32 | 0 | public OSGiClassLoader(BundleContext context) { |
| 33 | 0 | this.context = context; |
| 34 | 0 | } |
| 35 | ||
| 36 | @Override | |
| 37 | public Class<?> loadClass(String className) { | |
| 38 | try { | |
| 39 | 0 | return context.getBundle().loadClass(className); |
| 40 | 0 | } catch (ClassNotFoundException e) { |
| 41 | 0 | throw new MappingException(e); |
| 42 | } | |
| 43 | } | |
| 44 | ||
| 45 | @Override | |
| 46 | public URL loadResource(String uri) { | |
| 47 | 0 | return context.getBundle().getResource(uri); |
| 48 | } | |
| 49 | ||
| 50 | } |