View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  /**
24   * 
25   */
26  package com.gisgraphy.geoloc;
27  
28  import com.gisgraphy.serializer.common.IoutputFormatVisitor;
29  import com.gisgraphy.serializer.common.OutputFormat;
30  
31  /**
32   * Visitor (visitor pattern) to return error message according to the format for
33   * the geoloc service
34   * 
35   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
36   * 
37   */
38  public class GeolocErrorVisitor implements IoutputFormatVisitor {
39  
40      private String errorMessage = IoutputFormatVisitor.DEFAULT_ERROR_MESSAGE;
41  
42      public GeolocErrorVisitor() {
43  	super();
44      }
45  
46      /**
47       * @param errorMessage
48       *                The error Message
49       */
50      public GeolocErrorVisitor(String errorMessage) {
51  	super();
52  	this.errorMessage = errorMessage;
53      }
54  
55      /*
56       * (non-Javadoc)
57       * 
58       * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitXML(com.gisgraphy.domain.valueobject.Output.OutputFormat)
59       */
60      public String visitXML(OutputFormat format) {
61  	return String
62  		.format(
63  			"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><results xmlns=\"http://gisgraphy.com\"><error>%s</error><numFound>0</numFound></results>",
64  			errorMessage);
65      }
66  
67      /*
68       * (non-Javadoc)
69       * 
70       * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitJSON(com.gisgraphy.domain.valueobject.Output.OutputFormat)
71       */
72      public String visitJSON(OutputFormat format) {
73  	return String.format("{\"numFound\":0,\"error\":\"%s\",\"result\":[]}",
74  		errorMessage);
75      }
76  
77      /*
78       * (non-Javadoc)
79       * 
80       * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitPYTHON(com.gisgraphy.domain.valueobject.Output.OutputFormat)
81       */
82      public String visitPYTHON(OutputFormat format) {
83  	return visitXML(format);
84      }
85  
86      /*
87       * (non-Javadoc)
88       * 
89       * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitRUBY(com.gisgraphy.domain.valueobject.Output.OutputFormat)
90       */
91      public String visitRUBY(OutputFormat format) {
92  	return visitXML(format);
93      }
94  
95      /*
96       * (non-Javadoc)
97       * 
98       * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitPHP(com.gisgraphy.domain.valueobject.Output.OutputFormat)
99       */
100     public String visitPHP(OutputFormat format) {
101 	return visitXML(format);
102     }
103 
104     /*
105      * (non-Javadoc)
106      * 
107      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitATOM(com.gisgraphy.domain.valueobject.Output.OutputFormat)
108      */
109     public String visitATOM(OutputFormat outputFormat) {
110 	return visitXML(outputFormat);
111     }
112 
113     /*
114      * (non-Javadoc)
115      * 
116      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitGEORSS(com.gisgraphy.domain.valueobject.Output.OutputFormat)
117      */
118     public String visitGEORSS(OutputFormat outputFormat) {
119 	return visitXML(outputFormat);
120     }
121     
122     /* (non-Javadoc)
123      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitUNSUPPORTED(com.gisgraphy.domain.valueobject.Output.OutputFormat)
124      */
125     public String visitUNSUPPORTED(OutputFormat format) {
126 		return "";
127 	}
128 
129 
130     /* (non-Javadoc)
131      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#getErrorMessage()
132      */
133     public String getErrorMessage() {
134         return errorMessage;
135     }
136 
137     public String visitYAML(OutputFormat format) {
138 	return errorMessage;
139     }
140 
141 }