2013-05-06 18 views

risposta

9

Per fare questo, il metodo più semplice è quello di iniettare bundlecontext nel vostro fagioli

blueprint.xml

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

Il possibile riferimento:

blueprintBundle Fornisce oggetto Bundle di fascio .

blueprintBundleContext Fornisce l'oggetto BundleContext del pacchetto.

blueprintContainer fornisce l'oggetto BlueprintContainer per il pacchetto.

blueprintConverter fornisce l'oggetto Converter per il bundle che fornisce l'accesso alla struttura tipo di conversione Blueprint Container. La conversione del tipo ha più informazioni. fonte: http://www.ibm.com/developerworks/opensource/library/os-osgiblueprint/

E nella tua classe:

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; 
} 
Problemi correlati