Changeset 1811 in josm for trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java
- Timestamp:
- 2009-07-19T17:38:55+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java
r1806 r1811 8 8 import java.util.Collection; 9 9 10 import org.openstreetmap.josm.Main;11 10 import org.openstreetmap.josm.data.osm.DataSet; 12 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 15 14 import org.openstreetmap.josm.data.osm.Way; 16 15 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 17 18 18 /** … … 21 21 * which refer to the node. For a {@see Way} or a {@see Relation}, only relations are 22 22 * read. 23 * 23 * 24 24 * OsmServerBackreferenceReader uses the API calls <code>[node|way|relation]/#id/relations</code> 25 25 * and <code>node/#id/ways</code> to retrieve the referring primitives. The default behaviour 26 26 * of these calls is to reply incomplete primitives only. 27 * 27 * 28 28 * If you set {@see #setReadFull(boolean)} to true this reader uses a {@see MultiFetchServerObjectReader} 29 29 * to complete incomplete primitives. 30 * 30 * 31 31 * 32 32 */ … … 42 42 /** 43 43 * constructor 44 * 44 * 45 45 * @param primitive the primitive to be read. Must not be null. primitive.id > 0 expected 46 * 46 * 47 47 * @exception IllegalArgumentException thrown if primitive is null 48 48 * @exception IllegalArgumentException thrown if primitive.id <= 0 … … 60 60 /** 61 61 * constructor 62 * 62 * 63 63 * @param id the id of the primitive. > 0 expected 64 64 * @param type the type of the primitive. Must not be null. 65 * 65 * 66 66 * @exception IllegalArgumentException thrown if id <= 0 67 67 * @exception IllegalArgumentException thrown if type is null 68 * 68 * 69 69 */ 70 70 public OsmServerBackreferenceReader(long id, OsmPrimitiveType type) throws IllegalArgumentException { … … 80 80 /** 81 81 * constructor 82 * 82 * 83 83 * @param id the id of the primitive. > 0 expected 84 84 * @param type the type of the primitive. Must not be null. 85 85 * @param readFull true, if referers should be read fully (i.e. including their immediate children) 86 * 86 * 87 87 */ 88 88 public OsmServerBackreferenceReader(OsmPrimitive primitive, boolean readFull) { … … 93 93 /** 94 94 * constructor 95 * 95 * 96 96 * @param primitive the primitive whose referers are to be read 97 97 * @param readFull true, if referers should be read fully (i.e. including their immediate children) 98 * 98 * 99 99 * @exception IllegalArgumentException thrown if id <= 0 100 100 * @exception IllegalArgumentException thrown if type is null 101 * 101 * 102 102 */ 103 103 public OsmServerBackreferenceReader(long id, OsmPrimitiveType type, boolean readFull) throws IllegalArgumentException { … … 108 108 /** 109 109 * Replies true if this reader also reads immediate children of referring primitives 110 * 110 * 111 111 * @return true if this reader also reads immediate children of referring primitives 112 112 */ … … 117 117 /** 118 118 * Set true if this reader should reads immediate children of referring primitives too. False, otherweise. 119 * 119 * 120 120 * @param readFull true if this reader should reads immediate children of referring primitives too. False, otherweise. 121 121 */ … … 126 126 /** 127 127 * Reads referring ways from the API server and replies them in a {@see DataSet} 128 * 128 * 129 129 * @return the data set 130 130 * @throws OsmTransferException 131 131 */ 132 protected DataSet getReferringWays( ) throws OsmTransferException {132 protected DataSet getReferringWays(ProgressMonitor progressMonitor) throws OsmTransferException { 133 133 InputStream in = null; 134 try {135 Main.pleaseWaitDlg.progress.setValue(0);136 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));134 progressMonitor.beginTask(null, 2); 135 try { 136 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server...")); 137 137 StringBuffer sb = new StringBuffer(); 138 138 sb.append(primitiveType.getAPIName()) 139 139 .append("/").append(id).append("/ways"); 140 140 141 in = getInputStream(sb.toString(), Main.pleaseWaitDlg);141 in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 142 142 if (in == null) 143 143 return null; 144 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading referring ways ..."));145 return OsmReader.parseDataSet(in, Main.pleaseWaitDlg);144 progressMonitor.subTask(tr("Downloading referring ways ...")); 145 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true)); 146 146 } catch(OsmTransferException e) { 147 147 throw e; … … 151 151 throw new OsmTransferException(e); 152 152 } finally { 153 progressMonitor.finishTask(); 153 154 if (in != null) { 154 155 try { … … 162 163 163 164 * Reads referring relations from the API server and replies them in a {@see DataSet} 164 * 165 * 165 166 * @return the data set 166 167 * @throws OsmTransferException 167 168 */ 168 protected DataSet getReferringRelations( ) throws OsmTransferException {169 protected DataSet getReferringRelations(ProgressMonitor progressMonitor) throws OsmTransferException { 169 170 InputStream in = null; 170 try {171 Main.pleaseWaitDlg.progress.setValue(0);172 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));171 progressMonitor.beginTask(null, 2); 172 try { 173 progressMonitor.subTask(tr("Contacting OSM Server...")); 173 174 StringBuffer sb = new StringBuffer(); 174 175 sb.append(primitiveType.getAPIName()) 175 176 .append("/").append(id).append("/relations"); 176 177 177 in = getInputStream(sb.toString(), Main.pleaseWaitDlg);178 in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 178 179 if (in == null) 179 180 return null; 180 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading referring relations ..."));181 return OsmReader.parseDataSet(in, Main.pleaseWaitDlg);181 progressMonitor.subTask(tr("Downloading referring relations ...")); 182 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true)); 182 183 } catch(OsmTransferException e) { 183 184 throw e; … … 187 188 throw new OsmTransferException(e); 188 189 } finally { 190 progressMonitor.finishTask(); 189 191 if (in != null) { 190 192 try { … … 200 202 * incomplete primitives are read from the server with an individual <tt>/api/0.6/[way,relation]/#id/full</tt> 201 203 * request. 202 * 204 * 203 205 * <ul> 204 206 * <li>if this reader reads referers for an {@see Node}, referring ways are always … … 207 209 * are only read fully if {@see #setReadFull(boolean)} is set to true.</li> 208 210 * </ul> 209 * 211 * 210 212 * The method replies the modified dataset. 211 * 213 * 212 214 * @param ds the original dataset 213 215 * @return the modified dataset 214 216 * @throws OsmTransferException thrown if an exception occurs. 215 217 */ 216 protected DataSet readIncompletePrimitives(DataSet ds) throws OsmTransferException { 217 Collection<Way> waysToCheck = new ArrayList<Way>(ds.ways); 218 if (isReadFull() ||primitiveType.equals(OsmPrimitiveType.NODE)) { 219 for (Way way: waysToCheck) { 220 if (way.id > 0 && way.incomplete) { 221 OsmServerObjectReader reader = new OsmServerObjectReader(way.id, OsmPrimitiveType.from(way), true /* read full */); 222 DataSet wayDs = reader.parseOsm(); 223 MergeVisitor visitor = new MergeVisitor(ds, wayDs); 224 visitor.merge(); 218 protected DataSet readIncompletePrimitives(DataSet ds, ProgressMonitor progressMonitor) throws OsmTransferException { 219 progressMonitor.beginTask(null, 2); 220 try { 221 Collection<Way> waysToCheck = new ArrayList<Way>(ds.ways); 222 if (isReadFull() ||primitiveType.equals(OsmPrimitiveType.NODE)) { 223 for (Way way: waysToCheck) { 224 if (way.id > 0 && way.incomplete) { 225 OsmServerObjectReader reader = new OsmServerObjectReader(way.id, OsmPrimitiveType.from(way), true /* read full */); 226 DataSet wayDs = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false)); 227 MergeVisitor visitor = new MergeVisitor(ds, wayDs); 228 visitor.merge(); 229 } 225 230 } 226 231 } 227 }228 if (isReadFull()) {229 Collection<Relation> relationsToCheck = new ArrayList<Relation>(ds.relations);230 for (Relation relation: relationsToCheck) {231 if (relation.id > 0 && relation.incomplete) {232 OsmServerObjectReader reader = new OsmServerObjectReader(relation.id, OsmPrimitiveType.from(relation), true /* read full */);233 DataSet wayDs = reader.parseOsm();234 MergeVisitor visitor = new MergeVisitor(ds, wayDs);235 visitor.merge();232 if (isReadFull()) { 233 Collection<Relation> relationsToCheck = new ArrayList<Relation>(ds.relations); 234 for (Relation relation: relationsToCheck) { 235 if (relation.id > 0 && relation.incomplete) { 236 OsmServerObjectReader reader = new OsmServerObjectReader(relation.id, OsmPrimitiveType.from(relation), true /* read full */); 237 DataSet wayDs = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false)); 238 MergeVisitor visitor = new MergeVisitor(ds, wayDs); 239 visitor.merge(); 240 } 236 241 } 237 242 } 238 } 239 return ds; 243 return ds; 244 } finally { 245 progressMonitor.finishTask(); 246 } 240 247 } 241 248 … … 243 250 * Reads the referring primitives from the OSM server, parses them and 244 251 * replies them as {@see DataSet} 245 * 252 * 246 253 * @return the dataset with the referring primitives 247 254 * @exception OsmTransferException thrown if an error occurs while communicating with the server 248 255 */ 249 256 @Override 250 public DataSet parseOsm() throws OsmTransferException { 251 DataSet ret = new DataSet(); 252 if (primitiveType.equals(OsmPrimitiveType.NODE)) { 253 DataSet ds = getReferringWays(); 257 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 258 progressMonitor.beginTask(null, 3); 259 try { 260 DataSet ret = new DataSet(); 261 if (primitiveType.equals(OsmPrimitiveType.NODE)) { 262 DataSet ds = getReferringWays(progressMonitor.createSubTaskMonitor(1, false)); 263 MergeVisitor visitor = new MergeVisitor(ret,ds); 264 visitor.merge(); 265 ret = visitor.getMyDataSet(); 266 } 267 DataSet ds = getReferringRelations(progressMonitor.createSubTaskMonitor(1, false)); 254 268 MergeVisitor visitor = new MergeVisitor(ret,ds); 255 269 visitor.merge(); 256 270 ret = visitor.getMyDataSet(); 257 } 258 DataSet ds = getReferringRelations(); 259 MergeVisitor visitor = new MergeVisitor(ret,ds); 260 visitor.merge(); 261 ret = visitor.getMyDataSet(); 262 readIncompletePrimitives(ret); 263 return ret; 271 readIncompletePrimitives(ret, progressMonitor.createSubTaskMonitor(1, false)); 272 return ret; 273 } finally { 274 progressMonitor.finishTask(); 275 } 264 276 } 265 277 }
Note:
See TracChangeset
for help on using the changeset viewer.