Revision 12418 trunk/libraries/libGPE/src/org/gvsig/gpe/writers/GPEWriterHandler.java
GPEWriterHandler.java | ||
---|---|---|
1 | 1 |
package org.gvsig.gpe.writers; |
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 |
import java.util.Stack; |
|
5 | 4 |
|
6 | 5 |
import org.gvsig.gpe.GPEErrorHandler; |
7 | 6 |
import org.gvsig.gpe.utils.GeographicalUtils; |
7 |
import org.gvsig.gpe.utils.TypedObjectStack; |
|
8 |
import org.gvsig.gpe.utils.TypedObjectStack.TypedObject; |
|
8 | 9 |
import org.gvsig.gpe.warnings.NotSupportedElementWarning; |
10 |
import org.gvsig.gpe.warnings.NotSupportedFeatureWarning; |
|
11 |
import org.gvsig.gpe.warnings.NotSupportedLayerWarning; |
|
9 | 12 |
import org.gvsig.gpe.warnings.PolygonAutomaticallyClosedWarning; |
10 | 13 |
import org.gvsig.xmlschema.som.IXSElementDeclaration; |
11 | 14 |
import org.gvsig.xmlschema.som.IXSSchemaDocument; |
... | ... | |
54 | 57 |
* |
55 | 58 |
* $Id$ |
56 | 59 |
* $Log$ |
57 |
* Revision 1.14 2007-06-28 13:04:33 jorpiell |
|
60 |
* Revision 1.15 2007-06-29 12:19:14 jorpiell |
|
61 |
* The schema validation is made independently of the concrete writer |
|
62 |
* |
|
63 |
* Revision 1.14 2007/06/28 13:04:33 jorpiell |
|
58 | 64 |
* The Qname has been updated to the 1.5 JVM machine. The schema validation is made in the GPEWriterHandlerImplementor class |
59 | 65 |
* |
60 | 66 |
* Revision 1.13 2007/06/22 12:19:52 jorpiell |
... | ... | |
113 | 119 |
public class GPEWriterHandler { |
114 | 120 |
private IGPEWriterHandlerImplementor writerImplementor = null; |
115 | 121 |
//Used to know the current parsed elements |
116 |
private Stack currentLayer = null; |
|
117 |
private Stack currentFeature = null; |
|
118 |
private Stack currentElement = null; |
|
122 |
private TypedObjectStack layerStack = null; |
|
123 |
private TypedObjectStack featureStack = null; |
|
124 |
private TypedObjectStack elementStack = null; |
|
125 |
//Boolean variable that indicates that an object has |
|
126 |
//to be removed because it is not valid |
|
127 |
private boolean isRemoved = false; |
|
119 | 128 |
|
120 | 129 |
/** |
121 | 130 |
* The constructor |
... | ... | |
124 | 133 |
*/ |
125 | 134 |
public GPEWriterHandler(IGPEWriterHandlerImplementor writerImplementor){ |
126 | 135 |
this.writerImplementor = writerImplementor; |
127 |
currentLayer = new Stack();
|
|
128 |
currentFeature = new Stack();
|
|
129 |
currentElement = new Stack();
|
|
136 |
layerStack = new TypedObjectStack();
|
|
137 |
featureStack = new TypedObjectStack();
|
|
138 |
elementStack = new TypedObjectStack();
|
|
130 | 139 |
} |
131 | 140 |
|
132 | 141 |
/** |
... | ... | |
227 | 236 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startPoint(java.lang.String, double, double, double, java.lang.String) |
228 | 237 |
*/ |
229 | 238 |
public void startPoint(String id, double x, double y, double z, String srs) { |
239 |
if (isRemoved) return; |
|
230 | 240 |
writerImplementor.startPoint(id, x, y, z, srs); |
231 | 241 |
} |
232 | 242 |
|
... | ... | |
235 | 245 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endPoint() |
236 | 246 |
*/ |
237 | 247 |
public void endPoint() { |
248 |
if (isRemoved) return; |
|
238 | 249 |
writerImplementor.endPoint(); |
239 | 250 |
} |
240 | 251 |
|
... | ... | |
243 | 254 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startLineString(java.lang.String, double[], double[], double[], java.lang.String) |
244 | 255 |
*/ |
245 | 256 |
public void startLineString(String id, double[] x, double[] y, double[] z, String srs) { |
257 |
if (isRemoved) return; |
|
246 | 258 |
writerImplementor.startLineString(id, x, y, z, srs); |
247 | 259 |
} |
248 | 260 |
|
... | ... | |
251 | 263 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endLineString() |
252 | 264 |
*/ |
253 | 265 |
public void endLineString() { |
266 |
if (isRemoved) return; |
|
254 | 267 |
writerImplementor.endLineString(); |
255 | 268 |
} |
256 | 269 |
|
... | ... | |
259 | 272 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startLinearRing(java.lang.String, double[], double[], double[], java.lang.String) |
260 | 273 |
*/ |
261 | 274 |
public void startLinearRing(String id, double[] x, double[] y, double[] z, String srs) { |
275 |
if (isRemoved) return; |
|
262 | 276 |
if (!GeographicalUtils.isClosed(x, y, z)){ |
263 | 277 |
x = GeographicalUtils.closePolygon(x); |
264 | 278 |
y = GeographicalUtils.closePolygon(y); |
... | ... | |
273 | 287 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endLinearRing() |
274 | 288 |
*/ |
275 | 289 |
public void endLinearRing() { |
290 |
if (isRemoved) return; |
|
276 | 291 |
writerImplementor.endLinearRing(); |
277 | 292 |
} |
278 | 293 |
|
... | ... | |
281 | 296 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startPolygon(java.lang.String, double[], double[], double[], java.lang.String) |
282 | 297 |
*/ |
283 | 298 |
public void startPolygon(String id, double[] x, double[] y, double[] z, String srs) { |
299 |
if (isRemoved) return; |
|
284 | 300 |
if (!GeographicalUtils.isClosed(x, y, z)){ |
285 | 301 |
x = GeographicalUtils.closePolygon(x); |
286 | 302 |
y = GeographicalUtils.closePolygon(y); |
... | ... | |
295 | 311 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endPolygon() |
296 | 312 |
*/ |
297 | 313 |
public void endPolygon() { |
314 |
if (isRemoved) return; |
|
298 | 315 |
writerImplementor.endPolygon(); |
299 | 316 |
} |
300 | 317 |
|
... | ... | |
303 | 320 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startInnerBoundary(java.lang.String, double[], double[], double[], java.lang.String) |
304 | 321 |
*/ |
305 | 322 |
public void startInnerBoundary(String id, double[] x, double[] y, double[] z, String srs) { |
323 |
if (isRemoved) return; |
|
306 | 324 |
if (!GeographicalUtils.isClosed(x, y, z)){ |
307 | 325 |
x = GeographicalUtils.closePolygon(x); |
308 | 326 |
y = GeographicalUtils.closePolygon(y); |
... | ... | |
317 | 335 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endInnerBoundary() |
318 | 336 |
*/ |
319 | 337 |
public void endInnerBoundary() { |
338 |
if (isRemoved) return; |
|
320 | 339 |
writerImplementor.endInnerBoundary(); |
321 | 340 |
} |
322 | 341 |
|
... | ... | |
325 | 344 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#initialize() |
326 | 345 |
*/ |
327 | 346 |
public void initialize() { |
347 |
if (isRemoved) return; |
|
328 | 348 |
writerImplementor.initialize(); |
329 | 349 |
} |
330 | 350 |
|
... | ... | |
341 | 361 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startBbox(java.lang.String, double[], double[], double[], java.lang.String) |
342 | 362 |
*/ |
343 | 363 |
public void startBbox(String id, double[] x, double[] y, double[] z, String srs) { |
364 |
if (isRemoved) return; |
|
344 | 365 |
writerImplementor.startBbox(id, x, y, z, srs); |
345 | 366 |
} |
346 | 367 |
|
... | ... | |
349 | 370 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endBbox() |
350 | 371 |
*/ |
351 | 372 |
public void endBbox() { |
373 |
if (isRemoved) return; |
|
352 | 374 |
writerImplementor.endBbox(); |
353 | 375 |
} |
354 | 376 |
|
... | ... | |
357 | 379 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startElement(java.lang.String, java.lang.Object, java.lang.Object) |
358 | 380 |
*/ |
359 | 381 |
public void startElement(String name, Object value, String xsElementName) { |
360 |
PairNameType featurePair = (PairNameType)currentFeature.lastElement(); |
|
361 |
boolean isRemoved = false; |
|
382 |
if (isRemoved){ |
|
383 |
elementStack.push(name,xsElementName,isRemoved); |
|
384 |
return; |
|
385 |
} |
|
386 |
TypedObject feature = featureStack.lastElement(); |
|
362 | 387 |
//If is a simple element |
363 |
if (currentElement.size() == 0){ |
|
364 |
IXSElementDeclaration xsFeature = getSchemaDocument().getElementDeclarationByName(featurePair.getName()); |
|
365 |
if (xsFeature != null){ |
|
388 |
if (elementStack.size() == 0){ |
|
389 |
//If the feature has type |
|
390 |
if (feature.getType() != null){ |
|
391 |
IXSElementDeclaration xsFeature = getSchemaDocument().getElementDeclarationByName(feature.getType()); |
|
392 |
//If the feature is null has been declarated inside the layer |
|
393 |
if (xsFeature == null){ |
|
394 |
TypedObject layer = layerStack.lastElement(); |
|
395 |
//The layer has to have a type |
|
396 |
IXSElementDeclaration xsLayer = getSchemaDocument().getElementDeclarationByName(layer.getType()); |
|
397 |
xsFeature = xsLayer.getSubElementByName(feature.getType()); |
|
398 |
} |
|
399 |
//If the feature has a type it will be always on the schema |
|
366 | 400 |
IXSElementDeclaration xsElement = xsFeature.getSubElementByName(name); |
401 |
//If the element doesn't exist on the feature |
|
367 | 402 |
if (xsElement == null){ |
403 |
isRemoved = true; |
|
368 | 404 |
getErrorHandler().addWarning(new NotSupportedElementWarning(name, |
369 | 405 |
xsElementName, |
370 |
featurePair.getName(), |
|
371 |
featurePair.getType())); |
|
372 |
isRemoved = true; |
|
373 |
} |
|
406 |
feature.getName(), |
|
407 |
feature.getType())); |
|
408 |
} |
|
374 | 409 |
} |
375 | 410 |
}else{ //Is a complex element |
376 |
//TODO |
|
411 |
TypedObject parentElement = elementStack.lastElement(); |
|
412 |
//TODO complex element validation |
|
377 | 413 |
} |
378 |
currentElement.push(new PairNameType(name,xsElementName,isRemoved));
|
|
414 |
elementStack.push(name,xsElementName,isRemoved);
|
|
379 | 415 |
if (!isRemoved){ |
380 |
writerImplementor.startElement(name, value, xsElementName); |
|
381 |
}
|
|
416 |
writerImplementor.startElement(name, value, xsElementName);
|
|
417 |
} |
|
382 | 418 |
} |
383 | 419 |
|
384 | 420 |
/*+ |
... | ... | |
386 | 422 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endElement() |
387 | 423 |
*/ |
388 | 424 |
public void endElement() { |
389 |
PairNameType nameType = (PairNameType)currentElement.pop();
|
|
390 |
if (!nameType.isRemoved){
|
|
425 |
TypedObject element = elementStack.pop();
|
|
426 |
if (!element.isRemoved()){
|
|
391 | 427 |
writerImplementor.endElement(); |
392 |
} |
|
428 |
}else{ |
|
429 |
if (!layerStack.lastElement().isRemoved()){ |
|
430 |
if (!featureStack.lastElement().isRemoved()){ |
|
431 |
if (elementStack.size() == 0){ |
|
432 |
isRemoved = false; |
|
433 |
}else{ |
|
434 |
TypedObject parentElement = elementStack.lastElement(); |
|
435 |
isRemoved = parentElement.isRemoved(); |
|
436 |
} |
|
437 |
} |
|
438 |
} |
|
439 |
} |
|
393 | 440 |
} |
394 | 441 |
|
395 | 442 |
/* |
... | ... | |
397 | 444 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startLayer(java.lang.String, java.lang.String, java.lang.String, java.lang.String) |
398 | 445 |
*/ |
399 | 446 |
public void startLayer(String id, String name, String description, String srs, String xsElementName) { |
400 |
currentLayer.push(new PairNameType(name,xsElementName,false)); |
|
401 |
writerImplementor.startLayer(id, name, description, srs, xsElementName); |
|
447 |
if (isRemoved){ |
|
448 |
layerStack.push(name,xsElementName,isRemoved); |
|
449 |
return; |
|
450 |
} |
|
451 |
//If is a root layer |
|
452 |
if (layerStack.size() == 0){ |
|
453 |
//If it has a schema |
|
454 |
if (xsElementName != null){ |
|
455 |
//If the schema doesn't exists the layer can't be added |
|
456 |
if (getSchemaDocument().getElementDeclarationByName(xsElementName) == null){ |
|
457 |
isRemoved = true; |
|
458 |
getErrorHandler().addWarning(new NotSupportedLayerWarning(name, |
|
459 |
xsElementName)); |
|
460 |
} |
|
461 |
} |
|
462 |
}else{//It is a child layer |
|
463 |
TypedObject parentLayer = layerStack.lastElement(); |
|
464 |
//If the parent layer has a XML schema type |
|
465 |
if (parentLayer.getType() != null){ |
|
466 |
IXSElementDeclaration xsParentLayer = getSchemaDocument().getElementDeclarationByName(parentLayer.getType()); |
|
467 |
//If the parent layer has a schema |
|
468 |
if (xsParentLayer != null){ |
|
469 |
IXSElementDeclaration xsLayer = xsParentLayer.getSubElementByName(xsElementName); |
|
470 |
//If the layer name doesn't exist on the parent schema |
|
471 |
if (xsLayer == null){ |
|
472 |
isRemoved = true; |
|
473 |
getErrorHandler().addWarning(new NotSupportedLayerWarning(name, |
|
474 |
xsElementName, |
|
475 |
parentLayer.getName(), |
|
476 |
parentLayer.getType())); |
|
477 |
} |
|
478 |
} |
|
479 |
} |
|
480 |
} |
|
481 |
layerStack.push(name,xsElementName,isRemoved); |
|
482 |
if (!isRemoved){ |
|
483 |
writerImplementor.startLayer(id, name, description, srs, xsElementName); |
|
484 |
} |
|
402 | 485 |
} |
403 | 486 |
|
404 | 487 |
/* |
... | ... | |
406 | 489 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endLayer() |
407 | 490 |
*/ |
408 | 491 |
public void endLayer() { |
409 |
PairNameType nameType = (PairNameType)currentLayer.pop();
|
|
410 |
if (!nameType.isRemoved){
|
|
492 |
TypedObject layer = layerStack.pop();
|
|
493 |
if (!layer.isRemoved()){
|
|
411 | 494 |
writerImplementor.endLayer(); |
495 |
}else{ |
|
496 |
if (layerStack.size() == 0){ |
|
497 |
isRemoved = false; |
|
498 |
}else{ |
|
499 |
TypedObject parentLayer = layerStack.lastElement(); |
|
500 |
isRemoved = parentLayer.isRemoved(); |
|
501 |
} |
|
412 | 502 |
} |
413 | 503 |
} |
414 | 504 |
|
... | ... | |
417 | 507 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startFeature(java.lang.String, java.lang.String) |
418 | 508 |
*/ |
419 | 509 |
public void startFeature(String id, String name, String xsElementName) { |
420 |
currentFeature.push(new PairNameType(name,xsElementName,false)); |
|
421 |
writerImplementor.startFeature(id, name, xsElementName); |
|
510 |
if (isRemoved){ |
|
511 |
featureStack.push(name,xsElementName,isRemoved); |
|
512 |
return; |
|
513 |
} |
|
514 |
TypedObject layer = layerStack.lastElement(); |
|
515 |
//If the parent layer has type |
|
516 |
if (layer.getType() != null){ |
|
517 |
IXSElementDeclaration xsLayer = getSchemaDocument().getElementDeclarationByName(layer.getType()); |
|
518 |
//If the layer schema exists |
|
519 |
if (xsLayer != null){ |
|
520 |
IXSElementDeclaration xsFeature = xsLayer.getSubElementByName(xsElementName); |
|
521 |
//If the feature type doesn't exist on the layer |
|
522 |
if (xsFeature == null){ |
|
523 |
isRemoved = true; |
|
524 |
getErrorHandler().addWarning(new NotSupportedFeatureWarning(name, |
|
525 |
xsElementName, |
|
526 |
layer.getName(), |
|
527 |
layer.getType())); |
|
528 |
} |
|
529 |
} |
|
530 |
}else{//The layer doesn't has type |
|
531 |
//If the feature has type |
|
532 |
if (xsElementName != null){ |
|
533 |
//If the feature type is not on the schema |
|
534 |
if (getSchemaDocument().getElementDeclarationByName(xsElementName) == null){ |
|
535 |
isRemoved = true; |
|
536 |
getErrorHandler().addWarning(new NotSupportedFeatureWarning(name, |
|
537 |
xsElementName)); |
|
538 |
} |
|
539 |
} |
|
540 |
} |
|
541 |
featureStack.push(name,xsElementName,isRemoved); |
|
542 |
if (!isRemoved){ |
|
543 |
writerImplementor.startFeature(id, name, xsElementName); |
|
544 |
} |
|
422 | 545 |
} |
423 | 546 |
|
424 | 547 |
/* |
... | ... | |
426 | 549 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endFeature() |
427 | 550 |
*/ |
428 | 551 |
public void endFeature() { |
429 |
PairNameType nameType = (PairNameType)currentFeature.pop();
|
|
430 |
if (!nameType.isRemoved){
|
|
552 |
TypedObject feature = featureStack.pop();
|
|
553 |
if (!feature.isRemoved()){
|
|
431 | 554 |
writerImplementor.endFeature(); |
432 |
} |
|
555 |
}else{ |
|
556 |
if (!layerStack.lastElement().isRemoved()){ |
|
557 |
if (featureStack.size() == 0){ |
|
558 |
isRemoved = false; |
|
559 |
}else{ |
|
560 |
TypedObject parentFeature = featureStack.lastElement(); |
|
561 |
isRemoved = parentFeature.isRemoved(); |
|
562 |
} |
|
563 |
} |
|
564 |
} |
|
433 | 565 |
} |
434 | 566 |
|
435 | 567 |
/* |
... | ... | |
437 | 569 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startMultiPoint(java.lang.String, java.lang.String) |
438 | 570 |
*/ |
439 | 571 |
public void startMultiPoint(String id, String srs) { |
572 |
if (isRemoved) return; |
|
440 | 573 |
writerImplementor.startMultiPoint(id, srs); |
441 | 574 |
} |
442 | 575 |
|
... | ... | |
445 | 578 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endMuliPoint() |
446 | 579 |
*/ |
447 | 580 |
public void endMultiPoint() { |
581 |
if (isRemoved) return; |
|
448 | 582 |
writerImplementor.endMultiPoint(); |
449 | 583 |
} |
450 | 584 |
|
... | ... | |
453 | 587 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startMultiLineString(java.lang.String, java.lang.String) |
454 | 588 |
*/ |
455 | 589 |
public void startMultiLineString(String id, String srs) { |
590 |
if (isRemoved) return; |
|
456 | 591 |
writerImplementor.startMultiLineString(id, srs); |
457 | 592 |
} |
458 | 593 |
|
... | ... | |
461 | 596 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endMultiLineString() |
462 | 597 |
*/ |
463 | 598 |
public void endMultiLineString() { |
599 |
if (isRemoved) return; |
|
464 | 600 |
writerImplementor.endMultiLineString(); |
465 | 601 |
} |
466 | 602 |
|
... | ... | |
469 | 605 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startMultiPolygon(java.lang.String, java.lang.String) |
470 | 606 |
*/ |
471 | 607 |
public void startMultiPolygon(String id, String srs) { |
608 |
if (isRemoved) return; |
|
472 | 609 |
writerImplementor.startMultiPolygon(id, srs); |
473 | 610 |
} |
474 | 611 |
|
... | ... | |
477 | 614 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endMultiPolygon() |
478 | 615 |
*/ |
479 | 616 |
public void endMultiPolygon() { |
617 |
if (isRemoved) return; |
|
480 | 618 |
writerImplementor.endMultiPolygon(); |
481 | 619 |
} |
482 | 620 |
|
... | ... | |
485 | 623 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#startMultiGeometry(java.lang.String, java.lang.String) |
486 | 624 |
*/ |
487 | 625 |
public void startMultiGeometry(String id, String srs) { |
626 |
if (isRemoved) return; |
|
488 | 627 |
writerImplementor.startMultiGeometry(id, srs); |
489 | 628 |
} |
490 | 629 |
|
... | ... | |
493 | 632 |
* @see org.gvsig.gpe.writers.IGPEWriterHandler#endMultiGeometry() |
494 | 633 |
*/ |
495 | 634 |
public void endMultiGeometry() { |
635 |
if (isRemoved) return; |
|
496 | 636 |
writerImplementor.endMultiGeometry(); |
497 | 637 |
} |
498 | 638 |
|
... | ... | |
508 | 648 |
*/ |
509 | 649 |
public void setSchemaDocument(IXSSchemaDocument schemaDocument) { |
510 | 650 |
writerImplementor.setSchemaDocument(schemaDocument); |
511 |
} |
|
512 |
|
|
513 |
/** |
|
514 |
* This class implements a pair of element name |
|
515 |
* ald XML schema element type. |
|
516 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es) |
|
517 |
*/ |
|
518 |
private class PairNameType{ |
|
519 |
private String name = null; |
|
520 |
private String type = null; |
|
521 |
private boolean isRemoved = false; |
|
522 |
|
|
523 |
public PairNameType(String name, String type, boolean isRemoved) { |
|
524 |
this.name = name; |
|
525 |
this.type = type; |
|
526 |
this.isRemoved = isRemoved; |
|
527 |
} |
|
528 |
|
|
529 |
/** |
|
530 |
* @return the name |
|
531 |
*/ |
|
532 |
public String getName() { |
|
533 |
return name; |
|
534 |
} |
|
535 |
|
|
536 |
/** |
|
537 |
* @return the type |
|
538 |
*/ |
|
539 |
public String getType() { |
|
540 |
return type; |
|
541 |
} |
|
542 |
|
|
543 |
/** |
|
544 |
* @return the isRemoved |
|
545 |
*/ |
|
546 |
public boolean isRemoved() { |
|
547 |
return isRemoved; |
|
548 |
} |
|
549 |
} |
|
550 |
|
|
651 |
} |
|
551 | 652 |
} |
Also available in: Unified diff