001/** 002 * GRANITE DATA SERVICES 003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S. 004 * 005 * This file is part of the Granite Data Services Platform. 006 * 007 * *** 008 * 009 * Community License: GPL 3.0 010 * 011 * This file is free software: you can redistribute it and/or modify 012 * it under the terms of the GNU General Public License as published 013 * by the Free Software Foundation, either version 3 of the License, 014 * or (at your option) any later version. 015 * 016 * This file is distributed in the hope that it will be useful, but 017 * WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 019 * GNU General Public License for more details. 020 * 021 * You should have received a copy of the GNU General Public License 022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 023 * 024 * *** 025 * 026 * Available Commercial License: GraniteDS SLA 1.0 027 * 028 * This is the appropriate option if you are creating proprietary 029 * applications and you are not prepared to distribute and share the 030 * source code of your application under the GPL v3 license. 031 * 032 * Please visit http://www.granitedataservices.com/license for more 033 * details. 034 */ 035package org.granite.client.tide; 036 037import java.lang.annotation.Annotation; 038import java.util.List; 039import java.util.Map; 040 041/** 042 * SPI to integrate with DI containers 043 * 044 * @author William DRAI 045 */ 046public interface InstanceStore { 047 048 /** 049 * Set a named bean in the container 050 * Not applicable to statically configured containers (Spring/CDI) 051 * @param name bean name 052 * @param instance bean instance 053 * @param <T> bean type 054 * @return the attached bean instance (usually the same instance as the one provided) 055 */ 056 public <T> T set(String name, T instance); 057 058 /** 059 * Set a bean in the container without specifying a name 060 * Not applicable to statically configured containers (Spring/CDI) 061 * The bean will be accessible only by its type 062 * @param instance bean instance 063 * @param <T> bean type 064 * @return the attached bean instance (usually the same instance as the one provided) 065 */ 066 public <T> T set(T instance); 067 068 /** 069 * Remove a bean from the container 070 * Not applicable to statically configured containers (Spring/CDI) 071 * @param name bean name 072 */ 073 public void remove(String name); 074 075 /** 076 * Clear all beans from the container 077 * Not applicable to statically configured containers (Spring/CDI) 078 */ 079 public void clear(); 080 081 /** 082 * Return all bean names set in this container 083 * @return list of bean names 084 */ 085 public List<String> allNames(); 086 087 /** 088 * Lookup a bean by its name 089 * The implementation is free to create and return a default instance (such as a service proxy) if no bean exists 090 * @param name bean name 091 * @param context context to lookup 092 * @param <T> expected bean type 093 * @return bean instance or null if not found 094 */ 095 public <T> T byName(String name, Context context); 096 097 /** 098 * Lookup a bean by its name 099 * Does not create a proxy if no bean found 100 * @param name bean name 101 * @param context context to lookup 102 * @param <T> bean type 103 * @return bean instance or null if not found 104 */ 105 public <T> T getNoProxy(String name, Context context); 106 107 /** 108 * Lookup a bean by its type 109 * If more than one instance is found, should throw a runtime exception 110 * @param type expected bean type 111 * @param context context to lookup 112 * @param <T> expected bean type 113 * @return bean instance 114 */ 115 public <T> T byType(Class<T> type, Context context); 116 117 /** 118 * Return an array of all bean instances implementing the expected type 119 * @param type expected bean type 120 * @param context context to lookup 121 * @param create if true, should create an instance if none is existing 122 * @param <T> expected bean type 123 * @return array of bean instances or null if no bean found 124 */ 125 public <T> T[] allByType(Class<T> type, Context context, boolean create); 126 127 /** 128 * Return a map of all bean instances annotated with the specified annotation 129 * @param annotationClass annotation 130 * @param context context to lookup 131 * @return map of bean instances keyed by name 132 */ 133 public Map<String, Object> allByAnnotatedWith(Class<? extends Annotation> annotationClass, Context context); 134}