Package org.jvnet.basicjaxb.config
Class LocatorUnmarshaller<T>
java.lang.Object
org.jvnet.basicjaxb.config.LocatorUnmarshaller<T>
- Type Parameters:
T-
An facade for an unmarshaller of an XML file that delegates to a JAXB Unmarshaller.
This implementation adds a method to unmarshal using a string locator. The locator
represents either a classpath, a URL or a file.
Sample locators:
- file:///PATH/src/test/samples/po.xml
- file:src/test/samples/po.xml
- classpath:/org/jvnet/basicjaxb/tests/po/po.xml
- classpath:po.xml
- /PATH/src/test/samples/po.xml
- src/test/samples/po.xml
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLocatorUnmarshaller(jakarta.xml.bind.Unmarshaller unmarshaller) Construct with a JAXB Unmarshaller. -
Method Summary
Modifier and TypeMethodDescriptionjakarta.xml.bind.UnmarshallervoidsetUnmarshaller(jakarta.xml.bind.Unmarshaller unmarshaller) Unmarshal an XML instance using the given locator.Unmarshal an XML instance using the given locator.
-
Field Details
-
PROTOCOL_CLASSPATH
Represents a URL protocol for a classpath lookup.- See Also:
-
PROTOCOL_FILE
Represents a URL protocol for a file lookup.- See Also:
-
-
Constructor Details
-
LocatorUnmarshaller
public LocatorUnmarshaller(jakarta.xml.bind.Unmarshaller unmarshaller) Construct with a JAXB Unmarshaller.- Parameters:
unmarshaller- The unmarshaller to delegate to.
-
-
Method Details
-
getUnmarshaller
public jakarta.xml.bind.Unmarshaller getUnmarshaller() -
setUnmarshaller
public void setUnmarshaller(jakarta.xml.bind.Unmarshaller unmarshaller) -
unmarshal
Unmarshal an XML instance using the given locator. The locator can represent a URL or a File. If the URL protocol is "classpath:" then the XML file will be located as a resource stream.- Parameters:
locator- The location of an XML file or resource.- Returns:
- An object instance of type T.
- Throws:
IOException- If an error occurred when inputting from the reader.jakarta.xml.bind.JAXBException- If any unexpected errors occur while unmarshalling.
-
unmarshal
public T unmarshal(String locator, Class<?> clazz) throws IOException, jakarta.xml.bind.JAXBException Unmarshal an XML instance using the given locator. The locator can represent a URL or a File. If the URL protocol is "classpath:" then the XML file will be located as a resource stream.- Parameters:
locator- The location of an XML file or resource.clazz- A classpath location for relative locators.- Returns:
- An object instance of type T.
- Throws:
IOException- If an error occurred when inputting from the reader.jakarta.xml.bind.JAXBException- If any unexpected errors occur while unmarshalling.
-