
: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 xref:core:metamodel:about.adoc[Core Metamodel] module provides a default implementation, xref:refguide:core:index/metamodel/services/grid/bootstrap/GridSystemServiceBootstrap.adoc[].

An *SPI* is provided via nested _interface_ `FallbackLayoutDataSource`,
that allows to customize layout fallback behavior on a per class basis.
(Without having to override the heavy weight `GridSystemServiceBootstrap`.)

[source,java]
.FallbackLayoutDataSource SPI
----
interface FallbackLayoutDataSource {
    Try<String> tryLoadAsStringUtf8(Class<?> domainClass); <.>
}
----
<.> Provides custom default for given `domainClass`
or return an `Try.empty()` if indifferent.

For example:
[source,java]
.FallbackLayoutDataSource example
----
@Service
public class FallbackLayoutForManager implements FallbackLayoutDataSource {

    @Override
    public Try<String> tryLoadAsStringUtf8(final Class<?> domainClass) {
        return domainClass.getSimpleName().endsWith("Manager")
                ? DataSource.ofResource(getClass(), "ManagerLayout.xml") // <.>
                    .tryReadAsStringUtf8()
                : Try.empty(); // <.>
    }

}
----
<.> Provides a custom layout for all domain classes that have a name ending with 'Manager'.
<.> Indifferent for given domain type. Tells the framework to fall through.

(The framework also provides xref:vw:ROOT:about.adoc[Web UI (Wicket viewer)] components that are capable of interpreting and rendering this metadata.
