当前位置: 首页>>代码示例>>Java>>正文


Java Bundle.loadClass方法代码示例

本文整理汇总了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
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:41,代码来源:UtilN4.java

示例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;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:NetigsoLoader.java

示例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;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:26,代码来源:BundleEvaluator.java

示例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);
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:24,代码来源:OsgiAnnotationPostProcessor.java

示例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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:32,代码来源:RpcImplementationBean.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:NetigsoServices.java

示例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);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:ModuleInfoBundleTracker.java

示例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;
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:13,代码来源:NamespacePlugins.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:OSGiClassLoader.java

示例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);
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:9,代码来源:BlueprintTypeCompatibilityChecker.java

示例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;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:38,代码来源:EvaluationFilterResults.java

示例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;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:22,代码来源:BundleEvaluator.java

示例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 "";
}
 
开发者ID:eclipse,项目名称:gemoc-studio-modeldebugging,代码行数:30,代码来源:LaunchConfigurationMainTab.java

示例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;
    }
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:12,代码来源:Activator.java

示例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;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:29,代码来源:ValidationRunner.java


注:本文中的org.osgi.framework.Bundle.loadClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。