偶也研究OSGi了之一

偶也开始研究OSGi了,这东西真不错。不过官方的OSGi标准包太大了,前两天偶根据规范实现了其Module Layer部分并根据大家提到的一些不足,增加了自定义ClassPath和NativeCode的功能,这下应该可以用在基于Spring的Webapp上了~

不多说了,看看测试代码吧:

java 代码
  1. public class TFramework extends TestCase {      
  2.      
  3.   private Framework framework;      
  4.      
  5.   public void setUp() {      
  6.     framework = new Framework();      
  7.     framework.addFrameworkListener(new IFrameworkListener() {      
  8.       public void frameworkEvent(IFrameworkEvent event) {      
  9.         if (event.getMessage() != null) {      
  10.           System.out.println(event.getMessage());      
  11.         }      
  12.         if (event.getThrowable() != null) {      
  13.           event.getThrowable().printStackTrace();      
  14.         }      
  15.       }      
  16.     });      
  17.   }      
  18.      
  19.   public void tearDown() {      
  20.     framework = null;      
  21.     System.out.println();      
  22.   }      
  23.      
  24.   public void testBundle() throws Exception {      
  25.      
  26.     framework.addClassPath("C:\\osgi\\ws\\commons-logging.jar");      
  27.     framework.addLibraryPath("C:\\osgi\\os");      
  28.      
  29.     // ----------------------------------------------   
  30.     // Bundle-SymbolicName: com.yipsilon.osgi.test   
  31.     // Bundle-Version: 1.0.0.20061212   
  32.     // Bundle-NativeCode: swt-gdip-win32-3235.dll,swt-awt-win32-3235.dll,swt-wgl-win32-3235.dll,swt-win32-3235.dll   
  33.     // Bundle-Activator: com.yipsilon.osgi.test.Activator   
  34.     // Export-Package: com.yipsilon.osgi.test   
  35.     // Import-Package: org.apache.commons.logging   
  36.     // Bundle-ClassPath: swt.3.2.1.v3235.jar   
  37.     // ----------------------------------------------   
  38.   
  39.     framework.installBundle("C:\\osgi\\test.jar");      
  40.      
  41.     ClassLoader cl = framework.getClassLoader();      
  42.      
  43.     URL explicitURL = cl.getResource("com/yipsilon/osgi/test/Test.class");      
  44.     URL implicitURL = cl.getResource("com/yipsilon/osgi/test1/Hello.class");      
  45.     URL externalURL = cl.getResource("org/apache/commons/logging/LogFactory.class");      
  46.      
  47.     System.out.println("implicitURL: " + (implicitURL != null));  // Returns true      
  48.     System.out.println("explicitURL: " + (explicitURL != null)); // Returns true      
  49.     System.out.println("externalURL: " + (externalURL != null)); // Returns true      
  50.      
  51.     Class explicitClass = cl.loadClass("com.yipsilon.osgi.test.Test");      
  52.     Class implicitClass = cl.loadClass("com.yipsilon.osgi.test1.Hello");      
  53.     Class externalClass = cl.loadClass("org.apache.commons.logging.LogFactory");      
  54.      
  55.     System.out.println("implicitClass: " + (implicitClass != null)); // Returns false      
  56.     System.out.println("explicitClass: " + (explicitClass != null)); // Returns true      
  57.     System.out.println("externalClass: " + (externalClass != null)); // Returns true      
  58.   }      
  59. }  

看完了知道这东西该怎么用了吧... 嘿嘿!!

不过要真正实现Webapp功能,还需要加一些东西,这些稍后我会开发出来~~进度的快慢全凭偶的空闲时间的多少... faint

PS:怎么附件加不进去呐??才1.5MB而已....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值