KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.StringTokenizer JavaDoc;
22
23 import org.apache.ws.jaxme.xs.jaxb.*;
24 import org.apache.ws.jaxme.xs.jaxb.JAXBSchemaBindings;
25 import org.apache.ws.jaxme.xs.jaxb.JAXBXsObjectFactory;
26 import org.apache.ws.jaxme.xs.parser.XSContext;
27 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
28 import org.apache.ws.jaxme.xs.xml.XsEAnnotation;
29 import org.apache.ws.jaxme.xs.xml.XsEAppinfo;
30 import org.apache.ws.jaxme.xs.xml.impl.XsESchemaImpl;
31 import org.xml.sax.SAXException JavaDoc;
32
33
34 /**
35  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
36  */

37 public class JAXBXsSchemaImpl extends XsESchemaImpl implements JAXBXsSchema {
38   private JAXBSchemaBindings schemaBindings;
39   private String JavaDoc jaxbVersion;
40   private String JavaDoc[] jaxbExtensionBindingPrefixes;
41
42   public void setJaxbVersion(String JavaDoc pVersion) {
43     jaxbVersion = pVersion;
44   }
45
46   public void setJaxbExtensionBindingPrefixes(String JavaDoc pExtensionBindingPrefixes) {
47     List JavaDoc result = new ArrayList JavaDoc();
48     for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(pExtensionBindingPrefixes); st.hasMoreTokens(); ) {
49       result.add(st.nextToken());
50     }
51     jaxbExtensionBindingPrefixes = (String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]);
52   }
53
54   public String JavaDoc[] getJaxbExtensionBindingPrefixes() {
55     return jaxbExtensionBindingPrefixes == null ? new String JavaDoc[0] : jaxbExtensionBindingPrefixes;
56   }
57
58   public String JavaDoc getJaxbVersion() {
59     return jaxbVersion;
60   }
61
62   /** <p>Creates a new instance of JAXBXsSchemaImpl.</p>
63    */

64   public JAXBXsSchemaImpl(XSContext pContext) {
65     super(pContext);
66   }
67
68   public void validate() throws SAXException {
69     if (isValidated()) {
70       return;
71     }
72     super.validate();
73     Object JavaDoc[] childs = getChilds();
74     for (int i = 0; i < childs.length; i++) {
75       if (!(childs[i] instanceof XsEAnnotation)) {
76         continue;
77       }
78       XsEAnnotation annotation = (XsEAnnotation) childs[i];
79       XsEAppinfo[] appinfos = annotation.getAppinfos();
80       for (int j = 0; j < appinfos.length; j++) {
81         Object JavaDoc[] appinfoChilds = appinfos[j].getChilds();
82         for (int k = 0; k < appinfoChilds.length; k++) {
83           if (!(appinfoChilds[k] instanceof JAXBSchemaBindings)) {
84             continue;
85           }
86           if (schemaBindings == null) {
87             schemaBindings = (JAXBSchemaBindings) appinfoChilds[k];
88           } else {
89             throw new LocSAXException("A schema must have at most a single instance of 'schemaBindings'",
90                                        appinfos[j].getLocator());
91           }
92         }
93       }
94     }
95
96     if (schemaBindings == null) {
97       schemaBindings = ((JAXBXsObjectFactory) getObjectFactory()).newJAXBSchemaBindings(this);
98     }
99   }
100
101   public JAXBSchemaBindings getJAXBSchemaBindings() {
102     return schemaBindings;
103   }
104
105   public boolean setAttribute(String JavaDoc pQName, String JavaDoc pNamespaceURI, String JavaDoc pLocalName,
106                                 String JavaDoc pValue) throws SAXException {
107     if (JAXBParser.JAXB_SCHEMA_URI.equals(pNamespaceURI)) {
108       if ("version".equals(pLocalName)) {
109         setJaxbVersion(pValue);
110         return true;
111       } else if ("extensionBindingPrefixes".equals(pLocalName)) {
112         setJaxbExtensionBindingPrefixes(pValue);
113         return true;
114       } else {
115         throw new LocSAXException("Invalid attribute: " + pQName, getLocator());
116       }
117     } else {
118       return super.setAttribute(pQName, pNamespaceURI, pLocalName, pValue);
119     }
120   }
121 }
122
Popular Tags