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 public static final String STANDARD_FILE_NAME_MAPPING = "standard";
40
41 public static final String FULL_FILE_NAME_MAPPING = "full";
42
43 public static final FileNameMappingFactory INSTANCE = new FileNameMappingFactory();
44
45 private final Map mappings;
46
47 private FileNameMappingFactory()
48 {
49 mappings = new HashMap();
50 mappings.put( STANDARD_FILE_NAME_MAPPING, new StandardFileNameMapping() );
51 mappings.put( FULL_FILE_NAME_MAPPING, new FullFileNameMapping() );
52 }
53
54 public FileNameMapping getDefaultFileNameMapping()
55 {
56 return getFileNameMapping( STANDARD_FILE_NAME_MAPPING );
57 }
58
59
60
61
62
63
64
65
66
67 public FileNameMapping getFileNameMapping( final String nameOrClass )
68 throws IllegalStateException
69 {
70
71 if ( mappings.containsKey( nameOrClass ) )
72 {
73 return (FileNameMapping) mappings.get( nameOrClass );
74 }
75 else
76 {
77 try
78 {
79 final Class c = Class.forName( nameOrClass );
80 final FileNameMapping fnm = (FileNameMapping) c.newInstance();
81 mappings.put( nameOrClass, fnm );
82 return fnm;
83 }
84 catch ( ClassNotFoundException e )
85 {
86 throw new IllegalStateException(
87 "File name mapping implementation[" + nameOrClass + "] was not found " + e.getMessage() );
88 }
89 catch ( InstantiationException e )
90 {
91 throw new IllegalStateException( "Could not instanciate file name mapping implementation[" +
92 nameOrClass + "] make sure it has a default public constructor" );
93 }
94 catch ( IllegalAccessException e )
95 {
96 throw new IllegalStateException( "Could not access file name mapping implementation[" + nameOrClass +
97 "] make sure it has a default public constructor" );
98 }
99 catch ( ClassCastException e )
100 {
101 throw new IllegalStateException( "Specified class[" + nameOrClass + "] does not implement[" +
102 FileNameMapping.class.getName() + "]" );
103 }
104 }
105 }
106 }