001/* 002 * Copyright 2020 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.runtime.model; 017 018import java.util.Optional; 019 020/** 021 * Object that gives some context for definitions manipulation 022 */ 023public final class DefinitionContext 024{ 025 private Optional<Object> _object = Optional.empty(); 026 private boolean _isEdition; 027 028 private DefinitionContext() 029 { 030 // Empty private constructor 031 } 032 033 /** 034 * Creates a new instance of a {@link DefinitionContext} 035 * @return the created instance 036 */ 037 public static DefinitionContext newInstance() 038 { 039 return new DefinitionContext(); 040 } 041 042 /** 043 * Retrieves the context object for the definition 044 * @return the context object 045 */ 046 public Optional<Object> getObject() 047 { 048 return _object; 049 } 050 051 /** 052 * Set the context object 053 * @param object the context object to set 054 * @return the current {@link DefinitionContext} 055 */ 056 public DefinitionContext withObject(Object object) 057 { 058 _object = Optional.ofNullable(object); 059 return this; 060 } 061 062 /** 063 * Checks if the context is in edition 064 * @return <code>true</code> if the context is in edition, <code>false</code> otherwise 065 */ 066 public boolean isEdition() 067 { 068 return _isEdition; 069 } 070 071 /** 072 * Set to <code>true</code> if the context is in edition (default to <code>false</code>) 073 * @param isEdition <code>true</code> if the context is in edition, <code>false</code> otherwise 074 * @return the current {@link DefinitionContext} 075 */ 076 public DefinitionContext withEdition(boolean isEdition) 077 { 078 _isEdition = isEdition; 079 return this; 080 } 081}