001/* 002 * Copyright 2018 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.repository.data.holder.group.impl; 017 018import java.io.IOException; 019import java.util.Map; 020import java.util.Optional; 021 022import org.ametys.plugins.repository.data.UnknownDataException; 023import org.ametys.plugins.repository.data.holder.DataHolder; 024import org.ametys.plugins.repository.data.holder.ModifiableModelLessDataHolder; 025import org.ametys.plugins.repository.data.holder.group.ModifiableComposite; 026import org.ametys.plugins.repository.data.holder.impl.DefaultModifiableModelLessDataHolder; 027import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData; 028import org.ametys.plugins.repository.data.type.RepositoryModelItemType; 029import org.ametys.runtime.model.exception.BadDataPathCardinalityException; 030import org.ametys.runtime.model.exception.BadItemTypeException; 031import org.ametys.runtime.model.exception.NotUniqueTypeException; 032import org.ametys.runtime.model.exception.UnknownTypeException; 033import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint; 034 035/** 036 * Class for modifiable model free composites 037 */ 038public class ModifiableModelLessComposite extends ModelLessComposite implements ModifiableComposite, ModifiableModelLessDataHolder 039{ 040 /** The modifiable repository data of this composite */ 041 protected ModifiableRepositoryData _modifiableRepositoryData; 042 043 /** the default implementation of a {@link ModifiableModelLessDataHolder} to use */ 044 protected ModifiableModelLessDataHolder _modifiableDefaultDataHolder; 045 046 /** 047 * Creates a modifiable model free composite 048 * @param typeExtensionPoint the extension point to use to get available element types 049 * @param repositoryData the repository data to use 050 * @param parent the parent of the created {@link DataHolder} 051 * @param root the root {@link DataHolder} 052 */ 053 public ModifiableModelLessComposite(AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> typeExtensionPoint, ModifiableRepositoryData repositoryData, ModifiableModelLessDataHolder parent, ModifiableModelLessDataHolder root) 054 { 055 super(typeExtensionPoint, repositoryData, parent, root); 056 _modifiableRepositoryData = repositoryData; 057 _modifiableDefaultDataHolder = new DefaultModifiableModelLessDataHolder(typeExtensionPoint, repositoryData, Optional.of(parent), Optional.of(root)); 058 } 059 060 @Override 061 public ModifiableModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException 062 { 063 return (ModifiableModelLessComposite) super.getComposite(compositePath); 064 } 065 066 public ModifiableModelLessComposite getComposite(String compositePath, boolean createNew) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException 067 { 068 return getDefaultDataHolder().getComposite(compositePath, createNew); 069 } 070 071 public boolean synchronizeValues(Map<String, Object> values) throws IOException 072 { 073 return getDefaultDataHolder().synchronizeValues(values); 074 } 075 076 public void setValue(String dataPath, Object value) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, UnknownDataException, BadDataPathCardinalityException 077 { 078 getDefaultDataHolder().setValue(dataPath, value); 079 } 080 081 public void setValue(String dataPath, Object value, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, UnknownDataException, BadDataPathCardinalityException 082 { 083 getDefaultDataHolder().setValue(dataPath, value, dataTypeId); 084 } 085 086 public void removeValue(String dataPath) throws IllegalArgumentException, UnknownDataException, BadDataPathCardinalityException 087 { 088 getDefaultDataHolder().removeValue(dataPath); 089 } 090 091 @Override 092 public Optional<? extends ModifiableModelLessDataHolder> getParentDataHolder() 093 { 094 return getDefaultDataHolder().getParentDataHolder(); 095 } 096 097 @Override 098 public ModifiableModelLessDataHolder getRootDataHolder() 099 { 100 return getDefaultDataHolder().getRootDataHolder(); 101 } 102 103 @Override 104 protected ModifiableModelLessDataHolder getDefaultDataHolder() 105 { 106 return _modifiableDefaultDataHolder; 107 } 108 109 @Override 110 public ModifiableRepositoryData getRepositoryData() 111 { 112 return _modifiableRepositoryData; 113 } 114}