001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.orm.hibernate.tuplizer.proxy; 020 021import java.util.Iterator; 022import java.util.Set; 023 024import lucee.commons.lang.ExceptionUtil; 025import lucee.runtime.Component; 026import lucee.runtime.PageContext; 027import lucee.runtime.component.Member; 028import lucee.runtime.component.Property; 029import lucee.runtime.dump.DumpData; 030import lucee.runtime.dump.DumpProperties; 031import lucee.runtime.orm.hibernate.CommonUtil; 032import lucee.runtime.type.Struct; 033 034/* 035 * this implementation "simulates" all ComponentPro methods from core 036 */ 037 038public abstract class ComponentProReflectionProxy extends ComponentProxy { 039 040 private static final long serialVersionUID = -7646935560408716588L; 041 042 043 044 public Property[] getProperties(boolean onlyPeristent, boolean includeBaseProperties, boolean overrideProperties, boolean inheritedMappedSuperClassOnly) { 045 return getProperties(getComponent(), onlyPeristent, includeBaseProperties, overrideProperties, inheritedMappedSuperClassOnly); 046 } 047 048 049 public static Property[] getProperties(Component c, boolean onlyPeristent, boolean includeBaseProperties, boolean overrideProperties, boolean inheritedMappedSuperClassOnly) { 050 try{ 051 java.lang.reflect.Method m = c.getClass().getMethod("getProperties", new Class[]{boolean.class, boolean.class, boolean.class , boolean.class}); 052 return (Property[])m.invoke(c, new Object[]{onlyPeristent, includeBaseProperties, overrideProperties, inheritedMappedSuperClassOnly}); 053 } 054 catch(Throwable t){ 055 ExceptionUtil.rethrowIfNecessary(t); 056 throw new RuntimeException(t); 057 } 058 } 059 060 public boolean isPersistent() { 061 return isPersistent(getComponent()); 062 } 063 064 public static boolean isPersistent(Component c) { 065 try{ 066 java.lang.reflect.Method m = c.getClass().getMethod("isPersistent", new Class[]{}); 067 return CommonUtil.toBooleanValue(m.invoke(c, new Object[]{})); 068 } 069 catch(Throwable t){ 070 ExceptionUtil.rethrowIfNecessary(t); 071 throw new RuntimeException(t); 072 } 073 } 074 075 public boolean isAccessors() { 076 Component c = getComponent(); 077 try{ 078 java.lang.reflect.Method m = c.getClass().getMethod("isAccessors", new Class[]{}); 079 return CommonUtil.toBooleanValue(m.invoke(c, new Object[]{})); 080 } 081 catch(Throwable t){ 082 ExceptionUtil.rethrowIfNecessary(t); 083 throw new RuntimeException(t); 084 } 085 } 086 087 public Object getMetaStructItem(Key name) { 088 return getMetaStructItem(getComponent(), name); 089 } 090 091 public static Object getMetaStructItem(Component c, Key name) { 092 try{ 093 java.lang.reflect.Method m = c.getClass().getMethod("getMetaStructItem", new Class[]{Key.class}); 094 return m.invoke(c, new Object[]{name}); 095 } 096 catch(Throwable t){ 097 ExceptionUtil.rethrowIfNecessary(t); 098 throw new RuntimeException(t); 099 } 100 } 101 102 public Set<Key> keySet(int access) { 103 Component c = getComponent(); 104 try{ 105 java.lang.reflect.Method m = c.getClass().getMethod("keySet", new Class[]{int.class}); 106 return (Set<Key>)m.invoke(c, new Object[]{access}); 107 } 108 catch(Throwable t){ 109 ExceptionUtil.rethrowIfNecessary(t); 110 throw new RuntimeException(t); 111 } 112 } 113 114 public Object call(PageContext pc, int access, Key name, Object[] args) { 115 Component c = getComponent(); 116 try{ 117 java.lang.reflect.Method m = c.getClass().getMethod("call", new Class[]{PageContext.class, int.class, Key.class, Object[].class}); 118 return m.invoke(c, new Object[]{pc, access, name, args}); 119 } 120 catch(Throwable t){ 121 ExceptionUtil.rethrowIfNecessary(t); 122 throw new RuntimeException(t); 123 } 124 } 125 126 public Object callWithNamedValues(PageContext pc, int access, Key name, Struct args) { 127 Component c = getComponent(); 128 try{ 129 java.lang.reflect.Method m = c.getClass().getMethod("callWithNamedValues", new Class[]{PageContext.class, int.class, Key.class, Struct.class}); 130 return m.invoke(c, new Object[]{pc, access, name, args}); 131 } 132 catch(Throwable t){ 133 ExceptionUtil.rethrowIfNecessary(t); 134 throw new RuntimeException(t); 135 } 136 } 137 138 public int size(int access) { 139 Component c = getComponent(); 140 try{ 141 java.lang.reflect.Method m = c.getClass().getMethod("size", new Class[]{int.class}); 142 return CommonUtil.toIntValue(m.invoke(c, new Object[]{access})); 143 } 144 catch(Throwable t){ 145 ExceptionUtil.rethrowIfNecessary(t); 146 throw new RuntimeException(t); 147 } 148 } 149 150 public Key[] keys(int access) { 151 Component c = getComponent(); 152 try{ 153 java.lang.reflect.Method m = c.getClass().getMethod("keys", new Class[]{int.class}); 154 return (Key[]) m.invoke(c, new Object[]{access}); 155 } 156 catch(Throwable t){ 157 ExceptionUtil.rethrowIfNecessary(t); 158 throw new RuntimeException(t); 159 } 160 } 161 162 public Iterator<Entry<Key, Object>> entryIterator(int access) { 163 Component c = getComponent(); 164 try{ 165 java.lang.reflect.Method m = c.getClass().getMethod("entryIterator", new Class[]{int.class}); 166 return (Iterator<Entry<Key, Object>>)m.invoke(c, new Object[]{access}); 167 } 168 catch(Throwable t){ 169 ExceptionUtil.rethrowIfNecessary(t); 170 throw new RuntimeException(t); 171 } 172 } 173 174 public Iterator<Object> valueIterator(int access) { 175 Component c = getComponent(); 176 try{ 177 java.lang.reflect.Method m = c.getClass().getMethod("valueIterator", new Class[]{int.class}); 178 return (Iterator<Object>)m.invoke(c, new Object[]{access}); 179 } 180 catch(Throwable t){ 181 ExceptionUtil.rethrowIfNecessary(t); 182 throw new RuntimeException(t); 183 } 184 } 185 186 187 public Object get(int access, Key key) { 188 Component c = getComponent(); 189 try{ 190 java.lang.reflect.Method m = c.getClass().getMethod("get", new Class[]{int.class,Key.class}); 191 return m.invoke(c, new Object[]{access,key}); 192 } 193 catch(Throwable t){ 194 ExceptionUtil.rethrowIfNecessary(t); 195 throw new RuntimeException(t); 196 } 197 } 198 199 public Object get(int access, Key key, Object defaultValue) { 200 Component c = getComponent(); 201 try{ 202 java.lang.reflect.Method m = c.getClass().getMethod("get", new Class[]{int.class,Key.class,Object.class}); 203 return m.invoke(c, new Object[]{access,key,defaultValue}); 204 } 205 catch(Throwable t){ 206 ExceptionUtil.rethrowIfNecessary(t); 207 throw new RuntimeException(t); 208 } 209 } 210 211 public Iterator<Key> keyIterator(int access) { 212 Component c = getComponent(); 213 try{ 214 java.lang.reflect.Method m = c.getClass().getMethod("keyIterator", new Class[]{int.class}); 215 return (Iterator<Key>) m.invoke(c, new Object[]{access}); 216 } 217 catch(Throwable t){ 218 ExceptionUtil.rethrowIfNecessary(t); 219 throw new RuntimeException(t); 220 } 221 } 222 223 public Iterator<String> keysAsStringIterator(int access) { 224 Component c = getComponent(); 225 try{ 226 java.lang.reflect.Method m = c.getClass().getMethod("keysAsStringIterator", new Class[]{int.class}); 227 return (Iterator<String>) m.invoke(c, new Object[]{access}); 228 } 229 catch(Throwable t){ 230 ExceptionUtil.rethrowIfNecessary(t); 231 throw new RuntimeException(t); 232 } 233 } 234 235 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp, int access) { 236 Component c = getComponent(); 237 try{ 238 java.lang.reflect.Method m = c.getClass().getMethod("toDumpData", new Class[]{PageContext.class, int.class, DumpProperties.class, int.class}); 239 return (DumpData) m.invoke(c, new Object[]{pageContext, maxlevel, dp, access}); 240 } 241 catch(Throwable t){ 242 ExceptionUtil.rethrowIfNecessary(t); 243 throw new RuntimeException(t); 244 } 245 } 246 247 public boolean contains(int access, Key name) { 248 Component c = getComponent(); 249 try{ 250 java.lang.reflect.Method m = c.getClass().getMethod("contains", new Class[]{int.class, Key.class}); 251 return CommonUtil.toBooleanValue(m.invoke(c, new Object[]{access, name})); 252 } 253 catch(Throwable t){ 254 ExceptionUtil.rethrowIfNecessary(t); 255 throw new RuntimeException(t); 256 } 257 } 258 259 public Member getMember(int access, Key key, boolean dataMember, boolean superAccess) { 260 Component c = getComponent(); 261 try{ 262 java.lang.reflect.Method m = c.getClass().getMethod("getMember", new Class[]{int.class, Key.class, boolean.class, boolean.class}); 263 return (Member) m.invoke(c, new Object[]{access, key, dataMember, superAccess}); 264 } 265 catch(Throwable t){ 266 ExceptionUtil.rethrowIfNecessary(t); 267 throw new RuntimeException(t); 268 } 269 } 270 271 public void setEntity(boolean entity) { 272 setEntity(getComponent(), entity); 273 } 274 275 public static void setEntity(Component c, boolean entity) { 276 try{ 277 java.lang.reflect.Method m = c.getClass().getMethod("setEntity", new Class[]{boolean.class}); 278 m.invoke(c, new Object[]{entity}); 279 return; 280 } 281 catch(Throwable t){ 282 ExceptionUtil.rethrowIfNecessary(t); 283 throw new RuntimeException(t); 284 } 285 } 286 287 public boolean isEntity() { 288 Component c = getComponent(); 289 try{ 290 java.lang.reflect.Method m = c.getClass().getMethod("isEntity", new Class[]{}); 291 return CommonUtil.toBooleanValue(m.invoke(c, new Object[]{})); 292 } 293 catch(Throwable t){ 294 ExceptionUtil.rethrowIfNecessary(t); 295 throw new RuntimeException(t); 296 } 297 } 298 299 public Component getBaseComponent() { 300 Component c = getComponent(); 301 try{ 302 java.lang.reflect.Method m = c.getClass().getMethod("getBaseComponent", new Class[]{}); 303 return (Component)m.invoke(c, new Object[]{}); 304 } 305 catch(Throwable t){ 306 ExceptionUtil.rethrowIfNecessary(t); 307 throw new RuntimeException(t); 308 } 309 } 310}