001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.guice; 018 019import com.google.inject.Injector; 020import org.apache.wicket.MetaDataKey; 021import org.apache.wicket.util.io.IClusterable; 022 023/** 024 * This is a holder for the Injector. The reason we need a holder is that metadata only supports 025 * storing serializable objects but Injector is not. The holder acts as a serializable wrapper for 026 * the context. Notice that although holder implements IClusterable it really is not because it has 027 * a reference to non-serializable context - but this is ok because metadata objects in application 028 * are never serialized. 029 */ 030public class GuiceInjectorHolder implements IClusterable 031{ 032 private static final long serialVersionUID = 1L; 033 034 /** 035 * Metadata key used to store Injector holder in application's metadata 036 */ 037 public static final MetaDataKey<GuiceInjectorHolder> INJECTOR_KEY = new MetaDataKey<>() 038 { 039 private static final long serialVersionUID = 1L; 040 }; 041 042 private final Injector injector; 043 044 /** 045 * Constructor 046 * 047 * @param injector 048 */ 049 public GuiceInjectorHolder(final Injector injector) 050 { 051 this.injector = injector; 052 } 053 054 /** 055 * @return the context 056 */ 057 public Injector getInjector() 058 { 059 return injector; 060 } 061}