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

This service provides a serializable 'bookmark' for any entity, and conversely to lookup an entity from a bookmark.

== API

[source,java]
.BookmarkService.java
----
interface BookmarkService {
  Optional<Bookmark> bookmarkFor(Object domainObject)     // <.>
  Optional<Bookmark> bookmarkFor(Class<?> type, String identifier)     // <.>
  Optional<Object> lookup(BookmarkHolder bookmarkHolder)     // <.>
  Optional<Object> lookup(Bookmark bookmark)     // <.>
  Optional<T> lookup(Bookmark bookmark, Class<T> cls)     // <.>
  Bookmark bookmarkForElseFail(Object domainObject)     // <.>
}
----

<.> xref:#bookmarkFor_Object[bookmarkFor(Object)]
+
--
Optionally returns the xref:refguide:applib:index/services/bookmark/Bookmark.adoc[Bookmark] for the given domain object, based on whether can create a bookmark for it.
--
<.> xref:#bookmarkFor_Class_String[bookmarkFor(Class, String)]
+
--
Optionally returns a xref:refguide:applib:index/services/bookmark/Bookmark.adoc[Bookmark] created from the constituent parts, based on whether can create a bookmark from these.
--
<.> xref:#lookup_BookmarkHolder[lookup(BookmarkHolder)]
<.> xref:#lookup_Bookmark[lookup(Bookmark)]
+
--
Reciprocal of _#bookmarkFor(Object)_
--
<.> xref:#lookup_Bookmark_Class[lookup(Bookmark, Class)]
+
--
As _#lookup(Bookmark)_ , but down-casting to the specified type.
--
<.> xref:#bookmarkForElseFail_Object[bookmarkForElseFail(Object)]
+
--
As per _#bookmarkFor(Object)_ , but requires that a non-null xref:refguide:applib:index/services/bookmark/Bookmark.adoc[Bookmark] is returned.
--

== Members

[#bookmarkFor_Object]
=== bookmarkFor(Object)

Optionally returns the xref:refguide:applib:index/services/bookmark/Bookmark.adoc[Bookmark] for the given domain object, based on whether can create a bookmark for it.

 *Note* : Not every domain object is bookmark-able: only entities, view models and services (NOT values or collections)

[#bookmarkFor_Class_String]
=== bookmarkFor(Class, String)

Optionally returns a xref:refguide:applib:index/services/bookmark/Bookmark.adoc[Bookmark] created from the constituent parts, based on whether can create a bookmark from these.

With constituent parts a _type_ and an _identifier_ that uniquely identifies an instance of this type.

[#lookup_BookmarkHolder]
=== lookup(BookmarkHolder)

[#lookup_Bookmark]
=== lookup(Bookmark)

Reciprocal of _#bookmarkFor(Object)_

[#lookup_Bookmark_Class]
=== lookup(Bookmark, Class)

As _#lookup(Bookmark)_ , but down-casting to the specified type.

[#bookmarkForElseFail_Object]
=== bookmarkForElseFail(Object)

As per _#bookmarkFor(Object)_ , but requires that a non-null xref:refguide:applib:index/services/bookmark/Bookmark.adoc[Bookmark] is returned.

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

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