intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.css.core / src / net / sourceforge / phpeclipse / css / core / profiles / AbstractProfile.java
1 /*
2  * Copyright (c) 2003-2004 Christopher Lenz and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial API and implementation
10  * 
11  * $Id: AbstractProfile.java,v 1.1 2004-09-02 18:07:14 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.css.core.profiles;
15
16 import java.util.Collection;
17 import java.util.Collections;
18 import java.util.HashMap;
19 import java.util.HashSet;
20 import java.util.Map;
21 import java.util.Set;
22
23 import net.sourceforge.phpeclipse.css.core.internal.model.PropertyInfo;
24 import net.sourceforge.phpeclipse.css.core.model.IPropertyInfo;
25
26 /**
27  * Abstract implementation of the <code>IProfile</code> interface.
28  */
29 public abstract class AbstractProfile implements IProfile {
30
31         // Instance Variables ------------------------------------------------------
32
33         /**
34          * The associated descriptor, as passed into the constructor by the profile
35          * manager when the profile is instantiated.
36          */
37         private IProfileDescriptor descriptor;
38
39         /**
40          * Map of the property names of this profile, containing the 
41          * <code>IPropertyInfo</code> objects keyed by property name.
42          */
43         private Map properties = new HashMap();
44
45         /**
46          * Set of the at rule keywords known to the profile.
47          */
48         private Set atKeywords = new HashSet();
49
50         /**
51          * Set of the at pseudo-classes known to the profile.
52          */
53         private Set pseudoClasses = new HashSet();
54
55         // Constructors ------------------------------------------------------------
56
57         /**
58          * Constructor.
59          * 
60          * @param descriptor the profile descriptor
61          */
62         public AbstractProfile(IProfileDescriptor descriptor) {
63                 this.descriptor = descriptor;
64         }
65
66         // IProfile Implementation -------------------------------------------------
67
68         /**
69          * @see net.sourceforge.phpeclipse.css.core.profiles.IProfile#getDescriptor()
70          */
71         public final IProfileDescriptor getDescriptor() {
72                 return this.descriptor;
73         }
74
75         /**
76          * @see IProfile#getAtKeywords()
77          */
78         public final Collection getAtKeywords() {
79                 return Collections.unmodifiableSet(this.atKeywords);
80         }
81
82         /**
83          * @see IProfile#getProperties()
84          */
85         public final Collection getProperties() {
86                 return Collections.unmodifiableSet(this.properties.keySet());
87         }
88
89         /**
90          * @see IProfile#getPropertyInfo(java.lang.String)
91          */
92         public final IPropertyInfo getPropertyInfo(String propertyName) {
93                 return (IPropertyInfo) this.properties.get(propertyName);
94         }
95
96         /**
97          * @see IProfile#getPseudoClassNames()
98          */
99         public final Collection getPseudoClassNames() {
100                 return Collections.unmodifiableSet(this.pseudoClasses);
101         }
102
103         // Protected Methods -------------------------------------------------------
104
105         protected final void addAtKeyword(String atKeyword) {
106                 this.atKeywords.add(atKeyword);
107         }
108
109         protected final void addProperty(String name, String category) {
110                 addProperty(new PropertyInfo(name, category));
111         }
112
113         protected final void addProperty(String name, String category,
114                 boolean shorthand) {
115                 addProperty(new PropertyInfo(name, category, shorthand));
116         }
117
118         protected final void addProperty(IPropertyInfo info) {
119                 this.properties.put(info.getName(), info);
120         }
121
122         protected final void addPseudoClass(String pseudoClass) {
123                 this.pseudoClasses.add(pseudoClass);
124         }
125
126 }