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