use of org.apache.sis.util.Workaround in project sis by apache.
the class GO_CharacterString method getCodeList.
/**
* Returns the code list wrapped in a JAXB element, or {@code null} if the {@link #text} is not a wrapper for
* a code list. Only one of {@link #getValue()} and {@code getCodeList()} should return a non-null value.
*
* <div class="note"><b>Note:</b>
* we have to rely on a somewhat complicated mechanism because the code lists implementations in GeoAPI
* do not have JAXB annotations. If those annotations are added in a future GeoAPI implementation, then
* we could replace this mechanism by a simple property annotated with {@code XmlElementRef}.</div>
*
* @since 0.7
*/
@XmlAnyElement
@Workaround(library = "GeoAPI", version = "3.0")
private Object getCodeList() {
if (type != ENUM) {
return null;
}
final CodeList<?> code = Types.forCodeTitle(text);
final String name = Types.getListName(code);
/*
* The namespace has have various value like CIT, SRV, MDQ, MRI, MSR, LAN, etc.
* The real namespace is declared in the @XmlElement annotation of the getElement
* method in the JAXB adapter. We could use reflection, but we do not in order to
* avoid potential class loading issue and also because not all CodeList are in the
* same package.
*/
String namespace = Namespaces.guessForType(name);
if (namespace == null) {
namespace = XMLConstants.NULL_NS_URI;
}
return new JAXBElement<>(new QName(namespace, name), CodeListUID.class, new CodeListUID(Context.current(), code));
}
use of org.apache.sis.util.Workaround in project sis by apache.
the class XML method unmarshal.
/**
* Unmarshal an object from the given stream, DOM or other sources.
* Together with the {@linkplain #unmarshal(Source, Map) Unmarshal Global Root Element} variant,
* this is the most flexible unmarshalling method provided in this {@code XML} class.
* The source is specified by the {@code input} argument implementation, for example
* {@link javax.xml.transform.stream.StreamSource} for reading from a file or input stream.
* The optional {@code properties} map can contain any key documented in this {@code XML} class,
* together with the keys documented in the <cite>supported properties</cite> section of the the
* {@link Unmarshaller} class.
*
* @param <T> compile-time value of the {@code declaredType} argument.
* @param input the file from which to read a XML representation.
* @param declaredType the JAXB mapped class of the object to unmarshal.
* @param properties an optional map of properties to give to the unmarshaller, or {@code null} if none.
* @return the object unmarshalled from the given input, wrapped in a JAXB element.
* @throws JAXBException if a property has an illegal value, or if an error occurred during the unmarshalling.
*
* @since 0.8
*/
public static <T> JAXBElement<T> unmarshal(final Source input, final Class<T> declaredType, final Map<String, ?> properties) throws JAXBException {
ensureNonNull("input", input);
ensureNonNull("declaredType", declaredType);
final MarshallerPool pool = getPool();
final Unmarshaller unmarshaller = pool.acquireUnmarshaller(properties);
final JAXBElement<T> element;
if (input instanceof StAXSource) {
// Same workaround than the one documented in above method.
@Workaround(library = "JDK", version = "1.8") final XMLStreamReader reader = ((StAXSource) input).getXMLStreamReader();
if (reader != null) {
element = unmarshaller.unmarshal(reader, declaredType);
} else {
element = unmarshaller.unmarshal(((StAXSource) input).getXMLEventReader(), declaredType);
}
} else {
element = unmarshaller.unmarshal(input, declaredType);
}
pool.recycle(unmarshaller);
return element;
}
use of org.apache.sis.util.Workaround in project sis by apache.
the class NoOp method parameters.
/**
* Work around for RFE #4093999 in Sun's bug database
* ("Relax constraint on placement of this()/super() call in constructors").
*/
@Workaround(library = "JDK", version = "1.7")
private static Parameters parameters(final double semiMajor, final double semiMinor) {
final ParameterValueGroup group = new ParameterBuilder().addName("No-operation").createGroupForMapProjection().createValue();
group.parameter(Constants.SEMI_MAJOR).setValue(semiMajor);
group.parameter(Constants.SEMI_MINOR).setValue(semiMinor);
return (Parameters) group;
}
use of org.apache.sis.util.Workaround in project sis by apache.
the class XML method marshal.
/**
* Marshal the given object to a stream, DOM or other destinations.
* This is the most flexible marshalling method provided in this {@code XML} class.
* The destination is specified by the {@code output} argument implementation, for example
* {@link javax.xml.transform.stream.StreamResult} for writing to a file or output stream.
* The optional {@code properties} map can contain any key documented in this {@code XML} class,
* together with the keys documented in the <cite>supported properties</cite> section of the the
* {@link Marshaller} class.
*
* @param object the root of content tree to be marshalled.
* @param output the file to be written.
* @param properties an optional map of properties to give to the marshaller, or {@code null} if none.
* @throws JAXBException if a property has an illegal value, or if an error occurred during the marshalling.
*
* @since 0.4
*/
public static void marshal(final Object object, final Result output, final Map<String, ?> properties) throws JAXBException {
ensureNonNull("object", object);
ensureNonNull("output", output);
final MarshallerPool pool = getPool();
final Marshaller marshaller = pool.acquireMarshaller();
if (properties != null) {
for (final Map.Entry<String, ?> entry : properties.entrySet()) {
marshaller.setProperty(entry.getKey(), entry.getValue());
}
}
/*
* STAX results are not handled by JAXB as of JDK 8. We have to handle those cases ourselves.
* This workaround should be removed if a future JDK version handles those cases.
*/
if (output instanceof StAXResult) {
@Workaround(library = "JDK", version = "1.8") final XMLStreamWriter writer = ((StAXResult) output).getXMLStreamWriter();
if (writer != null) {
marshaller.marshal(object, writer);
} else {
marshaller.marshal(object, ((StAXResult) output).getXMLEventWriter());
}
} else {
marshaller.marshal(object, output);
}
pool.recycle(marshaller);
}
use of org.apache.sis.util.Workaround in project sis by apache.
the class XML method unmarshal.
/**
* Unmarshal an object from the given stream, DOM or other sources.
* Together with the {@linkplain #unmarshal(Source, Class, Map) Unmarshal by Declared Type} variant,
* this is the most flexible unmarshalling method provided in this {@code XML} class.
* The source is specified by the {@code input} argument implementation, for example
* {@link javax.xml.transform.stream.StreamSource} for reading from a file or input stream.
* The optional {@code properties} map can contain any key documented in this {@code XML} class,
* together with the keys documented in the <cite>supported properties</cite> section of the the
* {@link Unmarshaller} class.
*
* @param input the file from which to read a XML representation.
* @param properties an optional map of properties to give to the unmarshaller, or {@code null} if none.
* @return the object unmarshalled from the given input.
* @throws JAXBException if a property has an illegal value, or if an error occurred during the unmarshalling.
*
* @since 0.4
*/
public static Object unmarshal(final Source input, final Map<String, ?> properties) throws JAXBException {
ensureNonNull("input", input);
final MarshallerPool pool = getPool();
final Unmarshaller unmarshaller = pool.acquireUnmarshaller(properties);
final Object object;
/*
* STAX sources are not handled by javax.xml.bind.helpers.AbstractUnmarshallerImpl implementation as of JDK 8.
* We have to handle those cases ourselves. This workaround should be removed if a future JDK version handles
* those cases.
*/
if (input instanceof StAXSource) {
@Workaround(library = "JDK", version = "1.8") final XMLStreamReader reader = ((StAXSource) input).getXMLStreamReader();
if (reader != null) {
object = unmarshaller.unmarshal(reader);
} else {
object = unmarshaller.unmarshal(((StAXSource) input).getXMLEventReader());
}
} else {
object = unmarshaller.unmarshal(input);
}
pool.recycle(unmarshaller);
return object;
}
Aggregations