= XmlSnapshotService
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Allows an XML document to be generated capturing the data of a root entity and specified related entities.

An XSD schema (to which the XML will be compatible) can also be generated.

This XML/XSD can be used for various purposes, such as mail merge/reporting, or adhoc auditing.

The service offers a basic API to create a snapshot of a single object, and a more flexible API that allows the size of the graph to be customized.

== API

[source,java]
.XmlSnapshotService.java
----
interface XmlSnapshotService {
  XmlSnapshotService.Snapshot snapshotFor(Object domainObject)     // <.>
  XmlSnapshotService.Snapshot.Builder builderFor(Object domainObject)     // <.>
  T getChildElementValue(Element el, String tagname, Class<T> expectedCls)     // <.>
}
----

<.> xref:#snapshotFor_Object[snapshotFor(Object)]
+
--
Exports the state of a domain object into a Snapshot (which can then be converted into XML, for example).
--
<.> xref:#builderFor_Object[builderFor(Object)]
+
--
Creates a Snapshot.Builder that allows the contents of the snapshot to include other related state.
--
<.> xref:#getChildElementValue_Element_String_Class[getChildElementValue(Element, String, Class)]
+
--
Convenience method to extract value of an XML element, based on its type.
--

== Members

[#snapshotFor_Object]
=== snapshotFor(Object)

Exports the state of a domain object into a Snapshot (which can then be converted into XML, for example).

[#builderFor_Object]
=== builderFor(Object)

Creates a Snapshot.Builder that allows the contents of the snapshot to include other related state.

[#getChildElementValue_Element_String_Class]
=== getChildElementValue(Element, String, Class)

Convenience method to extract value of an XML element, based on its type.

include::hooks/XmlSnapshotService_010-implementation.adoc[]

include::hooks/XmlSnapshotService_020-examples-and-usage.adoc[]
