Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: d3919071b3631a8a7856710e6665eb572fd67c06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.wst.wsdl.validation.internal;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import org.eclipse.wst.wsdl.validation.internal.resolver.URIResolver;
import org.eclipse.wst.wsdl.validation.internal.util.MessageGenerator;

/**
 * An implementation of the validation info interface.
 */
public class ValidationInfoImpl implements IValidationReport, ControllerValidationInfo
{
  private boolean WRAPPER_ERROR_SUPPORT_ENABLED = true;
  private final String _WARN_NO_VALDIATOR = "_WARN_NO_VALDIATOR";
  private final String _REF_FILE_ERROR_MESSAGE = "_REF_FILE_ERROR_MESSAGE";
  private String validating_file_uri = null;
  private URL validating_file_url = null;
  private boolean wsdlValid = false;
  private List messages = new Vector();
  //private List schemas = new Vector();
  private List nsNoVals = new Vector();
  private MessageGenerator messagegenerator = null;
  private boolean haserrors = false;
  private HashMap nestedMessages = new HashMap();
  private URIResolver uriResolver = null;
  private WSDLValidationConfiguration configuration;

  /**
   * Constructor.
   * 
   * @param uri
   *            The URI of the file for the validation.
   */
  public ValidationInfoImpl(String uri, MessageGenerator messagegenerator)
  {
    this.validating_file_uri = uri;
    if(uri != null)
    {
      uri = uri.replaceAll("%20"," ");
      this.validating_file_uri = uri;
      try
      {
        this.validating_file_url = new URL(uri);
      } catch (MalformedURLException e)
      {
      }
    }
    this.messagegenerator = messagegenerator;
  }
  /**
   * @see org.eclipse.wst.wsdl.validation.internal.IValidationReport#getFileURI()
   */
  public String getFileURI()
  {
    return validating_file_uri;
  }

  /**
   * @see org.eclipse.wst.wsdl.validation.internal.IValidationReport#isWSDLValid()
   */
  public boolean isWSDLValid()
  {
    return wsdlValid;
  }

  /**
   * @see org.eclipse.wst.wsdl.validation.internal.IValidationInfo#addError(java.lang.String,
   *      int, int)
   */
  public void addError(String message, int line, int column)
  {
    addError(message, line, column, validating_file_uri);
  }
  
  /**
   * @see org.eclipse.wst.wsdl.validation.internal.IValidationInfo#addError(java.lang.String,
   *      int, int)
   */
  public void addError(String message, int line, int column, String uri)
  {
    if(addMessage(message, line, column, uri, ValidationMessageImpl.SEV_ERROR))
    {
      haserrors = true;
    }
  }

  public void addError(String message, int line, int column, String uri, String errorKey, Object[] messageArguments)
  {
    if(addMessage(message, line, column, uri, ValidationMessageImpl.SEV_ERROR, errorKey, messageArguments))
    {
      haserrors = true;
    }
  }
  
  
  /**
   * @see org.eclipse.wst.wsdl.validation.internal.IValidationInfo#addWarning(java.lang.String,
   *      int, int)
   */
  public void addWarning(String message, int line, int column)
  {
    addWarning(message, line, column, validating_file_uri);
  }
  /**
   * @see org.eclipse.wst.wsdl.validation.internal.IValidationInfo#addWarning(java.lang.String,
   *      int, int)
   */
  public void addWarning(String message, int line, int column, String uri)
  {
    addMessage(message, line, column, uri, ValidationMessageImpl.SEV_WARNING);
  }
  
  /**
   * Add a message to the list. A message may not be added to the list in 
   * certain circumstances such as when the URI is invalid or the message 
   * is null.
   * 
   * @param message The message to add.
   * @param line The line location of the message.
   * @param column The column location of the message.
   * @param uri The URI of the file that contains the message.
   * @param severity The severity of the message.
   * @return True if the message was able to be added, false otherwise.
   */
  private boolean addMessage(String message, int line, int column, String uri, int severity)
  {
      return this.addMessage(message, line, column, uri, severity, null, null);
  }
  
