KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > 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.impl;
18
19 import org.apache.ws.jaxme.xs.XSObject;
20 import org.apache.ws.jaxme.xs.XSSchema;
21 import org.apache.ws.jaxme.xs.xml.XsObject;
22 import org.xml.sax.Locator JavaDoc;
23 import org.xml.sax.SAXException JavaDoc;
24
25
26 /**
27  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
28  */

29 public abstract class XSObjectImpl implements XSObject {
30   private final XSObject parent;
31   private final XsObject baseObject;
32
33   protected XSObjectImpl(XSObject pParent, XsObject pBaseObject) {
34     if (pParent == null) {
35       if (!(this instanceof XSSchema)) {
36         throw new IllegalStateException JavaDoc("Null parents are allowed for XSSchema objects only.");
37       }
38     } else {
39       if (this instanceof XSSchema) {
40         throw new IllegalStateException JavaDoc("An XSSchema object must have a null parent.");
41       }
42     }
43     parent = pParent;
44     baseObject = pBaseObject;
45   }
46
47   public XSObject getParentObject() { return parent; }
48   public XSSchema getXSSchema() {
49     if (parent == null) {
50       return (XSSchema) this;
51     } else {
52       return parent.getXSSchema();
53     }
54   }
55   public boolean isTopLevelObject() { return parent == null || parent instanceof XSSchema; }
56   public Locator JavaDoc getLocator() { return baseObject.getLocator(); }
57   protected XsObject getXsObject() { return baseObject; }
58   public void validate() throws SAXException JavaDoc {}
59
60
61   /**
62    * Utility method used to call validate() on every element within an
63    * array.
64    *
65    * @param objects Array must not have any null elements.
66    */

67   protected final void validateAllIn( XSObject[] objects )
68     throws SAXException JavaDoc
69   {
70     if ( objects == null ) {
71       return;
72     }
73
74     int numObjects = objects.length;
75
76     for ( int i=0; i<numObjects; i++ ) {
77       objects[i].validate();
78     }
79   }
80 }
81
Popular Tags