KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > sac > AbstractSiblingSelector


1 /*
2
3    Copyright 2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.css.engine.sac;
19
20 import org.w3c.css.sac.Selector;
21 import org.w3c.css.sac.SiblingSelector;
22 import org.w3c.css.sac.SimpleSelector;
23
24 /**
25  * This class provides an abstract implementation of the {@link
26  * org.w3c.css.sac.SiblingSelector} interface.
27  *
28  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
29  * @version $Id: AbstractSiblingSelector.java,v 1.4 2004/08/18 07:12:50 vhardy Exp $
30  */

31 public abstract class AbstractSiblingSelector
32     implements SiblingSelector,
33            ExtendedSelector {
34
35     /**
36      * The node type.
37      */

38     protected short nodeType;
39
40     /**
41      * The selector.
42      */

43     protected Selector selector;
44
45     /**
46      * The simple selector.
47      */

48     protected SimpleSelector simpleSelector;
49
50     /**
51      * Creates a new SiblingSelector object.
52      */

53     protected AbstractSiblingSelector(short type,
54                                       Selector sel,
55                                       SimpleSelector simple) {
56         nodeType = type;
57     selector = sel;
58     simpleSelector = simple;
59     }
60
61     /**
62      * Returns the node type.
63      */

64     public short getNodeType() {
65         return nodeType;
66     }
67
68     /**
69      * Indicates whether some other object is "equal to" this one.
70      * @param obj the reference object with which to compare.
71      */

72     public boolean equals(Object JavaDoc obj) {
73     if (obj == null || !(obj.getClass() != getClass())) {
74         return false;
75     }
76     AbstractSiblingSelector s = (AbstractSiblingSelector)obj;
77     return s.simpleSelector.equals(simpleSelector);
78     }
79
80     /**
81      * Returns the specificity of this selector.
82      */

83     public int getSpecificity() {
84     return ((ExtendedSelector)selector).getSpecificity() +
85                ((ExtendedSelector)simpleSelector).getSpecificity();
86     }
87
88     /**
89      * <b>SAC</b>: Implements {@link
90      * org.w3c.css.sac.SiblingSelector#getSelector()}.
91      */

92     public Selector getSelector() {
93     return selector;
94     }
95
96     /**
97      * <b>SAC</b>: Implements {@link
98      * org.w3c.css.sac.SiblingSelector#getSiblingSelector()}.
99      */

100     public SimpleSelector getSiblingSelector() {
101     return simpleSelector;
102     }
103 }
104
Popular Tags