本文整理了Java中org.apache.felix.framework.util.Util.loadClassUsingClass()
方法的一些代码示例,展示了Util.loadClassUsingClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.loadClassUsingClass()
方法的具体详情如下:
包路径:org.apache.felix.framework.util.Util
类名称:Util
方法名:loadClassUsingClass
[英]This is a simple utility class that attempts to load the named class using the class loader of the supplied class or the class loader of one of its super classes or their implemented interfaces. This is necessary during service registration to test whether a given service object implements its declared service interfaces.
To perform this test, the framework must try to load the classes associated with the declared service interfaces, so it must choose a class loader. The class loader of the registering bundle cannot be used, since this disallows third parties to register service on behalf of another bundle. Consequently, the class loader of the service object must be used. However, this is also not sufficient since the class loader of the service object may not have direct access to the class in question.
The service object's class loader may not have direct access to its service interface if it extends a super class from another bundle which implements the service interface from an imported bundle or if it implements an extension of the service interface from another bundle which imports the base interface from another bundle. In these cases, the service object's class loader only has access to the super class's class or the extended service interface, respectively, but not to the actual service interface.
Thus, it is necessary to not only try to load the service interface class from the service object's class loader, but from the class loaders of any interfaces it implements and the class loaders of all super classes.
[中]这是一个简单的实用程序类,它试图使用所提供类的类装入器或其一个超类或其实现接口的类装入器来装入命名类。在服务注册期间,这是测试给定服务对象是否实现其声明的服务接口所必需的。
要执行此测试,框架必须尝试加载与声明的服务接口关联的类,因此它必须选择一个类加载器。无法使用注册捆绑包的类加载器,因为这不允许第三方代表另一个捆绑包注册服务。因此,必须使用服务对象的类加载器。然而,这也是不够的,因为服务对象的类加载器可能无法直接访问所讨论的类。
服务对象的类加载器可能无法直接访问其服务接口,如果它从另一个bundle扩展了一个超级类,该bundle从导入的bundle实现了服务接口,或者如果它从另一个bundle实现了服务接口的扩展,该bundle从另一个bundle导入了基本接口。在这些情况下,服务对象的类加载器只能分别访问超类的类或扩展服务接口,而不能访问实际的服务接口。
因此,不仅需要尝试从服务对象的类加载器加载服务接口类,还需要从它实现的任何接口的类加载器和所有超类的类加载器加载服务接口类。
代码示例来源:origin: org.apache.servicemix.kernel/org.apache.servicemix.kernel.main
/**
* This method determines if the class loader of the service object
* has access to the specified class.
* @param clazz the class to test for reachability.
* @return <tt>true</tt> if the specified class is reachable from the
* service object's class loader, <tt>false</tt> otherwise.
**/
protected boolean isClassAccessible(Class clazz)
{
try
{
// Try to load from the service object or service factory class.
Class sourceClass = (m_factory != null)
? m_factory.getClass() : m_svcObj.getClass();
Class targetClass = Util.loadClassUsingClass(sourceClass, clazz.getName());
return (targetClass == clazz);
}
catch (Exception ex)
{
// Ignore this and return false.
}
return false;
}
代码示例来源:origin: org.apache.servicemix.kernel/org.apache.servicemix.kernel.main
private Object getFactoryUnchecked(Bundle bundle)
{
Object svcObj = m_factory.getService(bundle, this);
if (svcObj != null)
{
for (int i = 0; i < m_classes.length; i++)
{
Class clazz = Util.loadClassUsingClass(svcObj.getClass(), m_classes[i]);
if ((clazz == null) || !clazz.isAssignableFrom(svcObj.getClass()))
{
return null;
}
}
}
return svcObj;
}
代码示例来源:origin: org.apache.servicemix.kernel/org.apache.servicemix.kernel.main
for (int i = 0; i < ifcs.length; i++)
loadedClass = loadClassUsingClass(ifcs[i], name);
if (loadedClass != null)
代码示例来源:origin: apache/felix
return Util.loadClassUsingClass(sourceClass, clazz.getName(), Felix.m_secureAction) == clazz;
代码示例来源:origin: apache/felix
for (int i = 0; i < ifcs.length; i++)
loadedClass = loadClassUsingClass(ifcs[i], name, action);
if (loadedClass != null)
代码示例来源:origin: apache/felix
Class clazz = Util.loadClassUsingClass(
svcObj.getClass(), m_classes[i], Felix.m_secureAction);
if ((clazz == null) || !clazz.isAssignableFrom(svcObj.getClass()))
代码示例来源:origin: org.apache.servicemix.kernel/org.apache.servicemix.kernel.main
Class clazz = Util.loadClassUsingClass(svcObj.getClass(), classNames[i]);
if (clazz == null)
代码示例来源:origin: apache/felix
Class clazz = Util.loadClassUsingClass(svcObj.getClass(), classNames[i], m_secureAction);
if (clazz == null)
内容来源于网络,如有侵权,请联系作者删除!