001    package org.relaxng.datatype.helpers;
002    
003    import org.relaxng.datatype.*;
004    
005    /**
006     * Dummy implementation of {@link DatatypeBuilder}.
007     * 
008     * This implementation can be used for Datatypes which have no parameters.
009     * Any attempt to add parameters will be rejected.
010     * 
011     * <p>
012     * Typical usage would be:
013     * <PRE><XMP>
014     * class MyDatatypeLibrary implements DatatypeLibrary {
015     *     ....
016     *     DatatypeBuilder createDatatypeBuilder( String typeName ) {
017     *         return new ParameterleessDatatypeBuilder(createDatatype(typeName));
018     *     }
019     *     ....
020     * }
021     * </XMP></PRE>
022     * 
023     * @author <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
024     */
025    public final class ParameterlessDatatypeBuilder implements DatatypeBuilder {
026    
027            /** This type object is returned for the derive method. */
028            private final Datatype baseType;
029            
030            public ParameterlessDatatypeBuilder( Datatype baseType ) {
031                    this.baseType = baseType;
032            }
033            
034            public void addParameter( String name, String strValue, ValidationContext context )
035                            throws DatatypeException {
036                    throw new DatatypeException();
037            }
038            
039            public Datatype createDatatype() throws DatatypeException {
040                    return baseType;
041            }
042    }