|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DefaultHandlerRegistry.java | 33.3% | 50% | 50% | 47.8% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
*
|
|
| 3 |
* Copyright 2004 Protique Ltd
|
|
| 4 |
*
|
|
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 6 |
* you may not use this file except in compliance with the License.
|
|
| 7 |
* You may obtain a copy of the License at
|
|
| 8 |
*
|
|
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 10 |
*
|
|
| 11 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 14 |
* See the License for the specific language governing permissions and
|
|
| 15 |
* limitations under the License.
|
|
| 16 |
*
|
|
| 17 |
**/
|
|
| 18 |
package org.codehaus.activesoap.handler;
|
|
| 19 |
|
|
| 20 |
import org.codehaus.activesoap.handler.ProcedureNotPresentHandler;
|
|
| 21 |
import org.codehaus.activesoap.handler.QNameHandler;
|
|
| 22 |
import org.codehaus.activesoap.HandlerRegistry;
|
|
| 23 |
import org.codehaus.activesoap.Handler;
|
|
| 24 |
|
|
| 25 |
import javax.xml.namespace.QName;
|
|
| 26 |
import java.util.HashMap;
|
|
| 27 |
import java.util.Map;
|
|
| 28 |
|
|
| 29 |
/**
|
|
| 30 |
* Provides a registry of handlers indexed by specific {@link QName}
|
|
| 31 |
* instances as well as providing a default handler which is used for processing
|
|
| 32 |
* SOAP body elements (or REST root elements) if no QName could be matched.
|
|
| 33 |
*
|
|
| 34 |
* @version $Revision: 1.1 $
|
|
| 35 |
*/
|
|
| 36 |
public class DefaultHandlerRegistry implements HandlerRegistry { |
|
| 37 |
private Map handlers = new HashMap(); |
|
| 38 |
private Handler defaultHandler;
|
|
| 39 |
private Handler bodyHandler;
|
|
| 40 |
|
|
| 41 | 236 |
public DefaultHandlerRegistry() {
|
| 42 | 236 |
this(ProcedureNotPresentHandler.getInstance());
|
| 43 |
} |
|
| 44 |
|
|
| 45 | 236 |
public DefaultHandlerRegistry(Handler defaultHandler) {
|
| 46 | 236 |
this.defaultHandler = defaultHandler;
|
| 47 | 236 |
this.bodyHandler = new QNameHandler(this); |
| 48 |
} |
|
| 49 |
|
|
| 50 |
|
|
| 51 | 94 |
public synchronized Handler getHandler(QName name) { |
| 52 | 94 |
Handler answer = (Handler) handlers.get(name); |
| 53 | 94 |
if (answer == null) { |
| 54 | 49 |
answer = (Handler) handlers.get(name.getNamespaceURI()); |
| 55 |
} |
|
| 56 | 94 |
return answer;
|
| 57 |
} |
|
| 58 |
|
|
| 59 | 0 |
public synchronized void addHandler(String namepaceURI, Handler handler) { |
| 60 | 0 |
handlers.put(namepaceURI, handler); |
| 61 |
} |
|
| 62 |
|
|
| 63 | 0 |
public void addHandler(String[] namespaceURIs, Handler handler) { |
| 64 | 0 |
for (int i = 0; i < namespaceURIs.length; i++) { |
| 65 | 0 |
String namespaceURI = namespaceURIs[i]; |
| 66 | 0 |
addHandler(namespaceURI, handler); |
| 67 |
} |
|
| 68 |
} |
|
| 69 |
|
|
| 70 |
|
|
| 71 | 0 |
public void removeHandler(String[] namespaceURIs, Handler handler) { |
| 72 | 0 |
for (int i = 0; i < namespaceURIs.length; i++) { |
| 73 | 0 |
String namespaceURI = namespaceURIs[i]; |
| 74 | 0 |
removeHandler(namespaceURI, handler); |
| 75 |
} |
|
| 76 |
} |
|
| 77 |
|
|
| 78 | 95 |
public synchronized void addHandler(QName name, Handler handler) { |
| 79 | 95 |
handlers.put(name, handler); |
| 80 |
} |
|
| 81 |
|
|
| 82 | 0 |
public synchronized Handler removeHandler(QName name) { |
| 83 | 0 |
return (Handler) handlers.remove(name);
|
| 84 |
} |
|
| 85 |
|
|
| 86 | 0 |
public synchronized Handler removeHandler(String namepaceURI) { |
| 87 | 0 |
return (Handler) handlers.remove(namepaceURI);
|
| 88 |
} |
|
| 89 |
|
|
| 90 | 0 |
public synchronized Handler removeHandler(String namepaceURI, Handler handler) { |
| 91 |
// TODO we may wish to implement this differently if we handle
|
|
| 92 |
// many handlers to a single namespace/qname
|
|
| 93 | 0 |
return removeHandler(namepaceURI);
|
| 94 |
} |
|
| 95 |
|
|
| 96 | 23 |
public Handler getBodyHandler() {
|
| 97 | 23 |
return bodyHandler;
|
| 98 |
} |
|
| 99 |
|
|
| 100 | 4 |
public void setBodyHandler(Handler bodyHandler) { |
| 101 | 4 |
this.bodyHandler = bodyHandler;
|
| 102 |
} |
|
| 103 |
|
|
| 104 | 10 |
public Handler getDefaultHandler() {
|
| 105 | 10 |
return defaultHandler;
|
| 106 |
} |
|
| 107 |
|
|
| 108 | 9 |
public void setDefaultHandler(Handler defaultHandler) { |
| 109 | 9 |
this.defaultHandler = defaultHandler;
|
| 110 |
} |
|
| 111 |
|
|
| 112 |
/**
|
|
| 113 |
* Provide implementations with direct access to the handler map
|
|
| 114 |
*/
|
|
| 115 | 0 |
protected Map getHandlers() {
|
| 116 | 0 |
return handlers;
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
/**
|
|
| 120 |
* Provide implementations with direct access to the handler map
|
|
| 121 |
*/
|
|
| 122 | 0 |
protected void setHandlers(Map handlers) { |
| 123 | 0 |
this.handlers = handlers;
|
| 124 |
} |
|
| 125 |
} |
|
| 126 |
|
|
||||||||||