001/* 002 * Copyright 2024 Anyware Services 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.ametys.plugins.pagesubscription.context; 017 018import java.util.HashMap; 019import java.util.Map; 020 021import org.ametys.plugins.pagesubscription.type.SubscriptionType; 022 023/** 024 * Class to represent a context for {@link SubscriptionType} 025 */ 026public class SubscriptionContext 027{ 028 /** The map of parameters */ 029 protected Map<String, Object> _contextParameters; 030 031 /** 032 * Creates a new instance of a {@link SubscriptionContext} 033 */ 034 protected SubscriptionContext() 035 { 036 _contextParameters = new HashMap<>(); 037 } 038 039 /** 040 * Creates a new instance of a {@link SubscriptionContext} 041 * @return the created instance 042 */ 043 public static SubscriptionContext newInstance() 044 { 045 return new SubscriptionContext(); 046 } 047 048 /** 049 * Add a parameter to the context 050 * @param <T> the {@link SubscriptionContext} 051 * @param key the parameter key 052 * @param value the parameter value 053 * @return the context 054 */ 055 @SuppressWarnings("unchecked") 056 public <T extends SubscriptionContext> T addParameter(String key, Object value) 057 { 058 _contextParameters.put(key, value); 059 return (T) this; 060 } 061 062 /** 063 * Add parameters to the context 064 * @param <T> the {@link SubscriptionContext} 065 * @param parameters the parameters 066 * @return the context 067 */ 068 @SuppressWarnings("unchecked") 069 public <T extends SubscriptionContext> T addParameters(Map<String, Object> parameters) 070 { 071 _contextParameters.putAll(parameters); 072 return (T) this; 073 } 074 075 /** 076 * Get the parameter value 077 * @param key the parameter key 078 * @return the parameter value 079 */ 080 public Object getParameterValue(String key) 081 { 082 return _contextParameters.get(key); 083 } 084}