2013-05-06 13 views

答えて

9

、簡単な方法は、あなたの豆

blueprint.xml

<bean id="plugin" class="com.timactive.MyBean" init-method="start"> 
    <property name="bcontext" ref="blueprintBundleContext"></property> 
</bean> 

可能な参照にbundlecontextを注入することである。

blueprintBundle バンドルのバンドルオブジェクトを提供します。

blueprintBundleContext バンドルのBundleContextオブジェクトを提供します。

blueprintContainer バンドルにBlueprintContainerオブジェクトを提供します。

blueprintConverterブループリントコンテナの型変換機能へのアクセスを提供するバンドルのConverterオブジェクトを提供します。型変換にはより多くの情報があります。 ソース:http://www.ibm.com/developerworks/opensource/library/os-osgiblueprint/

そして、あなたのクラスで:

import org.osgi.framework.Bundle; 
import org.osgi.framework.BundleContext 
public class MyBean { 

    public BundleContext bcontext; 
    public boolean start(){ 
    try { 
    Bundle bundle = bcontext.getBundle(); 
    InputStream is = bundle.getEntry("/file.json").openStream(); 
    String jsondb = readFile(is); 

    } catch (IOException e) { 
       LOG.error("The file treefield.json not found", e); 
       return(false); 
      } 

     } 

     return(true); 
    } 

    private String readFile(InputStream is) throws IOException { 
     java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); 
     return s.hasNext() ? s.next() : ""; 
    } 
    public void setBcontext(BundleContext bcontext) { 
    this.bcontext = bcontext; 
} 
関連する問題