Changeset 2563 in josm for trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
- Timestamp:
- 03.12.2009 19:02:25 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
r2484 r2563 9 9 import org.openstreetmap.josm.data.osm.DataSet; 10 10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 11 import org.openstreetmap.josm.data.osm.PrimitiveId; 12 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 13 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 11 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 15 import org.xml.sax.SAXException; 13 16 17 /** 18 * OsmServerObjectReader reads an individual object from the OSM server. 19 * 20 * It can either download the object including or not including its immediate children. 21 * The former case is called a "full download". 22 * 23 */ 14 24 public class OsmServerObjectReader extends OsmServerReader { 25 /** the id of the object to download */ 26 private PrimitiveId id; 27 /** true if a full download is required, i.e. a download including the immediate children */ 28 private boolean full; 15 29 16 long id; 17 OsmPrimitiveType type; 18 boolean full; 19 20 public OsmServerObjectReader(long id, OsmPrimitiveType type, boolean full) { 21 this.id = id; 22 this.type = type; 30 /** 31 * Creates a new server object reader for a given id and a primitive type. 32 * 33 * @param id the object id. > 0 required. 34 * @param type the type. Must not be null. 35 * @param full true, if a full download is requested (i.e. a download including 36 * immediate children); false, otherwise 37 * @throws IllegalArgumentException thrown if id <= 0 38 * @throws IllegalArgumentException thrown if type is null 39 */ 40 public OsmServerObjectReader(long id, OsmPrimitiveType type, boolean full) throws IllegalArgumentException { 41 if (id <= 0) 42 throw new IllegalArgumentException(tr("Expected value > 0 for parameter ''{0}'', got {1}", "id", id)); 43 if (type == null) 44 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "type")); 45 this.id = new SimplePrimitiveId(id, type); 23 46 this.full = full; 24 47 } 48 25 49 /** 26 * Method to download single objects from OSM server. ways, relations, nodes 27 * @return the data requested 50 * Creates a new server object reader for an object with the given <code>id</code> 51 * 52 * @param id the object id. Must not be null. Unique id > 0 required. 53 * @param full true, if a full download is requested (i.e. a download including 54 * immediate children); false, otherwise 55 * @throws IllegalArgumentException thrown if id is null 56 * @throws IllegalArgumentException thrown if id.getUniqueId() <= 0 57 */ 58 public OsmServerObjectReader(PrimitiveId id, boolean full) { 59 if (id == null) 60 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "id")); 61 if (id.getUniqueId() <= 0) 62 throw new IllegalArgumentException(tr("Expected value > 0 for parameter ''{0}'', got {1}", "id.getUniqueId()", id.getUniqueId())); 63 this.id = id; 64 this.full = full; 65 } 66 67 /** 68 * Downloads and parses the data. 69 * 70 * @param progressMonitor the progress monitor. Set to {@see NullProgressMonitor#INSTANCE} if 71 * null 72 * @return the downloaded data 28 73 * @throws SAXException 29 74 * @throws IOException … … 31 76 @Override 32 77 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 78 if (progressMonitor == null) { 79 progressMonitor = NullProgressMonitor.INSTANCE; 80 } 33 81 progressMonitor.beginTask("", 1); 34 82 InputStream in = null; … … 36 84 progressMonitor.indeterminateSubTask(tr("Downloading OSM data...")); 37 85 StringBuffer sb = new StringBuffer(); 38 sb.append( type.getAPIName());86 sb.append(id.getType().getAPIName()); 39 87 sb.append("/"); 40 sb.append(id );41 if (full && ! type.equals(OsmPrimitiveType.NODE)) {88 sb.append(id.getUniqueId()); 89 if (full && ! id.getType().equals(OsmPrimitiveType.NODE)) { 42 90 sb.append("/full"); 43 91 } … … 59 107 try { 60 108 in.close(); 61 } catch(Exception e) { }109 } catch(Exception e) {/* ignore this exception */} 62 110 } 63 111 activeConnection = null; 64 112 } 65 113 } 66 67 114 }
Note: See TracChangeset
for help on using the changeset viewer.
