001package ball.util.ant.types;
002/*-
003 * ##########################################################################
004 * Utilities
005 * $Id: StringAttributeType.java 5285 2020-02-05 04:23:21Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/ball-util/trunk/src/main/java/ball/util/ant/types/StringAttributeType.java $
007 * %%
008 * Copyright (C) 2008 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import ball.util.ant.taskdefs.NotNull;
024import java.beans.ConstructorProperties;
025import java.util.LinkedHashMap;
026import java.util.Map;
027
028/**
029 * Class to provide a {@link String} name-value (attribute) for
030 * {@link.uri http://ant.apache.org/ Ant} {@link org.apache.tools.ant.Task}
031 * implementations.
032 *
033 * {@bean.info}
034 *
035 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
036 * @version $Revision: 5285 $
037 */
038public class StringAttributeType extends StringValueType
039                                 implements Map.Entry<String,String> {
040    private String name = null;
041
042    /**
043     * @param   name            The attribute name.
044     */
045    @ConstructorProperties({ "name" })
046    public StringAttributeType(String name) {
047        super();
048
049        this.name = name;
050    }
051
052    /**
053     * No-argument constructor.
054     */
055    public StringAttributeType() { this(null); }
056
057    @ConstructorProperties({ "name", "value" })
058    private StringAttributeType(String name, String value) {
059        this(name);
060
061        setValue(value);
062    }
063
064    private StringAttributeType(String name, Object value) {
065        this(name, (value != null) ? value.toString() : null);
066    }
067
068    @NotNull
069    public String getName() { return name; }
070    public void setName(String name) { this.name = name; }
071
072    @Override
073    public String getKey() { return getName(); }
074
075    @Override
076    public String toString() { return getName() + "=" + getValue(); }
077}