1
2
3
4
5
6
7
8
9 package org.jomc.model;
10
11 import java.io.ByteArrayInputStream;
12 import java.io.ByteArrayOutputStream;
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.InvalidClassException;
16 import java.io.NotSerializableException;
17 import java.io.ObjectInputStream;
18 import java.io.ObjectOutputStream;
19 import java.io.OptionalDataException;
20 import java.io.Serializable;
21 import java.io.StreamCorruptedException;
22 import java.lang.reflect.Array;
23 import java.lang.reflect.InvocationTargetException;
24 import java.math.BigDecimal;
25 import java.math.BigInteger;
26 import java.net.MalformedURLException;
27 import java.net.URI;
28 import java.net.URISyntaxException;
29 import java.net.URL;
30 import java.util.Calendar;
31 import java.util.Currency;
32 import java.util.Date;
33 import java.util.Locale;
34 import java.util.TimeZone;
35 import java.util.UUID;
36 import javax.activation.MimeType;
37 import javax.activation.MimeTypeParseException;
38 import javax.annotation.Generated;
39 import javax.xml.bind.JAXBElement;
40 import javax.xml.bind.annotation.XmlAccessType;
41 import javax.xml.bind.annotation.XmlAccessorType;
42 import javax.xml.bind.annotation.XmlAnyElement;
43 import javax.xml.bind.annotation.XmlAttribute;
44 import javax.xml.bind.annotation.XmlType;
45 import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
46 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
47 import javax.xml.datatype.Duration;
48 import javax.xml.datatype.XMLGregorianCalendar;
49 import javax.xml.namespace.QName;
50 import org.w3c.dom.Element;
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 @XmlAccessorType(XmlAccessType.FIELD)
86 @XmlType(name = "Property", namespace = "http://jomc.org/model", propOrder = {
87 "any"
88 })
89 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
90 public class Property
91 extends ModelObject
92 implements Cloneable, Inheritable
93 {
94
95 @XmlAnyElement(lax = true)
96 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
97 protected Object any;
98 @XmlAttribute(name = "name", required = true)
99 @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
100 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
101 protected String name;
102 @XmlAttribute(name = "type")
103 @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
104 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
105 protected String type;
106 @XmlAttribute(name = "value")
107 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
108 protected String value;
109 @XmlAttribute(name = "final")
110 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
111 protected Boolean _final;
112 @XmlAttribute(name = "override")
113 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
114 protected Boolean override;
115
116
117
118
119
120 public Property() {
121
122 super();
123 }
124
125
126
127
128
129
130
131
132
133
134 public Property(final Property o) {
135
136 super(o);
137 if (o == null) {
138 throw new NullPointerException("Cannot create a copy of 'Property' from 'null'.");
139 }
140
141 this.any = ((o.any == null)?null:copyOfAny(o.getAny()));
142
143 this.name = ((o.name == null)?null:o.getName());
144
145 this.type = ((o.type == null)?null:o.getType());
146
147 this.value = ((o.value == null)?null:o.getValue());
148
149 this._final = ((o._final == null)?null:o.isFinal());
150
151 this.override = ((o.override == null)?null:o.isOverride());
152 }
153
154
155
156
157
158
159
160
161
162
163 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
164 public Object getAny() {
165 return any;
166 }
167
168
169
170
171
172
173
174
175
176
177 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
178 public void setAny(Object value) {
179 this.any = value;
180 }
181
182
183
184
185
186
187
188
189
190 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
191 public String getName() {
192 return name;
193 }
194
195
196
197
198
199
200
201
202
203 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
204 public void setName(String value) {
205 this.name = value;
206 }
207
208
209
210
211
212
213
214
215
216 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
217 public String getType() {
218 return type;
219 }
220
221
222
223
224
225
226
227
228
229 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
230 public void setType(String value) {
231 this.type = value;
232 }
233
234
235
236
237
238
239
240
241
242 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
243 public String getValue() {
244 return value;
245 }
246
247
248
249
250
251
252
253
254
255 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
256 public void setValue(String value) {
257 this.value = value;
258 }
259
260
261
262
263
264
265
266
267
268 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
269 public boolean isFinal() {
270 if (_final == null) {
271 return false;
272 } else {
273 return _final;
274 }
275 }
276
277
278
279
280
281
282
283
284
285 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
286 public void setFinal(Boolean value) {
287 this._final = value;
288 }
289
290
291
292
293
294
295
296
297
298 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
299 public boolean isOverride() {
300 if (override == null) {
301 return false;
302 } else {
303 return override;
304 }
305 }
306
307
308
309
310
311
312
313
314
315 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
316 public void setOverride(Boolean value) {
317 this.override = value;
318 }
319
320
321
322
323
324
325
326
327
328 @SuppressWarnings("unchecked")
329 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
330 private static Object copyOfAny(final Object source) {
331
332 if (source!= null) {
333 if (source instanceof Element) {
334
335 return ((Element)((Element) source).cloneNode(true));
336 }
337 if (source instanceof Object) {
338
339 return copyOf(((Object) source));
340 }
341
342 throw new AssertionError((("Unexpected instance '"+ source)+"' for property 'Any' of class 'org.jomc.model.Property'."));
343 }
344 return null;
345 }
346
347
348
349
350
351
352
353
354
355 @SuppressWarnings("unchecked")
356 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
357 private static Object copyOf(final Object o) {
358
359 try {
360 if (o!= null) {
361 if (o.getClass().isPrimitive()) {
362 return o;
363 }
364 if (o.getClass().isArray()) {
365 return copyOfArray(o);
366 }
367
368 if (o instanceof Boolean) {
369 return o;
370 }
371 if (o instanceof Byte) {
372 return o;
373 }
374 if (o instanceof Character) {
375 return o;
376 }
377 if (o instanceof Double) {
378 return o;
379 }
380 if (o instanceof Enum) {
381 return o;
382 }
383 if (o instanceof Float) {
384 return o;
385 }
386 if (o instanceof Integer) {
387 return o;
388 }
389 if (o instanceof Long) {
390 return o;
391 }
392 if (o instanceof Short) {
393 return o;
394 }
395 if (o instanceof String) {
396 return o;
397 }
398 if (o instanceof BigDecimal) {
399 return o;
400 }
401 if (o instanceof BigInteger) {
402 return o;
403 }
404 if (o instanceof UUID) {
405 return o;
406 }
407 if (o instanceof QName) {
408 return o;
409 }
410 if (o instanceof Duration) {
411 return o;
412 }
413 if (o instanceof Currency) {
414 return o;
415 }
416
417 if (o instanceof File) {
418 return new File(o.toString());
419 }
420 if (o instanceof URI) {
421 return new URI(o.toString());
422 }
423 if (o instanceof URL) {
424 return new URL(o.toString());
425 }
426 if (o instanceof MimeType) {
427 return new MimeType(o.toString());
428 }
429
430 if (o instanceof XMLGregorianCalendar) {
431 return ((XMLGregorianCalendar) o).clone();
432 }
433 if (o instanceof Date) {
434 return ((Date) o).clone();
435 }
436 if (o instanceof Calendar) {
437 return ((Calendar) o).clone();
438 }
439 if (o instanceof TimeZone) {
440 return ((TimeZone) o).clone();
441 }
442 if (o instanceof Locale) {
443 return ((Locale) o).clone();
444 }
445 if (o instanceof Element) {
446 return ((Element)((Element) o).cloneNode(true));
447 }
448 if (o instanceof JAXBElement) {
449 return copyOf(((JAXBElement) o));
450 }
451 try {
452 return o.getClass().getMethod("clone", ((Class[]) null)).invoke(o, ((Object[]) null));
453 } catch (NoSuchMethodException e) {
454 if (o instanceof Serializable) {
455 return copyOf(((Serializable) o));
456 }
457
458 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
459 } catch (IllegalAccessException e) {
460
461 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
462 } catch (InvocationTargetException e) {
463
464 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
465 } catch (SecurityException e) {
466
467 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
468 } catch (IllegalArgumentException e) {
469
470 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
471 } catch (ExceptionInInitializerError e) {
472
473 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
474 }
475 }
476 return null;
477 } catch (MimeTypeParseException e) {
478 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
479 } catch (URISyntaxException e) {
480 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
481 } catch (MalformedURLException e) {
482 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
483 }
484 }
485
486
487
488
489
490
491
492
493
494 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
495 private static Object copyOfArray(final Object array) {
496
497 if (array!= null) {
498 if (array.getClass() == boolean[].class) {
499 return copyOf(((boolean[]) array));
500 }
501 if (array.getClass() == byte[].class) {
502 return copyOf(((byte[]) array));
503 }
504 if (array.getClass() == char[].class) {
505 return copyOf(((char[]) array));
506 }
507 if (array.getClass() == double[].class) {
508 return copyOf(((double[]) array));
509 }
510 if (array.getClass() == float[].class) {
511 return copyOf(((float[]) array));
512 }
513 if (array.getClass() == int[].class) {
514 return copyOf(((int[]) array));
515 }
516 if (array.getClass() == long[].class) {
517 return copyOf(((long[]) array));
518 }
519 if (array.getClass() == short[].class) {
520 return copyOf(((short[]) array));
521 }
522 final int len = Array.getLength(array);
523 final Object copy = Array.newInstance(array.getClass().getComponentType(), len);
524 for (int i = (len- 1); (i >= 0); i--) {
525 Array.set(copy, i, copyOf(Array.get(array, i)));
526 }
527 return copy;
528 }
529 return null;
530 }
531
532
533
534
535
536
537
538
539
540 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
541 private static boolean[] copyOf(final boolean[] array) {
542
543 if (array!= null) {
544 final boolean[] copy = ((boolean[]) Array.newInstance(array.getClass().getComponentType(), array.length));
545 System.arraycopy(array, 0, copy, 0, array.length);
546 return copy;
547 }
548 return null;
549 }
550
551
552
553
554
555
556
557
558
559 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
560 private static byte[] copyOf(final byte[] array) {
561
562 if (array!= null) {
563 final byte[] copy = ((byte[]) Array.newInstance(array.getClass().getComponentType(), array.length));
564 System.arraycopy(array, 0, copy, 0, array.length);
565 return copy;
566 }
567 return null;
568 }
569
570
571
572
573
574
575
576
577
578 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
579 private static char[] copyOf(final char[] array) {
580
581 if (array!= null) {
582 final char[] copy = ((char[]) Array.newInstance(array.getClass().getComponentType(), array.length));
583 System.arraycopy(array, 0, copy, 0, array.length);
584 return copy;
585 }
586 return null;
587 }
588
589
590
591
592
593
594
595
596
597 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
598 private static double[] copyOf(final double[] array) {
599
600 if (array!= null) {
601 final double[] copy = ((double[]) Array.newInstance(array.getClass().getComponentType(), array.length));
602 System.arraycopy(array, 0, copy, 0, array.length);
603 return copy;
604 }
605 return null;
606 }
607
608
609
610
611
612
613
614
615
616 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
617 private static float[] copyOf(final float[] array) {
618
619 if (array!= null) {
620 final float[] copy = ((float[]) Array.newInstance(array.getClass().getComponentType(), array.length));
621 System.arraycopy(array, 0, copy, 0, array.length);
622 return copy;
623 }
624 return null;
625 }
626
627
628
629
630
631
632
633
634
635 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
636 private static int[] copyOf(final int[] array) {
637
638 if (array!= null) {
639 final int[] copy = ((int[]) Array.newInstance(array.getClass().getComponentType(), array.length));
640 System.arraycopy(array, 0, copy, 0, array.length);
641 return copy;
642 }
643 return null;
644 }
645
646
647
648
649
650
651
652
653
654 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
655 private static long[] copyOf(final long[] array) {
656
657 if (array!= null) {
658 final long[] copy = ((long[]) Array.newInstance(array.getClass().getComponentType(), array.length));
659 System.arraycopy(array, 0, copy, 0, array.length);
660 return copy;
661 }
662 return null;
663 }
664
665
666
667
668
669
670
671
672
673 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
674 private static short[] copyOf(final short[] array) {
675
676 if (array!= null) {
677 final short[] copy = ((short[]) Array.newInstance(array.getClass().getComponentType(), array.length));
678 System.arraycopy(array, 0, copy, 0, array.length);
679 return copy;
680 }
681 return null;
682 }
683
684
685
686
687
688
689
690
691
692 @SuppressWarnings("unchecked")
693 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
694 private static JAXBElement copyOf(final JAXBElement element) {
695
696 if (element!= null) {
697 final JAXBElement copy = new JAXBElement(element.getName(), element.getDeclaredType(), element.getScope(), element.getValue());
698 copy.setNil(element.isNil());
699 copy.setValue(copyOf(copy.getValue()));
700 return copy;
701 }
702 return null;
703 }
704
705
706
707
708
709
710
711
712
713 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
714 private static Serializable copyOf(final Serializable serializable) {
715
716 if (serializable!= null) {
717 try {
718 final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
719 final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
720 out.writeObject(serializable);
721 out.close();
722 final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
723 final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
724 final Serializable copy = ((Serializable) in.readObject());
725 in.close();
726 return copy;
727 } catch (SecurityException e) {
728 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
729 } catch (ClassNotFoundException e) {
730 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
731 } catch (InvalidClassException e) {
732 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
733 } catch (NotSerializableException e) {
734 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
735 } catch (StreamCorruptedException e) {
736 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
737 } catch (OptionalDataException e) {
738 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
739 } catch (IOException e) {
740 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
741 }
742 }
743 return null;
744 }
745
746
747
748
749
750
751
752
753 @Override
754 @Generated(value = "com.sun.tools.xjc.Driver", date = "2013-04-21T08:43:16+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
755 public Property clone() {
756 {
757
758 final Property clone = ((Property) super.clone());
759
760 clone.any = ((this.any == null)?null:copyOfAny(this.getAny()));
761
762 clone.name = ((this.name == null)?null:this.getName());
763
764 clone.type = ((this.type == null)?null:this.getType());
765
766 clone.value = ((this.value == null)?null:this.getValue());
767
768 clone._final = ((this._final == null)?null:this.isFinal());
769
770 clone.override = ((this.override == null)?null:this.isOverride());
771 return clone;
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 public Object getJavaValue( final ClassLoader classLoader ) throws ModelObjectException, PropertyException
808 {
809 try
810 {
811 if ( this.getAny() != null )
812 {
813 if ( this.getType() == null )
814 {
815 throw new PropertyException( getMessage( "mandatoryType", this.getName() ) );
816 }
817
818 final Object anyObject = this.getAny() instanceof JAXBElement
819 ? ( (JAXBElement) this.getAny() ).getValue() : this.getAny();
820
821 return this.getJavaValue( classLoader, anyObject,
822 this.getJavaTypeName().getClass( classLoader, false ) );
823
824 }
825 else
826 {
827 if ( this.getJavaTypeName().isPrimitive() && this.getValue() == null )
828 {
829 throw new PropertyException( getMessage( "mandatoryPrimitiveValue", this.getName(),
830 this.getType() ) );
831
832 }
833
834 return this.getJavaValue( this.getJavaTypeName().isPrimitive()
835 ? this.getJavaTypeName().getBoxedName().getClass( classLoader, false )
836 : this.getJavaTypeName().getClass( classLoader, false ),
837 this.getValue() );
838
839 }
840 }
841 catch ( final ClassNotFoundException e )
842 {
843 throw new PropertyException( getMessage( "classNotFound", this.getName(), this.getType() ), e );
844 }
845 }
846
847
848
849
850
851
852
853
854
855
856
857
858 public JavaTypeName getJavaTypeName() throws ModelObjectException
859 {
860 final String typeName = this.getType() == null
861 ? this.getAny() == null
862 ? String.class.getName()
863 : Object.class.getName()
864 : this.getType();
865
866 try
867 {
868 return JavaTypeName.parse( typeName );
869 }
870 catch ( final java.text.ParseException e )
871 {
872 throw new ModelObjectException( getMessage( "javaTypeNameParseException", typeName, getMessage( e ) ), e );
873 }
874 }
875
876
877
878
879
880
881
882
883
884
885
886
887
888 public JavaIdentifier getJavaGetterMethodName() throws ModelObjectException
889 {
890 try
891 {
892 final JavaTypeName javaType = this.getJavaTypeName();
893 final String prefix = javaType.runtimeEquals( JavaTypeName.BOOLEAN )
894 || javaType.runtimeEquals( JavaTypeName.BOOLEAN_TYPE ) ? "is" : "get";
895
896 return JavaIdentifier.parse( prefix + JavaIdentifier.normalize(
897 this.getName() != null ? this.getName() : "", JavaIdentifier.NormalizationMode.CAMEL_CASE ) );
898
899 }
900 catch ( final java.text.ParseException e )
901 {
902 throw new ModelObjectException( getMessage( "javaIdentifierParseException", this.getName(),
903 getMessage( e ) ), e );
904
905 }
906 }
907
908
909
910
911
912
913
914
915
916
917
918
919 public JavaIdentifier getJavaSetterMethodName() throws ModelObjectException
920 {
921 try
922 {
923 return JavaIdentifier.parse( "set" + JavaIdentifier.normalize(
924 this.getName() != null ? this.getName() : "", JavaIdentifier.NormalizationMode.CAMEL_CASE ) );
925
926 }
927 catch ( final java.text.ParseException e )
928 {
929 throw new ModelObjectException( getMessage( "javaIdentifierParseException", this.getName(),
930 getMessage( e ) ), e );
931
932 }
933 }
934
935
936
937
938
939
940
941
942
943
944
945
946 public JavaIdentifier getJavaVariableName() throws ModelObjectException
947 {
948 try
949 {
950 return JavaIdentifier.normalize( this.getName() != null ? this.getName() : "",
951 JavaIdentifier.NormalizationMode.VARIABLE_NAME_CONVENTION );
952
953 }
954 catch ( final java.text.ParseException e )
955 {
956 throw new ModelObjectException( getMessage( "javaIdentifierParseException", this.getName(),
957 getMessage( e ) ), e );
958
959 }
960 }
961
962
963
964
965
966
967
968
969
970
971
972
973 public JavaIdentifier getJavaConstantName() throws ModelObjectException
974 {
975 try
976 {
977 return JavaIdentifier.normalize( this.getName() != null ? this.getName() : "",
978 JavaIdentifier.NormalizationMode.CONSTANT_NAME_CONVENTION );
979
980 }
981 catch ( final java.text.ParseException e )
982 {
983 throw new ModelObjectException( getMessage( "javaIdentifierParseException", this.getName(),
984 getMessage( e ) ), e );
985
986 }
987 }
988
989 private Object getJavaValue( final ClassLoader classLoader, final Object any, final Class<?> returnType )
990 throws PropertyException
991 {
992 if ( any != null )
993 {
994 final String methodName = "getJavaValue";
995
996 try
997 {
998 final java.lang.reflect.Method m = any.getClass().getMethod( methodName, ClassLoader.class );
999 final Object result = m.invoke( any, classLoader );
1000
1001 if ( result != null && !returnType.isAssignableFrom( result.getClass() ) )
1002 {
1003 throw new PropertyException( getMessage( "illegalMethodInvocationResult", methodName,
1004 any.getClass().getName(), result.getClass().getName(),
1005 returnType.getName() ) );
1006
1007 }
1008
1009 return result;
1010 }
1011 catch ( final IllegalAccessException e )
1012 {
1013 throw new PropertyException( getMessage( "methodAccessDenied", methodName,
1014 any.getClass().getName() ), e );
1015
1016 }
1017 catch ( final IllegalArgumentException e )
1018 {
1019 throw new AssertionError( e );
1020 }
1021 catch ( final InvocationTargetException e )
1022 {
1023 throw new PropertyException( getMessage( "methodInvocationFailure", methodName,
1024 any.getClass().getName() ), e );
1025
1026 }
1027 catch ( final SecurityException e )
1028 {
1029 throw new PropertyException( getMessage( "methodAccessDenied", methodName,
1030 any.getClass().getName() ), e );
1031
1032 }
1033 catch ( final NoSuchMethodException e )
1034 {
1035
1036 }
1037 }
1038
1039 return any;
1040 }
1041
1042 private Object getJavaValue( final Class<?> type, final String value ) throws PropertyException
1043 {
1044 if ( value != null )
1045 {
1046 try
1047 {
1048 if ( type == Character.class )
1049 {
1050 if ( value.length() != 1 )
1051 {
1052 throw new PropertyException( getMessage( "illegalValue", value, Character.class.getName() ) );
1053 }
1054
1055 return type.getConstructor( char.class ).newInstance( value.charAt( 0 ) );
1056 }
1057 else if ( type == String.class )
1058 {
1059 return value;
1060 }
1061 else
1062 {
1063 try
1064 {
1065 return type.getConstructor( String.class ).newInstance( value );
1066 }
1067 catch ( final NoSuchMethodException e )
1068 {
1069
1070 final java.lang.reflect.Method valueOf = type.getMethod( "valueOf", String.class );
1071
1072 if ( !type.isAssignableFrom( valueOf.getReturnType() ) )
1073 {
1074 throw new PropertyException( getMessage( "notAssignable", valueOf.getReturnType().getName(),
1075 valueOf.getName(), type.getName(),
1076 type.getName(), this.getName() ) );
1077
1078 }
1079
1080 return valueOf.invoke( null, value );
1081 }
1082 }
1083 }
1084 catch ( final InstantiationException e )
1085 {
1086 throw new PropertyException( getMessage( "instantiationException", type.getName() ), e );
1087 }
1088 catch ( final IllegalAccessException e )
1089 {
1090 throw new PropertyException( getMessage( "accessDenied", type.getName() ), e );
1091 }
1092 catch ( final IllegalArgumentException e )
1093 {
1094 throw new AssertionError( e );
1095 }
1096 catch ( final InvocationTargetException e )
1097 {
1098 throw new PropertyException( getMessage( "invocationFailure", type.getName() ), e );
1099 }
1100 catch ( final NoSuchMethodException e )
1101 {
1102 throw new PropertyException( getMessage( "constructorNotFound", type.getName() ), e );
1103 }
1104 }
1105
1106 return value;
1107 }
1108
1109 private static String getMessage( final Throwable t )
1110 {
1111 return t != null
1112 ? t.getMessage() != null && t.getMessage().trim().length() > 0
1113 ? t.getMessage()
1114 : getMessage( t.getCause() )
1115 : null;
1116
1117 }
1118
1119 private static String getMessage( final String key, final Object... arguments )
1120 {
1121 return java.text.MessageFormat.format( java.util.ResourceBundle.getBundle(
1122 Property.class.getName().replace( '.', '/' ), java.util.Locale.getDefault() ).getString( key ), arguments );
1123
1124 }
1125
1126 }