- @SuppressWarnings("unchecked")
- public <T> T getByKey(Class<T> clss, Object key) {
- return (T) model.get(findClass(clss)).get(key);
- }
-
- /**
- * Slow.
- *
- * @return the first found
- */
- public <T> T getByField(Class<T> clss, String field, Object value) {
- List<T> all = list(clss, null);
- T res = null;
- for (T obj : all) {
- if (new BeanWrapperImpl(obj).getPropertyValue(field).equals(value)) {
- res = obj;
- break;
- }
- }
- return res;
- }
-
- @SuppressWarnings("unchecked")
- public <T> List<T> list(Class<T> clss, Object filter) {
- List<T> res = new ArrayList<T>();
-
- Class classToUse = findClass(clss);
- if (classToUse != null)
- res.addAll((Collection<T>) model.get(classToUse).values());
-
- if (applicationContext != null)
- res.addAll(new GenericBeanFactoryAccessor(applicationContext)
- .getBeansOfType(clss).values());
-
- return res;
- }
-
- @SuppressWarnings("unchecked")
- protected Class findClass(Class parent) {
- if (model.containsKey(parent))
- return parent;
-
- for (Class clss : model.keySet()) {
- if (parent.isAssignableFrom(clss))
- return clss;// return the first found
- }
- return null;
- }
-
- public void setApplicationContext(ApplicationContext applicationContext)
- throws BeansException {
- this.applicationContext = applicationContext;
- }
-
- public void setExternalRefs(Map<String, Object> externalRefs) {
- this.externalRefs = externalRefs;
- }
-
- public Map<String, Object> getExternalRefs() {
- return externalRefs;
- }
-
- public void setScannedPackages(List<String> scannedPackages) {
- this.scannedPackages = scannedPackages;
- }
-
- public List<String> getScannedPackages() {
- return scannedPackages;
- }
-
- public void setWorkbooks(List<Resource> workbooks) {
- this.workbooks = workbooks;
- }
-
- public List<Resource> getWorkbooks() {
- return workbooks;
- }
-
- public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
- public List<Class<?>> getAdditionalClasses() {
- return additionalClasses;
- }
-
- public void setAdditionalClasses(List<Class<?>> additionalClasses) {
- this.additionalClasses = additionalClasses;
- }
-