Skip to main content
summaryrefslogtreecommitdiffstats
blob: f983bd96d58ddf5f9c37073982b0b1faafa18d8e (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
/*******************************************************************************
 * 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.wsdl20;

import java.util.Hashtable;
import java.util.Map;


/**
 * A registry to hold all the WSDL 2.0 validators.
 */
public class ValidatorRegistry
{

  protected static ValidatorRegistry verInstance;

  protected Map validatorReg = new Hashtable();

  /**
   * Constructor.
   */
  protected ValidatorRegistry()
  {
  }

  /**
   * Returns the instance of this registry.
   * 
   * @return The instance of this registry.
   */
  public static ValidatorRegistry getInstance()
  {
    if (verInstance == null)
    {
      verInstance = new ValidatorRegistry();
    }
    return verInstance;
  }

  /**
   * Register this validator delegate with the given namespace.
   * 
   * @param namespace The namespace the validator is associated with.
   * @param valDelegate The validator delegate to register.
   */
  public void registerValidator(String namespace, WSDL20ValidatorDelegate valDelegate)
  {
    // allow the null namespace but make it the empty string
    if (namespace == null)
    {
      namespace = "";
    }

    // add the validator to the hashtable
    validatorReg.put(namespace, valDelegate);
  }

  /**
   * Ask for the validator associated with this namespace. If none is found
   * return null.
   * 
   * @param namespace The namespace of the validator.
   * @return The WSDL 1.1 validator for the given namespace.
   */
  public IWSDL20Validator queryValidatorRegistry(String namespace)
  {
    // if the namespace is null allow it and treat it as the empty string
    if (namespace == null)
    {
      namespace = "";
    }
    WSDL20ValidatorDelegate delegate = (WSDL20ValidatorDelegate)validatorReg.get(namespace);
    if(delegate != null)
    {  
      return delegate.getValidator();
    }
    return null;
  }

  /**
   * Convenience method that tells whether a validator for a given namespace is registered.
   * 
   * @param namespace The namespace to check.
   * @return True if there is a validator registered, false otherwise.
   */
  public boolean hasRegisteredValidator(String namespace)
  {
    if (queryValidatorRegistry(namespace) != null)
    {
      return true;
    }
    return false;
  }
}

Back to the top