001/* 002 * Copyright 2011 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.blog.repository; 017 018import org.ametys.plugins.repository.AmetysObject; 019import org.ametys.plugins.repository.AmetysObjectIterable; 020import org.ametys.plugins.repository.AmetysObjectIterator; 021import org.ametys.plugins.repository.AmetysRepositoryException; 022import org.ametys.plugins.repository.data.holder.ModelLessDataHolder; 023import org.ametys.web.repository.page.Page; 024import org.ametys.web.repository.page.Zone; 025import org.ametys.web.repository.page.ZoneItem; 026 027/** 028 * Wrapper to present a modifiable zone into a unmodifiable one. 029 */ 030public class StaticZone implements Zone 031{ 032 033 /** The wrapped zone. */ 034 protected Zone _zone; 035 036 /** 037 * Construct a static zone, wrapping a given zone. 038 * @param zone the zone to wrap. 039 */ 040 public StaticZone(Zone zone) 041 { 042 _zone = zone; 043 } 044 045 public ModelLessDataHolder getDataHolder() 046 { 047 return _zone.getDataHolder(); 048 } 049 050 @Override 051 public String getName() throws AmetysRepositoryException 052 { 053 return _zone.getName(); 054 } 055 056 @Override 057 public String getPath() throws AmetysRepositoryException 058 { 059 return _zone.getPath(); 060 } 061 062 @Override 063 public String getId() throws AmetysRepositoryException 064 { 065 return _zone.getId(); 066 } 067 068 @Override 069 public <A extends AmetysObject> A getParent() throws AmetysRepositoryException 070 { 071 return _zone.getParent(); 072 } 073 074 @Override 075 public String getParentPath() throws AmetysRepositoryException 076 { 077 return _zone.getParentPath(); 078 } 079 080 @Override 081 public AmetysObjectIterable< ? extends ZoneItem> getZoneItems() throws AmetysRepositoryException 082 { 083 return new StaticZoneItemIterable(_zone.getZoneItems()); 084 } 085 086 @Override 087 public Page getPage() 088 { 089 return _zone.getPage(); 090 } 091 092 /** 093 * Static zone item iterable. 094 */ 095 protected class StaticZoneItemIterable implements AmetysObjectIterable<StaticZoneItem> 096 { 097 098 /** The wrapped iterable. */ 099 protected AmetysObjectIterable<? extends ZoneItem> _iterable; 100 101 /** 102 * Construct a StaticZoneItemIterable, wrapping an iterable. 103 * @param iterable zone item iterable. 104 */ 105 public StaticZoneItemIterable(AmetysObjectIterable<? extends ZoneItem> iterable) 106 { 107 _iterable = iterable; 108 } 109 110 @Override 111 public AmetysObjectIterator<StaticZoneItem> iterator() 112 { 113 return new StaticZoneItemIterator(_iterable.iterator()); 114 } 115 116 @Override 117 public long getSize() 118 { 119 return _iterable.getSize(); 120 } 121 122 @Override 123 public void close() 124 { 125 _iterable.close(); 126 } 127 128 } 129 130 class StaticZoneItemIterator implements AmetysObjectIterator<StaticZoneItem> 131 { 132 AmetysObjectIterator<? extends ZoneItem> _it; 133 134 public StaticZoneItemIterator(AmetysObjectIterator<? extends ZoneItem> it) 135 { 136 _it = it; 137 } 138 139 public boolean hasNext() 140 { 141 return _it.hasNext(); 142 } 143 144 public StaticZoneItem next() 145 { 146 return new StaticZoneItem(_it.next()); 147 } 148 149 public void skip(long skipNum) 150 { 151 _it.skip(skipNum); 152 } 153 154 public long getPosition() 155 { 156 return _it.getPosition(); 157 } 158 159 public long getSize() 160 { 161 return _it.getSize(); 162 } 163 164 public void remove() 165 { 166 _it.remove(); 167 } 168 } 169}