2013-05-06 8 views

Odpowiedz

9

Aby to zrobić, łatwa metoda jest wstrzykiwać bundlecontext w fasoli

blueprint.xml

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

Ewentualny referencyjny:

blueprintBundle Zapewnia Bundle Bundle za przedmiot .

blueprintBundleContext Udostępnia obiekt BundleContext pakietu.

blueprintContainerUdostępnia obiekt pakietu BlueprintContainer dla pakietu.

blueprintConverter Udostępnia obiekt konwertera dla pakietu, który zapewnia dostęp do obiektu konwersji typu Blueprint Container. Konwersja typów zawiera więcej informacji. źródło: http://www.ibm.com/developerworks/opensource/library/os-osgiblueprint/

A w swojej klasie:

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; 
} 
Powiązane problemy