Revision 8822 branches/v10/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/layers/FLyrWFS.java

View differences:

FLyrWFS.java
74 74
 *
75 75
 * $Id$
76 76
 * $Log$
77
 * Revision 1.10.2.5  2006-11-15 00:08:20  jjdelcerro
77
 * Revision 1.10.2.6  2006-11-16 15:38:51  jorpiell
78
 * Se han modificado los metodos para guargar y crear un XML a partir de una capa WFS.
79
 *
80
 * Revision 1.10.2.5  2006/11/15 00:08:20  jjdelcerro
78 81
 * *** empty log message ***
79 82
 *
80 83
 * Revision 1.18  2006/10/31 12:24:04  jorpiell
......
242 245
    		adapter.setDriver((VectorialDriver) wfsDriver);
243 246
    		setSource(adapter);
244 247

  
245

  
246
    		setLegend(LegendFactory.createSingleSymbolLegend(
248
    		if (getLegend() == null){
249
    			setLegend(LegendFactory.createSingleSymbolLegend(
247 250
    				getShapeType()));
251
    		}
248 252
    	} catch (Exception e){
249 253
    		e.printStackTrace();
250 254
    		throw new DriverIOException(e.getMessage());
......
522 526
	 * @return XMLEntity.
523 527
	 * @throws XMLException
524 528
	 */
525
	public XMLEntity getXMLEntity() throws XMLException {
529
	public XMLEntity getXMLEntity() throws XMLException {	
526 530
		XMLEntity xml = super.getXMLEntity();		
527 531
		
528 532
		// Full extent
......
537 541
		xml.putProperty("host", host.toExternalForm());
538 542
		
539 543
		// Layer name
540
		xml.putProperty("layerName", getLayerName());
544
		xml.putProperty("layerName", getLayerName());		
545
		xml.putProperty("name", getName());
541 546

  
542 547
		//Layer fields
548
		XMLElement[] fields = getFields();
543 549
		String strFields = "";
544
		XMLElement[] fields = getFields();
545 550
		for (int i=0 ; i<fields.length ; i++){
546
			strFields = strFields + fields[i].getName();
547
			if (i < fields.length - 1){
548
				strFields = strFields + "~##SEP1##~";
551
			//If is not the root node
552
			if (fields[i].getParentElement() != null){
553
				strFields = strFields + fields[i].getFullName();
554
				if (i < fields.length - 1){
555
					strFields = strFields + "~##SEP1##~";
556
				}
557
			}else{
558
				xml.putProperty("rootNode", true);
549 559
			}
550 560
		}
551 561
		xml.putProperty("fields", strFields);
......
576 586
	 *
577 587
	 * @throws XMLException
578 588
	 * @throws DriverException
579
	 * @throws DriverIOException
589
	 * @throws DriverI OException
580 590
	 */
581 591
	public void setXMLEntity(XMLEntity xml)throws XMLException {
582
		super.setXMLEntity(xml);
583
		
592
						
584 593
		// Host
585 594
		try {
586 595
			host = new URL(xml.getStringProperty("host"));
......
589 598
		}
590 599
		
591 600
		// Layer name
592
		setLayerName(xml.getStringProperty("layerName"));		
601
		setLayerName(xml.getStringProperty("layerName"));			
602
		setName(xml.getStringProperty("name"));		
593 603
		
594 604
		// User name
595 605
		if (xml.contains("user")){
......
625 635
		FMapWFSDriver driver;
626 636
		try {
627 637
			driver = FMapWFSDriverFactory.getFMapDriverForURL(host);
638
			setWfsDriver(driver);	
639
			WFSAdapter adapter = new WFSAdapter();
640
	    	adapter.setDriver((VectorialDriver) wfsDriver);
641
	    	setSource(adapter);
642
	    	super.setXMLEntity(xml);
643
	    	setLegend(LegendFactory.createFromXML(xml.getChild(0)));
628 644
		} catch (Exception e) {
629 645
			throw new XMLException(e);	
630 646
		}
631
		WFSLayerNode[] layers = driver.getLayerList();
647
		driver.getLayerList();
632 648
		WFSLayerNode layer = driver.getLayerInfo(getLayerName());			
633
		layer.setSelectedFields(layer.getFields());					
634
		XMLElement[] atts = null;
649
		XMLElement[] atts = null;		
635 650
		
651
//		The root element always exists
652
		XMLElement rootElement = (XMLElement)layer.getFields().get(0);
653
		
636 654
		if (xml.contains("fields")) {
637
			String[] fields = xml.getStringProperty("fields").split("~##SEP1##~");
638
			atts = new XMLElement[fields.length];
655
			String[] fields = xml.getStringProperty("fields").split("~##SEP1##~");	
656
			if ((fields.length == 1) && (fields[0].equals(""))){
657
				fields = new String[0];
658
			}
659
			//The root element always is a complex type
660
			Vector allFields = ((XMLComplexType)rootElement.getEntityType()).getAttributes();
661
			//If the root node has been selected
662
			if (xml.contains("rootNode")){
663
				if (xml.getBooleanProperty("rootNode")==true){
664
					atts = new XMLElement[fields.length + 1];
665
					atts[fields.length] = rootElement;
666
				}else{
667
					atts = new XMLElement[fields.length];
668
				}
669
			}else{
670
				atts = new XMLElement[fields.length];
671
			}
672
			//Adding the other fields
639 673
			for (int i=0 ; i<fields.length ; i++){
640
				for (int j=0 ; j<layer.getFields().size() ; j++){
641
					XMLElement attribute = (XMLElement)layer.getFields().get(j);
642
					if (attribute.getName().equals(fields[i])){
643
						atts[i] = attribute;
644
						break;
674
				for (int j=0 ; j<allFields.size() ; j++){
675
					XMLElement attribute = (XMLElement)allFields.get(j);
676
					if (attribute != null){
677
						XMLElement found = attribute.searchAttribute(fields[i]);
678
						if (found != null){
679
							atts[i] = found;
680
							break;
681
						}
645 682
					}
646 683
				}					
684
			}			
685
		}else{
686
			if (xml.contains("rootNode")){
687
				if (xml.getBooleanProperty("rootNode")==true){
688
					atts = new XMLElement[1];
689
					atts[0] = rootElement;
690
				}
647 691
			}
648
		}else{
649
			atts = new XMLElement[0];
650 692
		}
651 693
		layer.setSelectedFields(atts);
652
		setWfsDriver(driver);	
653 694
		setWfsLayerNode(layer);
654 695
		setFields(atts);	
655 696
		setAvailable(true);

Also available in: Unified diff