Affichage d'une map avec osgi

mb42 Messages postés 553 Statut Membre -  
mb42 Messages postés 553 Statut Membre -
Bonjour,

mon but est d'afficher une map avec une programmation par composant en utilisant OSGI et la notion de bundle

les outils de cette application eclipse,apache karaf

pour commencer j'arrive à afficher une map avec la notion de bundle

le code de cette application est le suivant :

pour la class :JGoogleMapEditorPan.java

import java.util.logging.Level; 
import java.util.logging.Logger; 
import javax.swing.JEditorPane; 
import javax.swing.JFrame; 
import javax.swing.text.html.HTMLDocument; 
import javax.swing.text.html.HTMLEditorKit; 
  
/** 
 * Afficher une carte GoogleMap dans un JEditorPane 
 * @author fobec 2010 
 */ 
public class JGoogleMapEditorPan extends JEditorPane { 
  
    private int zoomFactor = 7; 
    private String ApiKey = ""; 
    private String roadmap = "roadmap"; 
    public final String viewTerrain = "terrain"; 
    public final String viewSatellite = "satellite"; 
    public final String viewHybrid = "hybrid"; 
    public final String viewRoadmap = "roadmap"; 
  
    /** 
     * Constructeur: initialisation du EditorKit 
     */ 
    public JGoogleMapEditorPan() { 
        HTMLEditorKit kit = new HTMLEditorKit(); 
        HTMLDocument htmlDoc = (HTMLDocument) kit.createDefaultDocument(); 
        this.setEditable(false); 
        this.setContentType("text/html"); 
        this.setEditorKit(kit); 
        this.setDocument(htmlDoc); 
    } 
  
    /** 
     * Fixer le zoom 
     * @param zoom valeur de 0 à 21 
     */ 
    public void setZoom(int zoom) { 
        this.zoomFactor = zoom; 
    } 
  
    /** 
     * Fixer la clé de developpeur 
     * @param key APIKey fourni par Google 
     */ 
    public void setApiKey(String key) { 
        this.ApiKey = key; 
    } 
  
    /** 
     * Fixer le type de vue 
     * @param roadMap 
     */ 
    public void setRoadmap(String roadMap) { 
        this.roadmap = roadMap; 
    } 
  
    /** 
     * Afficher la carte d'après des coordonnées GPS 
     * @param latitude 
     * @param longitude 
     * @param width 
     * @param height 
     * @throws Exception erreur si la APIKey est non renseignée 
     */ 
    public void showCoordinate(String latitude, String longitude, int width, int height) throws Exception { 
        this.setMap(latitude, longitude, width, height); 
    } 
  
    /** 
     * Afficher la carte d'après une ville et son pays 
     * @param city 
     * @param country 
     * @param width 
     * @param height 
     * @throws Exception erreur si la APIKey est non renseignée 
     */ 
    public void showLocation(String city, String country, int width, int height) throws Exception { 
        this.setMap(city, country, width, height); 
    } 
  
    /** 
     * Assembler l'url et Générer le code HTML 
     * @param x 
     * @param y 
     * @param width 
     * @param height 
     * @throws Exception 
     */ 
    private void setMap(String x, String y, Integer width, Integer height) throws Exception { 
        if (this.ApiKey.isEmpty()) { 
            throw new Exception("Developper API Key not set !!!!"); 
        } 
  
        String url = "http://maps.google.com/maps/api/staticmap?"; 
        url += "center=" + x + "," + y; 
        url += "&zoom=" + this.zoomFactor; 
        url += "&size=" + width.toString() + "x" + height.toString(); 
        url += "&maptype=" + this.roadmap; 
        url += "&markers=color:blue" + x + "," + y; 
        url += "&sensor=false"; 
        url += "&key=" + this.ApiKey; 
  
        String html = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>"; 
        html += "<html><head></head><body>"; 
        html += "<img src='" + url + "'>"; 
        html += "</body></html>"; 
        this.setText(html); 
    } 
  
  
  
}


et pour la class Activator.java

import java.util.logging.Level; 
import java.util.logging.Logger; 
  
import javax.swing.JFrame; 
  
import org.osgi.framework.BundleActivator; 
import org.osgi.framework.BundleContext; 
  
public class Activator implements BundleActivator { 
  
  
  
 public void start(BundleContext context) throws Exception { 
  
  
   JGoogleMapEditorPan googleMap = new JGoogleMapEditorPan(); 
  
  
  
   try { 
             googleMap.setApiKey("maCleGoogleMap"); 
             //  googleMap.setRoadmap(googleMap.viewHybrid); 
  
             /** 
             Afficher la ville de Strabourg 
              */ 
             googleMap.showLocation("strasbourg", "france", 390, 400); 
             /** 
              * Afficher Paris en fonction ses coordonnées GPS 
              */ 
             //  googleMap.showCoordinate("48.8667", "2.3333",390, 400); 
         } catch (Exception ex) { 
             Logger.getLogger(JGoogleMapEditorPan.class.getName()).log(Level.SEVERE, null, ex); 
         } 
  
         JFrame frame = new JFrame(); 
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
         frame.add(googleMap); 
         frame.setSize(400, 420); 
         frame.setLocation(200, 200); 
         frame.setVisible(true); 
  
  
  
  
  
  
  
  
 } 
  
  
 public void stop(BundleContext context) throws Exception { 
  
 } 
}


et pour MANIFEST.MF



Manifest-Version: 1.0 
Bundle-ManifestVersion: 2 
Bundle-Name: Mybundle 
Bundle-SymbolicName: com.test.mybundle 
Bundle-Version: 1.0.0.qualifier 
Bundle-Activator: com.test.mybundle.Activator 
Bundle-Vendor: TEST 
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 
import-Package: org.osgi.framework;version="1.3.0"


mais le problème est si je fait l'exécution de cette application :
RUN AS-->OSGI framwork la map est afficher

mais le but est d'afficher la map si je tape "START" dans le console

et de fermer cette map si je tappe "STOP"

pour le moment si je tape "START " la reponse est :

osgi> start
No bundle(s) specified!

merci d'avance
A voir également:

1 réponse

mb42 Messages postés 553 Statut Membre 7
 
eut être j'ai déjà mis une erreur lors de démarrage de bundle

en faite le nom de projet est : com.test.mybundle

après l'exécution de projet :

MANIFEST.MF -->run as --> OSGI framwork

la map est affichée (map avec swing)

après je tape : stop com.test.mybundle

et après je tape : start com.esprit.mybundle

à cette instant une nouvelle fenêtre de map est affichée

comme je dis le but est d'exécuter cette application avec apache karaf

pour cela je dois exporter cette application

en faite j'arrive à l'exporter :

export --> depoyable plug-ins and fragment --> com.test.mybundle --> destination ( C:\)

pour karaf je télécharge la version karaf 2.2.5 de cet url :http://karaf.apache.org/index/community/download.html

et pour la version d'eclipse je travail avec : Eclipse Java EE IDE for Web Developers

donc le problème est comment exécuter l'application avec karaf

et s'il y'a une configuration pour karaf n'hésiter pas à m'aidez

je travail avec un système windows
merci d'avance
0