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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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 (URISyntaxException e) {
478 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
479 } catch (MimeTypeParseException 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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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-01-03T05:01:35+01: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 public Object getJavaValue( final ClassLoader classLoader ) throws ModelObjectException, PropertyException
807 {
808 try
809 {
810 if ( this.getAny() != null )
811 {
812 if ( this.getType() == null )
813 {
814 throw new PropertyException( getMessage( "mandatoryType", this.getName() ) );
815 }
816
817 final Object anyObject = this.getAny() instanceof JAXBElement
818 ? ( (JAXBElement) this.getAny() ).getValue() : this.getAny();
819
820 return this.getJavaValue( classLoader, anyObject,
821 this.getJavaTypeName().getClass( classLoader, false ) );
822
823 }
824 else
825 {
826 if ( this.getJavaTypeName().isPrimitive() && this.getValue() == null )
827 {
828 throw new PropertyException( getMessage( "mandatoryPrimitiveValue", this.getName(),
829 this.getType() ) );
830
831 }
832
833 return this.getJavaValue( this.getJavaTypeName().isPrimitive()
834 ? this.getJavaTypeName().getBoxedName().getClass( classLoader, false )
835 : this.getJavaTypeName().getClass( classLoader, false ),
836 this.getValue() );
837
838 }
839 }
840 catch ( final ClassNotFoundException e )
841 {
842 throw new PropertyException( getMessage( "classNotFound", this.getName(), this.getType() ), e );
843 }
844 }
845
846
847
848
849
850
851
852
853
854
855
856
857 public JavaTypeName getJavaTypeName() throws ModelObjectException
858 {
859 final String typeName = this.getType() == null
860 ? this.getAny() == null
861 ? String.class.getName()
862 : Object.class.getName()
863 : this.getType();
864
865 try
866 {
867 return JavaTypeName.parse( typeName );
868 }
869 catch ( final java.text.ParseException e )
870 {
871 throw new ModelObjectException( getMessage( "javaTypeNameParseException", typeName, getMessage( e ) ), e );
872 }
873 }
874
875
876
877
878
879
880
881
882
883
884
885
886
887 public JavaIdentifier getJavaGetterMethodName() throws ModelObjectException
888 {
889 try
890 {
891 final JavaTypeName javaType = this.getJavaTypeName();
892 final String prefix = javaType.runtimeEquals( JavaTypeName.BOOLEAN )
893 || javaType.runtimeEquals( JavaTypeName.BOOLEAN_TYPE ) ? "is" : "get";
894
895 return JavaIdentifier.parse( prefix + JavaIdentifier.normalize(
896 this.getName() != null ? this.getName() : "", JavaIdentifier.NormalizationMode.CAMEL_CASE ) );
897
898 }
899 catch ( final java.text.ParseException e )
900 {
901 throw new ModelObjectException( getMessage( "javaIdentifierParseException", this.getName(),
902 getMessage( e ) ), e );
903
904 }
905 }
906
907
908
909
910
911
912
913
914
915
916
917
918 public JavaIdentifier getJavaSetterMethodName() throws ModelObjectException
919 {
920 try
921 {
922 return JavaIdentifier.parse( "set" + JavaIdentifier.normalize(
923 this.getName() != null ? this.getName() : "", JavaIdentifier.NormalizationMode.CAMEL_CASE ) );
924
925 }
926 catch ( final java.text.ParseException e )
927 {
928 throw new ModelObjectException( getMessage( "javaIdentifierParseException", this.getName(),
929 getMessage( e ) ), e );
930
931 }
932 }
933
934
935
936
937
938
939
940
941
942
943
944
945 public JavaIdentifier getJavaVariableName() throws ModelObjectException
946 {
947 try
948 {
949 return JavaIdentifier.normalize( this.getName() != null ? this.getName() : "",
950 JavaIdentifier.NormalizationMode.VARIABLE_NAME_CONVENTION );
951
952 }
953 catch ( final java.text.ParseException e )
954 {
955 throw new ModelObjectException( getMessage( "javaIdentifierParseException", this.getName(),
956 getMessage( e ) ), e );
957
958 }
959 }
960
961
962
963
964
965
966
967
968
969
970
971
972 public JavaIdentifier getJavaConstantName() throws ModelObjectException
973 {
974 try
975 {
976 return JavaIdentifier.normalize( this.getName() != null ? this.getName() : "",
977 JavaIdentifier.NormalizationMode.CONSTANT_NAME_CONVENTION );
978
979 }
980 catch ( final java.text.ParseException e )
981 {
982 throw new ModelObjectException( getMessage( "javaIdentifierParseException", this.getName(),
983 getMessage( e ) ), e );
984
985 }
986 }
987
988 private Object getJavaValue( final ClassLoader classLoader, final Object any, final Class<?> returnType )
989 throws PropertyException
990 {
991 if ( any != null )
992 {
993 final String methodName = "getJavaValue";
994
995 try
996 {
997 final java.lang.reflect.Method m = any.getClass().getMethod( methodName, ClassLoader.class );
998 final Object result = m.invoke( any, classLoader );
999
1000 if ( result != null && !returnType.isAssignableFrom( result.getClass() ) )
1001 {
1002 throw new PropertyException( getMessage( "illegalMethodInvocationResult", methodName,
1003 any.getClass().getName(), result.getClass().getName(),
1004 returnType.getName() ) );
1005
1006 }
1007
1008 return result;
1009 }
1010 catch ( final IllegalAccessException e )
1011 {
1012 throw new PropertyException( getMessage( "methodAccessDenied", methodName,
1013 any.getClass().getName() ), e );
1014
1015 }
1016 catch ( final IllegalArgumentException e )
1017 {
1018 throw new AssertionError( e );
1019 }
1020 catch ( final InvocationTargetException e )
1021 {
1022 throw new PropertyException( getMessage( "methodInvocationFailure", methodName,
1023 any.getClass().getName() ), e );
1024
1025 }
1026 catch ( final SecurityException e )
1027 {
1028 throw new PropertyException( getMessage( "methodAccessDenied", methodName,
1029 any.getClass().getName() ), e );
1030
1031 }
1032 catch ( final NoSuchMethodException e )
1033 {
1034
1035 }
1036 }
1037
1038 return any;
1039 }
1040
1041 private Object getJavaValue( final Class<?> type, final String value ) throws PropertyException
1042 {
1043 if ( value != null )
1044 {
1045 try
1046 {
1047 if ( type == Character.class )
1048 {
1049 if ( value.length() != 1 )
1050 {
1051 throw new PropertyException( getMessage( "illegalValue", value, Character.class.getName() ) );
1052 }
1053
1054 return type.getConstructor( new Class<?>[]
1055 {
1056 char.class
1057 } ).newInstance( new Object[]
1058 {
1059 value.charAt( 0 )
1060 } );
1061
1062 }
1063 else if ( type == String.class )
1064 {
1065 return value;
1066 }
1067 else
1068 {
1069 return type.getConstructor( new Class<?>[]
1070 {
1071 String.class
1072 } ).newInstance( value );
1073
1074 }
1075 }
1076 catch ( final InstantiationException e )
1077 {
1078 throw new PropertyException( getMessage( "instantiationException", type.getName() ), e );
1079 }
1080 catch ( final IllegalAccessException e )
1081 {
1082 throw new PropertyException( getMessage( "constructorAccessDenied", type.getName() ), e );
1083 }
1084 catch ( final IllegalArgumentException e )
1085 {
1086 throw new AssertionError( e );
1087 }
1088 catch ( final InvocationTargetException e )
1089 {
1090 throw new PropertyException( getMessage( "constructorInvocationFailure", type.getName() ), e );
1091 }
1092 catch ( final NoSuchMethodException e )
1093 {
1094 throw new PropertyException( getMessage( "constructorNotFound", type.getName() ), e );
1095 }
1096 }
1097
1098 return value;
1099 }
1100
1101 private static String getMessage( final Throwable t )
1102 {
1103 return t != null ? t.getMessage() != null ? t.getMessage() : getMessage( t.getCause() ) : null;
1104 }
1105
1106 private static String getMessage( final String key, final Object... arguments )
1107 {
1108 return java.text.MessageFormat.format( java.util.ResourceBundle.getBundle(
1109 Property.class.getName().replace( '.', '/' ), java.util.Locale.getDefault() ).getString( key ), arguments );
1110
1111 }
1112
1113 }