  /**
   * Add a message to the list. A message may not be added to the list in 
   * certain circumstances such as when the URI is invalid or the message 
   * is null.
   * 
   * @param message The message to add.
   * @param line The line location of the message.
   * @param column The column location of the message.
   * @param uri The URI of the file that contains the message.
   * @param severity The severity of the message.
   * @param errorKey The Xerces Error Key
   * @param messageArguments The Xerces arguments used to create the error message
   * @return True if the message was able to be added, false otherwise.
   */
  private boolean addMessage(String message, int line, int column, String uri, int severity, String errorKey, Object[] messageArguments)
  {
    boolean successfullyAdded = false;
    // If the message is null there is nothing to report.
    if(message == null)
    {
      return successfullyAdded;
    }
    String errorURI = uri;
    URL errorURL = null;
    if (errorURI != null)
    {
      try
      {
        errorURI = errorURI.replaceAll("%20", " ");
        errorURL = new URL(errorURI);
      } catch (MalformedURLException e)
      {
      }
      //errorURI = normalizeURI(errorURI);
    }
//    else
//    {
//      errorURI = validating_file_uri;
//      errorURL = validating_file_url;
//    }
    //boolean doDialog = true;
    if (errorURL != null)
    {
      successfullyAdded = true;
      // Add to the appropriate list if nested error support is off or
      // this message is for the current file.
      if (!WRAPPER_ERROR_SUPPORT_ENABLED || validating_file_url.sameFile(errorURL))
      {

        ValidationMessageImpl valmes = new ValidationMessageImpl(message, line,
            column, severity, uri, errorKey, messageArguments);
        messages.add(valmes);
      }
      // If nested error support is enabled create a nested error.
      else if (WRAPPER_ERROR_SUPPORT_ENABLED)
      {
        String nesteduri = errorURL.toExternalForm();
        ValidationMessageImpl nestedmess = new ValidationMessageImpl(message, line,
            column, severity, nesteduri);

        ValidationMessageImpl container = (ValidationMessageImpl) nestedMessages.get(nesteduri);
        if(container == null)
        {
          // Initially set the nested error to a warning. This will automatically be changed
          // to an error if a nested message has a severity of error.
          container = new ValidationMessageImpl(messagegenerator.getString(_REF_FILE_ERROR_MESSAGE, nesteduri), 1, 0, IValidationMessage.SEV_WARNING, nesteduri);
          nestedMessages.put(nesteduri, container);
          messages.add(container);
        }
        container.addNestedMessage(nestedmess);
      }
    }

    return successfullyAdded;
  }

  /**
   * @see org.eclipse.wst.wsdl.validation.internal.IValidationReport#getValidationMessages()
   */
  public IValidationMessage[] getValidationMessages()
  {
    return (IValidationMessage[])messages.toArray(new IValidationMessage[messages.size()]);
  }

  /**
   * @see org.eclipse.wst.wsdl.validation.internal.IValidationInfo#addNamespaceWithNoValidator(java.lang.String)
   */
  public void addNamespaceWithNoValidator(String namespace)
  {
    // If the list doesn't already contain this namespace, add it to the list
    // and create a warning message.
    if (!nsNoVals.contains(namespace))
    {
      nsNoVals.add(namespace);
      addWarning(messagegenerator.getString(_WARN_NO_VALDIATOR, namespace), 1, 0);

    }

  }

  /**
   * @see org.eclipse.wst.wsdl.validation.internal.ControllerValidationInfo#completeWSDLValidation()
   */
  public void completeWSDLValidation()
  {
    if (haserrors)
    {
      wsdlValid = false;
    }
    else
    {
      wsdlValid = true;
    }
  }

  /**
   * @see org.eclipse.wst.wsdl.validation.internal.IValidationReport#hasErrors()
   */
  public boolean hasErrors()
  {
    return haserrors;
  }
  
  /* (non-Javadoc)
   * @see org.eclipse.wsdl.validate.ValidationReport#getNestedMessages()
   */
  public HashMap getNestedMessages()
  {
    return nestedMessages;
  }
  
  public void setURIResolver(URIResolver uriResolver)
  {
  	this.uriResolver = uriResolver;
  }
  
  public URIResolver getURIResolver()
  {
  	return uriResolver;
  }

	/* (non-Javadoc)
	 * @see org.eclipse.wsdl.validate.ValidationInfo#getAttribute(java.lang.String)
	 */
	public Object getAttribute(String name) 
	{
		if(configuration == null)
		{
			return null;
		}
		return configuration.getProperty(name);
	}
	
	public void setConfiguration(WSDLValidationConfiguration configuration)
	{
		this.configuration = configuration;
	}
	public boolean isValid() {
		return !hasErrors();
	}
}

Back to the top