001/*
002 * Copyright (c) 2000 World Wide Web Consortium,
003 * (Massachusetts Institute of Technology, Institut National de
004 * Recherche en Informatique et en Automatique, Keio University). All
005 * Rights Reserved. This program is distributed under the W3C's Software
006 * Intellectual Property License. This program is distributed in the
007 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
008 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
009 * PURPOSE.
010 * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
011 *
012 * $Id: SelectorFactoryImpl.java,v 1.1.1.1 2006/04/23 14:51:53 taqua Exp $
013 */
014package org.w3c.flute.parser.selectors;
015
016import org.w3c.css.sac.SelectorFactory;
017import org.w3c.css.sac.ConditionalSelector;
018import org.w3c.css.sac.NegativeSelector;
019import org.w3c.css.sac.SimpleSelector;
020import org.w3c.css.sac.ElementSelector;
021import org.w3c.css.sac.CharacterDataSelector;
022import org.w3c.css.sac.ProcessingInstructionSelector;
023import org.w3c.css.sac.SiblingSelector;
024import org.w3c.css.sac.DescendantSelector;
025import org.w3c.css.sac.Selector;
026import org.w3c.css.sac.Condition;
027import org.w3c.css.sac.CSSException;
028
029/**
030 * @version $Revision: 1.1.1.1 $
031 * @author  Philippe Le Hegaret
032 */
033public class SelectorFactoryImpl implements SelectorFactory {
034
035    /**
036     * Creates a conditional selector.
037     * 
038     * @param selector a selector.
039     * @param condition a condition
040     * @return the conditional selector.
041     * @exception CSSException If this selector is not supported.
042     */    
043    public ConditionalSelector createConditionalSelector(SimpleSelector selector,
044                                                  Condition condition) 
045            throws CSSException {
046  return new ConditionalSelectorImpl(selector, condition);
047    }
048
049    /**
050     * Creates an any node selector.
051     * 
052     * @return the any node selector.
053     * @exception CSSException If this selector is not supported.
054     */    
055    public SimpleSelector createAnyNodeSelector() throws CSSException {
056        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
057    }
058
059    /**
060     * Creates an root node selector.
061     * 
062     * @return the root node selector.
063     * @exception CSSException If this selector is not supported.
064     */    
065    public SimpleSelector createRootNodeSelector() throws CSSException {
066        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
067    }
068
069    /**
070     * Creates an negative selector.
071     * 
072     * @param selector a selector.
073     * @return the negative selector.
074     * @exception CSSException If this selector is not supported.
075     */    
076    public NegativeSelector createNegativeSelector(SimpleSelector selector) 
077            throws CSSException {
078        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
079    }
080
081    /**
082     * Creates an element selector.
083     * 
084     * @param namespaceURI the <a href="http://www.w3.org/TR/REC-xml-names/#dt-NSName">namespace
085     *                     URI</a> of the element selector.
086     * @param tagName the <a href="http://www.w3.org/TR/REC-xml-names/#NT-LocalPart">local
087     *        part</a> of the element name. <code>NULL</code> if this element
088     *        selector can match any element.</p>
089     * @return the element selector
090     * @exception CSSException If this selector is not supported.
091     */    
092    public ElementSelector createElementSelector(String namespaceURI, String localName) 
093            throws CSSException {
094        if (namespaceURI != null) {
095            throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
096        } else {
097            return new ElementSelectorImpl(localName);
098        }
099    }
100
101    /**
102     * Creates a text node selector.
103     * 
104     * @param data the data
105     * @return the text node selector
106     * @exception CSSException If this selector is not supported.
107     */    
108    public CharacterDataSelector createTextNodeSelector(String data)
109            throws CSSException {
110        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
111    }
112
113    /**
114     * Creates a cdata section node selector.
115     * 
116     * @param data the data
117     * @return the cdata section node selector
118     * @exception CSSException If this selector is not supported.
119     */    
120    public CharacterDataSelector createCDataSectionSelector(String data)
121            throws CSSException {
122        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
123    }
124
125    /**
126     * Creates a processing instruction node selector.
127     * 
128     * @param target the target
129     * @param data the data
130     * @return the processing instruction node selector
131     * @exception CSSException If this selector is not supported.
132     */    
133    public ProcessingInstructionSelector 
134        createProcessingInstructionSelector(String target,
135                                            String data)
136            throws CSSException {
137        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
138    }
139
140    /**
141     * Creates a comment node selector.
142     * 
143     * @param data the data
144     * @return the comment node selector
145     * @exception CSSException If this selector is not supported.
146     */    
147    public CharacterDataSelector createCommentSelector(String data)
148            throws CSSException {
149        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
150    }
151
152    /**
153     * Creates a pseudo element selector.
154     * 
155     * @param pseudoName the pseudo element name. <code>NULL</code> if this
156     *                   element selector can match any pseudo element.</p>
157     * @return the element selector
158     * @exception CSSException If this selector is not supported.
159     */    
160    public ElementSelector createPseudoElementSelector(String namespaceURI, 
161                                                String pseudoName) 
162            throws CSSException {
163        if (namespaceURI != null) {
164            throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
165        } else {
166            return new PseudoElementSelectorImpl(pseudoName);
167        }
168    }
169
170    /**
171     * Creates a descendant selector.
172     *
173     * @param parent the parent selector
174     * @param descendant the descendant selector
175     * @return the combinator selector.
176     * @exception CSSException If this selector is not supported.
177     */    
178    public DescendantSelector createDescendantSelector(Selector parent,
179                                                       SimpleSelector descendant)
180            throws CSSException {
181        return new DescendantSelectorImpl(parent, descendant);
182    }
183
184    /**
185     * Creates a child selector.
186     *
187     * @param parent the parent selector
188     * @param child the child selector
189     * @return the combinator selector.
190     * @exception CSSException If this selector is not supported.
191     */    
192    public DescendantSelector createChildSelector(Selector parent,
193                                                  SimpleSelector child)
194            throws CSSException {
195        return new ChildSelectorImpl(parent, child);
196    }
197
198    /**
199     * Creates a direct adjacent selector.
200     *
201     * @param child the child selector
202     * @param adjacent the direct adjacent selector
203     * @return the combinator selector.
204     * @exception CSSException If this selector is not supported.
205     */
206    public SiblingSelector createDirectAdjacentSelector(short nodeType,
207                                                        Selector child,
208                                                        SimpleSelector directAdjacent)
209            throws CSSException {
210        if (nodeType != 1) {        
211            throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
212        } else {
213            return new DirectAdjacentSelectorImpl(child, directAdjacent);
214        }
215    }
216
217}