From 91fc545b5951fed72292505c747c22b423770657 Mon Sep 17 00:00:00 2001 From: wyc20131204 Date: Wed, 12 Mar 2014 22:27:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0fixflow-core=E5=92=8Cexpand?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=AF=B9OSGI=E9=A1=B9=E7=9B=AE=E7=9A=84?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主要是在OSGI项目中,文件路径都变成一个 bundleresource:\222.33\com.....core.impl的路径,改路径只能被OSGI的框架识别,需要将这个路径转化为本地路径,通过eclipse的org.eclipse.core.runtime.FileLocator类可以实现转换,转换以后就变成D:/bin/....这种本地文件路径了。通过加入判断,core和expand可直接运行在OSGI项目中和bundle工程中。 --- .../impl/ProcessEngineConfigurationImpl.java | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/fixflow-core/src/com/founder/fix/fixflow/core/impl/ProcessEngineConfigurationImpl.java b/fixflow-core/src/com/founder/fix/fixflow/core/impl/ProcessEngineConfigurationImpl.java index a14325c8..4260d5c7 100644 --- a/fixflow-core/src/com/founder/fix/fixflow/core/impl/ProcessEngineConfigurationImpl.java +++ b/fixflow-core/src/com/founder/fix/fixflow/core/impl/ProcessEngineConfigurationImpl.java @@ -37,6 +37,7 @@ import org.dom4j.Document; import org.dom4j.Element; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; @@ -275,9 +276,16 @@ private void initRulesConfig() { for (RulesResource rulesResource : rulesResources) { String classPath = rulesResource.getSrc(); Document document = null; + String filePath = this.getClass().getClassLoader().getResource(classPath).toString(); try { - InputStream in = ReflectUtil.getResourceAsStream(classPath); - document = XmlUtil.read(in); + //用于处理osgi项目文件加载 + if(filePath.startsWith("bundleresource")){ + InputStream in = new FileInputStream(FileLocator.toFileURL(this.getClass().getClassLoader().getResource(classPath)).toString().substring(6)); + document = XmlUtil.read(in); + }else{ + InputStream in = ReflectUtil.getResourceAsStream(classPath); + document = XmlUtil.read(in); + } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -483,16 +491,24 @@ private void initDataVariableConfig() { String filePath = this.getClass().getClassLoader().getResource(classPath).toString(); Resource resource = null; try { - if (!filePath.startsWith("jar")) { - filePath = java.net.URLDecoder.decode(ReflectUtil.getResource(classPath).getFile(), "utf-8"); - resource = resourceSet.createResource(URI.createFileURI(filePath)); - } else { - resource = resourceSet.createResource(URI.createURI(filePath)); + //用于处理osgi项目文件加载 + if(filePath.startsWith("bundleresource")){ + resource = resourceSet.createResource(URI.createURI(FileLocator.toFileURL(this.getClass().getClassLoader().getResource(classPath)).toString())); + } + else if(filePath.startsWith("jar")) { + resource = resourceSet.createResource(URI.createURI(filePath)); + } + else{ + filePath = java.net.URLDecoder.decode(ReflectUtil.getResource(classPath).getFile(), "utf-8"); + resource = resourceSet.createResource(URI.createFileURI(filePath)); } } catch (UnsupportedEncodingException e2) { e2.printStackTrace(); throw new FixFlowException("流程配置文件加载失败!", e2); + }catch (IOException e) { + e.printStackTrace(); + throw new FixFlowException("bundle项目文件路径获取失败!", e); } // register package in local resource registry @@ -557,16 +573,24 @@ protected void initEmfFile() { String filePath = this.getClass().getClassLoader().getResource(classPath).toString(); Resource resource = null; try { - if (!filePath.startsWith("jar")) { + //用于处理osgi项目文件加载 + if(filePath.startsWith("bundleresource")){ + resource = resourceSet.createResource(URI.createURI(FileLocator.toFileURL(this.getClass().getClassLoader().getResource(classPath)).toString())); + } + else if(filePath.startsWith("jar")) { + resource = resourceSet.createResource(URI.createURI(filePath)); + } + else{ filePath = java.net.URLDecoder.decode(ReflectUtil.getResource(classPath).getFile(), "utf-8"); resource = resourceSet.createResource(URI.createFileURI(filePath)); - } else { - resource = resourceSet.createResource(URI.createURI(filePath)); } } catch (UnsupportedEncodingException e2) { e2.printStackTrace(); throw new FixFlowException("流程配置文件加载失败!", e2); + }catch (IOException e) { + e.printStackTrace(); + throw new FixFlowException("bundle项目文件路径获取失败!", e); } // register package in local resource registry