KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > jaxb > impl > JAXBElementImpl


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  */

17 package org.apache.ws.jaxme.xs.jaxb.impl;
18
19 import org.apache.ws.jaxme.xs.XSObject;
20 import org.apache.ws.jaxme.xs.impl.XSElementImpl;
21 import org.apache.ws.jaxme.xs.impl.XSUtil;
22 import org.apache.ws.jaxme.xs.jaxb.JAXBClass;
23 import org.apache.ws.jaxme.xs.jaxb.JAXBElement;
24 import org.apache.ws.jaxme.xs.jaxb.JAXBProperty;
25 import org.apache.ws.jaxme.xs.jaxb.JAXBSchemaBindings;
26 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
27 import org.apache.ws.jaxme.xs.xml.XsTElement;
28 import org.xml.sax.SAXException JavaDoc;
29
30
31 /**
32  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
33  */

34 public class JAXBElementImpl extends XSElementImpl implements JAXBElement {
35   private JAXBClass jaxbClass;
36   private JAXBProperty jaxbProperty;
37
38   /** <p>Creates a new instance of JAXBElementImpl.</p>
39    */

40   protected JAXBElementImpl(XSObject pParent, XsTElement pBaseElement)
41       throws SAXException {
42     super(pParent, pBaseElement);
43   }
44
45   public JAXBSchemaBindings getJAXBSchemaBindings() {
46     return ((JAXBXsSchemaImpl) getXsObject().getXsESchema()).getJAXBSchemaBindings();
47   }
48
49
50   public JAXBClass getJAXBClass() { return jaxbClass; }
51   public JAXBProperty getJAXBProperty() { return jaxbProperty; }
52
53   public void validate() throws SAXException {
54     if (isValidated()) {
55       return;
56     }
57     super.validate();
58     jaxbClass = (JAXBClass) XSUtil.getSingleAppinfo(getAnnotations(), JAXBClass.class);
59     jaxbProperty = (JAXBProperty) XSUtil.getSingleAppinfo(getAnnotations(), JAXBProperty.class);
60
61     if (jaxbProperty == null) {
62       XsTElement elem = (XsTElement) getXsObject();
63       if (elem.getRef() != null) {
64         JAXBElement refElem = (JAXBElement) getXSSchema().getElement(elem.getRef());
65         if (refElem != null) {
66           jaxbProperty = refElem.getJAXBProperty();
67         }
68       }
69     } else {
70       if (isGlobal()) {
71         if (jaxbProperty != null && jaxbProperty.getBaseType() != null) {
72           throw new LocSAXException("The element jaxb:property/jaxb:baseType is forbidden in global elements." +
73                                      " You may set it in the reference using the element locally. [JAXB 6.8.1.2.1]",
74                                      jaxbProperty.getLocator());
75         }
76       }
77     }
78
79     if (jaxbClass != null && jaxbClass.getImplClass() != null) {
80       if (isGlobal()) {
81         if (jaxbClass != null && jaxbClass.getImplClass() != null) {
82           throw new LocSAXException("The implClass attribute is invalid for global elements. [JAXB 6.7.3.4]",
83                                      jaxbClass.getLocator());
84         }
85       } else {
86         if (jaxbClass != null && jaxbClass.getImplClass() != null) {
87           throw new LocSAXException("The implClass attribute is invalid for local elements. [JAXB 6.7.3.5]",
88                                      jaxbClass.getLocator());
89         }
90       }
91     }
92   }
93 }
94
Popular Tags