001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * docs/licenses/cddl.txt 011 * or http://www.opensource.org/licenses/cddl1.php. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * docs/licenses/cddl.txt. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2013-2014 UnboundID Corp. 026 */ 027 package com.unboundid.directory.sdk.common.types; 028 029 030 /** 031 * Context used to provide named objects to Velocity templates as they are 032 * they are used to render output. Objects stored in context are available 033 * to templates as they are rendered using variable references like 034 * '$variable'. 035 * 036 * See http://velocity.apache.org/ for more information on using Velocity. 037 */ 038 public interface VelocityContext 039 { 040 041 042 /** 043 * Indicates whether a call to {@code put} will update this context 044 * if a value already exists in the context by the specified key. 045 * 046 * @return boolean where true indicates overrides are permitted. 047 */ 048 boolean isPermitOverrides(); 049 050 051 052 /** 053 * Adds a named object to this context. If overrides are not permitted 054 * and an object already exists in this context for the given key this 055 * method will throw a runtime exception. Following a successful call 056 * to this method, the object will be available to templates using a 057 * reference like '$key'. 058 * 059 * @param key The key which which to store the object in context. 060 * Keys prefixed with a '_' are reserved for internal use. 061 * Attempting to set a named object using a key prefixed with 062 * '_' will throw a runtime exception. Likewise attempting to 063 * put a named object in this context with a previously used 064 * key in which overrides are not permitted with throw a 065 * runtime exception. 066 * 067 * @param value The context value. 068 * 069 * @return The old object or null if there was no old object. 070 */ 071 Object put(String key, Object value); 072 073 074 075 /** 076 * Gets the named object associated with a given key. 077 * 078 * @param key associated with the named object. 079 * 080 * @return The associated named object within this context or {@code null} 081 * if no object exists for the given key. 082 */ 083 Object get(String key); 084 085 086 087 /** 088 * Indicates whether a named object exists in this context for a given key. 089 * 090 * @param key to use for checking whether an associated object exists in 091 * this context. 092 * 093 * @return boolean where true indicates a named object exists for the given 094 * key. 095 */ 096 boolean containsKey(Object key); 097 098 099 100 /** 101 * Obtains an array of all keys for this context. 102 * 103 * @return array of all keys for this context. 104 */ 105 Object[] getKeys(); 106 107 108 109 /** 110 * Removes the value associated with the specified key from the context. 111 * 112 * @param key The name of the value to remove. 113 * 114 * @return The value the key was mapped to, or {@code null} the key 115 * was not previously associated with any named object in this 116 * context. 117 */ 118 Object remove(Object key); 119 120 }