KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > xml > impl > XsObjectImpl


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.xml.impl;
18
19 import org.apache.ws.jaxme.xs.parser.XSContext;
20 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
21 import org.apache.ws.jaxme.xs.xml.*;
22 import org.apache.ws.jaxme.xs.xml.XsObject;
23 import org.xml.sax.Locator JavaDoc;
24 import org.xml.sax.SAXException JavaDoc;
25 import org.xml.sax.helpers.LocatorImpl JavaDoc;
26 import org.xml.sax.helpers.NamespaceSupport JavaDoc;
27
28
29 /** <p>Base class for all the types, attributes, elements, ...</p>
30  *
31  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
32  */

33 public class XsObjectImpl implements XsObject {
34   private final XsObject parent;
35   private boolean isValidated;
36   private final Locator JavaDoc locator;
37
38   protected XsObjectImpl(XsObject pParent) {
39     if (pParent == null) {
40       if (!(this instanceof XsESchema)) {
41         throw new IllegalStateException JavaDoc("Only the schema may have a null parent.");
42       }
43     } else {
44       if (this instanceof XsESchema) {
45         throw new IllegalStateException JavaDoc("The schema must have a null parent.");
46       }
47     }
48     parent = pParent;
49     XSContext context = getContext();
50     if (context != null) {
51       Locator JavaDoc loc = context.getLocator();
52       locator = loc == null ? null : new LocatorImpl JavaDoc(getContext().getLocator());
53     } else {
54       locator = null;
55     }
56   }
57
58   public XsESchema getXsESchema() {
59     if (parent == null) {
60       return (XsESchema) this;
61     } else {
62       return parent.getXsESchema();
63     }
64   }
65
66   public boolean isTopLevelObject() { return parent == null || parent instanceof XsESchema; }
67   public XsObject getParentObject() { return parent; }
68
69   public XsObjectFactory getObjectFactory() { return getContext().getXsObjectFactory(); }
70   public Locator JavaDoc getLocator() { return locator; }
71   protected NamespaceSupport JavaDoc getNamespaceSupport() { return getContext().getNamespaceSupport(); }
72   protected XsQName asXsQName(String JavaDoc pName) throws SAXException {
73     return asXsQName(getXsESchema(), getLocator(), getNamespaceSupport(), pName);
74   }
75   protected static XsQName asXsQName(XsESchema pSchema, Locator JavaDoc pLocator, NamespaceSupport JavaDoc pNss, String JavaDoc pName) throws SAXException {
76     String JavaDoc[] parts = pNss.processName(pName, new String JavaDoc[3], false);
77     if (parts == null) {
78       throw new LocSAXException("Undeclared namespace prefix: " + pName, pLocator);
79     }
80     if (pSchema instanceof XsESchemaImpl
81         && pSchema.getTargetNamespace() == null
82         && (parts[0] == null || "".equals(parts[0]))) {
83         // xs:include may map the target namespace
84
return ((XsESchemaImpl) pSchema).newXsQName(parts[1], XsQName.prefixOf(pName));
85     } else {
86         return new XsQName(parts[0], parts[1], XsQName.prefixOf(pName));
87     }
88   }
89   public XSContext getContext() { return getXsESchema().getContext(); }
90
91   protected final boolean isValidated() {
92     return isValidated;
93   }
94
95   public void validate() throws SAXException {
96     isValidated = true;
97   }
98 }
99
Popular Tags