|
|||||||||||||||||||
| 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 | |||||||||||||||
| StaxHandler.java | 50% | 52.9% | 66.7% | 53.2% |
|
||||||||||||||
| 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.stax;
|
|
| 19 |
|
|
| 20 |
import org.codehaus.activesoap.Handler;
|
|
| 21 |
import org.codehaus.activesoap.MessageExchange;
|
|
| 22 |
import org.codehaus.activesoap.handler.stax.AnyAttribute;
|
|
| 23 |
import org.codehaus.activesoap.handler.stax.AnyContent;
|
|
| 24 |
import org.codehaus.activesoap.handler.stax.AnyElementMarshaler;
|
|
| 25 |
|
|
| 26 |
import javax.xml.namespace.QName;
|
|
| 27 |
import javax.xml.stream.XMLStreamConstants;
|
|
| 28 |
import javax.xml.stream.XMLStreamException;
|
|
| 29 |
import javax.xml.stream.XMLStreamReader;
|
|
| 30 |
|
|
| 31 |
/**
|
|
| 32 |
* A useful base class for any handlers implementd directly on top of StAX\
|
|
| 33 |
* @version $Revision: 1.2 $
|
|
| 34 |
*/
|
|
| 35 |
public abstract class StaxHandler implements Handler { |
|
| 36 |
|
|
| 37 | 0 |
protected void populateAnyContent(MessageExchange exchange, AnyElementMarshaler anyElementMarshaler, AnyContent property) throws XMLStreamException { |
| 38 | 0 |
XMLStreamReader in = exchange.getIn(); |
| 39 | 0 |
boolean complete = false; |
| 40 | 0 |
int elements = 0;
|
| 41 | 0 |
while (in.hasNext() && !complete) {
|
| 42 | 0 |
int code = in.next();
|
| 43 | 0 |
switch (code) {
|
| 44 |
case XMLStreamConstants.START_ELEMENT:
|
|
| 45 | 0 |
elements++; |
| 46 | 0 |
property.getAny().add(anyElementMarshaler.parseElement(in)); |
| 47 | 0 |
break;
|
| 48 |
|
|
| 49 |
case XMLStreamConstants.END_ELEMENT:
|
|
| 50 | 0 |
if (--elements <= 0) {
|
| 51 | 0 |
complete = true;
|
| 52 |
} |
|
| 53 | 0 |
break;
|
| 54 |
|
|
| 55 |
case XMLStreamConstants.END_DOCUMENT:
|
|
| 56 | 0 |
complete = true;
|
| 57 | 0 |
break;
|
| 58 |
} |
|
| 59 |
} |
|
| 60 |
} |
|
| 61 |
|
|
| 62 | 10 |
protected void populateAnyAttributes(MessageExchange exchange, AnyAttribute value) throws XMLStreamException { |
| 63 | 10 |
XMLStreamReader in = exchange.getIn(); |
| 64 | 10 |
int elements = 0;
|
| 65 | 10 |
boolean complete = false; |
| 66 |
|
|
| 67 | 10 |
while (in.hasNext() && !complete) {
|
| 68 | 32 |
int code = in.next();
|
| 69 | 32 |
switch (code) {
|
| 70 |
case XMLStreamConstants.CHARACTERS:
|
|
| 71 | 10 |
value.putValue(in.getNamespaceContext(), in.getText().trim()); |
| 72 | 10 |
break;
|
| 73 |
|
|
| 74 |
case XMLStreamConstants.START_ELEMENT:
|
|
| 75 | 6 |
++elements; |
| 76 | 6 |
populateAttributes(in, value); |
| 77 | 6 |
break;
|
| 78 |
|
|
| 79 |
case XMLStreamConstants.END_ELEMENT:
|
|
| 80 | 10 |
if (--elements <= 0) {
|
| 81 | 10 |
complete = true;
|
| 82 |
} |
|
| 83 | 10 |
break;
|
| 84 |
|
|
| 85 |
case XMLStreamConstants.END_DOCUMENT:
|
|
| 86 | 0 |
complete = true;
|
| 87 | 0 |
break;
|
| 88 |
|
|
| 89 |
default:
|
|
| 90 |
} |
|
| 91 |
} |
|
| 92 |
} |
|
| 93 |
|
|
| 94 | 9 |
protected void populateAttributes(XMLStreamReader in, AnyAttribute value) { |
| 95 | 9 |
for (int i = 0, size = in.getAttributeCount(); i < size; i++) { |
| 96 | 1 |
QName attributeName = in.getAttributeName(i); |
| 97 | 1 |
String attributeValue = in.getAttributeValue(i); |
| 98 | 1 |
value.putAttributeValue(in.getNamespaceContext(), attributeName, attributeValue); |
| 99 |
} |
|
| 100 |
} |
|
| 101 |
|
|
| 102 |
} |
|
| 103 |
|
|
||||||||||