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.Collection; 020import java.util.List; 021import java.util.Optional; 022 023import org.xml.sax.ContentHandler; 024import org.xml.sax.SAXException; 025 026import org.ametys.plugins.repository.data.DataComment; 027import org.ametys.plugins.repository.data.external.ExternalizableDataProvider.ExternalizableDataStatus; 028import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder; 029import org.ametys.plugins.repository.data.holder.impl.DefaultModelAwareDataHolder; 030import org.ametys.plugins.repository.data.repositorydata.RepositoryData; 031import org.ametys.runtime.model.ModelItem; 032import org.ametys.runtime.model.ModelItemContainer; 033import org.ametys.runtime.model.ModelItemGroup; 034import org.ametys.runtime.model.exception.BadDataPathCardinalityException; 035import org.ametys.runtime.model.exception.BadItemTypeException; 036import org.ametys.runtime.model.exception.UndefinedItemPathException; 037import org.ametys.runtime.model.type.DataContext; 038 039/** 040 * Class for model aware repeater entries 041 */ 042public class ModelAwareRepeaterEntry extends AbstractRepeaterEntry implements ModelAwareDataHolder 043{ 044 /** the default implementation of a {@link ModelAwareDataHolder} to use */ 045 protected ModelAwareDataHolder _defaultDataHolder; 046 047 /** the repeater containing this entry */ 048 protected ModelAwareRepeater _repeater; 049 050 /** the definition of this repeater entry */ 051 protected ModelItemGroup _definition; 052 053 /** 054 * Creates a model aware repeater entry 055 * @param repositoryData the repository data of the repeater entry 056 * @param repeater the repeater containing this entry 057 * @param definition the definition of the repeater 058 */ 059 public ModelAwareRepeaterEntry(RepositoryData repositoryData, ModelAwareRepeater repeater, ModelItemGroup definition) 060 { 061 super(repositoryData); 062 _defaultDataHolder = new DefaultModelAwareDataHolder(repositoryData, Optional.of(repeater.getParentDataHolder()), Optional.of(repeater.getRootDataHolder()), definition); 063 _repeater = repeater; 064 _definition = definition; 065 } 066 067 public ModelAwareComposite getComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 068 { 069 return getDefaultDataHolder().getComposite(compositePath); 070 } 071 072 public ModelAwareComposite getLocalComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 073 { 074 return getDefaultDataHolder().getLocalComposite(compositePath); 075 } 076 077 public ModelAwareComposite getExternalComposite(String compositePath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 078 { 079 return getDefaultDataHolder().getExternalComposite(compositePath); 080 } 081 082 public ModelAwareRepeater getRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 083 { 084 return getDefaultDataHolder().getRepeater(repeaterPath); 085 } 086 087 public ModelAwareRepeater getLocalRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 088 { 089 return getDefaultDataHolder().getLocalRepeater(repeaterPath); 090 } 091 092 public ModelAwareRepeater getExternalRepeater(String repeaterPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 093 { 094 return getDefaultDataHolder().getExternalRepeater(repeaterPath); 095 } 096 097 public <T> T getValue(String dataPath, boolean allowMultiValuedPathSegments) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 098 { 099 return getDefaultDataHolder().getValue(dataPath, allowMultiValuedPathSegments); 100 } 101 102 public <T> T getValue(String dataPath, boolean useDefaultFromModel, T defaultValue) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 103 { 104 return getDefaultDataHolder().getValue(dataPath, useDefaultFromModel, defaultValue); 105 } 106 107 public <T> T getLocalValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 108 { 109 return getDefaultDataHolder().getLocalValue(dataPath); 110 } 111 112 public <T> T getExternalValue(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException 113 { 114 return getDefaultDataHolder().getExternalValue(dataPath); 115 } 116 117 public ExternalizableDataStatus getStatus(String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadDataPathCardinalityException 118 { 119 return getDefaultDataHolder().getStatus(dataPath); 120 } 121 122 public List<DataComment> getComments(String dataName) throws IllegalArgumentException, UndefinedItemPathException 123 { 124 return getDefaultDataHolder().getComments(dataName); 125 } 126 127 public boolean hasLocalValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException 128 { 129 return getDefaultDataHolder().hasLocalValue(dataPath); 130 } 131 132 public boolean hasExternalValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException 133 { 134 return getDefaultDataHolder().hasExternalValue(dataPath); 135 } 136 137 public boolean hasNonEmptyLocalValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException 138 { 139 return getDefaultDataHolder().hasNonEmptyLocalValue(dataPath); 140 } 141 142 public boolean hasNonEmptyExternalValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException 143 { 144 return getDefaultDataHolder().hasNonEmptyExternalValue(dataPath); 145 } 146 147 public boolean hasComments(String dataName) throws IllegalArgumentException, UndefinedItemPathException 148 { 149 return getDefaultDataHolder().hasComments(dataName); 150 } 151 152 public Collection< ? extends ModelItemContainer> getModel() 153 { 154 return getDefaultDataHolder().getModel(); 155 } 156 157 public ModelItem getDefinition(String path) throws IllegalArgumentException, UndefinedItemPathException 158 { 159 return getDefaultDataHolder().getDefinition(path); 160 } 161 162 public boolean hasDefinition(String path) throws IllegalArgumentException 163 { 164 return getDefaultDataHolder().hasDefinition(path); 165 } 166 167 public void dataToSAX(ContentHandler contentHandler, String dataPath, DataContext context) throws SAXException, IOException 168 { 169 getDefaultDataHolder().dataToSAX(contentHandler, dataPath, context); 170 } 171 172 public Optional<? extends ModelAwareDataHolder> getParentDataHolder() 173 { 174 return getDefaultDataHolder().getParentDataHolder(); 175 } 176 177 public ModelAwareDataHolder getRootDataHolder() 178 { 179 return getDefaultDataHolder().getRootDataHolder(); 180 } 181 182 @Override 183 protected ModelAwareDataHolder getDefaultDataHolder() 184 { 185 return _defaultDataHolder; 186 } 187}