001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2012-2015 ForgeRock AS.
015 */
016
017package org.forgerock.services.context;
018
019
020import static org.forgerock.util.Reject.checkNotNull;
021
022import org.forgerock.json.JsonValue;
023import org.forgerock.util.generator.IdGenerator;
024
025/**
026 * A {@link Context} which has an a globally unique ID but no parent. All request context
027 * chains are terminated by a {@link RootContext} as the top-most context.
028 */
029public final class RootContext extends AbstractContext {
030
031    /**
032     * Construct a new {@link RootContext} with the default {@code IdGenerator}.
033     *
034     * @see IdGenerator#DEFAULT
035     */
036    public RootContext() {
037        this(IdGenerator.DEFAULT.generate());
038    }
039
040    /**
041     * Construct a new {@link RootContext} with the given {@code id} (uniqueness is not verified).
042     * @param id context identifier (uniqueness is not verified, cannot be {@code null})
043     */
044    public RootContext(String id) {
045        // No parent
046        super(checkNotNull(id, "The identifier can't be null."), "root", null);
047    }
048
049    /**
050     * Restore from JSON representation.
051     *
052     * @param savedContext
053     *            The JSON representation from which this context's attributes
054     *            should be parsed.
055     * @param classLoader
056     *            The ClassLoader which can properly resolve the persisted class-name.
057     */
058    public RootContext(final JsonValue savedContext, final ClassLoader classLoader) {
059        super(savedContext, classLoader);
060    }
061
062}