001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/sos/ComponentDescriptionDocument.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2006 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/deegree/
008     lat/lon GmbH
009     http://www.lat-lon.de
010    
011     This library is free software; you can redistribute it and/or
012     modify it under the terms of the GNU Lesser General Public
013     License as published by the Free Software Foundation; either
014     version 2.1 of the License, or (at your option) any later version.
015    
016     This library is distributed in the hope that it will be useful,
017     but WITHOUT ANY WARRANTY; without even the implied warranty of
018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019     Lesser General Public License for more details.
020    
021     You should have received a copy of the GNU Lesser General Public
022     License along with this library; if not, write to the Free Software
023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024    
025     Contact:
026    
027     Andreas Poth
028     lat/lon GmbH
029     Aennchenstraße 19  
030     53177 Bonn
031     Germany
032     E-Mail: poth@lat-lon.de
033    
034     Prof. Dr. Klaus Greve
035     lat/lon GmbH
036     Aennchenstraße 19
037     53177 Bonn
038     Germany
039     E-Mail: fitzke@lat-lon.de
040    
041     ---------------------------------------------------------------------------*/
042    package org.deegree.ogcwebservices.sos;
043    
044    import java.io.IOException;
045    import java.net.MalformedURLException;
046    import java.net.URI;
047    import java.net.URISyntaxException;
048    import java.net.URL;
049    import java.util.ArrayList;
050    import java.util.List;
051    
052    import org.deegree.framework.xml.XMLParsingException;
053    import org.deegree.framework.xml.XMLTools;
054    import org.deegree.model.metadata.iso19115.Address;
055    import org.deegree.model.metadata.iso19115.CitedResponsibleParty;
056    import org.deegree.model.metadata.iso19115.ContactInfo;
057    import org.deegree.model.metadata.iso19115.FunctionCode;
058    import org.deegree.model.metadata.iso19115.Linkage;
059    import org.deegree.model.metadata.iso19115.OnlineResource;
060    import org.deegree.model.metadata.iso19115.Phone;
061    import org.deegree.model.metadata.iso19115.RoleCode;
062    import org.deegree.ogcbase.OGCDocument;
063    import org.deegree.ogcwebservices.sos.sensorml.BasicResponse;
064    import org.deegree.ogcwebservices.sos.sensorml.Classifier;
065    import org.deegree.ogcwebservices.sos.sensorml.ComponentDescription;
066    import org.deegree.ogcwebservices.sos.sensorml.CoordinateReferenceSystem;
067    import org.deegree.ogcwebservices.sos.sensorml.Discussion;
068    import org.deegree.ogcwebservices.sos.sensorml.EngineeringCRS;
069    import org.deegree.ogcwebservices.sos.sensorml.GeoLocation;
070    import org.deegree.ogcwebservices.sos.sensorml.GeoPositionModel;
071    import org.deegree.ogcwebservices.sos.sensorml.GeographicCRS;
072    import org.deegree.ogcwebservices.sos.sensorml.Identifier;
073    import org.deegree.ogcwebservices.sos.sensorml.LocationModel;
074    import org.deegree.ogcwebservices.sos.sensorml.ProjectedCRS;
075    import org.deegree.ogcwebservices.sos.sensorml.Quantity;
076    import org.deegree.ogcwebservices.sos.sensorml.Reference;
077    import org.deegree.ogcwebservices.sos.sensorml.ResponseModel;
078    import org.deegree.ogcwebservices.sos.sensorml.TypedQuantity;
079    import org.w3c.dom.Node;
080    import org.xml.sax.SAXException;
081    
082    /**
083     * gets the metadata from a XSL transformed wfs result
084     * 
085     * @author <a href="mailto:mkulbe@lat-lon.de">Matthias Kulbe </a>
086     * @author last edited by: $Author: apoth $
087     * 
088     * @version $Revision: 6748 $, $Date: 2007-05-03 10:34:24 +0200 (Do, 03 Mai 2007) $
089     */
090    public abstract class ComponentDescriptionDocument extends OGCDocument {
091    
092        /**
093         * exceptions decleration must be there because this method will be overeritten by extending
094         * classes
095         * 
096         * @throws IOException
097         * @throws SAXException
098         */
099        public void createEmptyDocument()
100                                throws IOException, SAXException {
101            // nothing to do
102        }
103    
104        /**
105         * gets the identifiedAs part of a item
106         * 
107         * @param node
108         * @return the identifiedAs part of a item (maybe <code>null</code>)
109         * @throws XMLParsingException
110         */
111        protected Identifier getIdentifiedAs( Node node )
112                                throws XMLParsingException {
113    
114            if ( node != null ) {
115                // value is required
116                String value = XMLTools.getRequiredNodeAsString( node, "sml:Identifier/text()", nsContext );
117                // type is optional
118                String type = XMLTools.getNodeAsString( node, "sml:Identifier/@type", nsContext, null );
119                // codeSpace is optional
120                String codeSpace = XMLTools.getNodeAsString( node, "sml:Identifier/@codespace", nsContext, null );
121    
122                int typeId = 0;
123    
124                // type must compare to one of this values
125                if ( type == null ) {
126                    typeId = 0;
127                } else if ( "shortName".equalsIgnoreCase( type ) ) {
128                    typeId = 1;
129                } else if ( "longName".equalsIgnoreCase( type ) ) {
130                    typeId = 2;
131                } else if ( "serialNumber".equalsIgnoreCase( type ) ) {
132                    typeId = 3;
133                } else if ( "modelNumber".equalsIgnoreCase( type ) ) {
134                    typeId = 4;
135                } else if ( "missionNumber".equalsIgnoreCase( type ) ) {
136                    typeId = 5;
137                } else if ( "partNumber".equalsIgnoreCase( type ) ) {
138                    typeId = 6;
139                } else {
140                    throw new XMLParsingException( type + " is not a valid type for Identifier" );
141                }
142    
143                return new Identifier( value, typeId, codeSpace );
144            }
145            return null;
146        }
147    
148        /**
149         * gets the classifiedAs part of a item
150         * 
151         * @param node
152         * @return the classifiedAs part of a item (maybe <code>null</code>)
153         * @throws XMLParsingException
154         */
155        protected Classifier getClassifiedAs( Node node )
156                                throws XMLParsingException {
157    
158            if ( node != null ) {
159                // value is required
160                String value = XMLTools.getRequiredNodeAsString( node, "sml:Classifier/text()", nsContext );
161                // type ist required
162                String type = XMLTools.getRequiredNodeAsString( node, "sml:Classifier/@type", nsContext );
163                // codeSpace is optional
164                String codeSpace = XMLTools.getNodeAsString( node, "sml:Classifier/@codespace", nsContext, null );
165    
166                return new Classifier( value, type, codeSpace );
167            }
168            return null;
169    
170        }
171    
172        /**
173         * gets the attachedTo part of a Item
174         * 
175         * @param node
176         * @return the attachedTo part of a Item (maybe <code>null</code>)
177         * @throws XMLParsingException
178         */
179        protected String getAttachedTo( Node node )
180                                throws XMLParsingException {
181            if ( node != null ) {
182                return XMLTools.getNodeAsString( node, "sml:Component/text()", nsContext, null );
183            }
184            return null;
185        }
186    
187        /**
188         * gets the hasCRS part of a Item
189         * 
190         * @param node
191         * @return the hasCRS part of a Item (maybe <code>null</code>)
192         * @throws XMLParsingException
193         */
194        protected EngineeringCRS getHasCRS( Node node )
195                                throws XMLParsingException {
196            if ( node != null ) {
197                return getEngineeringCRS( node );
198            }
199            return null;
200        }
201    
202        /**
203         * 
204         * @param node
205         * @return
206         * @throws XMLParsingException
207         */
208        protected EngineeringCRS getEngineeringCRS( Node node )
209                                throws XMLParsingException {
210            if ( node != null ) {
211                String srsName = XMLTools.getRequiredNodeAsString( node, "gml:EngineeringCRS/gml:srsName/text()", nsContext );
212                return new EngineeringCRS( srsName );
213            }
214            return null;
215        }
216    
217        /**
218         * 
219         * @param node
220         * @return
221         * @throws XMLParsingException
222         */
223        protected CoordinateReferenceSystem getCoordinateReferenceSystemCRS( Node node )
224                                throws XMLParsingException {
225            if ( node != null ) {
226                // is GeographicCRS
227                if ( ( XMLTools.getNode( node, "gml:GeographicCRS", nsContext ) ) != null ) {
228                    String srsName = XMLTools.getNodeAsString( node, "gml:GeographicCRS/gml:srsName/text()", nsContext,
229                                                               null );
230                    if ( srsName != null ) {
231                        return new GeographicCRS( srsName );
232                    }
233    
234                }
235    
236                // is ProjectedCRS
237                if ( ( XMLTools.getNode( node, "gml:ProjectedCRS", nsContext ) ) != null ) {
238                    String srsName = XMLTools.getNodeAsString( node, "gml:ProjectedCRS/gml:srsName/text()", nsContext, null );
239                    if ( srsName != null ) {
240                        return new ProjectedCRS( srsName );
241                    }
242    
243                }
244    
245            }
246            return null;
247        }
248    
249        /**
250         * 
251         * @param node
252         * @return
253         * @throws XMLParsingException
254         * @throws URISyntaxException
255         */
256        protected Object getUsesParametersFromGeoLocation( Node node )
257                                throws XMLParsingException, URISyntaxException {
258            if ( node != null ) {
259                if ( ( XMLTools.getNode( node, "sml:GeoLocation", nsContext ) ) != null ) {
260                    String id = XMLTools.getNodeAsString( node, "sml:GeoLocation/@id", nsContext, null );
261    
262                    // required
263                    Quantity latitude = getQuantity( XMLTools.getRequiredNode( node, "sml:GeoLocation/sml:latitude",
264                                                                               nsContext ) );
265                    Quantity longitude = getQuantity( XMLTools.getRequiredNode( node, "sml:GeoLocation/sml:longitude",
266                                                                                nsContext ) );
267    
268                    // optional
269                    Quantity altitude = getQuantity( XMLTools.getNode( node, "sml:GeoLocation/sml:altitude", nsContext ) );
270                    Quantity trueHeading = getQuantity( XMLTools.getNode( node, "sml:GeoLocation/sml:trueHeading",
271                                                                          nsContext ) );
272                    Quantity speed = getQuantity( XMLTools.getNode( node, "sml:GeoLocation/sml:speed", nsContext ) );
273    
274                    return new GeoLocation( id, latitude, longitude, altitude, trueHeading, speed );
275                }
276    
277            }
278            return null;
279        }
280    
281        /**
282         * 
283         * @param node
284         * @return
285         * @throws XMLParsingException
286         * @throws URISyntaxException
287         */
288        protected Object getUsesParametersFromResponseModel( Node node )
289                                throws XMLParsingException, URISyntaxException {
290            if ( node != null ) {
291                if ( ( XMLTools.getNode( node, "sml:BasicResponse", nsContext ) ) != null ) {
292    
293                    // required
294                    TypedQuantity resolution = getTypedQuantity( XMLTools.getRequiredNode(
295                                                                                           node,
296                                                                                           "sml:BasicResponse/sml:resolution",
297                                                                                           nsContext ) );
298    
299                    return new BasicResponse( resolution );
300                }
301    
302                // can add other types, but now not implemented
303    
304            }
305            return null;
306        }
307    
308        /**
309         * 
310         * @param node
311         * @return
312         * @throws XMLParsingException
313         * @throws URISyntaxException
314         */
315        protected Quantity getQuantity( Node node )
316                                throws XMLParsingException, URISyntaxException {
317            if ( node != null ) {
318                String value = XMLTools.getRequiredNodeAsString( node, "sml:Quantity/text()", nsContext );
319    
320                if ( value != null ) {
321                    Quantity temp = new Quantity( Double.parseDouble( value ) );
322    
323                    // gets the uom parameter
324                    String paramUom = XMLTools.getNodeAsString( node, "sml:Quantity/@uom", nsContext, null );
325                    if ( paramUom != null ) {
326    
327                        temp.setUom( new URI( paramUom ) );
328                    }
329    
330                    // gets the min parameter
331                    String paramMin = XMLTools.getNodeAsString( node, "sml:Quantity/@min", nsContext, null );
332                    if ( paramMin != null ) {
333    
334                        temp.setMin( Double.parseDouble( paramMin ) );
335                    }
336    
337                    // gets the max parameter
338                    String paramMax = XMLTools.getNodeAsString( node, "sml:Quantity/@max", nsContext, null );
339                    if ( paramMax != null ) {
340    
341                        temp.setMax( Double.parseDouble( paramMax ) );
342                    }
343    
344                    // gets the fixed parameter
345                    String paramFixed = XMLTools.getNodeAsString( node, "sml:Quantity/@fixed", nsContext, null );
346                    if ( paramFixed != null ) {
347                        if ( paramFixed.equalsIgnoreCase( "true" ) ) {
348    
349                            temp.setFixed( true );
350                        } else if ( paramFixed.equalsIgnoreCase( "false" ) ) {
351    
352                            temp.setFixed( false );
353                        }
354                    }
355                    return temp;
356                }
357    
358            }
359    
360            return null;
361        }
362    
363        /**
364         * 
365         * @param node
366         * @return
367         * @throws XMLParsingException
368         * @throws URISyntaxException
369         */
370        protected TypedQuantity getTypedQuantity( Node node )
371                                throws XMLParsingException, URISyntaxException {
372            if ( node != null ) {
373    
374                String value = XMLTools.getRequiredNodeAsString( node, "sml:TypedQuantity/text()", nsContext );
375    
376                String type = XMLTools.getRequiredNodeAsString( node, "sml:TypedQuantity/@type", nsContext );
377    
378                TypedQuantity temp = new TypedQuantity( Double.parseDouble( value ), new URI( type ) );
379    
380                // gets the uom parameter
381                String paramUom = XMLTools.getNodeAsString( node, "sml:TypedQuantity/@uom", nsContext, null );
382                if ( paramUom != null ) {
383    
384                    temp.setUom( new URI( paramUom ) );
385                }
386    
387                // gets the min parameter
388                String paramMin = XMLTools.getNodeAsString( node, "sml:TypedQuantity/@min", nsContext, null );
389                if ( paramMin != null ) {
390    
391                    temp.setMin( Double.parseDouble( paramMin ) );
392                }
393    
394                // gets the max parameter
395                String paramMax = XMLTools.getNodeAsString( node, "sml:TypedQuantity/@max", nsContext, null );
396                if ( paramMax != null ) {
397    
398                    temp.setMax( Double.parseDouble( paramMax ) );
399                }
400    
401                // gets the fixed parameter
402                String paramFixed = XMLTools.getNodeAsString( node, "sml:TypedQuantity/@fixed", nsContext, null );
403                if ( paramFixed != null ) {
404                    if ( paramFixed.equalsIgnoreCase( "false" ) ) {
405    
406                        temp.setFixed( false );
407                    }
408                }
409    
410                // gets the codeSpace parameter
411                String codeSpaceAsString = XMLTools.getNodeAsString( node, "sml:TypedQuantity/@codeSpace", nsContext, null );
412                if ( codeSpaceAsString != null ) {
413                    URI codeSpace = new URI( codeSpaceAsString );
414                    temp.setCodeSpace( codeSpace );
415                }
416                return temp;
417            }
418    
419            return null;
420        }
421    
422        /**
423         * 
424         * @param node
425         * @return
426         * @throws XMLParsingException
427         * @throws MalformedURLException
428         */
429        protected ComponentDescription getDescribedBy( Node node )
430                                throws MalformedURLException, XMLParsingException {
431            if ( node != null ) {
432    
433                boolean create = false;
434    
435                // get optional id
436                String id = XMLTools.getNodeAsString( node, "sml:ComponentDescription/@id", nsContext, null );
437                if ( id != null )
438                    create = true;
439    
440                // get optional description
441                ArrayList<Discussion> descriptions = new ArrayList<Discussion>();
442                List descriptionList = XMLTools.getNodes( node, "sml:ComponentDescription/sml:description", nsContext );
443                if ( ( descriptionList != null ) && ( descriptionList.size() > 0 ) )
444                    create = true;
445                for ( int i = 0; i < descriptionList.size(); i++ ) {
446                    descriptions.add( getDiscussion( (Node) descriptionList.get( i ) ) );
447                }
448    
449                // get optional reference
450                List referenceList = XMLTools.getNodes( node, "sml:ComponentDescription/sml:reference", nsContext );
451                if ( ( referenceList != null ) && ( referenceList.size() > 0 ) ) {
452                    create = true;
453    
454                }
455                ArrayList<Reference> references = new ArrayList<Reference>( referenceList.size() );
456                for ( int i = 0; i < referenceList.size(); i++ ) {
457                    Reference actreference = getReference( (Node) referenceList.get( i ) );
458                    if ( actreference != null ) {
459                        references.add( actreference );
460                    }
461                }
462    
463                // get optional operatedBy
464                List operatedByList = XMLTools.getNodes( node, "sml:ComponentDescription/sml:operatedBy", nsContext );
465                if ( ( operatedByList != null ) && ( operatedByList.size() > 0 ) ) {
466                    create = true;
467    
468                }
469                ArrayList<CitedResponsibleParty> operatedBys = new ArrayList<CitedResponsibleParty>( operatedByList.size() );
470                for ( int i = 0; i < operatedByList.size(); i++ ) {
471                    CitedResponsibleParty actResponsibleParty = getResponsibleParty( (Node) operatedByList.get( i ) );
472                    if ( actResponsibleParty != null ) {
473                        operatedBys.add( actResponsibleParty );
474                    }
475                }
476    
477                // get optional manufactedBy
478                List manufactedByList = XMLTools.getNodes( node, "sml:ComponentDescription/sml:manufactedBy", nsContext );
479                if ( ( manufactedByList != null ) && ( manufactedByList.size() > 0 ) ) {
480                    create = true;
481    
482                }
483                ArrayList<CitedResponsibleParty> manufactedBys = new ArrayList<CitedResponsibleParty>(
484                                                                                                       manufactedByList.size() );
485                for ( int i = 0; i < manufactedByList.size(); i++ ) {
486                    CitedResponsibleParty actResponsibleParty = getResponsibleParty( (Node) manufactedByList.get( i ) );
487                    if ( actResponsibleParty != null ) {
488                        manufactedBys.add( actResponsibleParty );
489                    }
490                }
491    
492                // get optional deployedBys
493                List deployedByList = XMLTools.getNodes( node, "sml:ComponentDescription/sml:deployedBy", nsContext );
494                if ( ( deployedByList != null ) && ( deployedByList.size() > 0 ) ) {
495                    create = true;
496    
497                }
498                ArrayList<CitedResponsibleParty> deployedBys = new ArrayList<CitedResponsibleParty>( deployedByList.size() );
499                for ( int i = 0; i < deployedByList.size(); i++ ) {
500                    CitedResponsibleParty actResponsibleParty = getResponsibleParty( (Node) deployedByList.get( i ) );
501                    if ( actResponsibleParty != null ) {
502                        deployedBys.add( actResponsibleParty );
503                    }
504                }
505    
506                if ( create ) {
507                    return new ComponentDescription(
508                                                     id,
509                                                     ( manufactedBys.toArray( new CitedResponsibleParty[manufactedBys.size()] ) ),
510                                                     ( deployedBys.toArray( new CitedResponsibleParty[deployedBys.size()] ) ),
511                                                     ( operatedBys.toArray( new CitedResponsibleParty[operatedBys.size()] ) ),
512                                                     ( descriptions.toArray( new Discussion[descriptions.size()] ) ),
513                                                     ( references.toArray( new Reference[references.size()] ) ) );
514                }
515    
516            }
517            return null;
518    
519        }
520    
521        /**
522         * 
523         * @param node
524         * @return
525         * @throws XMLParsingException
526         * @throws URISyntaxException
527         */
528        protected LocationModel getLocatedUsing( Node node )
529                                throws XMLParsingException, URISyntaxException {
530    
531            if ( node != null ) {
532                if ( ( XMLTools.getNode( node, "sml:GeoPositionModel", nsContext ) ) != null ) {
533    
534                    String id = XMLTools.getNodeAsString( node, "sml:GeoPositionModel/@id", nsContext, null );
535    
536                    // get identifiedAs
537                    ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
538                    List identifierList = XMLTools.getNodes( node, "sml:GeoPositionModel/sml:identifiedAs", nsContext );
539                    for ( int i = 0; i < identifierList.size(); i++ ) {
540                        identifiers.add( getIdentifiedAs( (Node) identifierList.get( i ) ) );
541                    }
542    
543                    // get ClassifiedAs
544                    ArrayList<Classifier> classifiers = new ArrayList<Classifier>();
545                    List classifierList = XMLTools.getNodes( node, "sml:GeoPositionModel/sml:classifiedAs", nsContext );
546                    for ( int i = 0; i < classifierList.size(); i++ ) {
547                        classifiers.add( getClassifiedAs( (Node) classifierList.get( i ) ) );
548                    }
549    
550                    // get optional description
551                    ArrayList<Discussion> descriptions = new ArrayList<Discussion>();
552                    List descriptionList = XMLTools.getNodes( node, "sml:GeoPositionModel/sml:description", nsContext );
553                    for ( int i = 0; i < descriptionList.size(); i++ ) {
554                        descriptions.add( getDiscussion( (Node) descriptionList.get( i ) ) );
555                    }
556    
557                    // get sourceCRS
558                    Node tNode = XMLTools.getRequiredNode( node, "sml:GeoPositionModel/sml:sourceCRS", nsContext );
559                    EngineeringCRS sourceCRS = getEngineeringCRS( tNode );
560    
561                    // get referenceCRS
562                    tNode = XMLTools.getRequiredNode( node, "sml:GeoPositionModel/sml:referenceCRS", nsContext );
563                    CoordinateReferenceSystem referenceCRS = getCoordinateReferenceSystemCRS( tNode );
564    
565                    // get usesParameters
566                    ArrayList<Object> usesParameters = new ArrayList<Object>();
567                    List usesParametersList = XMLTools.getNodes( node, "sml:GeoPositionModel/sml:usesParameters", nsContext );
568                    if ( ( usesParametersList == null ) || ( usesParametersList.size() <= 0 ) ) {
569                        throw new XMLParsingException( "at least one usesParameters required" );
570                    }
571                    for ( int i = 0; i < usesParametersList.size(); i++ ) {
572                        usesParameters.add( getUsesParametersFromGeoLocation( (Node) usesParametersList.get( i ) ) );
573                    }
574    
575                    return new GeoPositionModel( id, ( identifiers.toArray( new Identifier[identifiers.size()] ) ),
576                                                 ( classifiers.toArray( new Classifier[classifiers.size()] ) ),
577                                                 ( descriptions.toArray( new Discussion[descriptions.size()] ) ),
578                                                 sourceCRS, referenceCRS,
579                                                 usesParameters.toArray( new Object[usesParameters.size()] ) );
580                }
581    
582            }
583            return null;
584    
585        }
586    
587        /**
588         * 
589         * @param node
590         * @return
591         * @throws XMLParsingException
592         * @throws URISyntaxException
593         */
594        protected ResponseModel getDerivedFrom( Node node )
595                                throws XMLParsingException, URISyntaxException {
596    
597            if ( node != null ) {
598    
599                String id = XMLTools.getNodeAsString( node, "sml:ResponseModel/@id", nsContext, null );
600    
601                // get identifiedAs
602                ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
603                List identifierList = XMLTools.getNodes( node, "sml:ResponseModel/sml:identifiedAs", nsContext );
604                for ( int i = 0; i < identifierList.size(); i++ ) {
605                    identifiers.add( getIdentifiedAs( (Node) identifierList.get( i ) ) );
606                }
607    
608                // get ClassifiedAs
609                ArrayList<Classifier> classifiers = new ArrayList<Classifier>();
610                List classifierList = XMLTools.getNodes( node, "sml:ResponseModel/sml:classifiedAs", nsContext );
611                for ( int i = 0; i < classifierList.size(); i++ ) {
612                    classifiers.add( getClassifiedAs( (Node) classifierList.get( i ) ) );
613                }
614    
615                // get optional description
616                ArrayList<Discussion> descriptions = new ArrayList<Discussion>();
617                List descriptionList = XMLTools.getNodes( node, "sml:ResponseModel/sml:description", nsContext );
618                for ( int i = 0; i < descriptionList.size(); i++ ) {
619                    descriptions.add( getDiscussion( (Node) descriptionList.get( i ) ) );
620                }
621    
622                // get usesParameters
623                // in spec this parameter is optional, but now is required for set
624                // time resolution
625                ArrayList<Object> usesParameters = new ArrayList<Object>();
626                List usesParametersList = XMLTools.getNodes( node, "sml:ResponseModel/sml:usesParameters", nsContext );
627                for ( int i = 0; i < usesParametersList.size(); i++ ) {
628                    usesParameters.add( getUsesParametersFromResponseModel( (Node) usesParametersList.get( i ) ) );
629                }
630    
631                // only creats the object if least one value set
632                if ( ( id != null ) || ( identifiers.size() > 0 ) || ( classifiers.size() > 0 )
633                     || ( descriptions.size() > 0 ) || ( usesParameters.size() > 0 ) ) {
634                    return new ResponseModel( id, ( identifiers.toArray( new Identifier[identifiers.size()] ) ),
635                                              ( classifiers.toArray( new Classifier[classifiers.size()] ) ),
636                                              ( descriptions.toArray( new Discussion[descriptions.size()] ) ),
637                                              usesParameters.toArray( new Object[usesParameters.size()] ) );
638                }
639            }
640            return null;
641    
642        }
643    
644        /**
645         * 
646         * @param node
647         * @return
648         * @throws MalformedURLException
649         * @throws XMLParsingException
650         */
651        protected Reference getReference( Node node )
652                                throws MalformedURLException, XMLParsingException {
653    
654            if ( node != null ) {
655                Object getvalue = null;
656    
657                getvalue = getOnlineResource( node );
658    
659                if ( getvalue != null ) {
660    
661                    return new Reference( getvalue );
662                }
663            }
664            return null;
665    
666        }
667    
668        /**
669         * 
670         * @param node
671         * @return
672         * @throws XMLParsingException
673         */
674        protected Discussion getDiscussion( Node node )
675                                throws XMLParsingException {
676            if ( node != null ) {
677                // required
678                String value = XMLTools.getRequiredNodeAsString( node, "text()", nsContext );
679                URI topic = null;
680                // optional
681                String topicString = XMLTools.getNodeAsString( node, "@topic", nsContext, null );
682                URI codeSpace = null;
683                // optional
684                String codeSpaceString = XMLTools.getNodeAsString( node, "@codeSpace", nsContext, null );
685                // optional
686                String id = XMLTools.getNodeAsString( node, "@id", nsContext, null );
687    
688                try {
689                    if ( topicString != null )
690                        topic = new URI( topicString );
691    
692                    if ( codeSpaceString != null )
693                        codeSpace = new URI( codeSpaceString );
694                } catch ( URISyntaxException e ) {
695                    throw new XMLParsingException( "URISyntaxException: not a valid URI" );
696                }
697    
698                return new Discussion( value, topic, codeSpace, id );
699            }
700            return null;
701    
702        }
703    
704        /**
705         * 
706         * @param node
707         * @return
708         * @throws XMLParsingException
709         * @throws MalformedURLException
710         */
711        protected OnlineResource getOnlineResource( Node node )
712                                throws XMLParsingException, MalformedURLException {
713    
714            if ( node != null ) {
715                String function = XMLTools.getNodeAsString( node, "iso19115:CI_OnlineResource/iso19115:function/text()",
716                                                            nsContext, null );
717    
718                String linkageString = XMLTools.getNodeAsString( node,
719                                                                 "iso19115:CI_OnlineResource/iso19115:linkage/text()",
720                                                                 nsContext, null );
721    
722                String protocol = XMLTools.getNodeAsString( node, "iso19115:CI_OnlineResource/iso19115:protocol/text()",
723                                                            nsContext, null );
724    
725                String applicationProfile = XMLTools.getNodeAsString(
726                                                                      node,
727                                                                      "iso19115:CI_OnlineResource/iso19115:applicationProfile/text()",
728                                                                      nsContext, null );
729    
730                String name = XMLTools.getNodeAsString( node, "iso19115:CI_OnlineResource/iso19115:name/text()", nsContext,
731                                                        null );
732    
733                String description = XMLTools.getNodeAsString( node,
734                                                               "iso19115:CI_OnlineResource/iso19115:description/text()",
735                                                               nsContext, null );
736    
737                if ( linkageString != null ) {
738                    return new OnlineResource( applicationProfile, new FunctionCode( function ),
739                                               new Linkage( new URL( linkageString ) ), description, name, protocol );
740                }
741            }
742            return null;
743        }
744    
745        /**
746         * 
747         * @param node
748         * @return
749         * @throws XMLParsingException
750         */
751        protected Phone getPhone( Node node )
752                                throws XMLParsingException {
753    
754            if ( node != null ) {
755                // get voices
756                String[] voices = XMLTools.getNodesAsStrings( node, "iso19115:phone/iso19115:voice/text()", nsContext );
757                // get facsimiles
758                String[] facsimiles = XMLTools.getNodesAsStrings( node, "iso19115:phone/iso19115:facsimile/text()",
759                                                                  nsContext );
760                return new Phone( facsimiles, null, null, voices );
761            }
762            return null;
763        }
764    
765        /**
766         * 
767         * @param node
768         * @return
769         * @throws XMLParsingException
770         */
771        protected Address getAddress( Node node )
772                                throws XMLParsingException {
773    
774            if ( node != null ) {
775                String city = XMLTools.getNodeAsString( node, "iso19115:address/iso19115:city/text()", nsContext, null );
776    
777                String administrativeArea = XMLTools.getNodeAsString(
778                                                                      node,
779                                                                      "iso19115:address/iso19115:administrativeArea/text()",
780                                                                      nsContext, null );
781    
782                String postalCode = XMLTools.getNodeAsString( node, "iso19115:address/iso19115:postalCode/text()",
783                                                              nsContext, null );
784    
785                String country = XMLTools.getNodeAsString( node, "iso19115:address/iso19115:country/text()", nsContext,
786                                                           null );
787    
788                // get deliveryPoints
789                String[] deliveryPoints = XMLTools.getNodesAsStrings( node,
790                                                                      "iso19115:address/iso19115:deliveryPoint/text()",
791                                                                      nsContext );
792                // get electronicMailAdresses
793                String[] electronicMailAdresses = XMLTools.getNodesAsStrings(
794                                                                              node,
795                                                                              "iso19115:address/iso19115:electronicMailAddress/text()",
796                                                                              nsContext );
797                return new Address( administrativeArea, city, country, deliveryPoints, electronicMailAdresses, postalCode );
798            }
799            return null;
800        }
801    
802        /**
803         * 
804         * @param node
805         * @return
806         * @throws MalformedURLException
807         * @throws XMLParsingException
808         */
809        protected ContactInfo getContactInfo( Node node )
810                                throws MalformedURLException, XMLParsingException {
811    
812            if ( node != null ) {
813                Phone phone = getPhone( node );
814                Address address = getAddress( node );
815                OnlineResource onlineResource = getOnlineResource( node );
816                String hoursOfService = XMLTools.getNodeAsString( node, "iso19115:hoursOfService/text()", nsContext, null );
817                String contactInstructions = XMLTools.getNodeAsString( node, "iso19115:contactInstructions/text()",
818                                                                       nsContext, null );
819    
820                return new ContactInfo( address, contactInstructions, hoursOfService, onlineResource, phone );
821            }
822            return null;
823        }
824    
825        /**
826         * 
827         * @param node
828         * @return
829         * @throws XMLParsingException
830         * @throws XMLParsingException
831         * @throws MalformedURLException
832         */
833        protected CitedResponsibleParty getResponsibleParty( Node node )
834                                throws MalformedURLException, XMLParsingException {
835    
836            if ( node != null ) {
837                // gets individualNames
838                String[] individualNames = XMLTools.getNodesAsStrings(
839                                                                       node,
840                                                                       "iso19115:CI_ResponsibleParty/iso19115:individualName/text()",
841                                                                       nsContext );
842    
843                // gets organisationNames
844                String[] organisationNames = XMLTools.getNodesAsStrings(
845                                                                         node,
846                                                                         "iso19115:CI_ResponsibleParty/iso19115:organisationName/text()",
847                                                                         nsContext );
848    
849                // gets positionNames
850                String[] positionNames = XMLTools.getNodesAsStrings(
851                                                                     node,
852                                                                     "iso19115:CI_ResponsibleParty/iso19115:positionName/text()",
853                                                                     nsContext );
854    
855                // gets role_CodeList
856                List role_CodeListList = XMLTools.getNodes(
857                                                            node,
858                                                            "iso19115:CI_ResponsibleParty/iso19115:role/iso19115:CI_RoleCode_CodeList",
859                                                            nsContext );
860                ArrayList<RoleCode> role_CodeList = new ArrayList<RoleCode>( role_CodeListList.size() );
861                for ( int i = 0; i < role_CodeListList.size(); i++ ) {
862                    role_CodeList.add( new RoleCode( XMLTools.getRequiredNodeAsString( (Node) role_CodeListList.get( i ),
863                                                                                       "text()", nsContext ) ) );
864                }
865    
866                // gets contactInfo
867                List contactInfoList = XMLTools.getNodes( node, "iso19115:CI_ResponsibleParty/iso19115:contactInfo",
868                                                          nsContext );
869                ArrayList<ContactInfo> contactInfo = new ArrayList<ContactInfo>( contactInfoList.size() );
870                for ( int i = 0; i < contactInfoList.size(); i++ ) {
871                    contactInfo.add( getContactInfo( (Node) contactInfoList.get( i ) ) );
872                }
873    
874                return new CitedResponsibleParty( contactInfo.toArray( new ContactInfo[contactInfo.size()] ),
875                                                  individualNames, organisationNames, positionNames,
876                                                  role_CodeList.toArray( new RoleCode[role_CodeList.size()] ) );
877            }
878            return null;
879        }
880    }