Ignore:
Timestamp:
2012-03-23T21:49:59+01:00 (12 years ago)
Author:
donvip
Message:

opendata: change in handlers management (use of classes instead of objects) to allow several instances of the same handler

Location:
applications/editors/josm/plugins/opendata
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/modules/be.bruxelles/src/org/openstreetmap/josm/plugins/opendata/modules/be/bruxelles/BruxellesModule.java

    r28000 r28143  
    2424        public BruxellesModule(ModuleInformation info) {
    2525                super(info);
    26                 handlers.add(new BDHandler());
     26                handlers.add(BDHandler.class);
    2727    }
    2828}
  • applications/editors/josm/plugins/opendata/modules/be.datagovbe/src/org/openstreetmap/josm/plugins/opendata/modules/be/datagovbe/DataGovBeModule.java

    r28000 r28143  
    2424        public DataGovBeModule(ModuleInformation info) {
    2525                super(info);
    26                 handlers.add(new ArchitecturalHeritageHandler());
     26                handlers.add(ArchitecturalHeritageHandler.class);
    2727    }
    2828}
  • applications/editors/josm/plugins/opendata/modules/fr.cg41/src/org/openstreetmap/josm/plugins/opendata/modules/fr/cg41/Cg41Module.java

    r28000 r28143  
    2525        public Cg41Module(ModuleInformation info) {
    2626                super(info);
    27                 handlers.add(new ArretsBusHandler());
    28                 handlers.add(new ZonesInondablesBrayeHandler());
     27                handlers.add(ArretsBusHandler.class);
     28                handlers.add(ZonesInondablesBrayeHandler.class);
    2929    }
    3030}
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/DataGouvFrModule.java

    r28142 r28143  
    3636        public DataGouvFrModule(ModuleInformation info) {
    3737                super(info);
    38         handlers.add(new Etab1er2ndDegreHandler());
    39         handlers.add(new EtabAEFEHandler());
    40         handlers.add(new BibliothequesHandler());
    41         handlers.add(new EtabSupHandler());
    42         handlers.add(new AssainissementHandler());
    43         handlers.add(new RegistreParcellaireHandler());
    44         handlers.add(new GeoFlaHandler());
    45         handlers.add(new PassageNiveauHandler());
    46         handlers.add(new ROEHandler());
    47         handlers.add(new ForetsPubliquesHandler());
    48         handlers.add(new ReservesBiologiquesHandler());
    49         handlers.add(new EauxDeSurfaceHandler());
    50         handlers.add(new InventaireForestierNationalHandler());
     38        handlers.add(Etab1er2ndDegreHandler.class);
     39        handlers.add(EtabAEFEHandler.class);
     40        handlers.add(BibliothequesHandler.class);
     41        handlers.add(EtabSupHandler.class);
     42        handlers.add(AssainissementHandler.class);
     43        handlers.add(RegistreParcellaireHandler.class);
     44        handlers.add(GeoFlaHandler.class);
     45        handlers.add(PassageNiveauHandler.class);
     46        handlers.add(ROEHandler.class);
     47        handlers.add(ForetsPubliquesHandler.class);
     48        handlers.add(ReservesBiologiquesHandler.class);
     49        handlers.add(EauxDeSurfaceHandler.class);
     50        handlers.add(InventaireForestierNationalHandler.class);
    5151    }
    5252}
  • applications/editors/josm/plugins/opendata/modules/fr.lemans/src/org/openstreetmap/josm/plugins/opendata/modules/fr/lemans/LeMansModule.java

    r28091 r28143  
    3030        public LeMansModule(ModuleInformation info) {
    3131                super(info);
    32                 handlers.add(new ServicesCommunautairesMunicipauxHandler());
    33                 handlers.add(new CantonsSartheHandler());
    34                 handlers.add(new CommunesHandler());
    35                 handlers.add(new CodesPostauxHandler());
    36                 handlers.add(new CirconscriptionsLegislativesHandler());
    37                 handlers.add(new ConseilsQuartiersHandler());
    38                 handlers.add(new PointsApportVolontaireHandler());
     32                handlers.add(ServicesCommunautairesMunicipauxHandler.class);
     33                handlers.add(CantonsSartheHandler.class);
     34                handlers.add(CommunesHandler.class);
     35                handlers.add(CodesPostauxHandler.class);
     36                handlers.add(CirconscriptionsLegislativesHandler.class);
     37                handlers.add(ConseilsQuartiersHandler.class);
     38                handlers.add(PointsApportVolontaireHandler.class);
    3939    }
    4040}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/ParisModule.java

    r28000 r28143  
    2424        public ParisModule(ModuleInformation info) {
    2525                super(info);
    26         handlers.add(new SanisettesHandler());
     26        handlers.add(SanisettesHandler.class);
    2727    }
    2828}
  • applications/editors/josm/plugins/opendata/modules/fr.sncf/src/org/openstreetmap/josm/plugins/opendata/modules/fr/sncf/SncfModule.java

    r28000 r28143  
    2424        public SncfModule(ModuleInformation info) {
    2525                super(info);
    26                 handlers.add(new EquipementsHandler());
     26                handlers.add(EquipementsHandler.class);
    2727    }
    2828}
  • applications/editors/josm/plugins/opendata/modules/fr.toulouse/src/org/openstreetmap/josm/plugins/opendata/modules/fr/toulouse/ToulouseModule.java

    r28096 r28143  
    6161        public ToulouseModule(ModuleInformation info) {
    6262                super(info);
    63         handlers.add(new SanisetteHandler());
    64         handlers.add(new NumerosRueHandler());
    65         handlers.add(new CommuneHandler());
    66         handlers.add(new VoirieHandler());
    67         handlers.add(new Zone30Handler());
    68         handlers.add(new HorodateurHandler());
    69         handlers.add(new VeloToulouseHandler());
    70         handlers.add(new AltimetrieVoieHandler());
    71         handlers.add(new MetroStationHandler());
    72         handlers.add(new TramwayStationHandler());
    73         handlers.add(new Parcelles1680Handler());
    74         handlers.add(new Parcelles1830Handler());
    75         handlers.add(new PMRHandler());
    76         handlers.add(new PistesCyclablesHandler());
    77         handlers.add(new BureauxVoteHandler());
    78         handlers.add(new Club3eAgeHandler());
    79         handlers.add(new CrechesHandler());
    80         handlers.add(new EcoleElementaireHandler());
    81         handlers.add(new EcoleMaternelleHandler());
    82         handlers.add(new LudothequeHandler());
    83         handlers.add(new MairieHandler());
    84         handlers.add(new MairieAnnexeHandler());
    85         handlers.add(new BibliothequesHandler());
    86         handlers.add(new MuseeHandler());
    87         handlers.add(new PolesTerritoriauxHandler());
    88         handlers.add(new QuartiersHandler());
    89         handlers.add(new SecteursHandler());
    90         handlers.add(new StationEpurationHandler());
    91         handlers.add(new TheatreHandler());
    92         handlers.add(new RecupEmballageHandler());
    93         handlers.add(new RecupVerreHandler());
    94         handlers.add(new ReseauTisseoHandler());
    95         handlers.add(new EcoleBalmaHandler());
    96         handlers.add(new PetiteEnfanceEtJeunesseBalmaHandler());
    97         handlers.add(new EquipementCulturelBalmaHandler());
    98         handlers.add(new InstallationSportiveBalmaHandler());
    99         handlers.add(new ChantiersPonctuelsHandler());
    100         handlers.add(new ChantiersLineairesHandler());
     63        handlers.add(SanisetteHandler.class);
     64        handlers.add(NumerosRueHandler.class);
     65        handlers.add(CommuneHandler.class);
     66        handlers.add(VoirieHandler.class);
     67        handlers.add(Zone30Handler.class);
     68        handlers.add(HorodateurHandler.class);
     69        handlers.add(VeloToulouseHandler.class);
     70        handlers.add(AltimetrieVoieHandler.class);
     71        handlers.add(MetroStationHandler.class);
     72        handlers.add(TramwayStationHandler.class);
     73        handlers.add(Parcelles1680Handler.class);
     74        handlers.add(Parcelles1830Handler.class);
     75        handlers.add(PMRHandler.class);
     76        handlers.add(PistesCyclablesHandler.class);
     77        handlers.add(BureauxVoteHandler.class);
     78        handlers.add(Club3eAgeHandler.class);
     79        handlers.add(CrechesHandler.class);
     80        handlers.add(EcoleElementaireHandler.class);
     81        handlers.add(EcoleMaternelleHandler.class);
     82        handlers.add(LudothequeHandler.class);
     83        handlers.add(MairieHandler.class);
     84        handlers.add(MairieAnnexeHandler.class);
     85        handlers.add(BibliothequesHandler.class);
     86        handlers.add(MuseeHandler.class);
     87        handlers.add(PolesTerritoriauxHandler.class);
     88        handlers.add(QuartiersHandler.class);
     89        handlers.add(SecteursHandler.class);
     90        handlers.add(StationEpurationHandler.class);
     91        handlers.add(TheatreHandler.class);
     92        handlers.add(RecupEmballageHandler.class);
     93        handlers.add(RecupVerreHandler.class);
     94        handlers.add(ReseauTisseoHandler.class);
     95        handlers.add(EcoleBalmaHandler.class);
     96        handlers.add(PetiteEnfanceEtJeunesseBalmaHandler.class);
     97        handlers.add(EquipementCulturelBalmaHandler.class);
     98        handlers.add(InstallationSportiveBalmaHandler.class);
     99        handlers.add(ChantiersPonctuelsHandler.class);
     100        handlers.add(ChantiersLineairesHandler.class);
    101101    }
    102102}
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java

    r28091 r28143  
    2828import java.util.Map;
    2929
    30 import javax.swing.ImageIcon;
    3130import javax.swing.JMenu;
    3231import javax.swing.JMenuItem;
     
    6059import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler;
    6160import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleInformation;
    62 import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils;
    6361import org.openstreetmap.josm.tools.Pair;
    6462
     
    115113                Map<DataSetCategory, JMenu> catMenus = new HashMap<DataSetCategory, JMenu>();
    116114                JMenu moduleMenu = null;
    117                 for (AbstractDataSetHandler handler: module.getHandlers()) {
     115                for (AbstractDataSetHandler handler: module.getNewlyInstanciatedHandlers()) {
    118116                        if (handler.getDataURL() != null || (handler.getDataURLs() != null && !handler.getDataURLs().isEmpty())) {
    119117                                if (moduleMenu == null) {
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataTask.java

    r28113 r28143  
    6666                this.handler = null;
    6767                for (Module module : ModuleHandler.moduleList) {
    68                         for (AbstractDataSetHandler handler : module.getHandlers()) {
     68                        for (AbstractDataSetHandler handler : module.getNewlyInstanciatedHandlers()) {
    6969                                if (handler.acceptsUrl(url)) {
    7070                                        this.handler = handler;
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/AbstractImporter.java

    r28044 r28143  
    4444    protected final AbstractDataSetHandler findDataSetHandler(File file) {
    4545        for (Module module : ModuleHandler.moduleList) {
    46                         for (AbstractDataSetHandler dsh : module.getHandlers()) {
     46                        for (AbstractDataSetHandler dsh : module.getNewlyInstanciatedHandlers()) {
    4747                                if (dsh.acceptsFile(file)) {
    4848                                        return dsh;
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/AbstractModule.java

    r28044 r28143  
    3333public abstract class AbstractModule implements Module, OdConstants {
    3434
    35         protected final List<AbstractDataSetHandler> handlers = new ArrayList<AbstractDataSetHandler>();
    36        
     35        protected final List<Class<? extends AbstractDataSetHandler>> handlers = new ArrayList<Class <? extends AbstractDataSetHandler>>();
     36
     37        private final List<AbstractDataSetHandler> instanciatedHandlers = new ArrayList<AbstractDataSetHandler>();
     38
    3739        protected final ModuleInformation info;
    3840       
     
    5355         */
    5456        @Override
    55         public List<AbstractDataSetHandler> getHandlers() {
     57        public List<Class<? extends AbstractDataSetHandler>> getHandlers() {
    5658                return handlers;
    5759        }
     
    7173        public SourceProvider getMapPaintStyleSourceProvider() {
    7274                final List<SourceEntry> sources = new ArrayList<SourceEntry>();
    73                 for (AbstractDataSetHandler handler : handlers) {
     75                for (AbstractDataSetHandler handler : getInstanciatedHandlers()) {
    7476                        ExtendedSourceEntry src;
    7577                        if (handler != null && (src = handler.getMapPaintStyle()) != null) {
     
    111113        public SourceProvider getPresetSourceProvider() {
    112114                final List<SourceEntry> sources = new ArrayList<SourceEntry>();
    113                 for (AbstractDataSetHandler handler : handlers) {
     115                for (AbstractDataSetHandler handler : getInstanciatedHandlers()) {
    114116                        if (handler != null && handler.getTaggingPreset() != null) {
    115117                                sources.add(handler.getTaggingPreset());
     
    123125                };
    124126        }
     127       
     128        @Override
     129        public final List<AbstractDataSetHandler> getNewlyInstanciatedHandlers() {
     130                List<AbstractDataSetHandler> result = new ArrayList<AbstractDataSetHandler>();
     131                for (Class<? extends AbstractDataSetHandler> handlerClass : handlers) {
     132                        if (handlerClass != null) {
     133                                try {
     134                                        result.add(handlerClass.newInstance());
     135                                } catch (InstantiationException e) {
     136                                        System.err.println(e.getMessage());
     137                                } catch (IllegalAccessException e) {
     138                                        System.err.println(e.getMessage());
     139                                }
     140                        }
     141                }
     142                return result;
     143        }
     144
     145        private final List<AbstractDataSetHandler> getInstanciatedHandlers() {
     146                if (instanciatedHandlers.isEmpty()) {
     147                        instanciatedHandlers.addAll(getNewlyInstanciatedHandlers());
     148                }
     149                return instanciatedHandlers;
     150        }
    125151}
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/Module.java

    r28044 r28143  
    2525        public String getDisplayedName();
    2626
    27         public List<AbstractDataSetHandler> getHandlers();
    28        
     27        public List<Class<? extends AbstractDataSetHandler>> getHandlers();
     28
     29        public List<AbstractDataSetHandler> getNewlyInstanciatedHandlers();
     30
    2931        public SourceProvider getMapPaintStyleSourceProvider();
    3032       
Note: See TracChangeset for help on using the changeset viewer.