Source for org.w3c.flute.parser.selectors.SelectorFactoryImpl

   1: /*
   2:  * Copyright (c) 2000 World Wide Web Consortium,
   3:  * (Massachusetts Institute of Technology, Institut National de
   4:  * Recherche en Informatique et en Automatique, Keio University). All
   5:  * Rights Reserved. This program is distributed under the W3C's Software
   6:  * Intellectual Property License. This program is distributed in the
   7:  * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
   8:  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
   9:  * PURPOSE.
  10:  * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
  11:  *
  12:  * $Id: SelectorFactoryImpl.java,v 1.1.1.1 2006/04/23 14:51:53 taqua Exp $
  13:  */
  14: package org.w3c.flute.parser.selectors;
  15: 
  16: import org.w3c.css.sac.SelectorFactory;
  17: import org.w3c.css.sac.ConditionalSelector;
  18: import org.w3c.css.sac.NegativeSelector;
  19: import org.w3c.css.sac.SimpleSelector;
  20: import org.w3c.css.sac.ElementSelector;
  21: import org.w3c.css.sac.CharacterDataSelector;
  22: import org.w3c.css.sac.ProcessingInstructionSelector;
  23: import org.w3c.css.sac.SiblingSelector;
  24: import org.w3c.css.sac.DescendantSelector;
  25: import org.w3c.css.sac.Selector;
  26: import org.w3c.css.sac.Condition;
  27: import org.w3c.css.sac.CSSException;
  28: 
  29: /**
  30:  * @version $Revision: 1.1.1.1 $
  31:  * @author  Philippe Le Hegaret
  32:  */
  33: public class SelectorFactoryImpl implements SelectorFactory {
  34: 
  35:     /**
  36:      * Creates a conditional selector.
  37:      * 
  38:      * @param selector a selector.
  39:      * @param condition a condition
  40:      * @return the conditional selector.
  41:      * @exception CSSException If this selector is not supported.
  42:      */    
  43:     public ConditionalSelector createConditionalSelector(SimpleSelector selector,
  44:                           Condition condition) 
  45:         throws CSSException {
  46:   return new ConditionalSelectorImpl(selector, condition);
  47:     }
  48: 
  49:     /**
  50:      * Creates an any node selector.
  51:      * 
  52:      * @return the any node selector.
  53:      * @exception CSSException If this selector is not supported.
  54:      */    
  55:     public SimpleSelector createAnyNodeSelector() throws CSSException {
  56:     throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
  57:     }
  58: 
  59:     /**
  60:      * Creates an root node selector.
  61:      * 
  62:      * @return the root node selector.
  63:      * @exception CSSException If this selector is not supported.
  64:      */    
  65:     public SimpleSelector createRootNodeSelector() throws CSSException {
  66:     throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
  67:     }
  68: 
  69:     /**
  70:      * Creates an negative selector.
  71:      * 
  72:      * @param selector a selector.
  73:      * @return the negative selector.
  74:      * @exception CSSException If this selector is not supported.
  75:      */    
  76:     public NegativeSelector createNegativeSelector(SimpleSelector selector) 
  77:         throws CSSException {
  78:     throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
  79:     }
  80: 
  81:     /**
  82:      * Creates an element selector.
  83:      * 
  84:      * @param namespaceURI the <a href="http://www.w3.org/TR/REC-xml-names/#dt-NSName">namespace
  85:      *                     URI</a> of the element selector.
  86:      * @param tagName the <a href="http://www.w3.org/TR/REC-xml-names/#NT-LocalPart">local
  87:      *        part</a> of the element name. <code>NULL</code> if this element
  88:      *        selector can match any element.</p>
  89:      * @return the element selector
  90:      * @exception CSSException If this selector is not supported.
  91:      */    
  92:     public ElementSelector createElementSelector(String namespaceURI, String localName) 
  93:         throws CSSException {
  94:     if (namespaceURI != null) {
  95:         throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR);
  96:     } else {
  97:         return new ElementSelectorImpl(localName);
  98:     }
  99:     }
 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: }