001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.schematic;
017
018import org.modeshape.schematic.document.Document;
019
020/**
021 * A library of JSON documents.
022 * 
023 * @author Randall Hauch <rhauch@redhat.com> (C) 2011 Red Hat Inc.
024 */
025public interface DocumentLibrary {
026
027    /**
028     * Get the name of this library.
029     * 
030     * @return the library name; never null
031     */
032    String getName();
033
034    /**
035     * Get the document with the supplied key.
036     * 
037     * @param key the key or identifier for the document
038     * @return the document, or null if there was no document with the supplied key
039     */
040    Document get( String key );
041
042    /**
043     * Store the supplied document at the given key.
044     * 
045     * @param key the key or identifier for the document
046     * @param document the document that is to be stored
047     * @return the document that was previously stored at this key, or null if there was no document with the supplied key
048     */
049    Document put( String key,
050                  Document document );
051
052    /**
053     * Store the supplied document at the given key.
054     * 
055     * @param key the key or identifier for the document
056     * @param document the document that is to be stored
057     * @return the document that was previously stored at this key, or null if there was no document with the supplied key
058     */
059    Document putIfAbsent( String key,
060                          Document document );
061
062    /**
063     * Replace the existing document at the given key with the document that is supplied. This method does nothing if there is no
064     * document at the given key.
065     * 
066     * @param key the key or identifier for the document
067     * @param document the document that is to replace the existing document
068     * @return the document that was replaced, or null if nothing was replaced
069     */
070    Document replace( String key,
071                      Document document );
072
073    /**
074     * Remove the existing document at the given key.
075     * 
076     * @param key the key or identifier for the document
077     * @return the document that was removed, or null if there was no document with the supplied key
078     */
079    Document remove( String key );
080
081}