    001    package org.maltparser.core.options.option;
    002
    003    import org.maltparser.core.exception.MaltChainedException;
    004    import org.maltparser.core.options.OptionException;
    005    import org.maltparser.core.options.OptionGroup;
    006
    007    /**
    008     * A string option is an option that contains a string value.
    009     *
    010     * @author Johan Hall
    011     * @since 1.0
    012    **/
    013    public class StringOption extends Option {
    014            private String defaultValue;
    015
    016            /**
    017             * Creates a string option description
    018             *
    019             * @param group a reference to the option group.
    020             * @param name  the name of the option.
    021             * @param shortDescription      a short description of the option.
    022             * @param flag  a short string that can be used in the command line.
    023             * @param usage a string that explains the usage of the option.
    024             * @param defaultValue  a default value string.
    025             * @throws OptionException
    026             */
    027            public StringOption(OptionGroup group,
    028                                                    String name,
    029                                                    String shortDescription,
    030                                                    String flag,
    031                                                    String usage,
    032                                                    String defaultValue) throws MaltChainedException {
    033                    super(group, name, shortDescription, flag, usage);
    034                    setDefaultValue(defaultValue);
    035            }
    036
    037            /* (non-Javadoc)
    038             * @see org.maltparser.core.options.option.Option#getValueObject(java.lang.String)
    039             */
    040            public Object getValueObject(String value) throws MaltChainedException {
    041                    return new String(value);
    042            }
    043
    044            /* (non-Javadoc)
    045             * @see org.maltparser.core.options.option.Option#getDefaultValueObject()
    046             */
    047            public Object getDefaultValueObject() throws MaltChainedException {
    048                    return new String(defaultValue);
    049            }
    050
    051            /* (non-Javadoc)
    052             * @see org.maltparser.core.options.option.Option#setDefaultValue(java.lang.String)
    053             */
    054            public void setDefaultValue(String defaultValue) {
    055                    this.defaultValue = defaultValue;
    056            }
    057
    058            /* (non-Javadoc)
    059             * @see org.maltparser.core.options.option.Option#getDefaultValueString()
    060             */
    061            public String getDefaultValueString() {
    062                    return defaultValue;
    063            }
    064
    065            /* (non-Javadoc)
    066             * @see org.maltparser.core.options.option.Option#getStringRepresentation(java.lang.Object)
    067             */
    068            public String getStringRepresentation(Object value) {
    069                    if (value instanceof String) {
    070                            return value.toString();
    071                    }
    072                    return null;
    073            }
    074
    075            /* (non-Javadoc)
    076             * @see org.maltparser.core.options.option.Option#toString()
    077             */
    078            public String toString() {
    079                    final StringBuilder sb = new StringBuilder();
    080                    sb.append(super.toString());
    081                    sb.append("-----------------------------------------------------------------------------\n");
    082                    return sb.toString();
    083            }
    084    }