
: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.



== Implementation

The framework provides two implementations of this service, both to allow objects implementing `HasCommandDto` to be converted into serializable ``CommandDto``s, in other words XML.
// commandreplay moved to incubator for the time being
// This is used by the xref:userguide:commandlog:about.adoc[Command Log] and xref:userguide:commandreplay:about.adoc[Command Replay] extensions to allow commands to be replicated from a primary to secondary system, for regression testing.

The implementations are:

* xref:refguide:applib:index/services/commanddto/conmap/ContentMappingServiceForCommandDto.adoc[] will map any single instance of a `HasCommandDto` into a `CommandDto` XML document
* xref:refguide:applib:index/services/commanddto/conmap/ContentMappingServiceForCommandsDto.adoc[] will map a list of ``HasCommandDto``s into a `CommandsDto` XML document, and will wrap any single instance of a `CommandWithDto` into a singleton list and thence into a `CommandsDto` XML document.

If the action invocation or property edit represent provides an implementation of a `CommandDtoProcessor` (by way of xref:refguide:applib:index/annotation/Action.adoc#commandDtoProcessor[@Action#commandDtoProcessor()] or xref:refguide:applib:index/annotation/Property.adoc#commandDtoProcessor[@Property#commandDtoProcessor()]) then this is also called to post-process the persisted `CommandDto` if required.
A typical use case for this is to dynamically add in serialized ``Blob``s or ``Clob``s, the values of which are not captured by default in `CommandDto`.

To support the writing of custom implementations of this interface, the framework also provides `ContentMappingService.Util` which includes a couple of convenience utilities:

[source,java]
----
public static class Util {
    public static String determineDomainType(
        final List<MediaType> acceptableMediaTypes) { /* ... */ }
    public static boolean isSupported(
            final Class<?> clazz,
            final List<MediaType> acceptableMediaTypes) { /* ... */ }
}
----


