论坛首页 Java企业应用论坛

偶也研究OSGi了之一

浏览 9011 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-12-28  
SOA

偶也开始研究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而已....

   发表时间:2006-12-28  
很不错的东东,i like it!
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics