View Javadoc
1   package org.codehaus.plexus.components.io.filemappers;
2   
3   /*
4    * Copyright 2007 The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * 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, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import javax.annotation.Nonnull;
20  
21  /**
22   * A file mapper, which maps to a constant target name.
23   */
24  public class MergeFileMapper extends AbstractFileMapper
25  {
26      /**
27       * The merge mappers role-hint: "merge".
28       */
29      public static final String ROLE_HINT = "merge";
30  
31      private String targetName;
32  
33      /**
34       * Sets the merge mappers target name.
35       * 
36       * @throws IllegalArgumentException
37       *             The target name is null or empty.
38       */
39      public void setTargetName( String pName )
40      {
41          if ( pName == null )
42          {
43              throw new IllegalArgumentException( "The target name is null." );
44          }
45          if ( pName.length() == 0 )
46          {
47              throw new IllegalArgumentException( "The target name is empty." );
48          }
49          targetName = pName;
50      }
51  
52      /**
53       * Returns the merge mappers target name.
54       * 
55       * @throws IllegalArgumentException
56       *             The target name is null or empty.
57       */
58      public String getTargetName()
59      {
60          return targetName;
61      }
62  
63      @Nonnull public String getMappedFileName( @Nonnull String pName )
64      {
65          final String name = getTargetName();
66          if ( name == null )
67          {
68              throw new IllegalStateException( "The target file name has not been set." );
69          }
70          super.getMappedFileName( pName ); // Check for null, etc.
71          return name;
72      }
73  }