KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > XSElementOrAttrRef


1 /*
2  * Copyright 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;
18
19 /**
20  * Specifies an element or attribute relative to the declaring element. The
21  * reference cannot be to an element and a attribute, one of the two getters
22  * must return null.
23  *
24  * @see XSElement
25  * @see XSIdentityConstraint
26  *
27  * @author <a HREF="mailto:mrck1996@yahoo.co.uk">Chris Kirk</a>
28  */

29 public final class XSElementOrAttrRef {
30     private final XSElement _element;
31     private final XSAttribute _attribute;
32     
33     public XSElementOrAttrRef( XSElement element ) {
34         _element = element;
35         _attribute = null;
36     }
37     
38     public XSElementOrAttrRef( XSAttribute attribute ) {
39         _element = null;
40         _attribute = attribute;
41     }
42     
43     /**
44      * Fetches the element that this reference refers to. Returns null when
45      * isAttributeRef is true.
46      */

47     public XSElement getElement() {
48         return _element;
49     }
50     
51     /**
52      * Fetches the attribute that this reference refers to. Returns null when
53      * isAttributeRef is false.
54      */

55     public XSAttribute getAttribute() {
56         return _attribute;
57     }
58     
59     /**
60      * Returns true if this reference points at an attribute. Returns false
61      * when it references an element.
62      */

63     public boolean isAttributeRef() {
64         return _element == null;
65     }
66     
67     public int hashCode() {
68         Object JavaDoc o;
69         
70         if ( _element == null) {
71             o = _attribute;
72         } else {
73             o = _element;
74         }
75         
76         return o.hashCode();
77     }
78     
79     public boolean equals( Object JavaDoc o ) {
80         if ( o == null || !(o instanceof XSElementOrAttrRef)) {
81             return false;
82         }
83         
84         XSElementOrAttrRef other = (XSElementOrAttrRef) o;
85         if ( this.isAttributeRef() ) {
86             return this._attribute.equals( other._attribute );
87         } else {
88             return this._element.equals( other._element );
89         }
90     }
91 }
92
Popular Tags