1 package org.apache.maven.plugin.ear.output;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class FileNameMappingFactory
38 {
39 static final String STANDARD_FILE_NAME_MAPPING = "standard";
40
41 static final String FULL_FILE_NAME_MAPPING = "full";
42
43 private FileNameMappingFactory()
44 {
45 }
46
47 public static FileNameMapping getDefaultFileNameMapping()
48 {
49 return new StandardFileNameMapping() ;
50 }
51
52
53
54
55
56
57
58
59
60 public static FileNameMapping getFileNameMapping( final String nameOrClass )
61 throws IllegalStateException
62 {
63 if (STANDARD_FILE_NAME_MAPPING.equals( nameOrClass )){
64 return getDefaultFileNameMapping();
65 }
66 if (FULL_FILE_NAME_MAPPING.equals( nameOrClass )){
67 return new FullFileNameMapping();
68 }
69 try
70 {
71 final Class c = Class.forName( nameOrClass );
72 return (FileNameMapping) c.newInstance();
73 }
74 catch ( ClassNotFoundException e )
75 {
76 throw new IllegalStateException(
77 "File name mapping implementation[" + nameOrClass + "] was not found " + e.getMessage() );
78 }
79 catch ( InstantiationException e )
80 {
81 throw new IllegalStateException( "Could not instanciate file name mapping implementation[" +
82 nameOrClass + "] make sure it has a default public constructor" );
83 }
84 catch ( IllegalAccessException e )
85 {
86 throw new IllegalStateException( "Could not access file name mapping implementation[" + nameOrClass +
87 "] make sure it has a default public constructor" );
88 }
89 catch ( ClassCastException e )
90 {
91 throw new IllegalStateException( "Specified class[" + nameOrClass + "] does not implement[" +
92 FileNameMapping.class.getName() + "]" );
93 }
94 }
95 }