View Javadoc
1   package org.codehaus.mojo.taglist.tags;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /** The tag factory is used to create a tag based on the type of tag
23   *  defined in the pom.xml.
24   * 
25   */
26  public class TagFactory 
27  {
28      /** The XML name of the generic tag (case sensitive). */
29      private static String genericTag = "exact";
30      /** The XML name of the ignore case tag (case insensitive). */
31      private static String ignorecaseTag = "ignoreCase";
32      /** The XML name of the regular expression tag. */
33      private static String regexTag = "regEx";
34      
35      
36      /** Create a tag based on a tag type string.
37       * 
38       * @param tagType the XML string for the tag to create.
39       * @param rule the tag string to use in matching tags.
40       * @return the new tag. NULL if the tagType is unknown.
41       * @throws InvalidTagException if the tagType is unknown
42       */
43      public static AbsTag createTag ( final String tagType, final String rule )
44      throws InvalidTagException
45      {
46          AbsTag tag = null;
47          
48          if ( genericTag.equals( tagType ) )
49          {
50              tag = new GenericTag( rule );
51          }
52          else if ( ignorecaseTag.equals( tagType ) )
53          {
54              tag = new IgnoreCaseTag( rule );
55          }
56          else if ( regexTag.equals( tagType ) )
57          {
58              tag = new RegExTag( rule );
59          }
60          else 
61          {
62              throw new InvalidTagException( tagType );
63          }
64          
65          return ( tag );
66      }
67      
68      /** Returns the default tag type if one is not specified.
69       * 
70       * @return the default tag type string
71       */
72      public static final String getDefaultTagType()
73      {
74          return ( genericTag );
75      }
76      
77      /** Private constructor.  This is a utility class.
78       * 
79       */
80      private TagFactory ()
81      {
82          // Do nothing
83      }
84  }