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
|
/*******************************************************************************
* 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.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
/**
* A registry of IWSDLValidator validators. This holds the top level WSDL and WS-I validators.
* Validators are registered by the namespace they validate.
*/
public class ValidatorRegistry
{
/**
* The WSDL validator type.
*/
public final static Integer WSDL_VALIDATOR = new Integer(0);
/**
* The WS-I validator type.
*/
public final static Integer EXT_VALIDATOR = new Integer(1);
protected static ValidatorRegistry verInstance;
/*
This is a Map of Maps. The top-level Map is keyed by (Class)parentType,
and the inner Maps are keyed by (QName)elementType.
This idea is the same as is done in WSDL4J
*/
protected Map validatorReg = new Hashtable();
protected Iterator defaultValidatorIterator;
/**
* Constructor.
*/
protected ValidatorRegistry()
{
}
/**
* Returns the instance of the registry.
*
* @return The instance of the registry.
*/
public static ValidatorRegistry getInstance()
{
if (verInstance == null)
{
verInstance = new ValidatorRegistry();
}
return verInstance;
}
/**
* Register this validator of the given type with the given namespace.
*
* @param namespace The namespace the validator validates.
* @param valDelegate The validator delegate to register.
* @param type The type of validator.
*/
public void registerValidator(String namespace, WSDLValidatorDelegate valDelegate, Integer type)
{
// allow the null namespace but make it the empty string
if (namespace == null)
{
namespace = "";
}
// get the hastable for the type of validator we want
Hashtable typeValidatorReg = (Hashtable)validatorReg.get(type);
// if it's null if means we haven't defined this type of validator yet
if (typeValidatorReg == null)
{
typeValidatorReg = new Hashtable();
validatorReg.put(type, typeValidatorReg);
}
List namespacevals = (List)typeValidatorReg.get(namespace);
if(namespacevals == null)
{
namespacevals = new Vector();
typeValidatorReg.put(namespace, namespacevals);
}
namespacevals.add(valDelegate);
}
/**
* Ask for the validator associated with this namespace. If none is found
* return null.
*
* @param namespace The namespace for the validator that is being requested.
* @param type The type of validator that is being requested.
* @return An array of validator delegates if at least one is registered, null otherwise.
*/
public WSDLValidatorDelegate[] queryValidatorRegistry(String namespace, Integer type)
{
IWSDLValidator wsdlval = null;
// if the namespace is null allow it and treat it as the empty string
if (namespace == null)
{
namespace = "";
}
Hashtable typeValidatorReg = (Hashtable)validatorReg.get(type);
if (typeValidatorReg == null)
{
return null;
}
List valdels = (List)typeValidatorReg.get(namespace);
if(valdels != null)
{
return (WSDLValidatorDelegate[])valdels.toArray(new WSDLValidatorDelegate[valdels.size()]);
}
return null;
}
/**
* Returns true if there is a validator registered of the given type with the given namespace.
*
* @param namespace The namespace of the validator.
* @param type The type of the validator.
* @return True if there is a validator registered for the namespace, false otherwise.
*/
public boolean hasRegisteredValidator(String namespace, Integer type)
{
if (queryValidatorRegistry(namespace, type) != null)
{
return true;
}
return false;
}
}
|