X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fspring%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fspring%2FRequiredServiceBean.java;h=b2db73735a6893a18385cd3d88573a16c9d8154e;hb=17775e14ecfb286e59f67117e5cee7e21e95ab1f;hp=95e2e786628d6b6638ef98524053ca6668501268;hpb=6f8bb575523e672b9f8797e543f7c59d15db7253;p=utils diff --git a/system/spring/src/main/java/org/wamblee/system/spring/RequiredServiceBean.java b/system/spring/src/main/java/org/wamblee/system/spring/RequiredServiceBean.java index 95e2e786..b2db7373 100644 --- a/system/spring/src/main/java/org/wamblee/system/spring/RequiredServiceBean.java +++ b/system/spring/src/main/java/org/wamblee/system/spring/RequiredServiceBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2007 the original author or authors. + * Copyright 2005-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,48 +16,56 @@ package org.wamblee.system.spring; import org.springframework.beans.factory.FactoryBean; -import org.wamblee.system.ProvidedInterface; -import org.wamblee.system.RequiredInterface; -import org.wamblee.system.SystemAssemblyException; + +import org.wamblee.system.core.RequiredInterface; +import org.wamblee.system.core.SystemAssemblyException; + +import java.util.List; /** - * Bean which adds a service required by the spring component to - * the application context so that other spring beans can use it. - * + * Bean which adds a service required by the spring component to the application + * context so that other spring beans can use it. + * * @author Erik Brakkee */ class RequiredServiceBean implements FactoryBean { - - private RequiredInterface _required; - - /** - * Constructs the bean. - * @param aId Id of the bean in the service registry. - */ - public RequiredServiceBean(String aId) { - RequiredInterface[] required = SpringComponent.THIS.get().getRequiredServices(); - for ( RequiredInterface intf: required) { - if ( intf.getName().equals(aId)) { - _required = intf; - return; - } - } - throw new SystemAssemblyException("Cannot resolve provided component '" + aId + "'"); - } - - @Override - public Object getObject() throws Exception { - return _required.getImplementation(Object.class); - } - - @Override - public Class getObjectType() { - return null; - } - - @Override - public boolean isSingleton() { - return true; - } + private RequiredInterface _required; + + /** + * Constructs the bean. + * + * @param aId + * Id of the bean in the service registry. + */ + public RequiredServiceBean(String aId) { + List required = SpringComponent.THIS.get() + .getRequiredInterfaces(); + + for (RequiredInterface intf : required) { + if (intf.getName().equals(aId)) { + _required = intf; + + return; + } + } + + throw new SystemAssemblyException( + "Cannot resolve required component '" + aId + "'"); + } + + @Override + public Object getObject() throws Exception { + return SpringComponent.SCOPE.get().getInterfaceImplementation( + _required.getProvider(), Object.class); + } + + @Override + public Class getObjectType() { + return null; + } + @Override + public boolean isSingleton() { + return true; + } }