1
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 package fr.paris.lutece.plugins.pluginwizard.service.generator;
35
36 import fr.paris.lutece.plugins.pluginwizard.business.model.BusinessClass;
37 import fr.paris.lutece.plugins.pluginwizard.business.model.PluginModel;
38 import java.util.ArrayList;
39 import java.util.Collection;
40 import java.util.HashMap;
41 import java.util.List;
42 import java.util.Map;
43
44
45
46
47
48
49 public class BusinessClassGenerator extends AbstractGenerator
50 {
51 private static final String PATH = "SOURCE/java/fr/paris/lutece/plugins/";
52 private static final String PATH_SUFFIX = "/business/";
53 private List<BusinessFileConfig> _listFiles;
54
55
56
57
58
59
60
61 public void setFiles( List<BusinessFileConfig> listFiles )
62 {
63 if ( listFiles != null )
64 {
65 _listFiles = (List<BusinessFileConfig>) ( ( (ArrayList<BusinessFileConfig>) listFiles ).clone( ) );
66 }
67 else
68 {
69 _listFiles = null;
70 }
71 }
72
73
74
75
76 @Override
77 public Map<String, String> generate( PluginModel pm, String generationSchemeName )
78 {
79 HashMap<String, String> map = new HashMap<>( );
80 Collection<BusinessClass> listAllBusinessClasses = pm.getBusinessClasses( );
81
82 String strPluginName = pm.getPluginNameAsPackage( );
83 String strRadicalPackage = pm.getPluginNameAsRadicalPackage( );
84 String strRadicalPath = pm.getPluginNameAsRadicalPath( );
85
86 for ( BusinessClass businessClass : listAllBusinessClasses )
87 {
88 for ( BusinessFileConfig file : _listFiles )
89 {
90 String strClassName = file.getPrefix( ) + businessClass.getBusinessClass( ) + file.getSuffix( );
91 String strFilename = strClassName + ".java";
92 String strSourceCode = getSourceCode( strPluginName, businessClass, file.getTemplate( ), strRadicalPackage, pm.getPluginName( ) );
93 strSourceCode = strSourceCode.replace( "<", "<" );
94 strSourceCode = strSourceCode.replace( ">", ">" );
95 strSourceCode = strSourceCode.replace( "@i18n", "#i18n" );
96
97 String strPath = PATH.replace( "SOURCE", file.getSourcePath( ) ) + strRadicalPath + PATH_SUFFIX;
98
99 map.put( getFilePath( pm, strPath, strFilename ), strSourceCode );
100 }
101 }
102
103 return map;
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117 private String getSourceCode( String strPluginName, BusinessClass businessClass, String strTemplate, String strRadicalPackage, String strBeanName )
118 {
119 Map<String, Object> model = new HashMap<>( );
120 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
121 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
122 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
123 model.put( Markers.MARK_BEAN_NAME, strBeanName );
124
125 return build( strTemplate, model );
126 }
127 }