- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在将现有代码转换为 OSGi 环境。在我们的一个(尚未成为)OSGi 包中,我们有执行 XSLT 转换的代码。一段 XSLT 包括一个 java 扩展函数来创建一个唯一的数值。 Java 类也驻留在包中。这是样式表的片段:
<xsl:template match="m:property">
<xsl:variable name="uniqueDataStreamName" select="concat(../@id,'/',@name)" />
<xsl:variable name="uniqueDataStreamId"
select="java:com.xyz.TransformationUtils.makeDataStreamIdFromUniqueName($uniqueDataStreamName)" />
<data id="{number($uniqueDataStreamId)}">
<tag>
<xsl:value-of select="$uniqueDataStreamName" />
</tag>
<current_value>
<xsl:value-of select="@value" />
</current_value>
</data>
作为引用,这是转换的设置和调用方式:
protected Templates createTemplates(Source xsltSource) {
try {
TransformerFactory tf = TransformerFactory.newInstance();
Templates templates = tf.newTemplates(xsltSource);
return templates;
} catch (TransformerException e) {
throw new RuntimeException(e);
}
}
protected byte[] transform(byte[] input) throws TransformerException {
ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
templates.newTransformer().transform(
new StreamSource(new ByteArrayInputStream(input)),
new StreamResult(out));
return out.toByteArray();
}
在非 OSGi 环境中运行时,它可以工作。当在 OSGi 框架中运行时,它会失败,因为无法编译样式表,因为找不到类 TransformationUtils。我有点理解——加载 jaxp 转换器实现的类加载器在我们的包中看不到扩展类。但是,我很难找到解决方案。我试过使用 OSGi:fied Xalan 和 Xerces 包,但无济于事。
我的问题是:如何解决这个问题?可以吗?
最佳答案
答案取决于 XSLT 处理器如何查找扩展类。您可能需要阅读源代码和/或通过调试器运行它才能找到答案。
例如,如果 XSLT 处理器使用线程上下文类加载器 (TCCL),那么这通常会失败,因为 TCCL 在 OSGi 中未定义。您可以通过在调用 XSLT 处理器期间显式设置 TCCL 来解决此问题,例如:
ClassLoader orig = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(MyClass.class.getClassLoader());
try {
// invoke XSLT processor
} finally {
Thread.currentThread.setContextClassLoader(orig);
}
其中 MyClass
是您的包中的一个类,并且具有扩展类的可见性。
在最坏的情况下,处理器可能会使用自己的类加载器查找扩展,即通过简单调用 Class.forName()
。在这里做的最好的事情就是痛打图书馆的开发者,因为他们太愚蠢了。完成后,您可以使用片段将扩展类附加到处理器包……这是一个令人讨厌的 hack,但比其他一些可能的令人讨厌的 hack 更好。
关于osgi - 如何从 OSGi Bundle 中使用 Java 扩展执行 XSLT 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7380753/
我在 trying to share the Struts packages 时遇到了这个问题在 OSGi 容器内的多个包之间。我想避免在包内重复依赖项并在它们之间引入新的依赖项(通过让一个包导出其内
我正在考虑在我们的项目中管理版本控制的最佳方式。目前,我们 bundle 中的每个包都是导出的(这将在以后改进,所以不要因为这个失礼而挂断电话)。我们正在使用 maven-bundle-plugin,
我正在进行一个项目,我们将迁移基于大量定制技术的主要软件系统,使其基于 OSGi 服务。为此,我们可能需要某种与 OSGi 服务配合良好的消息总线。 同步和异步传送 仅点对点 保证交付 - 最好通过文
我的项目有一组自定义定义的注释,它们可以出现在 OSGi 4.3 框架中部署的任何包中。我想在类路径中找到任何带有这些注释的类。我尝试使用 BundleWiring.listResources(...
我创建了一个片段包来访问一些添加到第二方 jar 的功能。我的片段应该注册一个服务来公开这个新功能。它似乎不起作用。在我深入进行故障排除之前,我想知道这是否被允许?也就是说,Felix SCR 的 b
OSGi 是 Java 的动态模块化系统。好的,但是基线主题是什么,为什么要开发 OSGi?使用 OSGi 有什么好处?开发 OSGi 的主要故事是什么?它为什么存在? 最佳答案 如果你仔细观察,Ja
当一个包被更新(比如修复一个错误)时,当前正在使用正在更新的包的其他包会发生什么? 假设有两个捆绑包 service 和 dao。假设当我发出更新 dao 层的命令时,服务包中的类正在使用 dao 包
在 OSGi 下,组件与服务之间的主要区别是什么?据我了解,所有服务都必须是组件,但并非所有组件都必须是服务。 在示例用例中使用其中一种比另一种有什么好处? 最佳答案 “组件”的定义不如服务正式。 服
这合法吗?org.fragment1 的 MANIFEST.MF(org.host 是普通包,不是片段): Bundle-SymbolicName: org.fragment1 Fragment-Ho
在我当前的应用程序中,我在几个地方遇到了这种模式:我在一个 bundle 中有两个服务接口(interface),它们执行不同但相关的工作。 interface Service1 { ... } in
我的 OSGi 应用程序需要一个 jar(sample;version=A),并且我必须将相同的 jar(sample;version=B) 用于我开发的新包。 示例 jar 有一些增强功能,因此我不
osgi> install file:D:\f1\*.jar osgi> install --start file:D:\f1\*.jar 以上命令在 WSO2 OSGi 控制台中是非法的。如何从文件
和有什么不一样和 在spring DM的xml配置文件中。 最佳答案 可用于获取 对现有 OSGi 服务的引用,以便您的 bean 可以使用它。 可用于导出将 bean 作为 OSGi 服务,以
我有一个应用程序暂时使用 Equinox 作为 osgi 框架。直到现在我都使用系统属性 osgi.install.area 来指定我的包在哪里 ${osgi.install.area}/ plu
背景 在过去一年左右的时间里,我设计了许多工具,旨在帮助我为 XPage 编程。这些工具主要包括帮助程序 java 类、扩展日志记录(使用 OpenLogger 和我自己的东西),以及我个人觉得我不能
我有一个 OSGi 组件 MyComponent . 该组件引用了服务 MyService .现在MyService有几个实现 MyServiceImpl1和 MyServiceImpl2 . MyC
我有几个 OSGi 包,每个都可以从 OSGi 包存储库更新。 当我启动我的 OSGi 框架 (Apache Felix) 时,我希望第一个包启动并检查所有已安装包的更新。如果有可用更新,它应该更新每
当我们在 Apache Felix Web OSGi 控制台的配置选项卡中更新组件的任何配置时,这些配置设置保存在哪里?这是针对 AEM 6.0 或更高版本。 最佳答案 手动保存的配置设置存储在 cr
我有简单的 OSGI 事件监听器类 @Component(immediate = true) @Service(value = { EventHandler.class, JobConsumer.cl
我们正在开发一个网络应用程序(我们称之为图像库),我们已经确定了以下需求: 该应用程序迎合由一组用户组成的客户。 可以动态创建新客户并由客户管理其用户 客户有不同的功能集,可以动态更改 客户可以开发自
我是一名优秀的程序员,十分优秀!