hlship 2004/12/19 07:41:45
Modified: library/src/java/org/apache/hivemind/lib/impl
SpringBeanParameter.java SpringLookupFactory.java
library/src/test/hivemind/test/lib
TestSpringLookupFactory.java SpringBeans.xml
library/src/test/org/apache/hivemind/lib/groovy
TestGroovyModuleDescriptorProvider.java
TestHiveMindBuilder.java
library/src/java/org/apache/hivemind/lib/groovy
GroovyScriptProcessor.java HiveMindBuilder.java
library/src/documentation/content/xdocs/hivemind-lib
SpringLookupFactory.xml
library/src/descriptor/META-INF hivemodule.xml
Added: library/src/java/org/apache/hivemind/lib/impl
SpringObjectProvider.java
library/src/test/hivemind/test/lib SpringProvider.xml
TestSpringObjectProvider.java
library/src/test/hivemind/test/lib/impl
SimpleServiceDelegatingImpl.java
Log:
Add SpringObjectProvider (prefix "spring:").
Refactor SpringLookupFactory and parameters to use a Spring BeanFactory (not
a BeanFactorySource).
Revision Changes Path
1.3 +17 -14
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/SpringBeanParameter.java
Index: SpringBeanParameter.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/SpringBeanParameter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SpringBeanParameter.java 25 Jun 2004 20:20:05 -0000 1.2
+++ SpringBeanParameter.java 19 Dec 2004 15:41:45 -0000 1.3
@@ -16,37 +16,40 @@
import org.apache.hivemind.impl.BaseLocatable;
import org.apache.hivemind.lib.SpringBeanFactorySource;
+import org.springframework.beans.factory.BeanFactory;
/**
- * Parameter to [EMAIL PROTECTED]
org.apache.hivemind.lib.impl.SpringLookupFactory},
- * containing a (required) bean name to
- * obtain, and an (optional) bean factory source.
- *
+ * Parameter to [EMAIL PROTECTED]
org.apache.hivemind.lib.impl.SpringLookupFactory}, containing a (required)
+ * bean name to obtain, and an (optional) bean factory.
+ *
* @author Howard Lewis Ship
*/
public class SpringBeanParameter extends BaseLocatable
{
private String _name;
- private SpringBeanFactorySource _beanFactorySource;
- public SpringBeanFactorySource getBeanFactorySource()
- {
- return _beanFactorySource;
- }
+ /** @since 1.1 */
+ private BeanFactory _beanFactory;
public String getName()
{
return _name;
}
- public void setBeanFactorySource(SpringBeanFactorySource source)
+ public void setName(String string)
{
- _beanFactorySource = source;
+ _name = string;
}
- public void setName(String string)
+ /** @since 1.1 */
+ public BeanFactory getBeanFactory()
{
- _name = string;
+ return _beanFactory;
}
-}
+ /** @since 1.1 */
+ public void setBeanFactory(BeanFactory beanFactory)
+ {
+ _beanFactory = beanFactory;
+ }
+}
\ No newline at end of file
1.6 +8 -7
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/SpringLookupFactory.java
Index: SpringLookupFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/SpringLookupFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SpringLookupFactory.java 2 Nov 2004 17:46:09 -0000 1.5
+++ SpringLookupFactory.java 19 Dec 2004 15:41:45 -0000 1.6
@@ -33,7 +33,8 @@
*/
public class SpringLookupFactory extends BaseLocatable implements
ServiceImplementationFactory
{
- private SpringBeanFactorySource _defaultBeanFactorySource;
+ /** @since 1.1 */
+ private BeanFactory _defaultBeanFactory;
public Object createCoreServiceImplementation(
ServiceImplementationFactoryParameters factoryParameters)
@@ -41,18 +42,18 @@
SpringBeanParameter p = (SpringBeanParameter)
factoryParameters.getParameters().get(0);
String beanName = p.getName();
- SpringBeanFactorySource s = p.getBeanFactorySource();
- if (s == null)
- s = _defaultBeanFactorySource;
+ BeanFactory f = p.getBeanFactory();
- BeanFactory f = s.getBeanFactory();
+ if (f == null)
+ f = _defaultBeanFactory;
return f.getBean(beanName, factoryParameters.getServiceInterface());
}
- public void setDefaultBeanFactorySource(SpringBeanFactorySource source)
+ /** @since 1.1 */
+ public void setDefaultBeanFactory(BeanFactory defaultBeanFactory)
{
- _defaultBeanFactorySource = source;
+ _defaultBeanFactory = defaultBeanFactory;
}
}
1.1
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/impl/SpringObjectProvider.java
Index: SpringObjectProvider.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.lib.impl;
import org.apache.hivemind.Location;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.service.ObjectProvider;
import org.springframework.beans.factory.BeanFactory;
/**
* Implementation of [EMAIL PROTECTED]
org.apache.hivemind.service.ObjectProvider}
* mapped to the "spring:" prefix. The locator is the name of a bean inside
* a Spring BeanFactory. The BeanFactory to be used
* @author Howard M. Lewis Ship
* @since 1.1
*/
public class SpringObjectProvider implements ObjectProvider
{
private BeanFactory _beanFactory;
public Object provideObject(Module contributingModule, Class
propertyType, String locator,
Location location)
{
return _beanFactory.getBean(locator);
}
public void setBeanFactory(BeanFactory beanFactory)
{
_beanFactory = beanFactory;
}
}
1.7 +2 -11
jakarta-hivemind/library/src/test/hivemind/test/lib/TestSpringLookupFactory.java
Index: TestSpringLookupFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/hivemind/test/lib/TestSpringLookupFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TestSpringLookupFactory.java 2 Nov 2004 17:46:08 -0000 1.6
+++ TestSpringLookupFactory.java 19 Dec 2004 15:41:45 -0000 1.7
@@ -38,15 +38,6 @@
*/
public class TestSpringLookupFactory extends HiveMindTestCase
{
- private SpringBeanFactorySource buildSource(BeanFactory f)
- {
- SpringBeanFactoryHolderImpl result = new
SpringBeanFactoryHolderImpl();
-
- result.setBeanFactory(f);
-
- return result;
- }
-
private List buildParameters(String beanName, BeanFactory f)
{
SpringBeanParameter p = new SpringBeanParameter();
@@ -54,7 +45,7 @@
p.setName(beanName);
if (f != null)
- p.setBeanFactorySource(buildSource(f));
+ p.setBeanFactory(f);
return Collections.singletonList(p);
}
@@ -70,7 +61,7 @@
ServiceImplementationFactoryParameters fp =
(ServiceImplementationFactoryParameters) fpc
.getMock();
- lf.setDefaultBeanFactorySource(buildSource(beanFactory));
+ lf.setDefaultBeanFactory(beanFactory);
List params = buildParameters("fred", null);
1.2 +15 -0
jakarta-hivemind/library/src/test/hivemind/test/lib/SpringBeans.xml
Index: SpringBeans.xml
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/hivemind/test/lib/SpringBeans.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SpringBeans.xml 1 Jun 2004 14:17:14 -0000 1.1
+++ SpringBeans.xml 19 Dec 2004 15:41:45 -0000 1.2
@@ -1,4 +1,19 @@
<?xml version="1.0"?>
+<!--
+ Copyright 2004 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
1.1
jakarta-hivemind/library/src/test/hivemind/test/lib/SpringProvider.xml
Index: SpringProvider.xml
===================================================================
<?xml version="1.0"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<module id="hivemind.test.lib" version="1.1.0">
<service-point id="Adder" interface="hivemind.test.lib.SimpleService">
<invoke-factory>
<construct class="hivemind.test.lib.impl.SimpleServiceDelegatingImpl">
<set-object property="delegate" value="spring:Adder"/>
</construct>
</invoke-factory>
</service-point>
</module>
1.1
jakarta-hivemind/library/src/test/hivemind/test/lib/TestSpringObjectProvider.java
Index: TestSpringObjectProvider.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hivemind.test.lib;
import org.apache.hivemind.Registry;
import org.apache.hivemind.lib.SpringBeanFactoryHolder;
import org.apache.hivemind.lib.impl.SpringObjectProvider;
import org.apache.hivemind.test.HiveMindTestCase;
import org.easymock.MockControl;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
/**
* @author Howard M. Lewis Ship
* @since 1.1
*/
public class TestSpringObjectProvider extends HiveMindTestCase
{
public void testBasic()
{
Object bean = new Object();
MockControl control = newControl(BeanFactory.class);
BeanFactory bf = (BeanFactory) control.getMock();
bf.getBean("fred");
control.setReturnValue(bean);
replayControls();
SpringObjectProvider p = new SpringObjectProvider();
p.setBeanFactory(bf);
Object result = p.provideObject(null, null, "fred", null);
assertSame(bean, result);
verifyControls();
}
public void testSpringIntegration() throws Exception
{
// Spring setup
ClassPathResource springBeansResource = new
ClassPathResource("SpringBeans.xml",
TestSpringLookupFactory.class);
BeanFactory beanFactory = new XmlBeanFactory(springBeansResource);
Registry r = buildFrameworkRegistry("SpringProvider.xml");
SpringBeanFactoryHolder h = (SpringBeanFactoryHolder) r.getService(
"hivemind.lib.DefaultSpringBeanFactoryHolder",
SpringBeanFactoryHolder.class);
h.setBeanFactory(beanFactory);
SimpleService a = (SimpleService) r.getService(
"hivemind.test.lib.Adder",
SimpleService.class);
assertEquals(17, a.add(9, 8));
}
}
1.3 +1 -1
jakarta-hivemind/library/src/test/org/apache/hivemind/lib/groovy/TestGroovyModuleDescriptorProvider.java
Index: TestGroovyModuleDescriptorProvider.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/groovy/TestGroovyModuleDescriptorProvider.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestGroovyModuleDescriptorProvider.java 16 Nov 2004 10:27:12 -0000
1.2
+++ TestGroovyModuleDescriptorProvider.java 19 Dec 2004 15:41:45 -0000
1.3
@@ -1,4 +1,4 @@
-//Copyright 2004 The Apache Software Foundation
+// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
1.4 +1 -1
jakarta-hivemind/library/src/test/org/apache/hivemind/lib/groovy/TestHiveMindBuilder.java
Index: TestHiveMindBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/groovy/TestHiveMindBuilder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestHiveMindBuilder.java 19 Nov 2004 20:28:49 -0000 1.3
+++ TestHiveMindBuilder.java 19 Dec 2004 15:41:45 -0000 1.4
@@ -1,4 +1,4 @@
-// Copyright 2004 The Apache Software Foundation
+// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
1.3 +1 -1
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/groovy/GroovyScriptProcessor.java
Index: GroovyScriptProcessor.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/groovy/GroovyScriptProcessor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GroovyScriptProcessor.java 16 Nov 2004 10:27:12 -0000 1.2
+++ GroovyScriptProcessor.java 19 Dec 2004 15:41:45 -0000 1.3
@@ -1,4 +1,4 @@
-//Copyright 2004 The Apache Software Foundation
+// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
1.2 +1 -1
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/groovy/HiveMindBuilder.java
Index: HiveMindBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/groovy/HiveMindBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HiveMindBuilder.java 11 Nov 2004 14:13:44 -0000 1.1
+++ HiveMindBuilder.java 19 Dec 2004 15:41:45 -0000 1.2
@@ -1,4 +1,4 @@
-//Copyright 2004 The Apache Software Foundation
+// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
1.6 +11 -7
jakarta-hivemind/library/src/documentation/content/xdocs/hivemind-lib/SpringLookupFactory.xml
Index: SpringLookupFactory.xml
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/documentation/content/xdocs/hivemind-lib/SpringLookupFactory.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SpringLookupFactory.xml 21 Oct 2004 12:35:56 -0000 1.5
+++ SpringLookupFactory.xml 19 Dec 2004 15:41:45 -0000 1.6
@@ -31,20 +31,24 @@
lightweight container. SpringLookupFactory is a service
constructor that
obtains a core service implementation from a Spring
<code>BeanFactory</code>
.</p>
- <p>By default, the <code>BeanFactory</code> is obtained from
the <link
+ <p>By default, the <code>BeanFactory</code> is
+ the
+ <link
href="&hivedoc;/service/hivemind.lib.DefaultSpringBeanFactory.html">DefaultSpringBeanFactory</link>
+ (which is a projection of the BeanFactory held by the
+ <link
href="&hivedoc;/service/hivemind.lib.DefaultSpringBeanFactoryHolder.html">
- DefaultSpringBeanFactoryHolder</link>. Part of your
application startup
+ DefaultSpringBeanFactoryHolder</link> service).
+
+ Part of your application startup
code requires that you start a Spring instance and
inform the <link
href="&apiroot-lib;/SpringBeanFactoryHolder.html#setBeanFactory(org.springframework.beans.factory.BeanFactory)"
>DefaultSpringBeanFactoryHolder</link> about it.</p>
<p>The SpringLookupFactory expects exactly <em>one</em>
parameter element:</p>
<source><![CDATA[
-<lookup-bean name="..." source-service-id="..."/>]]> </source>
+<lookup-bean name="..." bean-factory="..."/>]]> </source>
<p>The <code>name</code> attribute is the name of the bean to
look for
inside the Spring BeanFactory.</p>
- <p>The optional <code>source-service-id</code> attribute allows
an alternate
- service to be used to obtain the Spring BeanFactory.
The identified service must
- implement the <link
href="&apiroot-lib;/SpringBeanFactorySource.html">
- SpringBeanFactorySource</link> interface.</p>
+ <p>The optional <code>bean-factory</code> attribute is an
&object-reference; that
+ allows an alternate Spring BeanFactory to be used.</p>
</body>
</document>
1.17 +38 -7
jakarta-hivemind/library/src/descriptor/META-INF/hivemodule.xml
Index: hivemodule.xml
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/descriptor/META-INF/hivemodule.xml,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- hivemodule.xml 7 Nov 2004 12:35:01 -0000 1.16
+++ hivemodule.xml 19 Dec 2004 15:41:45 -0000 1.17
@@ -88,24 +88,24 @@
<parameters-schema>
- Parameters are used to specify the bean name and, optionally, a
non-default BeanFactory source from which to obtain the Spring BeanFactory.
+ Parameters are used to specify the bean name and, optionally, a
non-default Spring
+ BeanFactory from which to obtain the bean.
<element name="lookup-bean">
<attribute name="name" required="true">
The name of the Spring bean to obtain.
</attribute>
- <attribute name="source-service-id" translator="service">
- An optional service implementing the SpringBeanFactorySource
interface.
+ <attribute name="bean-factory" translator="object">
+ An optional object implementing the Spring BeanFactory interface.
The default,
+ when not specified, is hivemind.lib.DefaultSpringBeanFactory.
</attribute>
- <conversion class="org.apache.hivemind.lib.impl.SpringBeanParameter">
- <map attribute="source-service-id" property="beanFactorySource"/>
- </conversion>
+ <conversion
class="org.apache.hivemind.lib.impl.SpringBeanParameter"/>
</element>
</parameters-schema>
<invoke-factory>
<construct
class="org.apache.hivemind.lib.impl.SpringLookupFactory">
- <set-service property="defaultBeanFactorySource"
service-id="DefaultSpringBeanFactoryHolder"/>
+ <set-service property="defaultBeanFactory"
service-id="DefaultSpringBeanFactory"/>
</construct>
</invoke-factory>
</service-point>
@@ -117,6 +117,37 @@
<create-instance
class="org.apache.hivemind.lib.impl.SpringBeanFactoryHolderImpl"/>
</service-point>
+
+ <service-point id="DefaultSpringBeanFactory"
interface="org.springframework.beans.factory.BeanFactory">
+
+ The default Spring BeanFactory referenced by the SpringLookupFactory.
This is a projection of the BeanFactory
+ held by the DefaultSpringBeanFactoryHolder service.
+
+ <invoke-factory service-id="ServicePropertyFactory">
+ <construct service-id="DefaultSpringBeanFactoryHolder"
property="beanFactory"/>
+ </invoke-factory>
+
+ </service-point>
+
+ <service-point id="SpringObjectProvider"
interface="org.apache.hivemind.service.ObjectProvider">
+
+ Provides the "spring:" prefix, which looks up Spring beans in a Spring
BeanFactory.
+
+ <invoke-factory>
+ <construct class="org.apache.hivemind.lib.impl.SpringObjectProvider">
+ <set-object property="beanFactory"
value="${hivemind.lib.spring-bean-factory}"/>
+ </construct>
+ </invoke-factory>
+
+ </service-point>
+
+ <contribution configuration-id="hivemind.FactoryDefaults">
+ <default symbol="hivemind.lib.spring-bean-factory"
value="service:DefaultSpringBeanFactory"/>
+ </contribution>
+
+ <contribution configuration-id="hivemind.ObjectProviders">
+ <provider prefix="spring" service-id="SpringObjectProvider"/>
+ </contribution>
<schema id="BeanFactoryContribution">
Schema used with the hivemind.lib.BeanFactoryBuilder service, to define
configuration that accepts definitions of classes
1.1
jakarta-hivemind/library/src/test/hivemind/test/lib/impl/SimpleServiceDelegatingImpl.java
Index: SimpleServiceDelegatingImpl.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hivemind.test.lib.impl;
import hivemind.test.lib.SimpleService;
/**
* Used to test the "spring:" prefix. The delegate, in this case, is a Spring
bean.
*
* @author Howard M. Lewis Ship
* @since 1.1
*/
public class SimpleServiceDelegatingImpl implements SimpleService
{
private SimpleService _delegate;
public int add(int a, int b)
{
return _delegate.add(a, b);
}
public void setDelegate(SimpleService delegate)
{
_delegate = delegate;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]