2013-05-06 3 views

ответ

9

Чтобы сделать это, легкий способ придать bundlecontext в вашем боба

blueprint.xml

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

Возможная ссылка:

blueprintBundle Предоставляет объект Bundle Bundle в ,

blueprintBundleContext Предоставляет объект BundleContext пакета.

blueprintContainer Предоставляет объект BlueprintContainer для комплекта.

blueprintConverter Предоставляет объект конвертер для пучка, который обеспечивает доступ к конверсии типа объекта Blueprint Container. Преобразование типа имеет более подробную информацию. источник: 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; 
}