本文整理匯總了Java中org.osgi.framework.Bundle.loadClass方法的典型用法代碼示例。如果您正苦於以下問題:Java Bundle.loadClass方法的具體用法?Java Bundle.loadClass怎麽用?Java Bundle.loadClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.osgi.framework.Bundle
的用法示例。
在下文中一共展示了Bundle.loadClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: takeSnapshotInGraphView
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
* Add a snapshot of the current state of 'root' to the {@code ASTGraphView}. Does nothing if in headless mode or
* the {@code ASTGraphView} is not installed or unavailable for some other reason. May be invoked from non-UI
* threads.
* <p>
* A copy of all required information is taken on the invoking thread before this method returns, so it is safe to
* change 'root' or its contents right after this method returns.
* <p>
* If 'root' is a {@link Resource} or an {@link EObject} contained in a {@code Resource}, then the name of the
* (containing) resource will be appended to the label.
*
* @param label
* the label for the new graph or <code>null</code>.
* @param root
* the root object to create the graph from; must be a {@link ResourceSet}, {@link Resource}, or
* {@link EObject}.
* @throws IllegalArgumentException
* if 'root' is <code>null</code> or of incorrect type.
*/
public static final void takeSnapshotInGraphView(String label, Object root) {
if (!(root instanceof ResourceSet || root instanceof Resource || root instanceof EObject))
throw new IllegalArgumentException("root must be a ResourceSet, Resource, or EObject");
// append name of root's containing resource to label (if any)
final Resource resource = root instanceof Resource ? (Resource) root
: (root instanceof EObject ? ((EObject) root).eResource() : null);
final URI uri = resource != null ? resource.getURI() : null;
final String name = uri != null ? uri.lastSegment() : null;
if (name != null)
label = label + " (" + name + ")";
// send request to ASTGraphView
try {
// we don't want a dependency on the debug bundle where ASTGraphView is located, so use reflection
final Bundle testViewBundle = Platform.getBundle("org.eclipse.n4js.smith.graph");
final Class<?> testViewClass = testViewBundle.loadClass("org.eclipse.n4js.smith.graph.ASTGraphView");
final Method m = testViewClass.getMethod("show", String.class, Object.class);
m.invoke(null, label, root);
} catch (Throwable e) {
// ignore
}
}
示例2: doLoadClass
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
@Override
protected Class<?> doLoadClass(String pkg, String name) {
Bundle b = bundle;
if (b == null) {
LOG.log(Level.WARNING, "Trying to load class before initialization finished {0}", pkg + '.' + name);
return null;
}
try {
return b.loadClass(name);
} catch (ClassNotFoundException ex) {
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(Level.FINEST, "No class found in " + this, ex);
}
return null;
}
}
示例3: getJarClasses
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
* Loads and returns the classes from a jar file into the specified bundle.
*
* @param bundle the bundle
* @param file the file
* @return the jar classes
*/
public List<Class<?>> getJarClasses(Bundle bundle, URL jarFileURL) {
List<Class<?>> classesOfJarFile = new ArrayList<Class<?>>();
if (bundle!=null) {
List<String> classNames = this.getJarClassReferences(bundle, jarFileURL);
for (int i = 0; i < classNames.size(); i++) {
String className = classNames.get(i);
try {
Class<?> classFound = bundle.loadClass(className);
classesOfJarFile.add(classFound);
} catch (ClassNotFoundException | NoClassDefFoundError cnfEx) {
// No print of the stack trace here
// cnfEx.printStackTrace();
}
}
}
return classesOfJarFile;
}
示例4: postProcessBeanFactory
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
public void postProcessBeanFactory(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory)
throws BeansException, OsgiException {
Bundle bundle = bundleContext.getBundle();
try {
// Try and load the annotation code using the bundle classloader
Class<?> annotationBppClass = bundle.loadClass(ANNOTATION_BPP_CLASS);
// instantiate the class
final BeanPostProcessor annotationBeanPostProcessor = (BeanPostProcessor) BeanUtils.instantiateClass(annotationBppClass);
// everything went okay so configure the BPP and add it to the BF
((BeanFactoryAware) annotationBeanPostProcessor).setBeanFactory(beanFactory);
((BeanClassLoaderAware) annotationBeanPostProcessor).setBeanClassLoader(beanFactory.getBeanClassLoader());
((BundleContextAware) annotationBeanPostProcessor).setBundleContext(bundleContext);
beanFactory.addBeanPostProcessor(annotationBeanPostProcessor);
}
catch (ClassNotFoundException exception) {
log.info("Spring-DM annotation package could not be loaded from bundle ["
+ OsgiStringUtils.nullSafeNameAndSymName(bundle) + "]; annotation processing disabled...");
if (log.isDebugEnabled())
log.debug("Cannot load annotation injection processor", exception);
}
}
示例5: getImplementedRpcServiceInterfaces
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
static List<Class<RpcService>> getImplementedRpcServiceInterfaces(final String interfaceName,
final Class<?> implementationClass, final Bundle bundle, final String logName)
throws ClassNotFoundException {
if (!Strings.isNullOrEmpty(interfaceName)) {
Class<?> rpcInterface = bundle.loadClass(interfaceName);
if (!rpcInterface.isAssignableFrom(implementationClass)) {
throw new ComponentDefinitionException(String.format(
"The specified \"interface\" %s for \"%s\" is not implemented by RpcService \"ref\" %s",
interfaceName, logName, implementationClass));
}
return Collections.singletonList((Class<RpcService>)rpcInterface);
}
List<Class<RpcService>> rpcInterfaces = new ArrayList<>();
for (Class<?> intface : implementationClass.getInterfaces()) {
if (RpcService.class.isAssignableFrom(intface)) {
rpcInterfaces.add((Class<RpcService>) intface);
}
}
if (rpcInterfaces.isEmpty()) {
throw new ComponentDefinitionException(String.format(
"The \"ref\" instance %s for \"%s\" does not implemented any RpcService interfaces",
implementationClass, logName));
}
return rpcInterfaces;
}
示例6: type
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
@Override
public Class<? extends Object> type(ServiceReference obj) {
String[] arr = (String[])obj.getProperty(Constants.OBJECTCLASS);
if (arr.length > 0) {
final Bundle bundle = obj.getBundle();
if (bundle != null) try {
return (Class<?>)bundle.loadClass(arr[0]);
} catch (ClassNotFoundException ex) {
Netigso.LOG.log(Level.INFO, "Cannot load service class", arr[0]); // NOI18N
}
}
return Object.class;
}
示例7: loadClass
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
private static Class<?> loadClass(final String moduleInfoClass, final Bundle bundle) {
try {
return bundle.loadClass(moduleInfoClass);
} catch (final ClassNotFoundException e) {
String errorMessage = logMessage("Could not find class {} in bundle {}, reason {}", moduleInfoClass, bundle,
e);
throw new IllegalStateException(errorMessage);
}
}
示例8: pass
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
public boolean pass(Bundle bundle) {
try {
Class<?> type = bundle.loadClass(NS_HANDLER_RESOLVER_CLASS_NAME);
return NamespaceHandlerResolver.class.equals(type);
} catch (Throwable th) {
// if the interface is not wired, ignore the bundle
log.warn("Bundle " + OsgiStringUtils.nullSafeNameAndSymName(bundle) + " cannot see class ["
+ NS_HANDLER_RESOLVER_CLASS_NAME + "]; ignoring it as a namespace resolver");
return false;
}
}
示例9: findClass
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
protected @Override Class<?> findClass(String name) throws ClassNotFoundException {
for (Bundle b : bundles()) {
try {
return b.loadClass(name);
} catch (ClassNotFoundException x) {
// normal, try next one
}
}
return super.findClass(name);
}
示例10: BlueprintTypeCompatibilityChecker
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
public BlueprintTypeCompatibilityChecker(Bundle extenderBundle) {
try {
containerPkgClass = extenderBundle.loadClass(CONTAINER_PKG_CLASS);
reflectPkgClass = extenderBundle.loadClass(REFLECT_PKG_CLASS);
} catch (ClassNotFoundException cnf) {
throw new IllegalStateException("Cannot load blueprint classes " + cnf);
}
}
示例11: getClassLocation
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
* Returns the ClassLocaton for the specified class name.
* @param className the class name
* @return the class location or null, if the class was not found
*/
public ClassLocaton getClassLocation(String className) {
if (className==null || className.equals("")==true) return null;
// --- Plan A: Try to find class in the AbstractBundleClassFilter -----
ClassLocaton classLocation = null;
for (int i = 0; i < this.size(); i++) {
AbstractBundleClassFilter abcf = this.get(i);
if (abcf!=null) {
classLocation = abcf.getClassLocation(className);
if (classLocation!=null) break;
}
}
// --- Plan B: If not found yet, try using direct bundle access -------
if (classLocation==null) {
Bundle[] bundles = this.bundleEvaluator.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
try {
Class<?> clazz = bundle.loadClass(className);
if (clazz!=null) {
classLocation = new ClassLocaton(className, bundle.getSymbolicName(), null);
break;
}
} catch (ClassNotFoundException cnEx) {
// cnEx.printStackTrace();
}
}
}
return classLocation;
}
示例12: findClass
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
* Tries to find the specified class in the bundle. If the class could not be found, the method returns <code>null</code>.
*
* @param bundle the bundle in which the class should be located
* @param className the class name
* @return the class or <code>null</code>
*/
public Class<?> findClass(Bundle bundle, String className) {
if (bundle!=null) {
try {
Class<?> c = bundle.loadClass(className);
return c;
} catch (ClassNotFoundException e) {
//cnfEx.printStackTrace();
if (this.debug==true) {
System.err.println(this.getClass().getSimpleName() + "#findClass(bundle, className) Could not find class '" + className + "'");
}
}
}
return null;
}
示例13: getModelInitializationMethodName
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
protected String getModelInitializationMethodName(){
String entryPointClassName = null;
final String prefix = "public static void ";
int startName = prefix.length();
int endName = _entryPointMethodText.getText().lastIndexOf("(");
if(endName == -1) return "";
String entryMethod = _entryPointMethodText.getText().substring(startName, endName);
int lastDot = entryMethod.lastIndexOf(".");
if(lastDot != -1){
entryPointClassName = entryMethod.substring(0, lastDot);
}
Bundle bundle = MelangeHelper.getMelangeBundle(_languageCombo.getText());
if(entryPointClassName != null && bundle != null){
try {
Class<?> entryPointClass = bundle.loadClass(entryPointClassName);
for(Method m : entryPointClass.getMethods()){
// TODO find a better search mechanism (check signature, inheritance, aspects, etc)
if(m.isAnnotationPresent(fr.inria.diverse.k3.al.annotationprocessor.InitializeModel.class)){
return entryPointClassName+"."+m.getName();
}
}
} catch (ClassNotFoundException e) {}
}
return "";
}
示例14: createEclipselinkProvider
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static PersistenceProvider createEclipselinkProvider(Bundle b) {
try {
Class<? extends PersistenceProvider> providerClass = (Class<? extends PersistenceProvider>)b.loadClass(Activator.ECLIPSELINK_JPA_PROVIDER_CLASS_NAME);
Constructor<? extends PersistenceProvider> con = providerClass.getConstructor();
return con.newInstance();
} catch (Exception e) {
LOG.debug("Unable to load EclipseLink provider class. Ignoring bundle " + b.getSymbolicName(), e);
return null;
}
}
示例15: isTargetClass
import org.osgi.framework.Bundle; //導入方法依賴的package包/類
private boolean isTargetClass ( final String className, final IContributor contributor, final Class<? extends EObject> clazz )
{
if ( className == null )
{
return false;
}
final Bundle bundle = findBundle ( contributor );
if ( bundle == null )
{
throw new IllegalStateException ( String.format ( "Unable to find bundle '%s'", contributor.getName () ) );
}
try
{
final Class<?> targetClazz = bundle.loadClass ( className );
if ( targetClazz.isAssignableFrom ( clazz ) )
{
return true;
}
}
catch ( final ClassNotFoundException e )
{
throw new IllegalStateException ( String.format ( "Unable to find target class '%s'", className ), e );
}
return false;
}