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.Optional; 020 021import org.xml.sax.ContentHandler; 022import org.xml.sax.SAXException; 023 024import org.ametys.plugins.repository.data.UnknownDataException; 025import org.ametys.plugins.repository.data.holder.DataHolder; 026import org.ametys.plugins.repository.data.holder.ModelLessDataHolder; 027import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder; 028import org.ametys.plugins.repository.data.repositorydata.RepositoryData; 029import org.ametys.plugins.repository.data.type.RepositoryModelItemType; 030import org.ametys.runtime.model.exception.BadDataPathCardinalityException; 031import org.ametys.runtime.model.exception.BadItemTypeException; 032import org.ametys.runtime.model.exception.NotUniqueTypeException; 033import org.ametys.runtime.model.exception.UnknownTypeException; 034import org.ametys.runtime.model.type.DataContext; 035import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint; 036 037/** 038 * Class for model free composites 039 */ 040public class ModelLessComposite extends AbstractComposite implements ModelLessDataHolder 041{ 042 /** the default implementation of a {@link ModelLessDataHolder} to use */ 043 protected ModelLessDataHolder _defaultDataHolder; 044 045 /** 046 * Creates a model free composite 047 * @param typeExtensionPoint the extension point to use to get available element types 048 * @param parent the parent of the created {@link DataHolder} 049 * @param root the root {@link DataHolder} 050 * @param repositoryData the repository data to use 051 */ 052 public ModelLessComposite(AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> typeExtensionPoint, RepositoryData repositoryData, ModelLessDataHolder parent, ModelLessDataHolder root) 053 { 054 super(repositoryData); 055 _defaultDataHolder = new DefaultModelLessDataHolder(typeExtensionPoint, repositoryData, Optional.of(parent), Optional.of(root)); 056 } 057 058 public ModelLessComposite getComposite(String compositePath) throws IllegalArgumentException, BadItemTypeException, BadDataPathCardinalityException 059 { 060 return getDefaultDataHolder().getComposite(compositePath); 061 } 062 063 public <T> T getValue(String dataPath) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException 064 { 065 return getDefaultDataHolder().getValue(dataPath); 066 } 067 068 public <T> T getValue(String dataPath, T defaultValue) throws IllegalArgumentException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException 069 { 070 return getDefaultDataHolder().getValue(dataPath, defaultValue); 071 } 072 073 public <T> T getValueOfType(String dataPath, String dataTypeId) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException 074 { 075 return getDefaultDataHolder().getValueOfType(dataPath, dataTypeId); 076 } 077 078 public <T> T getValueOfType(String dataPath, String dataTypeId, T defaultValue) throws IllegalArgumentException, UnknownTypeException, BadItemTypeException, BadDataPathCardinalityException 079 { 080 return getDefaultDataHolder().getValueOfType(dataPath, dataTypeId, defaultValue); 081 } 082 083 public boolean isMultiple(String dataPath) throws IllegalArgumentException, UnknownDataException, BadDataPathCardinalityException 084 { 085 return getDefaultDataHolder().isMultiple(dataPath); 086 } 087 088 public RepositoryModelItemType getType(String dataPath) throws IllegalArgumentException, UnknownDataException, UnknownTypeException, NotUniqueTypeException, BadDataPathCardinalityException 089 { 090 return getDefaultDataHolder().getType(dataPath); 091 } 092 093 public void dataToSAX(ContentHandler contentHandler, String dataPath, DataContext context) throws SAXException, IOException 094 { 095 getDefaultDataHolder().dataToSAX(contentHandler, dataPath, context); 096 } 097 098 public void dataToSAX(ContentHandler contentHandler, DataContext context) throws SAXException, IOException, UnknownTypeException, NotUniqueTypeException 099 { 100 getDefaultDataHolder().dataToSAX(contentHandler, context); 101 } 102 103 public Optional<? extends ModelLessDataHolder> getParentDataHolder() 104 { 105 return getDefaultDataHolder().getParentDataHolder(); 106 } 107 108 public ModelLessDataHolder getRootDataHolder() 109 { 110 return getDefaultDataHolder().getRootDataHolder(); 111 } 112 113 @Override 114 protected ModelLessDataHolder getDefaultDataHolder() 115 { 116 return _defaultDataHolder; 117 } 118}