View Javadoc

1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  package org.apache.jsieve;
21  
22  import static org.apache.jsieve.Constants.TAG_COMPARATOR;
23  
24  import org.apache.jsieve.parser.generated.Token;
25  
26  /**
27   * <p>
28   * A parsed representation of an RFC3028 TAG argument...
29   * </p>
30   * 
31   * <code>tag = ":" identifier</code>
32   */
33  public class TagArgument implements Argument {
34  
35      /**
36       * The Tag
37       */
38      private String fieldTag;
39  
40      /**
41       * Constructor for TagArgument.
42       */
43      private TagArgument() {
44          super();
45      }
46  
47      /**
48       * Constructor for TagArgument.
49       * 
50       * @param token
51       */
52      public TagArgument(Token token) {
53          this();
54          setTag(token);
55      }
56  
57      /**
58       * Method setTag.
59       * 
60       * @param token
61       */
62      protected void setTag(Token token) {
63          setTag(token.image);
64      }
65  
66      /**
67       * Returns the tag.
68       * 
69       * @return String
70       */
71      public String getTag() {
72          return fieldTag;
73      }
74  
75      /**
76       * Does this argument match the given tag?
77       * @param tag not null
78       * @return true when the tag identifier equals that given,
79       * false otherwise
80       */
81      public boolean is(String tag) {
82         return tag.equals(fieldTag); 
83      }
84      
85      /**
86       * Is this a comparator tag?
87       * @return true when identifier matches {@link Constants#TAG_COMPARATOR},
88       * false otherwise
89       */
90      public boolean isComparator() {
91          return this.is(TAG_COMPARATOR);
92      }
93      
94      /**
95       * Sets the tag.
96       * 
97       * @param tag
98       *            The tag to set
99       */
100     protected void setTag(String tag) {
101         fieldTag = tag;
102     }
103 
104     /**
105      * @see org.apache.jsieve.Argument#getValue()
106      */
107     public Object getValue() {
108         return getTag();
109     }
110 
111     /**
112      * @see java.lang.Object#toString()
113      */
114     public String toString() {
115         return (getValue() == null) ? "null" : getValue().toString();
116     }
117 
118 }