001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.isis.core.metamodel.runtimecontext.noruntime; 021 022import java.util.Collections; 023import java.util.List; 024 025import org.apache.isis.applib.profiles.Localization; 026import org.apache.isis.applib.query.Query; 027import org.apache.isis.applib.services.bookmark.Bookmark; 028import org.apache.isis.core.commons.authentication.AuthenticationSession; 029import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider; 030import org.apache.isis.core.commons.authentication.AuthenticationSessionProviderAbstract; 031import org.apache.isis.core.metamodel.adapter.DomainObjectServices; 032import org.apache.isis.core.metamodel.adapter.DomainObjectServicesAbstract; 033import org.apache.isis.core.metamodel.adapter.LocalizationDefault; 034import org.apache.isis.core.metamodel.adapter.LocalizationProvider; 035import org.apache.isis.core.metamodel.adapter.LocalizationProviderAbstract; 036import org.apache.isis.core.metamodel.adapter.ObjectAdapter; 037import org.apache.isis.core.metamodel.adapter.ObjectDirtier; 038import org.apache.isis.core.metamodel.adapter.ObjectDirtierAbstract; 039import org.apache.isis.core.metamodel.adapter.ObjectPersistor; 040import org.apache.isis.core.metamodel.adapter.ObjectPersistorAbstract; 041import org.apache.isis.core.metamodel.adapter.QuerySubmitter; 042import org.apache.isis.core.metamodel.adapter.QuerySubmitterAbstract; 043import org.apache.isis.core.metamodel.adapter.ServicesProvider; 044import org.apache.isis.core.metamodel.adapter.ServicesProviderAbstract; 045import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager; 046import org.apache.isis.core.metamodel.adapter.mgr.AdapterManagerAbstract; 047import org.apache.isis.core.metamodel.adapter.oid.Oid; 048import org.apache.isis.core.metamodel.adapter.oid.TypedOid; 049import org.apache.isis.core.metamodel.deployment.DeploymentCategory; 050import org.apache.isis.core.metamodel.runtimecontext.RuntimeContextAbstract; 051import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector; 052import org.apache.isis.core.metamodel.spec.ObjectInstantiationException; 053import org.apache.isis.core.metamodel.spec.ObjectInstantiator; 054import org.apache.isis.core.metamodel.spec.ObjectInstantiatorAbstract; 055import org.apache.isis.core.metamodel.spec.ObjectSpecification; 056import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation; 057 058public class RuntimeContextNoRuntime extends RuntimeContextAbstract { 059 060 private final DeploymentCategory deploymentCategory; 061 private final ServicesInjector servicesInjector; 062 private final AuthenticationSessionProviderAbstract authenticationSessionProvider; 063 private final AdapterManager adapterManager; 064 private final ObjectInstantiatorAbstract objectInstantiator; 065 private final ObjectDirtierAbstract objectDirtier; 066 private final ObjectPersistorAbstract objectPersistor; 067 private final DomainObjectServicesAbstract domainObjectServices; 068 private final LocalizationProviderAbstract localizationProvider; 069 private final QuerySubmitterAbstract querySubmitter; 070 071 public RuntimeContextNoRuntime() { 072 this(DeploymentCategory.PRODUCTION); 073 } 074 075 public RuntimeContextNoRuntime(DeploymentCategory deploymentCategory) { 076 this.deploymentCategory = deploymentCategory; 077 // Unlike most of the methods in this implementation, does nothing 078 // (because this will always be called, even in a no-runtime context). 079 servicesInjector = new ServicesInjector() { 080 @Override 081 public void injectServicesInto(final Object domainObject) { 082 } 083 084 @Override 085 public void injectServicesInto(List<Object> objects) { 086 } 087 088 @Override 089 public <T> T lookupService(Class<T> serviceClass) { 090 return null; 091 } 092 093 @Override 094 public void injectInto(Object candidate) { 095 } 096 097 @Override 098 public <T> List<T> lookupServices(Class<T> serviceClass) { 099 return null; 100 } 101 102 @Override 103 public List<Object> getRegisteredServices() { 104 return null; 105 } 106 }; 107 authenticationSessionProvider = new AuthenticationSessionProviderAbstract() { 108 @Override 109 public AuthenticationSession getAuthenticationSession() { 110 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 111 } 112 }; 113 adapterManager = new AdapterManagerAbstract() { 114 115 @Override 116 public ObjectAdapter getAdapterFor(final Object pojo) { 117 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 118 } 119 120 @Override 121 public ObjectAdapter adapterFor(final Object pojo, final ObjectAdapter ownerAdapter) { 122 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 123 } 124 125 @Override 126 public ObjectAdapter adapterFor(final Object pojo, final ObjectAdapter ownerAdapter, final OneToManyAssociation collection) { 127 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 128 } 129 130 @Override 131 public ObjectAdapter adapterFor(final Object domainObject) { 132 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 133 } 134 135 @Override 136 public ObjectAdapter adapterFor(TypedOid oid) { 137 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 138 } 139 140 @Override 141 public ObjectAdapter adapterFor(TypedOid oid, ConcurrencyChecking concurrencyChecking) { 142 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 143 } 144 145 @Override 146 public ObjectAdapter getAdapterFor(Oid oid) { 147 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 148 } 149 150 }; 151 objectInstantiator = new ObjectInstantiatorAbstract() { 152 153 @Override 154 public Object instantiate(final Class<?> cls) throws ObjectInstantiationException { 155 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 156 } 157 }; 158 objectDirtier = new ObjectDirtierAbstract() { 159 160 @Override 161 public void objectChanged(final Object object) { 162 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 163 } 164 165 @Override 166 public void objectChanged(final ObjectAdapter adapter) { 167 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 168 } 169 }; 170 objectPersistor = new ObjectPersistorAbstract() { 171 172 @Override 173 public void remove(final ObjectAdapter adapter) { 174 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 175 } 176 177 @Override 178 public void makePersistent(final ObjectAdapter adapter) { 179 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 180 } 181 }; 182 domainObjectServices = new DomainObjectServicesAbstract() { 183 184 185 @Override 186 public ObjectAdapter createTransientInstance(final ObjectSpecification spec) { 187 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 188 } 189 190 @Override 191 public ObjectAdapter createViewModelInstance(ObjectSpecification spec, String memento) { 192 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 193 } 194 195 @Override 196 public ObjectAdapter createAggregatedInstance(final ObjectSpecification spec, final ObjectAdapter parent) { 197 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 198 } 199 200 @Override 201 public Object lookup(Bookmark bookmark) { 202 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 203 } 204 205 @Override 206 public Bookmark bookmarkFor(Object domainObject) { 207 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 208 } 209 210 @Override 211 public Bookmark bookmarkFor(Class<?> cls, String identifier) { 212 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 213 } 214 215 @Override 216 public void resolve(final Object parent, final Object field) { 217 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 218 } 219 220 @Override 221 public void resolve(final Object parent) { 222 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 223 } 224 225 @Override 226 public boolean flush() { 227 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 228 } 229 230 @Override 231 public void commit() { 232 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 233 } 234 235 @Override 236 public void informUser(final String message) { 237 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 238 } 239 240 @Override 241 public void warnUser(final String message) { 242 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 243 } 244 245 @Override 246 public void raiseError(final String message) { 247 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 248 } 249 250 @Override 251 public List<String> getPropertyNames() { 252 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 253 } 254 255 @Override 256 public String getProperty(final String name) { 257 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 258 } 259 260 @Override 261 public void injectServicesInto(Object domainObject) { 262 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 263 } 264 265 }; 266 localizationProvider = new LocalizationProviderAbstract() { 267 268 private final Localization defaultLocalization = new LocalizationDefault(); 269 270 @Override 271 public Localization getLocalization() { 272 return defaultLocalization; 273 } 274 }; 275 querySubmitter = new QuerySubmitterAbstract() { 276 277 @Override 278 public <T> ObjectAdapter firstMatchingQuery(final Query<T> query) { 279 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 280 } 281 282 @Override 283 public <T> List<ObjectAdapter> allMatchingQuery(final Query<T> query) { 284 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 285 } 286 }; 287 } 288 289 // /////////////////////////////////////////// 290 // Components 291 // /////////////////////////////////////////// 292 293 @Override 294 public DeploymentCategory getDeploymentCategory() { 295 return deploymentCategory; 296 } 297 298 299 @Override 300 public AuthenticationSessionProvider getAuthenticationSessionProvider() { 301 return authenticationSessionProvider; 302 } 303 304 @Override 305 public AdapterManager getAdapterManager() { 306 return adapterManager; 307 } 308 309 @Override 310 public ObjectInstantiator getObjectInstantiator() { 311 return objectInstantiator; 312 } 313 314 @Override 315 public ObjectDirtier getObjectDirtier() { 316 return objectDirtier; 317 } 318 319 @Override 320 public ObjectPersistor getObjectPersistor() { 321 return objectPersistor; 322 } 323 324 @Override 325 public DomainObjectServices getDomainObjectServices() { 326 return domainObjectServices; 327 } 328 329 @Override 330 public QuerySubmitter getQuerySubmitter() { 331 return querySubmitter; 332 } 333 334 @Override 335 public ServicesInjector getDependencyInjector() { 336 return servicesInjector; 337 } 338 339 // /////////////////////////////////////////// 340 // allInstances, allMatching* 341 // /////////////////////////////////////////// 342 343 public List<ObjectAdapter> allInstances(final ObjectSpecification noSpec) { 344 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 345 } 346 347 // /////////////////////////////////////////// 348 // getServices, injectDependenciesInto 349 // /////////////////////////////////////////// 350 351 @Override 352 public ServicesProvider getServicesProvider() { 353 return new ServicesProviderAbstract() { 354 /** 355 * Just returns an empty array. 356 */ 357 @Override 358 public List<ObjectAdapter> getServices() { 359 return Collections.emptyList(); 360 } 361 362 @Override 363 public <T> T lookupService(Class<T> cls) { 364 return null; 365 } 366 }; 367 } 368 369 @Override 370 public LocalizationProvider getLocalizationProvider() { 371 return localizationProvider; 372 } 373 374 375 // /////////////////////////////////////////// 376 // getTransactionState 377 // /////////////////////////////////////////// 378 379 @Override 380 public TransactionState getTransactionState() { 381 throw new UnsupportedOperationException("Not supported by this implementation of RuntimeContext"); 382 } 383 384}