001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/owscommon_new/HTTP.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2008 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     Aennchenstr. 19
030     53115 Bonn
031     Germany
032     E-Mail: poth@lat-lon.de
033    
034     Prof. Dr. Klaus Greve
035     Department of Geography
036     University of Bonn
037     Meckenheimer Allee 166
038     53115 Bonn
039     Germany
040     E-Mail: greve@giub.uni-bonn.de
041    
042     
043     ---------------------------------------------------------------------------*/
044    package org.deegree.owscommon_new;
045    
046    import java.net.URL;
047    import java.util.ArrayList;
048    import java.util.List;
049    
050    import org.deegree.model.metadata.iso19115.Linkage;
051    import org.deegree.model.metadata.iso19115.OnlineResource;
052    
053    /**
054     * <code>HTTP</code> describes the distributed computing platform which a service uses. In terms
055     * of HTTP: it stores the links where it can be reached.
056     * 
057     * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
058     * @author last edited by: $Author: apoth $
059     * 
060     * @version 2.0, $Revision: 9346 $, $Date: 2007-12-27 17:39:07 +0100 (Do, 27 Dez 2007) $
061     * 
062     * @since 2.0
063     */
064    
065    public class HTTP implements DCP {
066    
067        private static final long serialVersionUID = 989887096571428263L;
068    
069        private List<List<DomainType>> constraints;
070    
071        private List<Type> types;
072    
073        private List<OnlineResource> links;
074    
075        /**
076         * Standard constructor that initializes all encapsulated data.
077         * 
078         * @param links
079         * @param constraints
080         * @param types
081         */
082        public HTTP( List<OnlineResource> links, List<List<DomainType>> constraints, List<Type> types ) {
083            this.links = links;
084            this.constraints = constraints;
085            this.types = types;
086        }
087    
088        /**
089         * @return Returns the constraints.
090         */
091        public List<List<DomainType>> getConstraints() {
092            return constraints;
093        }
094    
095        /**
096         * @return Returns the types.
097         */
098        public List<Type> getTypes() {
099            return types;
100        }
101    
102        /**
103         * @return the links.
104         */
105        public List<OnlineResource> getLinks() {
106            return links;
107        }
108    
109        /**
110         * @return a list of all Get method URLs.
111         */
112        public List<URL> getGetOnlineResources() {
113            List<URL> result = new ArrayList<URL>();
114    
115            for ( int i = 0; i < types.size(); ++i ) {
116                if ( types.get( i ) == Type.Get ) {
117                    result.add( links.get( i ).getLinkage().getHref() );
118                }
119            }
120    
121            return result;
122        }
123    
124        /**
125         * @return a list of all Get method URLs.
126         */
127        public List<URL> getPostOnlineResources() {
128            List<URL> result = new ArrayList<URL>();
129    
130            for ( int i = 0; i < types.size(); ++i ) {
131                if ( types.get( i ) == Type.Post ) {
132                    result.add( links.get( i ).getLinkage().getHref() );
133                }
134            }
135    
136            return result;
137        }
138    
139        /**
140         * @param urlsnew
141         */
142        public void setGetOnlineResources( List<URL> urlsnew ) {
143            List<OnlineResource> result = new ArrayList<OnlineResource>( links.size() );
144            List<Type> typesnew = new ArrayList<Type>( links.size() );
145    
146            for ( int i = 0; i < types.size(); ++i ) {
147                if ( types.get( i ) == Type.Post ) {
148                    result.add( links.get( i ) );
149                    typesnew.add( types.get( i ) );
150                }
151            }
152    
153            for ( URL url : urlsnew ) {
154                result.add( new OnlineResource( new Linkage( url ) ) );
155                typesnew.add( Type.Get );
156            }
157    
158            links = result;
159            types = typesnew;
160        }
161    
162        /**
163         * @param urlsnew
164         */
165        public void setPostOnlineResources( List<URL> urlsnew ) {
166            List<OnlineResource> result = new ArrayList<OnlineResource>( links.size() );
167            List<Type> typesnew = new ArrayList<Type>( links.size() );
168    
169            for ( int i = 0; i < types.size(); ++i ) {
170                if ( types.get( i ) == Type.Get ) {
171                    result.add( links.get( i ) );
172                }
173            }
174    
175            for ( URL url : urlsnew ) {
176                result.add( new OnlineResource( new Linkage( url ) ) );
177                typesnew.add( Type.Post );
178            }
179    
180            links = result;
181            types = typesnew;
182        }
183    
184        /**
185         * Enumeration type indicating the used HTTP request method.
186         * 
187         * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
188         * @author last edited by: $Author: apoth $
189         * 
190         * @version 2.0, $Revision: 9346 $, $Date: 2007-12-27 17:39:07 +0100 (Do, 27 Dez 2007) $
191         * 
192         * @since 2.0
193         */
194        public enum Type {
195            /**
196             * The Get HTTP method.
197             */
198            Get,
199            /**
200             * The Post HTTP method.
201             */
202            Post
203        }
204    
205    }