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; 020 021import org.xml.sax.ContentHandler; 022import org.xml.sax.SAXException; 023 024import org.ametys.plugins.repository.data.holder.DataHolder; 025import org.ametys.plugins.repository.data.holder.ModifiableDataHolder; 026import org.ametys.plugins.repository.data.holder.group.Composite; 027import org.ametys.plugins.repository.data.repositorydata.RepositoryData; 028import org.ametys.runtime.model.exception.BadDataPathCardinalityException; 029import org.ametys.runtime.model.exception.BadItemTypeException; 030import org.ametys.runtime.model.exception.NotUniqueTypeException; 031import org.ametys.runtime.model.exception.UndefinedItemPathException; 032import org.ametys.runtime.model.exception.UnknownTypeException; 033 034/** 035 * Abstract class for composites 036 */ 037public abstract class AbstractComposite implements Composite 038{ 039 /** The repository data of the repeater entry */ 040 protected RepositoryData _repositoryData; 041 042 /** 043 * Creates a repeater entry 044 * @param repositoryData the repository data of the repeater entry 045 */ 046 public AbstractComposite(RepositoryData repositoryData) 047 { 048 _repositoryData = repositoryData; 049 } 050 051 public boolean hasValue(String dataPath) throws IllegalArgumentException, BadDataPathCardinalityException 052 { 053 return getDefaultDataHolder().hasValue(dataPath); 054 } 055 056 public boolean hasNonEmptyValue(String dataPath) throws IllegalArgumentException 057 { 058 return getDefaultDataHolder().hasNonEmptyValue(dataPath); 059 } 060 061 public Collection<String> getDataNames() 062 { 063 return getDefaultDataHolder().getDataNames(); 064 } 065 066 public void copyTo(ModifiableDataHolder dataHolder) throws UndefinedItemPathException, BadItemTypeException, UnknownTypeException, NotUniqueTypeException 067 { 068 getDefaultDataHolder().copyTo(dataHolder); 069 } 070 071 public void dataToSAX(ContentHandler contentHandler, String dataPath) throws SAXException, IOException 072 { 073 getDefaultDataHolder().dataToSAX(contentHandler, dataPath); 074 } 075 076 /** 077 * Retrieves the default implementation of a {@link DataHolder} to use 078 * @return the {@link DataHolder} 079 */ 080 protected abstract DataHolder getDefaultDataHolder(); 081 082 public RepositoryData getRepositoryData() 083 { 084 return _repositoryData; 085 } 086}