TemplateParameterType.java
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2015.05.31 at 05:43:54 PM CEST
//
package org.jomc.tools.model;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.NotSerializableException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OptionalDataException;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.UUID;
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
import javax.annotation.Generated;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import org.w3c.dom.Element;
/**
* Model of a template parameter.
*
* <p>Java class for TemplateParameterType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="TemplateParameterType">
* <complexContent>
* <extension base="{http://jomc.org/tools/model}ToolsType">
* <sequence>
* <any processContents='lax' namespace='##other' minOccurs="0"/>
* </sequence>
* <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}token" />
* <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}token" />
* <attribute name="value" type="{http://www.w3.org/2001/XMLSchema}string" />
* </extension>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TemplateParameterType", namespace = "http://jomc.org/tools/model", propOrder = {
"any"
})
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public class TemplateParameterType
extends ToolsType
implements Cloneable
{
@XmlAnyElement(lax = true)
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
protected Object any;
@XmlAttribute(name = "name", required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "token")
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
protected String name;
@XmlAttribute(name = "type")
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "token")
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
protected String type;
@XmlAttribute(name = "value")
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
protected String value;
/**
* Creates a new {@code TemplateParameterType} instance.
*
*/
public TemplateParameterType() {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
super();
}
/**
* Creates a new {@code TemplateParameterType} instance by deeply copying a given {@code TemplateParameterType} instance.
*
*
* @param o
* The instance to copy.
* @throws NullPointerException
* if {@code o} is {@code null}.
*/
public TemplateParameterType(final TemplateParameterType o) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
super(o);
if (o == null) {
throw new NullPointerException("Cannot create a copy of 'TemplateParameterType' from 'null'.");
}
// 'Any' property.
this.any = ((o.any == null)?null:copyOfAny(o.getAny()));
// CBuiltinLeafInfo: java.lang.String
this.name = ((o.name == null)?null:o.getName());
// CBuiltinLeafInfo: java.lang.String
this.type = ((o.type == null)?null:o.getType());
// CBuiltinLeafInfo: java.lang.String
this.value = ((o.value == null)?null:o.getValue());
}
/**
* Gets the value of the any property.
*
* @return
* possible object is
* {@link Object }
* {@link Element }
*
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public Object getAny() {
return any;
}
/**
* Sets the value of the any property.
*
* @param value
* allowed object is
* {@link Object }
* {@link Element }
*
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public void setAny(Object value) {
this.any = value;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the type property.
*
* @return
* possible object is
* {@link String }
*
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public String getType() {
return type;
}
/**
* Sets the value of the type property.
*
* @param value
* allowed object is
* {@link String }
*
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public void setType(String value) {
this.type = value;
}
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link String }
*
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public void setValue(String value) {
this.value = value;
}
/**
* Creates and returns a deep copy of property {@code Any}.
*
* @param source
* The source to copy from or {@code null}.
* @return
* A deep copy of {@code source} or {@code null} if {@code source} is {@code null}.
*/
@SuppressWarnings("unchecked")
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static Object copyOfAny(final Object source) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (source!= null) {
if (source instanceof Element) {
// CWildcardTypeInfo: org.w3c.dom.Element
return ((Element)((Element) source).cloneNode(true));
}
if (source instanceof Object) {
// CBuiltinLeafInfo: java.lang.Object
return copyOf(((Object) source));
}
// Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
throw new AssertionError((("Unexpected instance '"+ source)+"' for property 'Any' of class 'org.jomc.tools.model.TemplateParameterType'."));
}
return null;
}
/**
* Creates and returns a deep copy of a given object.
*
* @param o
* The instance to copy or {@code null}.
* @return
* A deep copy of {@code o} or {@code null} if {@code o} is {@code null}.
*/
@SuppressWarnings("unchecked")
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static Object copyOf(final Object o) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
try {
if (o!= null) {
if (o.getClass().isPrimitive()) {
return o;
}
if (o.getClass().isArray()) {
return copyOfArray(o);
}
// Immutable types.
if (o instanceof Boolean) {
return o;
}
if (o instanceof Byte) {
return o;
}
if (o instanceof Character) {
return o;
}
if (o instanceof Double) {
return o;
}
if (o instanceof Enum) {
return o;
}
if (o instanceof Float) {
return o;
}
if (o instanceof Integer) {
return o;
}
if (o instanceof Long) {
return o;
}
if (o instanceof Short) {
return o;
}
if (o instanceof String) {
return o;
}
if (o instanceof BigDecimal) {
return o;
}
if (o instanceof BigInteger) {
return o;
}
if (o instanceof UUID) {
return o;
}
if (o instanceof QName) {
return o;
}
if (o instanceof Duration) {
return o;
}
if (o instanceof Currency) {
return o;
}
// String based types.
if (o instanceof File) {
return new File(o.toString());
}
if (o instanceof URI) {
return new URI(o.toString());
}
if (o instanceof URL) {
return new URL(o.toString());
}
if (o instanceof MimeType) {
return new MimeType(o.toString());
}
// Cloneable types.
if (o instanceof XMLGregorianCalendar) {
return ((XMLGregorianCalendar) o).clone();
}
if (o instanceof Date) {
return ((Date) o).clone();
}
if (o instanceof Calendar) {
return ((Calendar) o).clone();
}
if (o instanceof TimeZone) {
return ((TimeZone) o).clone();
}
if (o instanceof Locale) {
return ((Locale) o).clone();
}
if (o instanceof Element) {
return ((Element)((Element) o).cloneNode(true));
}
if (o instanceof JAXBElement) {
return copyOf(((JAXBElement) o));
}
try {
return o.getClass().getMethod("clone", ((Class[]) null)).invoke(o, ((Object[]) null));
} catch (NoSuchMethodException e) {
if (o instanceof Serializable) {
return copyOf(((Serializable) o));
}
// Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
} catch (IllegalAccessException e) {
// Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
} catch (InvocationTargetException e) {
// Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
} catch (SecurityException e) {
// Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
} catch (IllegalArgumentException e) {
// Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
} catch (ExceptionInInitializerError e) {
// Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
}
}
return null;
} catch (MimeTypeParseException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
} catch (MalformedURLException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
} catch (URISyntaxException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ o)+"'.")).initCause(e));
}
}
/**
* Creates and returns a deep copy of a given array.
*
* @param array
* The array to copy or {@code null}.
* @return
* A deep copy of {@code array} or {@code null} if {@code array} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static Object copyOfArray(final Object array) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (array!= null) {
if (array.getClass() == boolean[].class) {
return copyOf(((boolean[]) array));
}
if (array.getClass() == byte[].class) {
return copyOf(((byte[]) array));
}
if (array.getClass() == char[].class) {
return copyOf(((char[]) array));
}
if (array.getClass() == double[].class) {
return copyOf(((double[]) array));
}
if (array.getClass() == float[].class) {
return copyOf(((float[]) array));
}
if (array.getClass() == int[].class) {
return copyOf(((int[]) array));
}
if (array.getClass() == long[].class) {
return copyOf(((long[]) array));
}
if (array.getClass() == short[].class) {
return copyOf(((short[]) array));
}
final int len = Array.getLength(array);
final Object copy = Array.newInstance(array.getClass().getComponentType(), len);
for (int i = (len- 1); (i >= 0); i--) {
Array.set(copy, i, copyOf(Array.get(array, i)));
}
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given array.
*
* @param array
* The array to copy or {@code null}.
* @return
* A deep copy of {@code array} or {@code null} if {@code array} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static boolean[] copyOf(final boolean[] array) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (array!= null) {
final boolean[] copy = ((boolean[]) Array.newInstance(array.getClass().getComponentType(), array.length));
System.arraycopy(array, 0, copy, 0, array.length);
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given array.
*
* @param array
* The array to copy or {@code null}.
* @return
* A deep copy of {@code array} or {@code null} if {@code array} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static byte[] copyOf(final byte[] array) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (array!= null) {
final byte[] copy = ((byte[]) Array.newInstance(array.getClass().getComponentType(), array.length));
System.arraycopy(array, 0, copy, 0, array.length);
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given array.
*
* @param array
* The array to copy or {@code null}.
* @return
* A deep copy of {@code array} or {@code null} if {@code array} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static char[] copyOf(final char[] array) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (array!= null) {
final char[] copy = ((char[]) Array.newInstance(array.getClass().getComponentType(), array.length));
System.arraycopy(array, 0, copy, 0, array.length);
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given array.
*
* @param array
* The array to copy or {@code null}.
* @return
* A deep copy of {@code array} or {@code null} if {@code array} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static double[] copyOf(final double[] array) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (array!= null) {
final double[] copy = ((double[]) Array.newInstance(array.getClass().getComponentType(), array.length));
System.arraycopy(array, 0, copy, 0, array.length);
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given array.
*
* @param array
* The array to copy or {@code null}.
* @return
* A deep copy of {@code array} or {@code null} if {@code array} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static float[] copyOf(final float[] array) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (array!= null) {
final float[] copy = ((float[]) Array.newInstance(array.getClass().getComponentType(), array.length));
System.arraycopy(array, 0, copy, 0, array.length);
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given array.
*
* @param array
* The array to copy or {@code null}.
* @return
* A deep copy of {@code array} or {@code null} if {@code array} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static int[] copyOf(final int[] array) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (array!= null) {
final int[] copy = ((int[]) Array.newInstance(array.getClass().getComponentType(), array.length));
System.arraycopy(array, 0, copy, 0, array.length);
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given array.
*
* @param array
* The array to copy or {@code null}.
* @return
* A deep copy of {@code array} or {@code null} if {@code array} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static long[] copyOf(final long[] array) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (array!= null) {
final long[] copy = ((long[]) Array.newInstance(array.getClass().getComponentType(), array.length));
System.arraycopy(array, 0, copy, 0, array.length);
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given array.
*
* @param array
* The array to copy or {@code null}.
* @return
* A deep copy of {@code array} or {@code null} if {@code array} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static short[] copyOf(final short[] array) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (array!= null) {
final short[] copy = ((short[]) Array.newInstance(array.getClass().getComponentType(), array.length));
System.arraycopy(array, 0, copy, 0, array.length);
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given {@code JAXBElement} instance.
*
* @param element
* The instance to copy or {@code null}.
* @return
* A deep copy of {@code element} or {@code null} if {@code element} is {@code null}.
*/
@SuppressWarnings("unchecked")
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static JAXBElement copyOf(final JAXBElement element) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (element!= null) {
final JAXBElement copy = new JAXBElement(element.getName(), element.getDeclaredType(), element.getScope(), element.getValue());
copy.setNil(element.isNil());
copy.setValue(copyOf(copy.getValue()));
return copy;
}
return null;
}
/**
* Creates and returns a deep copy of a given {@code Serializable}.
*
* @param serializable
* The instance to copy or {@code null}.
* @return
* A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
*/
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
private static Serializable copyOf(final Serializable serializable) {
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
if (serializable!= null) {
try {
final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
out.writeObject(serializable);
out.close();
final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
final Serializable copy = ((Serializable) in.readObject());
in.close();
return copy;
} catch (SecurityException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
} catch (ClassNotFoundException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
} catch (InvalidClassException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
} catch (NotSerializableException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
} catch (StreamCorruptedException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
} catch (OptionalDataException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
} catch (IOException e) {
throw((AssertionError) new AssertionError((("Unexpected instance during copying object '"+ serializable)+"'.")).initCause(e));
}
}
return null;
}
/**
* Creates and returns a deep copy of this object.
*
*
* @return
* A deep copy of this object.
*/
@Override
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public TemplateParameterType clone() {
{
// CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
final TemplateParameterType clone = ((TemplateParameterType) super.clone());
// 'Any' property.
clone.any = ((this.any == null)?null:copyOfAny(this.getAny()));
// CBuiltinLeafInfo: java.lang.String
clone.name = ((this.name == null)?null:this.getName());
// CBuiltinLeafInfo: java.lang.String
clone.type = ((this.type == null)?null:this.getType());
// CBuiltinLeafInfo: java.lang.String
clone.value = ((this.value == null)?null:this.getValue());
return clone;
}
}
/**
* Gets the Java value of the template parameter.
* <p>
* The Java value of the template parameter is computed based on the following rules:
* <ol>
* <li>If property {@code any} is set, the Java value is computed based on the object returned by method
* {@code getAny()} by possibly unwrapping any {@code JAXBElement} instances. If that object declares a
* <blockquote><pre>public Object getJavaValue( ClassLoader )</pre></blockquote> method, the value returned by this
* method is the object returned by a call to that method. If that object does not declare such a method, the value
* returned by this method is that (possibly unwrapped) object.</li>
* <li>If property {@code value} is set, the Java value is computed based on the values of properties {@code type}
* and {@code value}. If property {@code type} is not set or equals {@code java.lang.String}, the value returned
* by this method is the string value returned by method {@code getValue()}. If property {@code type} equals a name
* of a Java primitive type, an instance of the wrapper class corresponding to that primitive type name is returned
* instantiated by passing the value of property {@code value} to the public constructor of that wrapper class
* taking a single {@code java.lang.String} argument. For all other values of property {@code type} an instance of
* a class with a name equal to the value of property {@code type} is returned, either instantiated by passing the
* value of property {@code value} to the public constructor of that class taking a single {@code java.lang.String}
* argument, or, failing that, by passing the value of property {@code value} to the static {@code valueOf} method
* of that class taking a single {@code java.lang.String} argument.</li>
* <li>If properties {@code any} and {@code value} are both {@code null}, this method returns {@code null}.</li>
* </ol></p>
*
* @param classLoader The class loader to use for getting the Java value; {@code null} to use the platform's
* bootstrap class loader.
*
* @return The Java value of the template parameter or {@code null}.
*
* @throws org.jomc.model.ModelObjectException if getting the Java value of the template parameter fails
* unexpectedly.
*
* @see #getJavaTypeName()
*/
public Object getJavaValue( final ClassLoader classLoader ) throws org.jomc.model.ModelObjectException
{
try
{
if ( this.getAny() != null )
{
if ( this.getType() == null )
{
throw new org.jomc.model.ModelObjectException( getMessage( "mandatoryType", this.getName() ) );
}
final Object anyObject = this.getAny() instanceof JAXBElement
? ( (JAXBElement) this.getAny() ).getValue() : this.getAny();
return this.getJavaValue( classLoader, anyObject,
this.getJavaTypeName().getClass( classLoader, false ) );
}
else
{
if ( this.getJavaTypeName().isPrimitive() && this.getValue() == null )
{
throw new org.jomc.model.ModelObjectException( getMessage( "mandatoryPrimitiveValue",
this.getName(), this.getType() ) );
}
return this.getJavaValue( this.getJavaTypeName().isPrimitive()
? this.getJavaTypeName().getBoxedName().getClass( classLoader, false )
: this.getJavaTypeName().getClass( classLoader, false ),
this.getValue() );
}
}
catch ( final ClassNotFoundException e )
{
throw new org.jomc.model.ModelObjectException( getMessage( "classNotFound", this.getName(),
this.getType() ), e );
}
}
/**
* Gets the Java type name of the template parameter.
*
* @return The Java type name of the type referenced by the template parameter or {@code null}, if the template
* parameter does not reference a type.
*
* @throws org.jomc.model.ModelObjectException if compiling the name of the type referenced by the template
* parameter to a {@code JavaTypeName} fails.
*/
public org.jomc.model.JavaTypeName getJavaTypeName() throws org.jomc.model.ModelObjectException
{
final String typeName = this.getType() == null
? this.getAny() == null
? String.class.getName()
: Object.class.getName()
: this.getType();
try
{
return org.jomc.model.JavaTypeName.parse( typeName );
}
catch ( final java.text.ParseException e )
{
throw new org.jomc.model.ModelObjectException( getMessage( "javaTypeNameParseException", typeName,
getMessage( e ) ), e );
}
}
private Object getJavaValue( final ClassLoader classLoader, final Object any, final Class<?> returnType )
throws org.jomc.model.ModelObjectException
{
if ( any != null )
{
final String methodName = "getJavaValue";
try
{
final java.lang.reflect.Method m = any.getClass().getMethod( methodName, ClassLoader.class );
final Object result = m.invoke( any, classLoader );
if ( result != null && !returnType.isAssignableFrom( result.getClass() ) )
{
throw new org.jomc.model.ModelObjectException( getMessage( "illegalMethodInvocationResult",
methodName, any.getClass().getName(),
result.getClass().getName(),
returnType.getName() ) );
}
return result;
}
catch ( final IllegalAccessException e )
{
throw new org.jomc.model.ModelObjectException( getMessage( "methodAccessDenied", methodName,
any.getClass().getName() ), e );
}
catch ( final IllegalArgumentException e )
{
throw new AssertionError( e );
}
catch ( final InvocationTargetException e )
{
throw new org.jomc.model.ModelObjectException( getMessage( "methodInvocationFailure", methodName,
any.getClass().getName() ), e );
}
catch ( final SecurityException e )
{
throw new org.jomc.model.ModelObjectException( getMessage( "methodAccessDenied", methodName,
any.getClass().getName() ), e );
}
catch ( final NoSuchMethodException e )
{
// Optional method not provided.
}
}
return any;
}
private Object getJavaValue( final Class<?> type, final String value ) throws org.jomc.model.ModelObjectException
{
if ( value != null )
{
try
{
if ( type == Character.class )
{
if ( value.length() != 1 )
{
throw new org.jomc.model.ModelObjectException( getMessage( "illegalValue", value,
Character.class.getName() ) );
}
return type.getConstructor( char.class ).newInstance( value.charAt( 0 ) );
}
else if ( type == String.class )
{
return value;
}
else
{
try
{
return type.getConstructor( String.class ).newInstance( value );
}
catch ( final NoSuchMethodException e )
{
final java.lang.reflect.Method valueOf = type.getMethod( "valueOf", String.class );
if ( !type.isAssignableFrom( valueOf.getReturnType() ) )
{
throw new org.jomc.model.ModelObjectException( getMessage(
"notAssignable", valueOf.getReturnType().getName(), valueOf.getName(), type.getName(),
type.getName(), this.getName() ) );
}
return valueOf.invoke( null, value );
}
}
}
catch ( final InstantiationException e )
{
throw new org.jomc.model.ModelObjectException( getMessage( "instantiationException", type.getName() ),
e );
}
catch ( final IllegalAccessException e )
{
throw new org.jomc.model.ModelObjectException( getMessage( "accessDenied", type.getName() ), e );
}
catch ( final IllegalArgumentException e )
{
throw new AssertionError( e );
}
catch ( final InvocationTargetException e )
{
throw new org.jomc.model.ModelObjectException( getMessage( "invocationFailure", type.getName() ), e );
}
catch ( final NoSuchMethodException e )
{
throw new org.jomc.model.ModelObjectException( getMessage( "constructorNotFound", type.getName() ), e );
}
}
return value;
}
private static String getMessage( final Throwable t )
{
return t != null
? t.getMessage() != null && t.getMessage().trim().length() > 0
? t.getMessage()
: getMessage( t.getCause() )
: null;
}
private static String getMessage( final String key, final Object... arguments )
{
return java.text.MessageFormat.format(
java.util.ResourceBundle.getBundle( TemplateParameterType.class.getName().replace( '.', '/' ),
java.util.Locale.getDefault() ).getString( key ),
arguments );
}
}