1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.devtools.generators.dd; |
17 | |
|
18 | |
import org.apache.commons.beanutils.PropertyUtils; |
19 | |
import org.kuali.rice.krad.bo.BusinessObject; |
20 | |
|
21 | |
import java.beans.PropertyDescriptor; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
@Deprecated |
27 | 0 | public class BeanDDCreator { |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public static void main(String[] args) throws Exception { |
34 | 0 | String className = args[0]; |
35 | 0 | Class<? extends BusinessObject> boClass = (Class<? extends BusinessObject>)Class.forName( className ); |
36 | 0 | PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors( boClass ); |
37 | |
|
38 | 0 | StringBuffer sb = new StringBuffer( 4000 ); |
39 | 0 | sb.append( "<beans xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + |
40 | |
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + |
41 | |
" xmlns:p=\"http://www.springframework.org/schema/p\"\r\n" + |
42 | |
" xsi:schemaLocation=\"http://www.springframework.org/schema/beans\r\n" + |
43 | |
" http://www.springframework.org/schema/beans/spring-beans-2.0.xsd\">\r\n" + |
44 | |
"\r\n" + |
45 | |
" <bean id=\"" ); |
46 | 0 | sb.append( boClass.getSimpleName() ); |
47 | 0 | sb.append( "\" parent=\"" ); |
48 | 0 | sb.append( boClass.getSimpleName() ); |
49 | 0 | sb.append( "-parentBean\" />\r\n" + |
50 | |
"\r\n" + |
51 | |
" <bean id=\"" ); |
52 | 0 | sb.append( boClass.getSimpleName() ); |
53 | 0 | sb.append( "-parentBean\" abstract=\"true\" parent=\"BusinessObjectEntry\"\r\n" + |
54 | |
" p:businessObjectClass=\"" ); |
55 | 0 | sb.append( boClass.getName() ); |
56 | 0 | sb.append( "\"\r\n" ); |
57 | 0 | sb.append( " p:titleAttribute=\"" ); |
58 | 0 | sb.append( "FILL ME IN" ); |
59 | 0 | sb.append( "\"\r\n" ); |
60 | 0 | sb.append( " p:objectLabel=\"" ); |
61 | 0 | sb.append( camelCaseToString( boClass.getSimpleName() ) ); |
62 | 0 | sb.append( "\"\r\n" ); |
63 | 0 | sb.append( " p:inquiryDefinition-ref=\"" ); |
64 | 0 | sb.append( boClass.getSimpleName() ); |
65 | 0 | sb.append( "-inquiryDefinition\"\r\n" ); |
66 | 0 | sb.append( " p:lookupDefinition-ref=\"" ); |
67 | 0 | sb.append( boClass.getSimpleName() ); |
68 | 0 | sb.append( "-lookupDefinition\" >\r\n" ); |
69 | 0 | sb.append( " <property name=\"attributes\" >\r\n" + |
70 | |
" <list>\r\n" ); |
71 | 0 | for ( PropertyDescriptor p : props ) { |
72 | 0 | if ( isNormalProperty(p) ) { |
73 | 0 | sb.append( " <ref bean=\"" ).append( boClass.getSimpleName() ).append( '-' ); |
74 | 0 | sb.append( p.getName() ); |
75 | 0 | sb.append( "\" />\r\n" ); |
76 | |
} |
77 | |
} |
78 | |
|
79 | 0 | sb.append( " </list>\r\n" + |
80 | |
" </property>\r\n" + |
81 | |
" </bean>\r\n" + |
82 | |
"\r\n" ); |
83 | 0 | for ( PropertyDescriptor p : props ) { |
84 | 0 | if ( isNormalProperty(p) ) { |
85 | |
|
86 | 0 | if ( p.getName().equals( "versionNumber" ) ) { |
87 | 0 | sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); |
88 | 0 | sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "GenericAttributes-versionNumber" ) ); |
89 | |
|
90 | 0 | } else if ( p.getName().endsWith("chartOfAccountsCode" ) ) { |
91 | 0 | sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); |
92 | 0 | sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "Chart-chartOfAccountsCode" ) ); |
93 | |
|
94 | 0 | } else if ( p.getName().endsWith("organizationCode" ) ) { |
95 | 0 | sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); |
96 | 0 | sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "Org-organizationCode" ) ); |
97 | |
|
98 | 0 | } else if ( p.getName().endsWith("accountNumber" ) ) { |
99 | 0 | sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); |
100 | 0 | sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "Account-accountNumber" ) ); |
101 | |
|
102 | 0 | } else if ( p.getName().equals("active" ) ) { |
103 | 0 | sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); |
104 | 0 | sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "GenericAttributes-activeIndicator" ) ); |
105 | |
|
106 | 0 | } else if ( p.getName().equals("codeAndDescription" ) ) { |
107 | 0 | sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); |
108 | 0 | sb.append( getSimpleAbstractInheritanceBeanWithLabel(boClass, p.getName(), "CommonField-CodeAndDescription", camelCaseToString(boClass.getSimpleName()) ) ); |
109 | |
|
110 | 0 | } else if ( p.getPropertyType() == Boolean.TYPE ) { |
111 | 0 | sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); |
112 | 0 | sb.append( getSimpleAbstractInheritanceBean(boClass, p.getName(), "GenericAttributes-genericBoolean" ) ); |
113 | |
|
114 | |
} else { |
115 | |
|
116 | 0 | sb.append( getSimpleParentBeanReference( boClass, p.getName() ) ); |
117 | |
|
118 | 0 | sb.append( " <bean id=\"" ).append( boClass.getSimpleName() ).append( '-' ); |
119 | 0 | sb.append( p.getName() ).append( "-parentBean\" parent=\"AttributeDefinition\" abstract=\"true\"\r\n" ); |
120 | 0 | sb.append( " p:name=\"" ).append( p.getName() ).append( "\"\r\n" ); |
121 | 0 | sb.append( " p:forceUppercase=\"false\"\r\n" ); |
122 | 0 | sb.append( " p:label=\"" ).append( camelCaseToString(p.getName()) ).append( "\"\r\n" ); |
123 | 0 | sb.append( " p:shortLabel=\"" ).append( camelCaseToString(p.getName()) ).append( "\"\r\n" ); |
124 | 0 | sb.append( " p:maxLength=\"10\"\r\n" ); |
125 | 0 | sb.append( " p:required=\"false\" >\r\n" ); |
126 | 0 | sb.append( " <property name=\"validationPattern\" >\r\n" + |
127 | |
" <bean parent=\"AnyCharacterValidationPattern\"\r\n" + |
128 | |
" p:allowWhitespace=\"true\" />\r\n" + |
129 | |
" </property>\r\n" + |
130 | |
" <property name=\"control\" >\r\n" + |
131 | |
" <bean parent=\"TextControlDefinition\"\r\n" + |
132 | |
" p:size=\"10\" />\r\n" + |
133 | |
" </property>\r\n" + |
134 | |
" </bean>\r\n" ); |
135 | |
|
136 | |
} |
137 | 0 | sb.append( "\r\n" ); |
138 | |
} |
139 | |
} |
140 | |
|
141 | |
|
142 | 0 | sb.append( getSimpleParentBeanReference( boClass, "inquiryDefinition" ) ); |
143 | 0 | sb.append( "\r\n" ); |
144 | 0 | sb.append( " <bean id=\"" ); |
145 | 0 | sb.append( boClass.getSimpleName() ); |
146 | 0 | sb.append( "-inquiryDefinition-parentBean\" abstract=\"true\" parent=\"InquiryDefinition\"\r\n" + |
147 | |
" p:title=\"" ); |
148 | 0 | sb.append( camelCaseToString(boClass.getSimpleName() ) ); |
149 | 0 | sb.append( " Inquiry\" >\r\n" + |
150 | |
" <property name=\"inquirySections\" >\r\n" + |
151 | |
" <list>\r\n" + |
152 | |
" <bean parent=\"InquirySectionDefinition\"\r\n" + |
153 | |
" p:title=\"" ); |
154 | 0 | sb.append( camelCaseToString(boClass.getSimpleName() ) ); |
155 | 0 | sb.append( " Attributes\"\r\n" + |
156 | |
" p:numberOfColumns=\"1\" >\r\n" + |
157 | |
" <property name=\"inquiryFields\" >\r\n" + |
158 | |
" <list>\r\n" ); |
159 | 0 | for ( PropertyDescriptor p : props ) { |
160 | 0 | if ( isNormalProperty(p) ) { |
161 | 0 | sb.append(" <bean parent=\"FieldDefinition\" p:attributeName=\"" ); |
162 | 0 | sb.append( p.getName() ).append( "\" />\r\n" ); |
163 | |
} |
164 | |
} |
165 | 0 | sb.append( " </list>\r\n" + |
166 | |
" </property>\r\n" + |
167 | |
" </bean>\r\n" + |
168 | |
" </list>\r\n" + |
169 | |
" </property>\r\n" + |
170 | |
" </bean>\r\n" + |
171 | |
"\r\n" ); |
172 | |
|
173 | 0 | sb.append( getSimpleParentBeanReference( boClass, "lookupDefinition" ) ); |
174 | 0 | sb.append( "\r\n" ); |
175 | 0 | sb.append( " <bean id=\"" ); |
176 | 0 | sb.append( boClass.getSimpleName() ); |
177 | 0 | sb.append( "-lookupDefinition-parentBean\" abstract=\"true\" parent=\"LookupDefinition\"\r\n" + |
178 | |
" p:title=\"" ); |
179 | 0 | sb.append( camelCaseToString(boClass.getSimpleName() ) ); |
180 | 0 | sb.append( " Lookup\" \r\n" ); |
181 | |
|
182 | |
|
183 | 0 | sb.append( "\" >\r\n" ); |
184 | 0 | sb.append( " <property name=\"defaultSort\" >\r\n" + |
185 | |
" <bean parent=\"SortDefinition\">\r\n" + |
186 | |
" <property name=\"attributeNames\" >\r\n" + |
187 | |
" <list>\r\n" + |
188 | |
" <value>FILL ME IN</value>\r\n" + |
189 | |
" </list>\r\n" + |
190 | |
" </property>\r\n" + |
191 | |
" <property name=\"sortAscending\" value=\"true\" />\r\n" + |
192 | |
" </bean>\r\n" + |
193 | |
" </property>\r\n" + |
194 | |
" <property name=\"lookupFields\" >\r\n" + |
195 | |
" <list>\r\n" ); |
196 | 0 | for ( PropertyDescriptor p : props ) { |
197 | 0 | if ( isNormalProperty(p) ) { |
198 | 0 | sb.append(" <bean parent=\"FieldDefinition\" p:attributeName=\"" ); |
199 | 0 | sb.append( p.getName() ).append( "\" />\r\n" ); |
200 | |
} |
201 | |
} |
202 | 0 | sb.append( " </list>\r\n" + |
203 | |
" </property>\r\n" + |
204 | |
" <property name=\"resultFields\" >\r\n" + |
205 | |
" <list>\r\n" ); |
206 | 0 | for ( PropertyDescriptor p : props ) { |
207 | 0 | if ( isNormalProperty(p) ) { |
208 | 0 | sb.append(" <bean parent=\"FieldDefinition\" p:attributeName=\"" ); |
209 | 0 | sb.append( p.getName() ).append( "\" />\r\n" ); |
210 | |
} |
211 | |
} |
212 | 0 | sb.append( " </list>\r\n" + |
213 | |
" </property>\r\n" + |
214 | |
" </bean>\r\n" ); |
215 | 0 | sb.append( "\r\n</beans>" ); |
216 | 0 | System.out.println( sb.toString() ); |
217 | 0 | } |
218 | |
|
219 | |
public static String getSimpleAbstractInheritanceBean( Class<? extends BusinessObject> boClass, String propertyName, String parentBean ) { |
220 | 0 | StringBuffer sb = new StringBuffer( 100 ); |
221 | 0 | sb.append( " <bean id=\"" ); |
222 | 0 | sb.append( boClass.getSimpleName() ); |
223 | 0 | sb.append( "-" ).append( propertyName ).append( "-parentBean\" abstract=\"true\" parent=\"" ); |
224 | 0 | sb.append( parentBean ).append( "\" \r\n" ); |
225 | 0 | sb.append( " p:name=\"" ).append( propertyName ).append( "\"\r\n" ); |
226 | 0 | sb.append( " p:required=\"false\" />\r\n" ); |
227 | 0 | return sb.toString(); |
228 | |
} |
229 | |
|
230 | |
public static String getSimpleAbstractInheritanceBeanWithLabel( Class<? extends BusinessObject> boClass, String propertyName, String parentBean, String label ) { |
231 | 0 | StringBuffer sb = new StringBuffer( 100 ); |
232 | 0 | sb.append( " <bean id=\"" ); |
233 | 0 | sb.append( boClass.getSimpleName() ); |
234 | 0 | sb.append( "-" ).append( propertyName ).append( "-parentBean\" abstract=\"true\" parent=\"" ); |
235 | 0 | sb.append( parentBean ).append( "\" \r\n" ); |
236 | 0 | sb.append( " p:name=\"" ).append( propertyName ).append( "\"\r\n" ); |
237 | 0 | sb.append( " p:label=\"" ).append( label ).append( "\"\r\n" ); |
238 | 0 | sb.append( " p:required=\"false\" />\r\n" ); |
239 | 0 | return sb.toString(); |
240 | |
} |
241 | |
|
242 | |
public static String getSimpleParentBeanReference( Class<? extends BusinessObject> boClass, String propertyName ) { |
243 | 0 | StringBuffer sb = new StringBuffer( 100 ); |
244 | 0 | sb.append( " <bean id=\"" ); |
245 | 0 | sb.append( boClass.getSimpleName() ); |
246 | 0 | sb.append( "-" ).append( propertyName ).append( "\" parent=\"" ); |
247 | 0 | sb.append( boClass.getSimpleName() ); |
248 | 0 | sb.append( "-" ).append( propertyName ).append( "-parentBean\" />\r\n" ); |
249 | 0 | return sb.toString(); |
250 | |
} |
251 | |
|
252 | |
public static boolean isNormalProperty( PropertyDescriptor p ) { |
253 | 0 | return p.getPropertyType()!= null |
254 | |
&& !BusinessObject.class.isAssignableFrom( p.getPropertyType() ) |
255 | |
&& !p.getName().equals( "objectId" ) |
256 | |
&& !p.getName().equals( "class" ) |
257 | |
&& !p.getName().startsWith( "boNote" ) |
258 | |
&& !p.getName().startsWith( "autoIncrementSet" ) |
259 | |
&& !p.getName().equals( "newCollectionRecord" ); |
260 | |
} |
261 | |
|
262 | |
public static String camelCaseToString( String className ) { |
263 | 0 | StringBuffer newName = new StringBuffer( className ); |
264 | |
|
265 | 0 | newName.replace(0, 1, newName.substring(0, 1).toUpperCase()); |
266 | |
|
267 | 0 | for ( int i = 0; i < newName.length(); i++ ) { |
268 | 0 | if ( Character.isUpperCase(newName.charAt(i)) ) { |
269 | 0 | newName.insert(i, ' '); |
270 | 0 | i++; |
271 | |
} |
272 | |
} |
273 | |
|
274 | 0 | return newName.toString().trim().replace( "Uc", "UC" ); |
275 | |
} |
276 | |
} |