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: ConditionFactoryImpl.java,v 1.1.1.1 2006/04/23 14:51:55 taqua Exp $
013 */
014package org.w3c.flute.parser.selectors;
015
016import org.w3c.css.sac.CSSException;
017import org.w3c.css.sac.Condition;
018import org.w3c.css.sac.AttributeCondition;
019import org.w3c.css.sac.LangCondition;
020import org.w3c.css.sac.ContentCondition;
021import org.w3c.css.sac.CombinatorCondition;
022import org.w3c.css.sac.PositionalCondition;
023import org.w3c.css.sac.NegativeCondition;
024import org.w3c.css.sac.ConditionFactory;
025
026/**
027 * @version $Revision: 1.1.1.1 $
028 * @author  Philippe Le Hegaret
029 */
030public class ConditionFactoryImpl implements ConditionFactory {
031
032    /**
033     * Creates an and condition
034     *
035     * @param first the first condition
036     * @param second the second condition
037     * @return A combinator condition
038     * @exception CSSException if this exception is not supported.
039     */    
040    public CombinatorCondition createAndCondition(Condition first, 
041                                                  Condition second)
042            throws CSSException {
043        return new AndConditionImpl(first, second);
044    }
045
046    /**
047     * Creates an or condition
048     *
049     * @param first the first condition
050     * @param second the second condition
051     * @return A combinator condition
052     * @exception CSSException if this exception is not supported.
053     */    
054    public CombinatorCondition createOrCondition(Condition first, 
055                                                 Condition second)
056            throws CSSException {
057        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
058    }
059
060    /**
061     * Creates a negative condition
062     *
063     * @param condition the condition
064     * @return A negative condition
065     * @exception CSSException if this exception is not supported.
066     */    
067    public NegativeCondition createNegativeCondition(Condition condition)
068            throws CSSException {
069        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
070    }
071
072
073    /**
074     * Creates a positional condition
075     *
076     * @param position the position of the node in the list.
077     * @param typeNode <code>true</code> if the list should contain
078     *                 only nodes of the same type (element, text node, ...).
079     * @param type <code>true</code> true if the list should contain
080     *             only nodes of the same node (for element, same localName
081     *             and same namespaceURI).
082     * @return A positional condition
083     * @exception CSSException if this exception is not supported.
084     */    
085    public PositionalCondition createPositionalCondition(int position, 
086                                                  boolean typeNode, 
087                                                  boolean type)
088            throws CSSException {
089        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
090    }
091
092    /**
093     * creates an attribute condition
094     *
095     * @param localName the localName of the attribute
096     * @param namespaceURI the namespace URI of the attribute
097     * @param specified <code>true</code> if the attribute must be specified
098     *                  in the document.
099     * @param value the value of this attribute.
100     * @return An attribute condition
101     * @exception CSSException if this exception is not supported.
102     */    
103    public AttributeCondition createAttributeCondition(String localName,
104                                                String namespaceURI,
105                                                boolean specified,
106                                                String value)
107            throws CSSException {
108        if ((namespaceURI != null) || specified) {
109            throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
110        } else {
111            return new AttributeConditionImpl(localName, value);
112        }
113    }
114
115    /**
116     * Creates an id condition
117     *
118     * @param value the value of the id.
119     * @return An Id condition
120     * @exception CSSException if this exception is not supported.
121     */    
122    public AttributeCondition createIdCondition(String value)
123            throws CSSException {
124        return new IdConditionImpl(value);
125    }
126
127    /**
128     * Creates a lang condition
129     *
130     * @param value the value of the language.
131     * @return A lang condition
132     * @exception CSSException if this exception is not supported.
133     */    
134    public LangCondition createLangCondition(String lang)
135            throws CSSException {
136        return new LangConditionImpl(lang);
137    }
138
139    /**
140     * Creates a "one of" attribute condition
141     *
142     * @param localName the localName of the attribute
143     * @param namespaceURI the namespace URI of the attribute
144     * @param specified <code>true</code> if the attribute must be specified
145     *                  in the document.
146     * @param value the value of this attribute.
147     * @return A "one of" attribute condition
148     * @exception CSSException if this exception is not supported.
149     */    
150    public AttributeCondition createOneOfAttributeCondition(String localName,
151                                                     String namespaceURI,
152                                                     boolean specified,
153                                                     String value)
154            throws CSSException {
155        if ((namespaceURI != null) || specified) {
156            throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
157        } else {
158            return new OneOfAttributeConditionImpl(localName, value);
159        }
160    }
161
162    /**
163     * Creates a "begin hyphen" attribute condition
164     *
165     * @param localName the localName of the attribute
166     * @param namespaceURI the namespace URI of the attribute
167     * @param specified <code>true</code> if the attribute must be specified
168     *                  in the document.
169     * @param value the value of this attribute.
170     * @return A "begin hyphen" attribute condition
171     * @exception CSSException if this exception is not supported.
172     */    
173    public AttributeCondition createBeginHyphenAttributeCondition(String localName,
174                                                           String namespaceURI,
175                                                           boolean specified,
176                                                           String value)
177            throws CSSException {
178        if ((namespaceURI != null) || specified) {
179            throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
180        } else {
181            return new BeginHyphenAttributeConditionImpl(localName, value);
182        }
183    }
184
185    /**
186     * Creates a class condition
187     *
188     * @param localName the localName of the attribute
189     * @param namespaceURI the namespace URI of the attribute
190     * @param specified <code>true</code> if the attribute must be specified
191     *                  in the document.
192     * @param value the name of the class.
193     * @return A class condition
194     * @exception CSSException if this exception is not supported.
195     */    
196    public AttributeCondition createClassCondition(String namespaceURI,
197                                            String value)
198            throws CSSException {
199        return new ClassConditionImpl(value);
200    }
201
202    /**
203     * Creates a pseudo class condition
204     *
205     * @param namespaceURI the namespace URI of the attribute
206     * @param value the name of the pseudo class
207     * @return A pseudo class condition
208     * @exception CSSException if this exception is not supported.
209     */    
210    public AttributeCondition createPseudoClassCondition(String namespaceURI,
211                                                         String value)
212            throws CSSException {
213        return new PseudoClassConditionImpl(value);
214    }
215
216    /**
217     * Creates a "only one" child condition
218     *
219     * @return A "only one" child condition
220     * @exception CSSException if this exception is not supported.
221     */    
222    public Condition createOnlyChildCondition() throws CSSException {
223        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
224    }
225
226    /**
227     * Creates a "only one" type condition
228     *
229     * @return A "only one" type condition
230     * @exception CSSException if this exception is not supported.
231     */    
232    public Condition createOnlyTypeCondition() throws CSSException {
233        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
234    }
235
236    /**
237     * Creates a content condition
238     *
239     * @param data the data in the content
240     * @return A content condition
241     * @exception CSSException if this exception is not supported.
242     */    
243    public ContentCondition createContentCondition(String data)
244            throws CSSException {
245        throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
246    }    
247}