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
23
24
25
26
27
28
29
30
31
32
33
34 public class FileNameMappingFactory
35 {
36 static final String STANDARD_FILE_NAME_MAPPING = "standard";
37
38 static final String FULL_FILE_NAME_MAPPING = "full";
39
40 static final String NO_VERSION_FILE_NAME_MAPPING = "no-version";
41
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 {
65 return getDefaultFileNameMapping();
66 }
67 if ( FULL_FILE_NAME_MAPPING.equals( nameOrClass ) )
68 {
69 return new FullFileNameMapping();
70 }
71 if ( NO_VERSION_FILE_NAME_MAPPING.equals( nameOrClass ) )
72 {
73 return new NoVersionFileNameMapping();
74 }
75 try
76 {
77 final Class c = Class.forName( nameOrClass );
78 return (FileNameMapping) c.newInstance();
79 }
80 catch ( ClassNotFoundException e )
81 {
82 throw new IllegalStateException(
83 "File name mapping implementation[" + nameOrClass + "] was not found " + e.getMessage() );
84 }
85 catch ( InstantiationException e )
86 {
87 throw new IllegalStateException( "Could not instantiate file name mapping implementation[" + nameOrClass +
88 "] make sure it has a default public constructor" );
89 }
90 catch ( IllegalAccessException e )
91 {
92 throw new IllegalStateException( "Could not access file name mapping implementation[" + nameOrClass +
93 "] make sure it has a default public constructor" );
94 }
95 catch ( ClassCastException e )
96 {
97 throw new IllegalStateException(
98 "Specified class[" + nameOrClass + "] does not implement[" + FileNameMapping.class.getName() + "]" );
99 }
100 }
101 }