|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.component.base.AbstractLoggableComponent
net.sf.mmm.util.xml.base.jaxb.XmlBeanMapper<T>
T - is the generic type of the JAXB bean.public class XmlBeanMapper<T>
This class is a little helper for the simple but common use of JAXB where you
simply want to read or
write the XML for a single JAXB
annotated java bean.
ATTENTION:
This class uses an IDValidator to validate duplicate or
unresolved XmlIDs on
un-marshaling. This is unfortunately not
the default for JAXB and also NOT part of the JAXB-API. So this feature
depends on the actual JAXB implementation you are using. We support the
default implementation build into the JRE (com.sun.internal.xml.bind).
However if jaxb-impl (com.sun.xml.bind) is NOT on your classpath
it will replace the default implementation. For this reason we also support
jaxb-impl as fallback. Other implementations are NOT supported
(everything should work but ID-validation is turned off then).
| Field Summary | |
|---|---|
private javax.xml.bind.JAXBContext |
jaxbContext
|
private BrowsableResourceFactory |
resourceFactory
|
private Class<T> |
xmlBeanClass
|
| Constructor Summary | |
|---|---|
XmlBeanMapper(Class<T> xmlBeanClass)
The constructor. |
|
| Method Summary | |
|---|---|
protected void |
doInitialize()
This method performs the actual initialization. |
protected javax.xml.bind.JAXBContext |
getJaxbContext()
|
protected javax.xml.bind.Marshaller |
getOrCreateMarshaller()
This method gets a Marshaller instance. |
protected javax.xml.bind.Unmarshaller |
getOrCreateUnmarshaller()
This method gets a Marshaller instance. |
protected DataResourceFactory |
getResourceFactory()
|
T |
loadXml(DataResource resource)
This method loads the JAXB-bean as XML from the given resource
. |
T |
loadXml(File file)
This method loads the JAXB-bean as XML from the given inputStream. |
T |
loadXml(InputStream inputStream,
Object source)
This method loads the JAXB-bean as XML from the given inputStream. |
T |
loadXml(String locationUrl)
This method loads the JAXB-bean as XML from the given location
. |
void |
saveXml(T jaxbBean,
DataResource resource)
This method saves the given jaxbBean as XML to the given
outputStream. |
void |
saveXml(T jaxbBean,
OutputStream outputStream)
This method saves the given jaxbBean as XML to the given
outputStream. |
void |
saveXml(T jaxbBean,
String locationUrl)
This method saves the given jaxbBean as XML to the given
locationUrl. |
void |
setResourceFactory(BrowsableResourceFactory browsableResourceFactory)
|
protected void |
validate(T jaxbBean)
This method is invoked after the jaxbBean has been loaded and
before it is saved. |
| Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent |
|---|
getLogger, setLogger |
| Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent |
|---|
doInitialized, getInitializationState, initialize |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final javax.xml.bind.JAXBContext jaxbContext
getJaxbContext()private final Class<T> xmlBeanClass
loadXml(InputStream, Object)private BrowsableResourceFactory resourceFactory
getResourceFactory()| Constructor Detail |
|---|
public XmlBeanMapper(Class<T> xmlBeanClass)
xmlBeanClass - is the JAXB-annotated-Class that should be
mapped.| Method Detail |
|---|
protected DataResourceFactory getResourceFactory()
@Inject public void setResourceFactory(BrowsableResourceFactory browsableResourceFactory)
browsableResourceFactory - is the BrowsableResourceFactory to
set.protected void doInitialize()
initialization. It is
called when AbstractComponent.initialize() is invoked for the first time.super.AbstractComponent.doInitialize().
doInitialize in class AbstractLoggableComponentprotected javax.xml.bind.Marshaller getOrCreateMarshaller()
Marshaller instance. This method potentially
allows reusing the Marshaller (if it is thread-safe).
Marshaller.protected javax.xml.bind.Unmarshaller getOrCreateUnmarshaller()
Marshaller instance. This method potentially
allows reusing the Marshaller (if it is thread-safe).
Unmarshaller.protected javax.xml.bind.JAXBContext getJaxbContext()
protected void validate(T jaxbBean)
jaxbBean has been loaded and
before it is saved. It does nothing by default but can be overridden to
implement custom validation logic.
jaxbBean - is the JAXB bean to validate.
public T loadXml(InputStream inputStream,
Object source)
inputStream.
inputStream - is the InputStream with the XML to parse.source - describes the source of the invalid XML. Typically this will
be the filename where the XML was read from. It is used in in the
exception message. This will help to find the problem easier.
public T loadXml(String locationUrl)
location
.
locationUrl - is the location URL for the resource pointing to the XML to parse.
public T loadXml(File file)
inputStream.
file - is the File with the XML to parse.
public T loadXml(DataResource resource)
resource
.
resource - is the DataResource with the XML to parse.
public void saveXml(T jaxbBean,
DataResource resource)
jaxbBean as XML to the given
outputStream.close the
outputStream.
jaxbBean - is the JAXB-bean to save as XML.resource - is the DataResource where to
write to.
public void saveXml(T jaxbBean,
OutputStream outputStream)
jaxbBean as XML to the given
outputStream.close the
outputStream.
jaxbBean - is the JAXB-bean to save as XML.outputStream - is the OutputStream where to write the XML to.
public void saveXml(T jaxbBean,
String locationUrl)
jaxbBean as XML to the given
locationUrl.
jaxbBean - is the JAXB-bean to save as XML.locationUrl - is the location URL for the resource where to write the XML to. Typically a file-URL.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||