2013-05-06 8 views

Antwort

9

Um dies zu tun, ist die einfache Methode Bundlecontext in Ihrem Bean

blueprint.xml

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

Der mögliche Bezug zu injizieren:

blueprintBundle Bietet Bundle Bundle-Objekt .

blueprintBundleContext Stellt das BundleContext-Objekt des Bundles bereit.

blueprintContainer Stellt das BlueprintContainer-Objekt für das Bundle bereit.

blueprintConverter Bietet das Converter-Objekt für das Bündel, das den Zugang zur Blueprint Container Typ-Umwandlungsanlage zur Verfügung stellt. Die Typkonvertierung enthält mehr Informationen. Quelle: http://www.ibm.com/developerworks/opensource/library/os-osgiblueprint/

Und in Ihrer Klasse:

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; 
} 
Verwandte Themen