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