Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
ExtSerializer |
|
| 1.0;1 |
1 | /* |
|
2 | * Copyright 2003, 2004 The Apache Software Foundation |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.xmlrpc.serializer; |
|
17 | ||
18 | import org.xml.sax.ContentHandler; |
|
19 | import org.xml.sax.SAXException; |
|
20 | ||
21 | ||
22 | /** Base class for external XML representations, like DOM, |
|
23 | * or JAXB. |
|
24 | */ |
|
25 | 1 | public abstract class ExtSerializer implements TypeSerializer { |
26 | /** Returns the unqualied tag name. |
|
27 | */ |
|
28 | protected abstract String getTagName(); |
|
29 | /** Performs the actual serialization. |
|
30 | */ |
|
31 | protected abstract void serialize(ContentHandler pHandler, Object pObject) throws SAXException; |
|
32 | ||
33 | public void write(ContentHandler pHandler, Object pObject) |
|
34 | throws SAXException { |
|
35 | 8 | final String tag = getTagName(); |
36 | 8 | final String exTag = "ex:" + getTagName(); |
37 | 8 | pHandler.startElement("", TypeSerializerImpl.VALUE_TAG, TypeSerializerImpl.VALUE_TAG, TypeSerializerImpl.ZERO_ATTRIBUTES); |
38 | 8 | pHandler.startElement(XmlRpcWriter.EXTENSIONS_URI, tag, exTag, TypeSerializerImpl.ZERO_ATTRIBUTES); |
39 | 8 | serialize(pHandler, pObject); |
40 | 8 | pHandler.endElement(XmlRpcWriter.EXTENSIONS_URI, tag, exTag); |
41 | 8 | pHandler.endElement("", TypeSerializerImpl.VALUE_TAG, TypeSerializerImpl.VALUE_TAG); |
42 | 8 | } |
43 | } |