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.Map;
019
020import org.apache.cocoon.ProcessingException;
021
022import org.ametys.runtime.i18n.I18nizableText;
023
024/**
025 * Reference to a view to included in another view.
026 * Use this temporary reference only in view parsers, and resolve it before using the first view
027 */
028public class TemporaryViewReference implements ViewItem
029{
030    private String _name;
031
032    public void setName(String name)
033    {
034        _name = name;
035    }
036    
037    public String getName()
038    {
039        return _name;
040    }
041
042    public void setLabel(I18nizableText label)
043    {
044        throw new UnsupportedOperationException("Cannot set a label to a view reference");
045    }
046
047    public void setDescription(I18nizableText description)
048    {
049        throw new UnsupportedOperationException("Cannot set a description to a view reference");
050    }
051
052    public I18nizableText getLabel()
053    {
054        throw new UnsupportedOperationException("Cannot get a label from a view reference");
055    }
056
057    public I18nizableText getDescription()
058    {
059        throw new UnsupportedOperationException("Cannot get a description from a view reference");
060    }
061
062    public Map<String, Object> toJSON(DefinitionContext context) throws ProcessingException
063    {
064        throw new UnsupportedOperationException("Cannot convert a view reference to JSON");
065    }
066    
067    public boolean equals(Object obj, boolean checkDetails)
068    {
069        throw new UnsupportedOperationException("Cannot compare view references");
070    }
071
072    public ViewItem createInstance()
073    {
074        return new TemporaryViewReference();
075    }
076
077    public void copyTo(ViewItem item)
078    {
079        assert item instanceof TemporaryViewReference;
080        item.setName(getName());
081    }
082
083}