forked from cellularmitosis/ADC-reference-library-2009-july
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting15.html
executable file
·1095 lines (976 loc) · 38.5 KB
/
listing15.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>JavaEOGenerator - /src/main/java/com/webobjects/generator/Configuration.java</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/Java/index.html">Java</a> > <a href="../../samplecode/Java/idxWebObjects-date.html">WebObjects</a> > <A HREF="javascript:location.replace('index.html');">JavaEOGenerator</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">JavaEOGenerator</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/src/main/java/com/webobjects/generator/Configuration.java</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/src/main/java/com/webobjects/entitygenerator/EntityBaseComponent.java</option>
<option value="listing2.html">/src/main/java/com/webobjects/entitygenerator/EntityComponent.java</option>
<option value="listing3.html">/src/main/java/com/webobjects/entitygenerator/EntityConfiguration.java</option>
<option value="listing4.html">/src/main/java/com/webobjects/entitygenerator/EntityContext.java</option>
<option value="listing5.html">/src/main/java/com/webobjects/entitygenerator/EntityGenerator.java</option>
<option value="listing6.html">/src/main/java/com/webobjects/entitygenerator/EOAttributeProxy.java</option>
<option value="listing7.html">/src/main/java/com/webobjects/entitygenerator/EOEntityProxy.java</option>
<option value="listing8.html">/src/main/java/com/webobjects/entitygenerator/EOEntityRelatedProxy.java</option>
<option value="listing9.html">/src/main/java/com/webobjects/entitygenerator/EOFetchSpecificationProxy.java</option>
<option value="listing10.html">/src/main/java/com/webobjects/entitygenerator/EOPropertyProxy.java</option>
<option value="listing11.html">/src/main/java/com/webobjects/entitygenerator/EORelationshipProxy.java</option>
<option value="listing12.html">/src/main/java/com/webobjects/eogenerator/EOGenerator.java</option>
<option value="listing13.html">/src/main/java/com/webobjects/eogenerator/EOGeneratorApplication.java</option>
<option value="listing14.html">/src/main/java/com/webobjects/eogenerator/EOGeneratorSession.java</option>
<option value="listing15.html">/src/main/java/com/webobjects/generator/Configuration.java</option>
<option value="listing16.html">/src/main/java/com/webobjects/generator/Generator.java</option>
<option value="listing17.html">/src/main/java/com/webobjects/generator/GeneratorComponent.java</option>
<option value="listing18.html">/src/main/java/com/webobjects/generator/GeneratorContext.java</option>
<option value="listing19.html">/src/main/java/com/webobjects/generator/GeneratorProxy.java</option>
<option value="listing20.html">/src/main/java/com/webobjects/generator/StringUtils.java</option>
<option value="listing21.html">/wo-resources/Resources/Main.wo/Main.html</option></select>
</p>
</form>
<p><strong><a href="JavaEOGenerator.zip">Download Sample</a></strong> (“JavaEOGenerator.zip”, 17.14M)<BR>
<strong><a href="JavaEOGenerator.dmg">Download Sample</a></strong> (“JavaEOGenerator.dmg”, 17.41M)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/*
* Copyright 2005 - 2007 Apple, Inc. All rights reserved.
*
* IMPORTANT: This Apple software is supplied to you by Apple, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software.
*
* In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated.
*
* The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
*
* IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package com.webobjects.generator;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.TreeMap;
/**
* @since 5.4
*/
public class Configuration {
Map<String, Option> _options;
List<String> _arguments;
Map<String, String> _additionalKeyValues;
List<URL> _searchPath;
/**
* Option leader key
*/
public static final String OptionLeader = "-";
/**
* Option key
*/
public static final String HelpOptionKey = "help";
/**
* Option key
*/
public static final String VerboseOptionKey = "verbose";
/**
* Option key
*/
public static final String VersionOptionKey = "version";
/**
* Option key variable prefix
*/
public static final String AdditionalKeyValueKey = "define-";
/**
* Option key
*/
public static final String EncodingKey = "encoding";
/**
* Option key
*/
public static final String TemplateEncodingKey = "templateEncoding";
/**
* Option key
*/
public static final String FileNameTemplateKey = "filenameTemplate";
/**
* Option key
*/
public static final String DestinationKey = "destination";
/**
* Option key
*/
public static final String SubClassDestinationKey = "subclassDestination";
/**
* Option key
*/
public static final String PackageDirectoriesKey = "packagedirs";
/**
* Option key
*/
public static final String PrefixKey = "prefix";
/**
* Option key
*/
public static final String TemplateDirectoryKey = "templatedir";
/**
* Option key
*/
public static final String JavaTemplateKey = "javaTemplate";
/**
* Option key
*/
public static final String SubClassJavaTemplatesKey = "subclassJavaTemplate";
/**
*
*/
public static class URLOption extends Option {
URL _value;
URL _defaultValue;
/**
* @param name
* @param description
*/
public URLOption(String name, String description) {
this(name, description, null);
}
/**
* @param name
* @param description
* @param defaultValue
*/
public URLOption(String name, String description, URL defaultValue) {
super(name, description);
_defaultValue = defaultValue;
}
/*
* (non-Javadoc)
*
* @see com.webobjects.generator.Configuration.Option#decodeOptions(java.util.Queue)
*/
@Override
public void decodeOptions(Queue<String> optionList) throws InvalidOptionException {
if (this.isSameOptionName(optionList)) {
String path = Option.optionValueFromList(optionList);
if (path.length() > 0) {
// First try for a URL
try {
_value = new URL(path);
} catch (Exception urlException) {
// We do not want to report the exception
try {
File aFile = new File(path);
if (!aFile.exists()) {
if (!aFile.mkdirs()) {
throw new InvalidOptionException(aFile + " does not exist and could not be created.");
}
}
_value = aFile.toURL();
} catch (Exception fileException) {
throw new InvalidOptionException(fileException);
}
}
} else {
_value = this.defaultValue();
}
}
}
/**
* @return value
*/
public URL value() {
return (_value != null ? _value : this.defaultValue());
}
/**
* Default value of the option
*
* @return null
*/
public URL defaultValue() {
return _defaultValue;
}
/*
* (non-Javadoc)
*
* @see com.webobjects.generator.Configuration.Option#toString()
*/
@Override
public String toString() {
return super.toString() + " default: '" + this.defaultValue() + "' value: '" + this.value() + "'";
}
}
/**
*
*/
public static class StringOption extends Option {
String _value;
String _defaultValue;
/**
* @param name
* @param description
*/
public StringOption(String name, String description) {
this(name, description, "");
}
/**
* @param name
* @param description
* @param defaultValue
*/
public StringOption(String name, String description, String defaultValue) {
super(name, description);
_defaultValue = defaultValue;
}
/*
* (non-Javadoc)
*
* @see com.webobjects.generator.Configuration.Option#decodeOptions(java.util.Queue)
*/
@Override
public void decodeOptions(Queue<String> optionList) throws InvalidOptionException {
if (this.isSameOptionName(optionList)) {
_value = Option.optionValueFromList(optionList);
}
}
/**
* @return value
*/
public String value() {
return ((_value != null) && (_value.length() > 0) ? _value : this.defaultValue());
}
/**
* Default value of the option
*
* @return empty String
*/
public String defaultValue() {
return (_defaultValue != null ? _defaultValue : "");
}
/*
* (non-Javadoc)
*
* @see com.webobjects.generator.Configuration.Option#toString()
*/
@Override
public String toString() {
return super.toString() + " default: '" + this.defaultValue() + "' value: '" + this.value() + "'";
}
}
/**
*
*/
public static class BooleanOption extends Option {
Boolean _value;
Boolean _defaultValue;
/**
* @param name
* @param description
*/
public BooleanOption(String name, String description) {
this(name, description, Boolean.FALSE);
}
/**
* @param name
* @param description
* @param defaultValue
*/
public BooleanOption(String name, String description, Boolean defaultValue) {
super(name, description);
_defaultValue = defaultValue;
}
/*
* (non-Javadoc)
*
* @see com.webobjects.generator.Configuration.Option#decodeOptions(java.util.Queue)
*/
@Override
public void decodeOptions(Queue<String> optionList) throws InvalidOptionException {
String aValue = Option.optionNameFromList(optionList);
_value = (aValue.length() > 0 ? new Boolean(this.name().equals(aValue.toLowerCase())) : this.defaultValue());
}
/**
* @return value
*/
public Boolean value() {
return (_value != null ? _value : this.defaultValue());
}
/**
* Default value of the option
*
* @return Boolean.FALSE
*/
public Boolean defaultValue() {
return (_defaultValue != null ? _defaultValue : Boolean.FALSE);
}
/*
* (non-Javadoc)
*
* @see com.webobjects.generator.Configuration.Option#toString()
*/
@Override
public String toString() {
return super.toString() + " default: '" + this.defaultValue() + "' value: '" + this.value() + "'";
}
}
/**
*
*/
public static abstract class Option {
String _name;
String _description;
/**
* @param name
* @param description
*/
public Option(String name, String description) {
super();
_name = (name != null ? name : "").toLowerCase();
_description = (description != null ? description : "");
}
/**
* Returns the option name
*
* @return option name
*/
public String name() {
return (_name != null ? _name : "");
}
/**
* Returns the option description
*
* @return option description
*/
public String description() {
return (_description != null ? _description : "");
}
/**
* Decode the options from the option list and remove the one it needs
*
* @param optionList
* @throws InvalidOptionException
*/
public abstract void decodeOptions(Queue<String> optionList) throws InvalidOptionException;
/**
* Checks if this option name is the same than the top of the list.
*
* @param optionList
* @return true if this option has the same name than the top of the list
*/
public boolean isSameOptionName(Queue<String> optionList) {
return this.name().equals(Option.optionNameFromList(optionList));
}
/**
* Return the option name i.e. strips the "-" or an empty string. Removing the option from the list if there is an option there.
*
* @param optionList
* @return option name from the top of the list
*/
public static String optionNameFromList(Queue<String> optionList) {
String result = "";
if ((!optionList.isEmpty()) && Option.isOption(optionList.peek())) {
result = Option.optionName(optionList.remove());
}
return result.toLowerCase();
}
/**
* Return the option name i.e. strips the "-" or an empty string.
*
* @param value
* @return name
*/
public static String optionName(String value) {
return (Option.isOption(value) ? value.trim().substring(OptionLeader.length()) : "");
}
/**
* Check if the string is an option
*
* @param value
* @return true if this is a non null option
*/
public static boolean isOption(String value) {
return (value != null) && (value.length() > 0) && (value.trim().startsWith(OptionLeader));
}
/**
* Return the option value or an empty string. Removing the option from the list if there is an option there.
*
* @param optionList
* @return value form the top of teh list
*/
public static String optionValueFromList(Queue<String> optionList) {
String result = "";
if ((!optionList.isEmpty()) && Option.isValue(optionList.peek())) {
result = Option.optionValue(optionList.remove());
}
return result;
}
/**
* Return the option value or an empty string. A value does not start by the option prefix.
*
* @param value
* @return value
*/
public static String optionValue(String value) {
return (Option.isValue(value) ? value.trim() : "");
}
/**
* Check if the string is a value option
*
* @param value
* @return true if this is a non null value
*/
public static boolean isValue(String value) {
return (value != null) && (value.length() > 0) && (!value.trim().startsWith(OptionLeader));
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return this.getClass().getName() + " name: '" + this.name() + "'";
}
}
/**
*
*/
public static class InvalidOptionException extends Exception {
private static final long serialVersionUID = 6860481828883562525L;
/**
* Sole constructor
*/
public InvalidOptionException() {
super();
}
/**
* Sole constructor
*
* @param message
* the detail message. The detail message is saved for later retrieval by the Throwable.getMessage() method.
*/
public InvalidOptionException(String message) {
super(message);
}
/**
* Sole constructor
*
* @param rootCause
* the cause (which is saved for later retrieval by the Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
*/
public InvalidOptionException(Exception rootCause) {
super(rootCause);
}
}
/**
* @param argv
*/
public Configuration(String[] argv) {
super();
this.buildOptionList();
LinkedList<String> optionList = new LinkedList<String>();
if (argv != null) {
for (int i = 0; i < argv.length; i++) {
optionList.add(argv[i]);
}
}
this.decodeOptions(optionList);
}
/**
* @param optionList
*/
protected void decodeOptions(Queue<String> optionList) {
while (!optionList.isEmpty()) {
String option = optionList.peek();
if (Option.isOption(option)) {
// If it is an option then decode it.
try {
Option anOption = this.optionForName(Option.optionName(option));
if (anOption != null) {
anOption.decodeOptions(optionList);
} else {
// Checks if it is a define option
// AdditionalKeyValueKey
String define = Option.optionName(option);
if (define.startsWith(AdditionalKeyValueKey)) {
String key = define.substring(AdditionalKeyValueKey.length());
optionList.remove();
if (!optionList.isEmpty()) {
String value = optionList.peek();
if (Option.isValue(value)) {
this.setValueForAdditionalKey(value, key);
optionList.remove();
}
}
} else {
// Spurious option ignore it.
optionList.remove();
}
}
} catch (InvalidOptionException exception) {
System.err.println("Invalid Option " + option);
}
} else {
// This is a loose value probably an argument
this.addArgumentToList(option);
optionList.remove();
}
}
}
/**
* Build the option list. Subclasses need to override this methods to add new options. All subclasses must call super.
*/
protected void buildOptionList() {
this.addOptionToList(new BooleanOption(HelpOptionKey, "Displays the command line options available in eogenerator, with synopses of their purposes.", Boolean.FALSE));
this.addOptionToList(new BooleanOption(VerboseOptionKey, "Causes more verbose debugging output to be logged to standard output.", Boolean.FALSE));
this.addOptionToList(new BooleanOption(VersionOptionKey, "Displays the version number for the generator.", Boolean.FALSE));
this.addOptionToList(new StringOption(EncodingKey, "Displays the version number for the generator.", "UTF-8"));
this.addOptionToList(new StringOption(TemplateEncodingKey, "Displays the version number for the generator.", "UTF-8"));
this
.addOptionToList(new StringOption(
FileNameTemplateKey,
"JavaEOGenerator differs from EOGenerator with this option. It uses the WOComponent generation engine in order to define a template which should be familiar to a lot of developers. A template will be defined using wo tags. For example, to generate the abstract superclasses into a separate \"eogen\" subpackage, something like the following can be used (coupled with changes to the templates of course): -filenameTemplate \"<wo:WOString value=\"[entity.classPackageName]\"/><wo:WOConditional condition=\"[isSuperclass]\">.base.<wo:WOString value=\"[superClassPrefix]\"/></wo:WOConditional><wo:WOConditional condition=\"[isSubclass]\">.</wo:WOConditional><wo:WOString value=\"[entity.classNameWithoutPackage]\"/>\nThis argument causes string to be used as a MiscMerge template, with the result being used as the base name for the generated files. Normally, filenames based on the entity's class name are used, which is sufficient for most situations. Occasionally it can be useful to have custom filename patterns (coupled with custom templates), and this parameter can allow for a lot of flexibility. For example, if you want Java interfaces to be generated along with the classes, a template of \"{javaClassName}Interface\" will cause 'Interface' to be appended to each filename. The delimiters for this template are '{' and '}', and the base object is the EOEntity instance (just like the regular class templates). Regular EOEntity methods can be used as keys, as can entries in the userInfo dictionary. When generating Java classes, if the generated filename has what looks like a Java package, it will override the package normally specified in the EOModel. The boolean variables \"isSubclass\" and \"isSuperclass\" are defined for use in if statements as necessary (Using WOConditionals). For example, \"<wo:WOString value=\"[entity.classPackageName]\"/><wo:WOConditional condition=\"[isSuperclass]\">.base.<wo:WOString value=\"[superClassPrefix]\"/></wo:WOConditional><wo:WOConditional condition=\"[isSubclass]\">.</wo:WOConditional><wo:WOString value=\"[entity.classNameWithoutPackage]\"/>",
"<wo:WOString value=\"[entity.classPackageName]\"/><wo:WOConditional condition=\"[isSuperclass]\">.base.<wo:WOString value=\"[superClassPrefix]\"/></wo:WOConditional><wo:WOConditional condition=\"[isSubclass]\">.</wo:WOConditional><wo:WOString value=\"[entity.classNameWithoutPackage]\"/>"));
this.addOptionToList(new URLOption(DestinationKey, "Used to specify a destination directory for generated source code files. By default, files are generated in the current directory."));
this
.addOptionToList(new URLOption(
SubClassDestinationKey,
"Used to specify a destination directory for the empty subclass source code files. This allows the generated files and the actively edited source to be placed in different directories. By default, the subclass files are generated/looked for in the -destination directory."));
this
.addOptionToList(new URLOption(
DestinationKey,
"Used to specify a destination directory for generated source code files. By default, files are generated in the current directory."));
this
.addOptionToList(new BooleanOption(
PackageDirectoriesKey,
"When doing Java generation, creates directories corresponding to the Java package name components underneath the -destination directory. This will generate the classes into a typical Java directory structure. [Note that the old ProjectBuilder, still sometimes used on Windows, does not support classes laid out in this manner. Xcode should not have this problem.]",
Boolean.TRUE));
this.addOptionToList(new StringOption(PrefixKey,
"Uses string as the prefix for the generated class names (to distinguish them from the real EO class names). By default this is a single underscore ( \"_\" ).", "_"));
this
.addOptionToList(new URLOption(TemplateDirectoryKey,
"Prepends directory to the search path used to find template files. Multiple -templatedir flags can be specified; the directories will be searched in the order they appear on the command line."));
this
.addOptionToList(new StringOption(
JavaTemplateKey,
"Used to specify alternate template files to use. File can be an absolute path, a relative path, or a filename found in one of the search path directories. If not specified, the default templates are used.",
"JavaSourceEOF.eotemplate"));
this
.addOptionToList(new StringOption(
SubClassJavaTemplatesKey,
"Used to specify alternate template files to use. File can be an absolute path, a relative path, or a filename found in one of the search path directories. If not specified, the default templates are used.",
"JavaSubClassSourceEOF.eotemplate"));
}
/**
* Add a new option to the options list.
*
* @param option
*/
protected void addOptionToList(Option option) {
if (_options == null) {
_options = new TreeMap<String, Option>();
}
_options.put(option.name(), option);
}
/**
* Returns the Option object for the name
*
* @param name
* @return option object
*/
protected Option optionForName(String name) {
return (_options != null ? _options.get(name.toLowerCase()) : null);
}
/**
* Return the list of arguments in the order they appeared on the command line. The returned list is immutable.
*
* @return argument list
*/
public List<String> arguments() {
return Collections.unmodifiableList(this._arguments());
}
/**
* Checks if arguments have been passed to the generator
*
* @return true if there are arguments
*/
public boolean hasArguments() {
return _arguments != null && _arguments.size() > 0;
}
private List<String> _arguments() {
if (_arguments == null) {
_arguments = new ArrayList<String>();
}
return _arguments;
}
/**
* @param argument
*/
protected void addArgumentToList(String argument) {
this._arguments().add(argument);
}
/**
* Return a dictionary of additional key values. The returned map is immutable.
*
* @return map of additional value pairs
*/
public Map<String, String> additionalKeyValues() {
return Collections.unmodifiableMap(this._additionalKeyValues());
}
/**
* Checks if additional key values have been passed to the generator
*
* @return true if the user defined additional value pairs
*/
public boolean hasAdditionalKeyValues() {
return _additionalKeyValues != null && _additionalKeyValues.size() > 0;
}
private Map<String, String> _additionalKeyValues() {
if (_additionalKeyValues == null) {
_additionalKeyValues = new TreeMap<String, String>();
}
return _additionalKeyValues;
}
/**
* @param key
* @param value
*/
protected void setValueForAdditionalKey(String value, String key) {
this._additionalKeyValues().put(key, value);
}
/**
* Return the value for the additional key
*
* @param key
* @return additional key value
*/
public String valueForAdditionalKey(String key) {
return this._additionalKeyValues().get(key);
}
/**
* Returns true if the verbose option was set.
*
* @return true if verbose
*/
public Boolean verbose() {
Option anOption = this.optionForName(VerboseOptionKey);
return (anOption instanceof BooleanOption ? ((BooleanOption) anOption).value() : Boolean.FALSE);
}
/**
* Returns true if the help option was set.
*
* @return true if help was requested
*/
public Boolean help() {
Option anOption = this.optionForName(HelpOptionKey);
return (anOption instanceof BooleanOption ? ((BooleanOption) anOption).value() : Boolean.FALSE);
}
/**
* Returns true if the version option was set.
*
* @return true if the version was requested
*/
public Boolean version() {
Option anOption = this.optionForName(VersionOptionKey);
return (anOption instanceof BooleanOption ? ((BooleanOption) anOption).value() : Boolean.FALSE);
}
/**
* Return the value of the encoding option
*
* @return encoding option
*/
public String encoding() {
Option anOption = this.optionForName(EncodingKey);
return (anOption instanceof StringOption ? ((StringOption) anOption).value() : "UTF8");
}
/**
* Return the value of the template encoding option
*
* @return template encoding option
*/
public String templateEncoding() {
Option anOption = this.optionForName(TemplateEncodingKey);
return (anOption instanceof StringOption ? ((StringOption) anOption).value() : "UTF8");
}
/**
* Return the value of the filename template option
*
* @return filename template option
*/
public String filenameTemplate() {
Option anOption = this.optionForName(FileNameTemplateKey);
return (anOption instanceof StringOption ? ((StringOption) anOption).value() : "");
}
/**
* Returns the file class destination option
*
* @return file class destination
*/
public URL destination() {
Option anOption = this.optionForName(DestinationKey);
return (anOption instanceof URLOption ? ((URLOption) anOption).value() : null);
}
/**
* Returns the file sub class destination option
*
* @return file sub class destination
*/
public URL subClassDestination() {
Option anOption = this.optionForName(SubClassDestinationKey);
return (anOption instanceof URLOption ? ((URLOption) anOption).value() : null);
}
/**
* Returns true if the packagedirs option was set.
*
* @return package directory option
*/
public Boolean packageDirectories() {
Option anOption = this.optionForName(PackageDirectoriesKey);
return (anOption instanceof BooleanOption ? ((BooleanOption) anOption).value() : Boolean.TRUE);
}
/**
* Return the value of thePrefix option
*
* @return Prefix option
*/
public String prefix() {
Option anOption = this.optionForName(PrefixKey);
return (anOption instanceof StringOption ? ((StringOption) anOption).value() : "_");
}
/**
* Return the value of the template directoryoption
*
* @return template directory option
*/
public URL templateDirectory() {
Option anOption = this.optionForName(TemplateDirectoryKey);
return (anOption instanceof URLOption ? ((URLOption) anOption).value() : null);
}
/**
* Return the value of the Java Template option
*
* @return Java Template option
*/
public URL javaTemplate() {
Option anOption = this.optionForName(JavaTemplateKey);
String value = (anOption instanceof StringOption ? ((StringOption) anOption).value() : "");
return this.templateURL(value);
}
/**
* Return the path to the sub class template file, using the templateDirectory if necessary.
*
* @return sub class template url
*/
public URL subClassJavaTemplate() {
Option anOption = this.optionForName(SubClassJavaTemplatesKey);
String value = (anOption instanceof StringOption ? ((StringOption) anOption).value() : "");
return this.templateURL(value);
}
/**
* Return the list of URL to search.
*
* @return rearch path URL list
*/
public List<URL> searchPath() {
if (_searchPath == null) {
List<URL> aList = new ArrayList<URL>();
if (this.templateDirectory() != null) {
aList.add(this.templateDirectory());
}
_searchPath = aList;
}
return Collections.unmodifiableList(_searchPath);
}
/**
* Return the path to the template file, using the templateDirectory if necessary.
*
* @param path
* @return class template url
*/
protected URL templateURL(String path) {
URL templateURL = null;
if (path.length() > 0) {
// First try for a URL
try {
templateURL = new URL(path);
} catch (Exception urlException) { /* We do not want to report the exception */}
if (templateURL == null) {
// next try the absolute path
try {
File aFile = new File(path);
if (aFile.exists()) {
templateURL = aFile.toURL();
}
} catch (Exception urlException) { /* We do not want to report the exception */}
}
if (templateURL == null) {
// and now for the relative path
for (URL parentDir : this.searchPath()) {
try {
URL fileURL = new URL(parentDir, path);
File aFile = new File(fileURL.toURI());
if (aFile.exists()) {
templateURL = aFile.toURL();
break;
}
} catch (Exception urlException) { /* We do not want to report the exception */}
}
}
}
return templateURL;