KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > ser > ElementSerializer


1 /*
2  * Copyright 2001-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
17 package org.apache.axis.encoding.ser;
18
19 import org.apache.axis.Constants;
20 import org.apache.axis.MessageContext;
21 import org.apache.axis.encoding.SerializationContext;
22 import org.apache.axis.encoding.Serializer;
23 import org.apache.axis.utils.Messages;
24 import org.apache.axis.wsdl.fromJava.Types;
25 import org.w3c.dom.Element JavaDoc;
26 import org.xml.sax.Attributes JavaDoc;
27
28 import javax.xml.namespace.QName JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 /**
32  * Serializer for DOM elements
33  *
34  * @author Glen Daniels (gdaniels@apache.org)
35  * Modified by @author Rich scheuerle <scheu@us.ibm.com>
36  */

37
38 public class ElementSerializer implements Serializer {
39     /**
40      * Serialize a DOM Element
41      */

42     public void serialize(QName JavaDoc name, Attributes JavaDoc attributes,
43                           Object JavaDoc value, SerializationContext context)
44         throws IOException JavaDoc
45     {
46         if (!(value instanceof Element JavaDoc))
47             throw new IOException JavaDoc(Messages.getMessage("cantSerialize01"));
48
49         MessageContext mc = context.getMessageContext();
50         context.setWriteXMLType(null);
51         boolean writeWrapper = (mc == null) ||
52                 mc.isPropertyTrue("writeWrapperForElements", true);
53         if (writeWrapper)
54             context.startElement(name, attributes);
55         context.writeDOMElement((Element JavaDoc)value);
56         if (writeWrapper)
57             context.endElement();
58     }
59
60     public String JavaDoc getMechanismType() { return Constants.AXIS_SAX; }
61
62     /**
63      * Return XML schema for the specified type, suitable for insertion into
64      * the &lt;types&gt; element of a WSDL document, or underneath an
65      * &lt;element&gt; or &lt;attribute&gt; declaration.
66      *
67      * @param javaType the Java Class we're writing out schema for
68      * @param types the Java2WSDL Types object which holds the context
69      * for the WSDL being generated.
70      * @return a type element containing a schema simpleType/complexType
71      * @see org.apache.axis.wsdl.fromJava.Types
72      */

73     public Element JavaDoc writeSchema(Class JavaDoc javaType, Types types) throws Exception JavaDoc {
74         return null;
75     }
76 }
77
Popular Tags