KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2002 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.DescendantSelector;
21 import org.w3c.css.sac.Selector;
22 import org.w3c.css.sac.SimpleSelector;
23
24 /**
25  * This class provides an abstract implementation of the {@link
26  * org.w3c.css.sac.DescendantSelector} interface.
27  *
28  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
29  * @version $Id: AbstractDescendantSelector.java,v 1.3 2004/08/18 07:12:50 vhardy Exp $
30  */

31 public abstract class AbstractDescendantSelector
32     implements DescendantSelector,
33            ExtendedSelector {
34
35     /**
36      * The ancestor selector.
37      */

38     protected Selector ancestorSelector;
39
40     /**
41      * The simple selector.
42      */

43     protected SimpleSelector simpleSelector;
44
45     /**
46      * Creates a new DescendantSelector object.
47      */

48     protected AbstractDescendantSelector(Selector ancestor,
49                                          SimpleSelector simple) {
50     ancestorSelector = ancestor;
51     simpleSelector = simple;
52     }
53
54     /**
55      * Indicates whether some other object is "equal to" this one.
56      * @param obj the reference object with which to compare.
57      */

58     public boolean equals(Object JavaDoc obj) {
59     if (obj == null || !(obj.getClass() != getClass())) {
60         return false;
61     }
62     AbstractDescendantSelector s = (AbstractDescendantSelector)obj;
63     return s.simpleSelector.equals(simpleSelector);
64     }
65
66     /**
67      * Returns the specificity of this selector.
68      */

69     public int getSpecificity() {
70     return ((ExtendedSelector)ancestorSelector).getSpecificity() +
71                ((ExtendedSelector)simpleSelector).getSpecificity();
72     }
73
74     /**
75      * <b>SAC</b>: Implements {@link
76      * org.w3c.css.sac.DescendantSelector#getAncestorSelector()}.
77      */

78     public Selector getAncestorSelector() {
79     return ancestorSelector;
80     }
81
82     /**
83      * <b>SAC</b>: Implements {@link
84      * org.w3c.css.sac.DescendantSelector#getSimpleSelector()}.
85      */

86     public SimpleSelector getSimpleSelector() {
87     return simpleSelector;
88     }
89 }
90
Popular Tags