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