KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jaxb > skeleton > Property


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jaxb.skeleton;
31
32 import java.io.IOException JavaDoc;
33
34 import javax.xml.XMLConstants JavaDoc;
35
36 import javax.xml.bind.JAXBException;
37 import javax.xml.bind.Marshaller;
38 import javax.xml.bind.Unmarshaller;
39 import javax.xml.bind.annotation.XmlAttribute;
40 import javax.xml.bind.annotation.XmlElement;
41 import javax.xml.bind.annotation.XmlElementWrapper;
42
43 import javax.xml.namespace.QName JavaDoc;
44
45 import javax.xml.stream.XMLStreamException;
46 import javax.xml.stream.XMLStreamReader;
47 import javax.xml.stream.XMLStreamWriter;
48
49 /**
50  * represents a property in a skeleton; requires an Accessor to access it
51  */

52 public abstract class Property {
53   public boolean isXmlPrimitiveType()
54   {
55     return true;
56   }
57
58   public String JavaDoc getMaxOccurs()
59   {
60     return null;
61   }
62
63   public abstract String JavaDoc getSchemaType();
64
65   public abstract Object JavaDoc read(Unmarshaller u, XMLStreamReader in, QName JavaDoc name)
66     throws IOException JavaDoc, XMLStreamException, JAXBException;
67   
68   public abstract void write(Marshaller m, XMLStreamWriter out,
69                              Object JavaDoc obj, QName JavaDoc name)
70     throws IOException JavaDoc, XMLStreamException, JAXBException;
71
72   protected void writeQNameStartElement(XMLStreamWriter out, QName JavaDoc name)
73     throws IOException JavaDoc, XMLStreamException
74   {
75     if (name == null)
76       return;
77
78     if (name.getPrefix() != null && ! "".equals(name.getPrefix())) {
79       out.writeStartElement(name.getPrefix(),
80                             name.getLocalPart(),
81                             name.getNamespaceURI());
82     }
83     else if (name.getNamespaceURI() != null &&
84              ! "".equals(name.getNamespaceURI())) {
85       out.writeStartElement(name.getNamespaceURI(), name.getLocalPart());
86     }
87     else
88       out.writeStartElement(name.getLocalPart());
89   }
90
91   protected void writeQNameEndElement(XMLStreamWriter out, QName JavaDoc name)
92     throws IOException JavaDoc, XMLStreamException
93   {
94     if (name == null)
95       return;
96
97     out.writeEndElement();
98   }
99 }
100
Popular Tags