KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > SVGAttribute


1 /*
2
3    Copyright 2001,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.svggen;
19
20 import java.util.HashSet JavaDoc;
21 import java.util.Set JavaDoc;
22
23 /**
24  * Represents an SVG attribute and provides convenience
25  * methods to determine whether or not the attribute applies
26  * to a given element type.
27  *
28  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
29  * @version $Id: SVGAttribute.java,v 1.5 2004/08/18 07:14:59 vhardy Exp $
30  */

31 public class SVGAttribute {
32     /**
33      * SVG syntax for the attribute
34      */

35     private String JavaDoc name;
36
37     /**
38      * Set of Element tags to which the attribute does or
39      * does not apply.
40      */

41     private Set JavaDoc applicabilitySet;
42
43     /**
44      * Controls the semantic of applicabilitySet. If
45      * true, then the applicabilitySet contains the elments
46      * to which the attribute applies. If false, the
47      * Set contains the elements to which the attribute
48      * does not apply.
49      */

50     private boolean isSetInclusive;
51
52     /**
53      * @param applicabilitySet Set of Element tags (Strings) to which
54      * the attribute applies
55      * @param isSetInclusive defines whether elements in applicabilitySet
56      * define the list of elements to which the attribute
57      * applies or to which it does not apply
58      */

59     public SVGAttribute(Set JavaDoc applicabilitySet, boolean isSetInclusive){
60         if(applicabilitySet == null)
61             applicabilitySet = new HashSet JavaDoc();
62
63         this.applicabilitySet = applicabilitySet;
64         this.isSetInclusive = isSetInclusive;
65     }
66
67     /**
68      * @param tag the tag of the Element to which the attribute
69      * could apply.
70      * @return true if the attribute applies to the given Element
71      */

72     public boolean appliesTo(String JavaDoc tag){
73         boolean tagInMap = applicabilitySet.contains(tag);
74         if(isSetInclusive)
75             return tagInMap;
76         else
77             return !tagInMap;
78     }
79 }
80
Popular Tags