1
2
3
4
5
6
7
8
9 package org.jomc.tools.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.XmlSchemaType;
45 import javax.xml.bind.annotation.XmlType;
46 import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
47 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
48 import javax.xml.datatype.Duration;
49 import javax.xml.datatype.XMLGregorianCalendar;
50 import javax.xml.namespace.QName;
51 import org.w3c.dom.Element;
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 @XmlAccessorType(XmlAccessType.FIELD)
79 @XmlType(name = "TemplateParameterType", namespace = "http://jomc.org/tools/model", propOrder = {
80 "any"
81 })
82 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
83 public class TemplateParameterType
84 extends ToolsType
85 implements Cloneable
86 {
87
88 @XmlAnyElement(lax = true)
89 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
90 protected Object any;
91 @XmlAttribute(name = "name", required = true)
92 @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
93 @XmlSchemaType(name = "token")
94 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
95 protected String name;
96 @XmlAttribute(name = "type")
97 @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
98 @XmlSchemaType(name = "token")
99 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
100 protected String type;
101 @XmlAttribute(name = "value")
102 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
103 protected String value;
104
105
106
107
108
109 public TemplateParameterType() {
110
111 super();
112 }
113
114
115
116
117
118
119
120
121
122
123 public TemplateParameterType(final TemplateParameterType o) {
124
125 super(o);
126 if (o == null) {
127 throw new NullPointerException("Cannot create a copy of 'TemplateParameterType' from 'null'.");
128 }
129
130 this.any = ((o.any == null)?null:copyOfAny(o.getAny()));
131
132 this.name = ((o.name == null)?null:o.getName());
133
134 this.type = ((o.type == null)?null:o.getType());
135
136 this.value = ((o.value == null)?null:o.getValue());
137 }
138
139
140
141
142
143
144
145
146
147
148 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
149 public Object getAny() {
150 return any;
151 }
152
153
154
155
156
157
158
159
160
161
162 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
163 public void setAny(Object value) {
164 this.any = value;
165 }
166
167
168
169
170
171
172
173
174
175 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
176 public String getName() {
177 return name;
178 }
179
180
181
182
183
184
185
186
187
188 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
189 public void setName(String value) {
190 this.name = value;
191 }
192
193
194
195
196
197
198
199
200
201 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
202 public String getType() {
203 return type;
204 }
205
206
207
208
209
210
211
212
213
214 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
215 public void setType(String value) {
216 this.type = value;
217 }
218
219
220
221
222
223
224
225
226
227 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
228 public String getValue() {
229 return value;
230 }
231
232
233
234
235
236
237
238
239
240 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
241 public void setValue(String value) {
242 this.value = value;
243 }
244
245
246
247
248
249
250
251
252
253 @SuppressWarnings("unchecked")
254 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
255 private static Object copyOfAny(final Object source) {
256
257 if (source!= null) {
258 if (source instanceof Element) {
259
260 return ((Element)((Element) source).cloneNode(true));
261 }
262 if (source instanceof Object) {
263
264 return copyOf(((Object) source));
265 }
266
267 throw new AssertionError((("Unexpected instance '"+ source)+"' for property 'Any' of class 'org.jomc.tools.model.TemplateParameterType'."));
268 }
269 return null;
270 }
271
272
273
274
275
276
277
278
279
280 @SuppressWarnings("unchecked")
281 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
282 private static Object copyOf(final Object o) {
283
284 try {
285 if (o!= null) {
286 if (o.getClass().isPrimitive()) {
287 return o;
288 }
289 if (o.getClass().isArray()) {
290 return copyOfArray(o);
291 }
292
293 if (o instanceof Boolean) {
294 return o;
295 }
296 if (o instanceof Byte) {
297 return o;
298 }
299 if (o instanceof Character) {
300 return o;
301 }
302 if (o instanceof Double) {
303 return o;
304 }
305 if (o instanceof Enum) {
306 return o;
307 }
308 if (o instanceof Float) {
309 return o;
310 }
311 if (o instanceof Integer) {
312 return o;
313 }
314 if (o instanceof Long) {
315 return o;
316 }
317 if (o instanceof Short) {
318 return o;
319 }
320 if (o instanceof String) {
321 return o;
322 }
323 if (o instanceof BigDecimal) {
324 return o;
325 }
326 if (o instanceof BigInteger) {
327 return o;
328 }
329 if (o instanceof UUID) {
330 return o;
331 }
332 if (o instanceof QName) {
333 return o;
334 }
335 if (o instanceof Duration) {
336 return o;
337 }
338 if (o instanceof Currency) {
339 return o;
340 }
341
342 if (o instanceof File) {
343 return new File(o.toString());
344 }
345 if (o instanceof URI) {
346 return new URI(o.toString());
347 }
348 if (o instanceof URL) {
349 return new URL(o.toString());
350 }
351 if (o instanceof MimeType) {
352 return new MimeType(o.toString());
353 }
354
355 if (o instanceof XMLGregorianCalendar) {
356 return ((XMLGregorianCalendar) o).clone();
357 }
358 if (o instanceof Date) {
359 return ((Date) o).clone();
360 }
361 if (o instanceof Calendar) {
362 return ((Calendar) o).clone();
363 }
364 if (o instanceof TimeZone) {
365 return ((TimeZone) o).clone();
366 }
367 if (o instanceof Locale) {
368 return ((Locale) o).clone();
369 }
370 if (o instanceof Element) {
371 return ((Element)((Element) o).cloneNode(true));
372 }
373 if (o instanceof JAXBElement) {
374 return copyOf(((JAXBElement) o));
375 }
376 try {
377 return o.getClass().getMethod("clone", ((Class[]) null)).invoke(o, ((Object[]) null));
378 } catch (NoSuchMethodException e) {
379 if (o instanceof Serializable) {
380 return copyOf(((Serializable) o));
381 }
382
383 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
384 } catch (IllegalAccessException e) {
385
386 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
387 } catch (InvocationTargetException e) {
388
389 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
390 } catch (SecurityException e) {
391
392 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
393 } catch (IllegalArgumentException e) {
394
395 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
396 } catch (ExceptionInInitializerError e) {
397
398 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
399 }
400 }
401 return null;
402 } catch (MimeTypeParseException e) {
403 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
404 } catch (MalformedURLException e) {
405 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
406 } catch (URISyntaxException e) {
407 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
408 }
409 }
410
411
412
413
414
415
416
417
418
419 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
420 private static Object copyOfArray(final Object array) {
421
422 if (array!= null) {
423 if (array.getClass() == boolean[].class) {
424 return copyOf(((boolean[]) array));
425 }
426 if (array.getClass() == byte[].class) {
427 return copyOf(((byte[]) array));
428 }
429 if (array.getClass() == char[].class) {
430 return copyOf(((char[]) array));
431 }
432 if (array.getClass() == double[].class) {
433 return copyOf(((double[]) array));
434 }
435 if (array.getClass() == float[].class) {
436 return copyOf(((float[]) array));
437 }
438 if (array.getClass() == int[].class) {
439 return copyOf(((int[]) array));
440 }
441 if (array.getClass() == long[].class) {
442 return copyOf(((long[]) array));
443 }
444 if (array.getClass() == short[].class) {
445 return copyOf(((short[]) array));
446 }
447 final int len = Array.getLength(array);
448 final Object copy = Array.newInstance(array.getClass().getComponentType(), len);
449 for (int i = (len- 1); (i >= 0); i--) {
450 Array.set(copy, i, copyOf(Array.get(array, i)));
451 }
452 return copy;
453 }
454 return null;
455 }
456
457
458
459
460
461
462
463
464
465 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
466 private static boolean[] copyOf(final boolean[] array) {
467
468 if (array!= null) {
469 final boolean[] copy = ((boolean[]) Array.newInstance(array.getClass().getComponentType(), array.length));
470 System.arraycopy(array, 0, copy, 0, array.length);
471 return copy;
472 }
473 return null;
474 }
475
476
477
478
479
480
481
482
483
484 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
485 private static byte[] copyOf(final byte[] array) {
486
487 if (array!= null) {
488 final byte[] copy = ((byte[]) Array.newInstance(array.getClass().getComponentType(), array.length));
489 System.arraycopy(array, 0, copy, 0, array.length);
490 return copy;
491 }
492 return null;
493 }
494
495
496
497
498
499
500
501
502
503 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
504 private static char[] copyOf(final char[] array) {
505
506 if (array!= null) {
507 final char[] copy = ((char[]) Array.newInstance(array.getClass().getComponentType(), array.length));
508 System.arraycopy(array, 0, copy, 0, array.length);
509 return copy;
510 }
511 return null;
512 }
513
514
515
516
517
518
519
520
521
522 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
523 private static double[] copyOf(final double[] array) {
524
525 if (array!= null) {
526 final double[] copy = ((double[]) Array.newInstance(array.getClass().getComponentType(), array.length));
527 System.arraycopy(array, 0, copy, 0, array.length);
528 return copy;
529 }
530 return null;
531 }
532
533
534
535
536
537
538
539
540
541 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
542 private static float[] copyOf(final float[] array) {
543
544 if (array!= null) {
545 final float[] copy = ((float[]) Array.newInstance(array.getClass().getComponentType(), array.length));
546 System.arraycopy(array, 0, copy, 0, array.length);
547 return copy;
548 }
549 return null;
550 }
551
552
553
554
555
556
557
558
559
560 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
561 private static int[] copyOf(final int[] array) {
562
563 if (array!= null) {
564 final int[] copy = ((int[]) Array.newInstance(array.getClass().getComponentType(), array.length));
565 System.arraycopy(array, 0, copy, 0, array.length);
566 return copy;
567 }
568 return null;
569 }
570
571
572
573
574
575
576
577
578
579 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
580 private static long[] copyOf(final long[] array) {
581
582 if (array!= null) {
583 final long[] copy = ((long[]) Array.newInstance(array.getClass().getComponentType(), array.length));
584 System.arraycopy(array, 0, copy, 0, array.length);
585 return copy;
586 }
587 return null;
588 }
589
590
591
592
593
594
595
596
597
598 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
599 private static short[] copyOf(final short[] array) {
600
601 if (array!= null) {
602 final short[] copy = ((short[]) Array.newInstance(array.getClass().getComponentType(), array.length));
603 System.arraycopy(array, 0, copy, 0, array.length);
604 return copy;
605 }
606 return null;
607 }
608
609
610
611
612
613
614
615
616
617 @SuppressWarnings("unchecked")
618 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
619 private static JAXBElement copyOf(final JAXBElement element) {
620
621 if (element!= null) {
622 final JAXBElement copy = new JAXBElement(element.getName(), element.getDeclaredType(), element.getScope(), element.getValue());
623 copy.setNil(element.isNil());
624 copy.setValue(copyOf(copy.getValue()));
625 return copy;
626 }
627 return null;
628 }
629
630
631
632
633
634
635
636
637
638 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
639 private static Serializable copyOf(final Serializable serializable) {
640
641 if (serializable!= null) {
642 try {
643 final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
644 final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
645 out.writeObject(serializable);
646 out.close();
647 final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
648 final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
649 final Serializable copy = ((Serializable) in.readObject());
650 in.close();
651 return copy;
652 } catch (SecurityException e) {
653 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
654 } catch (ClassNotFoundException e) {
655 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
656 } catch (InvalidClassException e) {
657 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
658 } catch (NotSerializableException e) {
659 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
660 } catch (StreamCorruptedException e) {
661 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
662 } catch (OptionalDataException e) {
663 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
664 } catch (IOException e) {
665 throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
666 }
667 }
668 return null;
669 }
670
671
672
673
674
675
676
677
678 @Override
679 @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
680 public TemplateParameterType clone() {
681 {
682
683 final TemplateParameterType clone = ((TemplateParameterType) super.clone());
684
685 clone.any = ((this.any == null)?null:copyOfAny(this.getAny()));
686
687 clone.name = ((this.name == null)?null:this.getName());
688
689 clone.type = ((this.type == null)?null:this.getType());
690
691 clone.value = ((this.value == null)?null:this.getValue());
692 return clone;
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 public Object getJavaValue( final ClassLoader classLoader ) throws org.jomc.model.ModelObjectException
730 {
731 try
732 {
733 if ( this.getAny() != null )
734 {
735 if ( this.getType() == null )
736 {
737 throw new org.jomc.model.ModelObjectException( getMessage( "mandatoryType", this.getName() ) );
738 }
739
740 final Object anyObject = this.getAny() instanceof JAXBElement
741 ? ( (JAXBElement) this.getAny() ).getValue() : this.getAny();
742
743 return this.getJavaValue( classLoader, anyObject,
744 this.getJavaTypeName().getClass( classLoader, false ) );
745
746 }
747 else
748 {
749 if ( this.getJavaTypeName().isPrimitive() && this.getValue() == null )
750 {
751 throw new org.jomc.model.ModelObjectException( getMessage( "mandatoryPrimitiveValue",
752 this.getName(), this.getType() ) );
753
754 }
755
756 return this.getJavaValue( this.getJavaTypeName().isPrimitive()
757 ? this.getJavaTypeName().getBoxedName().getClass( classLoader, false )
758 : this.getJavaTypeName().getClass( classLoader, false ),
759 this.getValue() );
760
761 }
762 }
763 catch ( final ClassNotFoundException e )
764 {
765 throw new org.jomc.model.ModelObjectException( getMessage( "classNotFound", this.getName(),
766 this.getType() ), e );
767
768 }
769 }
770
771
772
773
774
775
776
777
778
779
780 public org.jomc.model.JavaTypeName getJavaTypeName() throws org.jomc.model.ModelObjectException
781 {
782 final String typeName = this.getType() == null
783 ? this.getAny() == null
784 ? String.class.getName()
785 : Object.class.getName()
786 : this.getType();
787
788 try
789 {
790 return org.jomc.model.JavaTypeName.parse( typeName );
791 }
792 catch ( final java.text.ParseException e )
793 {
794 throw new org.jomc.model.ModelObjectException( getMessage( "javaTypeNameParseException", typeName,
795 getMessage( e ) ), e );
796
797 }
798 }
799
800 private Object getJavaValue( final ClassLoader classLoader, final Object any, final Class<?> returnType )
801 throws org.jomc.model.ModelObjectException
802 {
803 if ( any != null )
804 {
805 final String methodName = "getJavaValue";
806
807 try
808 {
809 final java.lang.reflect.Method m = any.getClass().getMethod( methodName, ClassLoader.class );
810 final Object result = m.invoke( any, classLoader );
811
812 if ( result != null && !returnType.isAssignableFrom( result.getClass() ) )
813 {
814 throw new org.jomc.model.ModelObjectException( getMessage( "illegalMethodInvocationResult",
815 methodName, any.getClass().getName(),
816 result.getClass().getName(),
817 returnType.getName() ) );
818
819 }
820
821 return result;
822 }
823 catch ( final IllegalAccessException e )
824 {
825 throw new org.jomc.model.ModelObjectException( getMessage( "methodAccessDenied", methodName,
826 any.getClass().getName() ), e );
827
828 }
829 catch ( final IllegalArgumentException e )
830 {
831 throw new AssertionError( e );
832 }
833 catch ( final InvocationTargetException e )
834 {
835 throw new org.jomc.model.ModelObjectException( getMessage( "methodInvocationFailure", methodName,
836 any.getClass().getName() ), e );
837
838 }
839 catch ( final SecurityException e )
840 {
841 throw new org.jomc.model.ModelObjectException( getMessage( "methodAccessDenied", methodName,
842 any.getClass().getName() ), e );
843
844 }
845 catch ( final NoSuchMethodException e )
846 {
847
848 }
849 }
850
851 return any;
852 }
853
854 private Object getJavaValue( final Class<?> type, final String value ) throws org.jomc.model.ModelObjectException
855 {
856 if ( value != null )
857 {
858 try
859 {
860 if ( type == Character.class )
861 {
862 if ( value.length() != 1 )
863 {
864 throw new org.jomc.model.ModelObjectException( getMessage( "illegalValue", value,
865 Character.class.getName() ) );
866
867 }
868
869 return type.getConstructor( char.class ).newInstance( value.charAt( 0 ) );
870 }
871 else if ( type == String.class )
872 {
873 return value;
874 }
875 else
876 {
877 try
878 {
879 return type.getConstructor( String.class ).newInstance( value );
880 }
881 catch ( final NoSuchMethodException e )
882 {
883 final java.lang.reflect.Method valueOf = type.getMethod( "valueOf", String.class );
884
885 if ( !type.isAssignableFrom( valueOf.getReturnType() ) )
886 {
887 throw new org.jomc.model.ModelObjectException( getMessage(
888 "notAssignable", valueOf.getReturnType().getName(), valueOf.getName(), type.getName(),
889 type.getName(), this.getName() ) );
890
891 }
892
893 return valueOf.invoke( null, value );
894 }
895 }
896 }
897 catch ( final InstantiationException e )
898 {
899 throw new org.jomc.model.ModelObjectException( getMessage( "instantiationException", type.getName() ),
900 e );
901
902 }
903 catch ( final IllegalAccessException e )
904 {
905 throw new org.jomc.model.ModelObjectException( getMessage( "accessDenied", type.getName() ), e );
906 }
907 catch ( final IllegalArgumentException e )
908 {
909 throw new AssertionError( e );
910 }
911 catch ( final InvocationTargetException e )
912 {
913 throw new org.jomc.model.ModelObjectException( getMessage( "invocationFailure", type.getName() ), e );
914 }
915 catch ( final NoSuchMethodException e )
916 {
917 throw new org.jomc.model.ModelObjectException( getMessage( "constructorNotFound", type.getName() ), e );
918 }
919 }
920
921 return value;
922 }
923
924 private static String getMessage( final Throwable t )
925 {
926 return t != null
927 ? t.getMessage() != null && t.getMessage().trim().length() > 0
928 ? t.getMessage()
929 : getMessage( t.getCause() )
930 : null;
931
932 }
933
934 private static String getMessage( final String key, final Object... arguments )
935 {
936 return java.text.MessageFormat.format(
937 java.util.ResourceBundle.getBundle( TemplateParameterType.class.getName().replace( '.', '/' ),
938 java.util.Locale.getDefault() ).getString( key ),
939 arguments );
940
941 }
942
943 }