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 package org.exolab.castor.builder.binding;
50
51 import java.util.Enumeration;
52
53 import org.apache.commons.logging.Log;
54 import org.apache.commons.logging.LogFactory;
55 import org.exolab.castor.builder.BindingComponent;
56 import org.exolab.castor.builder.BuilderConfiguration;
57 import org.exolab.castor.builder.GroupNaming;
58 import org.exolab.castor.builder.TypeConversion;
59 import org.exolab.castor.builder.binding.xml.ClassType;
60 import org.exolab.castor.builder.binding.xml.ComponentBindingType;
61 import org.exolab.castor.builder.binding.xml.ComponentBindingTypeChoice;
62 import org.exolab.castor.builder.binding.xml.EnumBindingType;
63 import org.exolab.castor.builder.binding.xml.FieldType;
64 import org.exolab.castor.builder.binding.xml.Interface;
65 import org.exolab.castor.builder.binding.xml.NamingXMLType;
66 import org.exolab.castor.builder.binding.xml.types.FieldTypeVisibilityType;
67 import org.exolab.castor.builder.types.XSClass;
68 import org.exolab.castor.builder.types.XSType;
69 import org.exolab.castor.xml.schema.Annotated;
70 import org.exolab.castor.xml.schema.AttributeDecl;
71 import org.exolab.castor.xml.schema.ComplexType;
72 import org.exolab.castor.xml.schema.ContentModelGroup;
73 import org.exolab.castor.xml.schema.ElementDecl;
74 import org.exolab.castor.xml.schema.Form;
75 import org.exolab.castor.xml.schema.Group;
76 import org.exolab.castor.xml.schema.ModelGroup;
77 import org.exolab.castor.xml.schema.Schema;
78 import org.exolab.castor.xml.schema.SimpleType;
79 import org.exolab.castor.xml.schema.Structure;
80 import org.exolab.castor.xml.schema.XMLType;
81 import org.exolab.javasource.JClass;
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 public final class XMLBindingComponent implements BindingComponent {
115
116
117
118
119 private static final Log LOG = LogFactory.getLog(XMLBindingComponent.class);
120
121
122
123
124 private ExtendedBinding _binding;
125
126
127
128
129
130 private ComponentBindingType _compBinding;
131
132
133
134
135 private BuilderConfiguration _config = null;
136
137
138
139
140 private Annotated _annotated;
141
142
143
144
145 private String _prefix;
146
147
148
149
150 private String _suffix;
151
152
153
154
155 private short _type = -1;
156
157
158
159
160 private int _hashCode = -1;
161 private String _javaClassName = null;
162 private String _javaMemberName = null;
163 private String _javaPackage = null;
164 private FieldType _member = null;
165 private ClassType _class = null;
166 private Interface _interface = null;
167 private EnumBindingType _enum = null;
168 private Schema _schema = null;
169 private boolean _userSpecifiedMemberName = false;
170
171
172
173
174 private GroupNaming _groupNaming = null;
175
176
177
178
179
180 private synchronized GroupNaming getGroupNaming() {
181 return _groupNaming;
182 }
183
184
185
186
187
188 private void setGroupNaming(final GroupNaming groupNaming) {
189 _groupNaming = groupNaming;
190 }
191
192
193
194
195 private TypeConversion _typeConversion = null;
196
197 private String _contentMemberName;
198
199
200
201
202
203
204
205 public XMLBindingComponent(final BuilderConfiguration config, final GroupNaming groupNaming) {
206 if (config == null) {
207 String error = "The argument 'config' must not be null.";
208 throw new IllegalArgumentException(error);
209 }
210 _config = config;
211 _typeConversion = new TypeConversion(_config);
212 setGroupNaming(groupNaming);
213 }
214
215
216
217
218
219
220
221
222 public ExtendedBinding getBinding() {
223 return _binding;
224 }
225
226
227
228
229
230
231
232
233 public void setBinding(final ExtendedBinding binding) {
234 _binding = binding;
235 }
236
237
238
239
240
241
242
243
244
245
246 public void setView(final Annotated annotated) {
247 if (annotated == null) {
248 throw new IllegalArgumentException("The XML Schema annotated structure is null.");
249 }
250
251 _annotated = annotated;
252
253
254 _javaClassName = null;
255 _javaMemberName = null;
256 _javaPackage = null;
257 _schema = null;
258 _member = null;
259 _class = null;
260 _interface = null;
261 _type = -1;
262 _prefix = null;
263 _suffix = null;
264 _userSpecifiedMemberName = false;
265 _compBinding = null;
266
267
268
269 if (_binding != null) {
270 _compBinding = _binding.getComponentBindingType(annotated);
271 NamingXMLType naming = _binding.getNamingXML();
272 if (naming != null) {
273 switch (annotated.getStructureType()) {
274 case Structure.COMPLEX_TYPE:
275 if (naming.getComplexTypeName() != null) {
276 _prefix = naming.getComplexTypeName().getPrefix();
277 _suffix = naming.getComplexTypeName().getSuffix();
278 }
279 break;
280 case Structure.ELEMENT:
281 if (naming.getElementName() != null) {
282 _prefix = naming.getElementName().getPrefix();
283 _suffix = naming.getElementName().getSuffix();
284 }
285 break;
286 case Structure.MODELGROUP:
287 if (naming.getModelGroupName() != null) {
288 _prefix = naming.getModelGroupName().getPrefix();
289 _suffix = naming.getModelGroupName().getSuffix();
290 }
291 break;
292 default:
293 break;
294 }
295 }
296 }
297
298 if (_compBinding != null) {
299 ComponentBindingTypeChoice choice = _compBinding.getComponentBindingTypeChoice();
300 if (choice.getInterface() != null) {
301 _type = INTERFACE;
302 _interface = choice.getInterface();
303 } else if (choice.getJavaClass() != null) {
304 _type = CLASS;
305 _class = choice.getJavaClass();
306 } else if (choice.getMember() != null) {
307 _type = MEMBER;
308 _member = choice.getMember();
309 } else if (choice.getEnumDef() != null) {
310 _type = ENUM_TYPE;
311 _enum = choice.getEnumDef();
312 } else if (choice.getContentMember() != null) {
313 _type = CONTENT_MEMBER_TYPE;
314 _contentMemberName = choice.getContentMember().getName();
315 } else {
316 String err = "Illegal Binding component:";
317 err += "it does not define a class, an interface or a member binding.";
318 throw new IllegalStateException(err);
319 }
320 }
321 }
322
323
324
325
326
327
328
329
330
331
332
333
334 public boolean equals(final Object object) {
335 if (object == null) {
336 return false;
337 }
338
339 boolean result = false;
340 if (object instanceof XMLBindingComponent) {
341 XMLBindingComponent temp = (XMLBindingComponent) object;
342 result = _annotated.equals(temp.getAnnotated());
343 if (_compBinding != null) {
344 if (temp.getComponentBinding() != null) {
345 result = result && (_compBinding.equals(temp.getComponentBinding()));
346 } else {
347 result = false;
348 }
349 } else if (temp.getComponentBinding() != null) {
350 result = false;
351 }
352 } else {
353 result = false;
354 }
355 return result;
356 }
357
358
359
360
361
362
363
364 public int hashCode() {
365 if (_hashCode == -1) {
366 int compBindingHash = 0;
367 if (_compBinding != null) {
368 compBindingHash = _compBinding.getName().hashCode();
369 }
370
371 _hashCode = 37 * (_annotated.hashCode()) + compBindingHash;
372 }
373 return _hashCode;
374 }
375
376
377
378
379
380
381
382 protected ComponentBindingType getComponentBinding() {
383 return _compBinding;
384 }
385
386
387
388
389
390
391
392
393 public Annotated getAnnotated() {
394 return _annotated;
395 }
396
397
398
399
400
401
402
403
404
405
406 public boolean createGroupItem() {
407 int maxOccurs = 0;
408 boolean result = false;
409 switch (_annotated.getStructureType()) {
410 case Structure.ELEMENT:
411 XMLType type = ((ElementDecl) _annotated).getType();
412 if (type.isComplexType()) {
413 maxOccurs = ((ComplexType) type).getMaxOccurs();
414 if (((maxOccurs > 1) || (maxOccurs < 0)) && (type.getName() == null)) {
415 result = true;
416 }
417 }
418 break;
419 case Structure.COMPLEX_TYPE:
420 maxOccurs = ((ComplexType) _annotated).getMaxOccurs();
421 if ((maxOccurs > 1) || (maxOccurs < 0)) {
422 result = true;
423 }
424 break;
425 case Structure.MODELGROUP:
426 case Structure.GROUP:
427 Group group = (Group) _annotated;
428 maxOccurs = group.getMaxOccurs();
429 if ((maxOccurs > 1) || (maxOccurs < 0)) {
430 result = true;
431 }
432 break;
433 case Structure.ATTRIBUTE:
434 default:
435 break;
436
437 }
438 return result;
439 }
440
441
442
443
444
445
446 public String getSchemaLocation() {
447 String location = null;
448 Schema schema = getSchema();
449 if (schema != null) {
450 location = schema.getSchemaLocation();
451 }
452
453 return location;
454 }
455
456
457
458
459
460
461 public String getTargetNamespace() {
462 String result = null;
463 Schema schema = null;
464 Form form = null;
465
466 switch (_annotated.getStructureType()) {
467 case Structure.ATTRIBUTE:
468 AttributeDecl attribute = (AttributeDecl) _annotated;
469
470 if (attribute.isReference()) {
471 attribute = attribute.getReference();
472 }
473
474 schema = attribute.getSchema();
475
476
477 if (attribute.getParent() == schema) {
478 break;
479 }
480
481
482 form = attribute.getForm();
483 if (form == null) {
484 form = schema.getAttributeFormDefault();
485 }
486
487 if ((form == null) || form.isUnqualified()) {
488
489 return null;
490 }
491
492 break;
493 case Structure.ELEMENT:
494
495 ElementDecl element = (ElementDecl) _annotated;
496 if (element.isReference()) {
497 element = element.getReference();
498 }
499
500 schema = element.getSchema();
501
502 if (element.getParent() == schema) {
503 break;
504 }
505
506
507 form = element.getForm();
508 if (form == null) {
509 form = schema.getElementFormDefault();
510 }
511
512
513 if ((form == null) || form.isUnqualified()) {
514 return null;
515 }
516
517 break;
518 case Structure.COMPLEX_TYPE:
519 ComplexType complexType = (ComplexType) _annotated;
520 schema = complexType.getSchema();
521 if (complexType.getParent() == schema) {
522 break;
523 }
524 return null;
525 case Structure.SIMPLE_TYPE:
526 SimpleType simpleType = (SimpleType) _annotated;
527 schema = simpleType.getSchema();
528 if (simpleType.getParent() == schema) {
529 break;
530 }
531 return null;
532 default:
533 break;
534 }
535 if (schema == null) {
536 schema = getSchema();
537 }
538
539 if (schema != null) {
540 result = schema.getTargetNamespace();
541 }
542 return result;
543 }
544
545
546
547
548
549
550 public Schema getSchema() {
551 if (_schema != null) {
552 return _schema;
553 }
554
555 switch (_annotated.getStructureType()) {
556 case Structure.ATTRIBUTE:
557
558 AttributeDecl attribute = (AttributeDecl) _annotated;
559 if (attribute.isReference()) {
560 attribute = attribute.getReference();
561 }
562 _schema = attribute.getSchema();
563 attribute = null;
564 break;
565 case Structure.ELEMENT:
566
567 ElementDecl element = (ElementDecl) _annotated;
568 if (element.isReference()) {
569 element = element.getReference();
570 }
571 _schema = element.getSchema();
572 element = null;
573 break;
574 case Structure.COMPLEX_TYPE:
575 _schema = ((ComplexType) _annotated).getSchema();
576 break;
577 case Structure.MODELGROUP:
578
579 ModelGroup group = (ModelGroup) _annotated;
580 if (group.isReference()) {
581 group = group.getReference();
582 }
583 _schema = group.getSchema();
584 group = null;
585 break;
586 case Structure.GROUP:
587 Structure parent = ((Group) _annotated).getParent();
588 short structure = parent.getStructureType();
589 while (structure == Structure.GROUP) {
590 parent = ((Group) parent).getParent();
591 structure = parent.getStructureType();
592 }
593 if (structure == Structure.COMPLEX_TYPE) {
594 _schema = ((ComplexType) parent).getSchema();
595 } else if (structure == Structure.MODELGROUP) {
596 _schema = ((ModelGroup) parent).getSchema();
597 }
598 break;
599 case Structure.SIMPLE_TYPE:
600 case Structure.UNION:
601 case Structure.LIST:
602 _schema = ((SimpleType) _annotated).getSchema();
603 break;
604 default:
605 break;
606 }
607
608 return _schema;
609 }
610
611
612
613
614
615
616
617
618
619 public XMLType getXMLType() {
620 XMLType result = null;
621 switch (_annotated.getStructureType()) {
622 case Structure.ELEMENT:
623 result = ((ElementDecl) _annotated).getType();
624 break;
625 case Structure.COMPLEX_TYPE:
626 result = ((ComplexType) _annotated);
627 break;
628 case Structure.SIMPLE_TYPE:
629 result = ((SimpleType) _annotated);
630 break;
631 case Structure.ATTRIBUTE:
632 result = ((AttributeDecl) _annotated).getSimpleType();
633 break;
634 case Structure.MODELGROUP:
635 default:
636 break;
637 }
638 return result;
639 }
640
641
642
643
644
645
646 public String getXMLName() {
647 String result = null;
648
649 if (_annotated != null) {
650 switch (_annotated.getStructureType()) {
651 case Structure.ELEMENT:
652 result = ((ElementDecl) _annotated).getName();
653 break;
654 case Structure.COMPLEX_TYPE:
655 result = ((ComplexType) _annotated).getName();
656 break;
657 case Structure.SIMPLE_TYPE:
658 result = ((SimpleType) _annotated).getName();
659 break;
660 case Structure.ATTRIBUTE:
661 result = ((AttributeDecl) _annotated).getName();
662 break;
663 case Structure.MODELGROUP:
664 case Structure.GROUP:
665 result = ((Group) _annotated).getName();
666 break;
667 default:
668 break;
669
670 }
671 }
672 return result;
673 }
674
675
676
677
678
679
680
681
682
683
684
685 public String getValue() {
686 String result = null;
687 switch (_annotated.getStructureType()) {
688 case Structure.ELEMENT:
689 result = ((ElementDecl) _annotated).getDefaultValue();
690 if (result == null) {
691 result = ((ElementDecl) _annotated).getFixedValue();
692 }
693 break;
694 case Structure.ATTRIBUTE:
695 result = ((AttributeDecl) _annotated).getDefaultValue();
696 if (result == null) {
697 result = ((AttributeDecl) _annotated).getFixedValue();
698 }
699 break;
700 case Structure.COMPLEX_TYPE:
701 case Structure.SIMPLE_TYPE:
702 case Structure.MODELGROUP:
703 default:
704 break;
705 }
706
707 return result;
708 }
709
710
711
712
713
714
715
716
717
718 public String getJavaClassName() {
719 if (_javaClassName == null) {
720 String result = null;
721
722 if (_compBinding != null) {
723 switch (getType()) {
724 case CLASS:
725 result = _class.getName();
726 break;
727 case INTERFACE:
728 result = _interface.getName();
729 break;
730 default:
731 break;
732 }
733 }
734
735 if (result == null || result.length() <= 0) {
736
737 if (_annotated != null && _annotated.getStructureType() == Structure.ELEMENT) {
738 ElementDecl element = (ElementDecl) _annotated;
739 if (element.isReference()) {
740 Annotated temp = _annotated;
741 setView(element.getReference());
742 result = getJavaClassName();
743 setView(temp);
744 temp = null;
745 } else if (_config.mappingSchemaType2Java()) {
746
747
748
749
750 XMLType xmlType = element.getType();
751 if (xmlType != null && xmlType.isComplexType()) {
752 ComplexType complexType = (ComplexType) xmlType;
753 Annotated temp = _annotated;
754 setView(complexType);
755 result = getJavaClassName();
756 setView(temp);
757 }
758 }
759 element = null;
760 }
761
762
763 if (result == null || result.length() <= 0) {
764
765 result = getXMLName();
766
767 if (result == null
768 && _annotated != null
769 && (_annotated.getStructureType() == Structure.GROUP
770 || _annotated.getStructureType() == Structure.MODELGROUP)) {
771 GroupNaming groupNaming = getGroupNaming();
772 result = groupNaming.createClassName((Group) _annotated, getJavaPackage());
773 if (result == null) {
774 String err = "Unable to create name for group.";
775 throw new IllegalStateException(err);
776 }
777 }
778
779 if (_prefix != null) {
780 result = _prefix + result;
781 }
782 if (_suffix != null) {
783 result = result + _suffix;
784 }
785 }
786 }
787
788 _javaClassName = _config.getJavaNaming().toJavaClassName(result);
789 }
790
791
792
793 return _javaClassName;
794 }
795
796
797
798
799
800
801
802
803
804 public String getJavaMemberName() {
805 if (_javaMemberName == null) {
806 String result = null;
807 if (_compBinding != null) {
808 switch (getType()) {
809 case CLASS:
810 result = _class.getName();
811 break;
812 case INTERFACE:
813 result = _interface.getName();
814 break;
815 case MEMBER:
816 result = _member.getName();
817 break;
818 default:
819 break;
820 }
821 }
822
823 if (result == null || result.length() <= 0) {
824 Annotated temp = null;
825 if (_annotated.getStructureType() == Structure.ATTRIBUTE) {
826 AttributeDecl att = (AttributeDecl) _annotated;
827 if (att.isReference()) {
828 temp = _annotated;
829 setView(att.getReference());
830 result = getJavaMemberName();
831 setView(temp);
832 }
833 att = null;
834 } else if (_annotated.getStructureType() == Structure.ELEMENT) {
835 ElementDecl element = (ElementDecl) _annotated;
836 if (element.isReference()) {
837 temp = _annotated;
838 setView(element.getReference());
839 result = getJavaMemberName();
840 boolean userSpecified = _userSpecifiedMemberName;
841 setView(temp);
842
843
844
845 if (!userSpecified) {
846 String refName = element.getReferenceName();
847 int count = 0;
848 int index = 0;
849 Structure structure = element.getParent();
850 if (structure instanceof ContentModelGroup) {
851 ContentModelGroup cmg = (ContentModelGroup) structure;
852 Enumeration<Structure> enumeration = cmg.enumerate();
853 while (enumeration.hasMoreElements()) {
854 Structure tmpStruct = enumeration.nextElement();
855 if (tmpStruct.getStructureType() == Structure.ELEMENT) {
856 ElementDecl tmpDecl = (ElementDecl) tmpStruct;
857 if (tmpDecl.isReference()
858 && tmpDecl.getReferenceName().equals(refName)) {
859 ++count;
860 if (tmpDecl == element) {
861 index = count;
862 }
863 }
864 }
865 }
866 }
867 if (count > 1) {
868 result = result + index;
869 }
870 }
871 }
872 element = null;
873 }
874 temp = null;
875
876
877 if (result == null || result.length() <= 0) {
878
879 result = getXMLName();
880
881 if (result == null
882 && (_annotated.getStructureType() == Structure.GROUP
883 || _annotated.getStructureType() == Structure.MODELGROUP)) {
884 result = getGroupNaming().createClassName(
885 (Group) _annotated, getJavaPackage());
886 if (result == null) {
887 String err = "Unable to create name for group.";
888 throw new IllegalStateException(err);
889 }
890 }
891
892 if (_prefix != null) {
893 result = _prefix + result;
894 }
895 if (_suffix != null) {
896 result = result + _suffix;
897 }
898 }
899 } else {
900 _userSpecifiedMemberName = true;
901 }
902 _javaMemberName = _config.getJavaNaming().toJavaMemberName(result);
903 }
904
905
906
907 return _javaMemberName;
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 public String getQualifiedName() {
933 String result = getJavaClassName();
934 String packageName = getJavaPackage();
935 if (packageName != null && packageName.length() > 0) {
936 packageName += '.';
937 result = packageName + result;
938 }
939 return result;
940 }
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957 public String getJavaPackage() {
958 if (_javaPackage == null) {
959 String packageName = null;
960 String schemaLocation = getSchemaLocation();
961 String targetNamespace = getTargetNamespace();
962
963 if (targetNamespace == null) {
964 targetNamespace = "";
965 }
966
967 if (_compBinding != null) {
968 switch (getType()) {
969 case CLASS:
970 packageName = _class.getPackage();
971 break;
972 default:
973 break;
974 }
975 }
976
977 if (isPackageNameNotSet(packageName)) {
978
979 if (isPackageNameNotSet(packageName)) {
980
981 packageName = _config.lookupPackageByNamespace(targetNamespace);
982 }
983
984 if (schemaLocation != null && isPackageNameNotSet(packageName)) {
985
986 packageName = _config.lookupPackageByLocation(schemaLocation);
987 }
988
989 }
990 _javaPackage = packageName;
991 }
992 return _javaPackage;
993 }
994
995
996
997
998
999
1000 private boolean isPackageNameNotSet(final String packageName) {
1001 return (packageName == null || packageName.length() == 0);
1002 }
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016 public int getUpperBound() {
1017 switch (_annotated.getStructureType()) {
1018
1019 case Structure.ELEMENT:
1020 return ((ElementDecl) _annotated).getMaxOccurs();
1021
1022 case Structure.COMPLEX_TYPE:
1023 return ((ComplexType) _annotated).getMaxOccurs();
1024
1025 case Structure.GROUP:
1026 case Structure.MODELGROUP:
1027 return ((Group) _annotated).getMaxOccurs();
1028
1029 case Structure.ATTRIBUTE:
1030 default:
1031 break;
1032 }
1033 return 1;
1034 }
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045 public int getLowerBound() {
1046 return getLowerBound(_annotated);
1047 }
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059 public String getExtends() {
1060 if (getType() == CLASS) {
1061 return _class.getExtends();
1062 }
1063 return _config.getProperty(BuilderConfiguration.Property.SUPER_CLASS, null);
1064 }
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074 public String[] getImplements() {
1075 if (getType() == CLASS) {
1076 return _class.getImplements();
1077 }
1078 return null;
1079 }
1080
1081
1082
1083
1084
1085
1086
1087
1088 public boolean hasBoundProperties() {
1089 if (getType() == CLASS && _class.hasBound()) {
1090 return _class.getBound();
1091 }
1092 return _config.boundPropertiesEnabled();
1093 }
1094
1095
1096
1097
1098
1099
1100
1101
1102 public boolean hasEquals() {
1103 if (getType() == CLASS && _class.hasEquals()) {
1104 return _class.getEquals();
1105 }
1106 return _config.equalsMethod();
1107 }
1108
1109
1110
1111
1112
1113
1114
1115
1116 public boolean isAbstract() {
1117 boolean result = false;
1118 if (getType() == CLASS && _class.hasAbstract()) {
1119 result = _class.getAbstract();
1120 }
1121
1122 if (!result) {
1123 switch(_annotated.getStructureType()) {
1124 case Structure.COMPLEX_TYPE:
1125 ComplexType cType = (ComplexType) _annotated;
1126 result = cType.isAbstract();
1127
1128
1129 result = result || _config.mappingSchemaElement2Java();
1130 break;
1131 case Structure.ELEMENT:
1132 ElementDecl eDecl = (ElementDecl) _annotated;
1133 result = eDecl.isAbstract();
1134 break;
1135 default:
1136 break;
1137 }
1138 }
1139 return result;
1140 }
1141
1142
1143
1144
1145
1146
1147
1148
1149 public boolean isFinal() {
1150 if (getType() == CLASS) {
1151 return _class.getFinal();
1152 }
1153 return false;
1154 }
1155
1156
1157
1158
1159
1160
1161
1162
1163 public boolean isFixed() {
1164
1165 switch (_annotated.getStructureType()) {
1166 case Structure.ELEMENT:
1167 String fixed = ((ElementDecl) _annotated).getFixedValue();
1168 return (fixed != null);
1169
1170 case Structure.ATTRIBUTE:
1171 return ((AttributeDecl) _annotated).isFixed();
1172
1173 case Structure.GROUP:
1174 case Structure.COMPLEX_TYPE:
1175 case Structure.SIMPLE_TYPE:
1176 case Structure.MODELGROUP:
1177 default:
1178 break;
1179 }
1180 return false;
1181 }
1182
1183
1184
1185
1186
1187
1188 public boolean isNillable() {
1189 switch (_annotated.getStructureType()) {
1190 case Structure.ELEMENT:
1191 return ((ElementDecl) _annotated).isNillable();
1192 default:
1193 break;
1194 }
1195 return false;
1196 }
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208 public boolean useWrapper() {
1209 if (_type != BindingComponent.MEMBER) {
1210 return _config.usePrimitiveWrapper();
1211 }
1212
1213 if (_member.hasWrapper()) {
1214 return _member.getWrapper();
1215 }
1216
1217 return false;
1218 }
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231 public XSType getJavaType() {
1232
1233 XSType result = null;
1234 boolean useWrapper = useWrapper();
1235 XMLType type = getXMLType();
1236
1237 if (type != null && type.isComplexType()) {
1238 if (_type == MEMBER && _member.getJavaType() != null) {
1239 String javaType = _member.getJavaType();
1240 if (javaType != null && javaType.length() > 0) {
1241 result = TypeConversion.convertType(javaType);
1242 }
1243 } else {
1244 result = new XSClass(new JClass(getJavaClassName()));
1245 }
1246 } else {
1247 if (_type == MEMBER) {
1248 String javaType = _member.getJavaType();
1249 if (javaType != null && javaType.length() > 0) {
1250 result = TypeConversion.convertType(javaType);
1251 }
1252 }
1253 }
1254
1255 if (result == null) {
1256
1257 if (type != null && type.isSimpleType()) {
1258 String packageName = null;
1259 String className = null;
1260 if (((SimpleType) type).getSchema() != getSchema()) {
1261 XMLBindingComponent comp = new XMLBindingComponent(_config, getGroupNaming());
1262 comp.setBinding(_binding);
1263 comp.setView(type);
1264 packageName = comp.getJavaPackage();
1265 if (comp.getClass() != null) {
1266 className = comp.getJavaClassName();
1267 }
1268 } else {
1269 packageName = getJavaPackage();
1270 if (_class != null) {
1271 className = getJavaClassName();
1272 }
1273 }
1274
1275 if ((packageName == null) || (packageName.length() == 0)) {
1276 String ns = ((SimpleType) type).getSchema().getTargetNamespace();
1277 packageName = _config.lookupPackageByNamespace(ns);
1278 }
1279
1280 result = _typeConversion.convertType((SimpleType) type,
1281 packageName, useWrapper, _config.useJava50(), className);
1282 }
1283 }
1284
1285 return result;
1286 }
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297 public String getCollectionType() {
1298 String result = null;
1299 if ((_type == MEMBER) && (_member.getCollection() != null)) {
1300 result = _member.getCollection().toString();
1301 }
1302 return result;
1303 }
1304
1305
1306
1307
1308
1309
1310 public String getValidator() {
1311 if (_type == MEMBER) {
1312 return _member.getValidator();
1313 }
1314 return null;
1315 }
1316
1317
1318
1319
1320
1321
1322 public String getXMLFieldHandler() {
1323 if (_type == MEMBER) {
1324 return _member.getHandler();
1325 }
1326 return null;
1327 }
1328
1329
1330
1331
1332
1333
1334 public String getVisiblity() {
1335 if (_type == MEMBER) {
1336 final FieldTypeVisibilityType visibility = _member.getVisibility();
1337 if (visibility != null) {
1338 return visibility.toString();
1339 }
1340 return "private";
1341 }
1342 return null;
1343 }
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358 public short getType() {
1359 return _type;
1360 }
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372 private static int getLowerBound(final Annotated annotated) {
1373 switch (annotated.getStructureType()) {
1374 case Structure.ELEMENT:
1375 return ((ElementDecl) annotated).getMinOccurs();
1376 case Structure.COMPLEX_TYPE:
1377 return ((ComplexType) annotated).getMinOccurs();
1378 case Structure.MODELGROUP:
1379 case Structure.GROUP:
1380 Group group = (Group) annotated;
1381
1382 Structure parent = group.getParent();
1383 if (parent != null && parent.getStructureType() == Structure.SCHEMA) {
1384 return 0;
1385 }
1386 int minOccurs = group.getMinOccurs();
1387
1388
1389 if (minOccurs == 1) {
1390 Enumeration<Annotated> enumeration = group.enumerate();
1391 while (enumeration.hasMoreElements()) {
1392 if (getLowerBound(enumeration.nextElement()) != 0) {
1393 return 1;
1394 }
1395 }
1396
1397
1398 return 0;
1399 }
1400 return minOccurs;
1401
1402 case Structure.ATTRIBUTE:
1403 if (((AttributeDecl) annotated).isRequired()) {
1404 return 1;
1405 }
1406 break;
1407 default:
1408 break;
1409 }
1410 return 0;
1411 }
1412
1413
1414
1415
1416
1417 public EnumBindingType getEnumBinding() {
1418 return _enum;
1419 }
1420
1421
1422
1423
1424
1425 public String getContentMemberName() {
1426 return _contentMemberName;
1427 }
1428
1429 }