001 // License: GPL. For details, see LICENSE file. 002 package org.openstreetmap.josm.io; 003 004 import java.io.PrintWriter; 005 006 /** 007 * This factory is called by everyone who needs an OsmWriter object, 008 * instead of directly calling the OsmWriter constructor. 009 * 010 * This enables plugins to substitute the original OsmWriter with 011 * their own version, altering the way JOSM writes objects to the 012 * server, and to disk. 013 * 014 * @author Frederik Ramm 015 * 016 */ 017 public class OsmWriterFactory { 018 019 public static OsmWriterFactory theFactory; 020 public static OsmWriter createOsmWriter(PrintWriter out, boolean osmConform, String version) { 021 // pre-set factory with this default implementation; can still be overwritten 022 // later. note that the default factory may already be used for constructing 023 // OsmWriters during the startup process. 024 if (theFactory == null) { 025 theFactory = new OsmWriterFactory(); 026 } 027 return theFactory.createOsmWriterImpl(out, osmConform, version); 028 } 029 protected OsmWriter createOsmWriterImpl(PrintWriter out, boolean osmConform, String version) { 030 return new OsmWriter(out, osmConform, version); 031 } 032 }