Return-Path: Delivered-To: apmail-hivemind-commits-archive@www.apache.org Received: (qmail 69925 invoked from network); 31 Jul 2006 14:22:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 31 Jul 2006 14:22:03 -0000 Received: (qmail 85205 invoked by uid 500); 31 Jul 2006 14:22:03 -0000 Delivered-To: apmail-hivemind-commits-archive@hivemind.apache.org Received: (qmail 85191 invoked by uid 500); 31 Jul 2006 14:22:03 -0000 Mailing-List: contact commits-help@hivemind.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hivemind.apache.org Delivered-To: mailing list commits@hivemind.apache.org Received: (qmail 85182 invoked by uid 99); 31 Jul 2006 14:22:03 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jul 2006 07:22:03 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jul 2006 07:21:58 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id D848B1A981A; Mon, 31 Jul 2006 07:21:36 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r427127 [1/2] - in /hivemind/trunk: ./ framework/src/descriptor/META-INF/ framework/src/documentation/content/xdocs/ framework/src/java/org/apache/hivemind/ framework/src/java/org/apache/hivemind/impl/ framework/src/java/org/apache/hivemind... Date: Mon, 31 Jul 2006 14:21:29 -0000 To: commits@hivemind.apache.org From: knut@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060731142136.D848B1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: knut Date: Mon Jul 31 07:21:27 2006 New Revision: 427127 URL: http://svn.apache.org/viewvc?rev=427127&view=rev Log: - Implemented support for assembly instructions () inside element. - Modified "object" translator to delegate to "smart" translator if colon separator is missing. Added: hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyInstruction.java hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyParameters.java hivemind/trunk/framework/src/java/org/apache/hivemind/impl/AssemblyParametersImpl.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AssemblyInstructionImpl.java hivemind/trunk/framework/src/test/hivemind/test/services/AssemblyInstructions.xml hivemind/trunk/framework/src/test/hivemind/test/services/TestAssemblyInstruction.java hivemind/trunk/src/documentation/content/xdocs/assembly.xml Modified: hivemind/trunk/framework/src/descriptor/META-INF/hivemodule.xml hivemind/trunk/framework/src/documentation/content/xdocs/BuilderFactory.xml hivemind/trunk/framework/src/java/org/apache/hivemind/ServiceImplementationFactoryParameters.java hivemind/trunk/framework/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java hivemind/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ServiceImplementationFactoryParametersImpl.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderClassResolverFacet.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorHandlerFacet.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorLogFacet.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFactoryLogic.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderLogFacet.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderMessagesFacet.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderParameter.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderServiceIdFacet.java hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ObjectTranslator.java hivemind/trunk/framework/src/java/org/apache/hivemind/util/ConstructorUtils.java hivemind/trunk/framework/src/test/hivemind/test/ant/TestConstructRegistry.java hivemind/trunk/framework/src/test/hivemind/test/services/AutowireTarget.java hivemind/trunk/framework/src/test/hivemind/test/services/TestBuilderFactory.java hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestBuilderFactory.java hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestObjectTranslator.java hivemind/trunk/src/documentation/content/xdocs/descriptor.xml hivemind/trunk/src/documentation/content/xdocs/links.ent hivemind/trunk/src/documentation/content/xdocs/services.xml hivemind/trunk/src/documentation/content/xdocs/site.xml hivemind/trunk/status.xml Modified: hivemind/trunk/framework/src/descriptor/META-INF/hivemodule.xml URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/descriptor/META-INF/hivemodule.xml?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/descriptor/META-INF/hivemodule.xml (original) +++ hivemind/trunk/framework/src/descriptor/META-INF/hivemodule.xml Mon Jul 31 07:21:27 2006 @@ -164,6 +164,67 @@ + + + If true unclaimed properties will be attempted to connect to services. + The name of a public instance method (taking no parameters) to be invoked after the service has been assembled. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Configures a property of the service instance using an object. + + The name of a property of the service instance to configure. + The value to set the property to, in the form of a prefix and a locator for that prefix. Prefixes are defined by the ObjectProviders configuration point. Each prefix provides a different interpretation for the locator, such as a service id or class name. + + + + + + + + + + + + Registers the new services as an event listener for events produced by the specified service. + + The service which will produce events. + If given, the name of an event set for which the service will be registered. If omitted, the service will be registered for all events sets for which it implements the necessary listener interfaces. + + + + + + + + + + Used to construct a service from a class name and optional constructor parameters and properties. @@ -468,7 +529,7 @@ - + @@ -652,7 +713,7 @@ - Translator that works with ObjectProviders to find or create objects. + Translator that works with ObjectProviders to find or create objects. In case of a missing colon in the input value it will delegate to the smart translator. autowiring). + + If you are looking into implementing your own service implementation factory and need + it to support property dependency injection as available in BuilderFactory then check + whether assembly instructions cut it for you. + +
construct Added: hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyInstruction.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyInstruction.java?rev=427127&view=auto ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyInstruction.java (added) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyInstruction.java Mon Jul 31 07:21:27 2006 @@ -0,0 +1,49 @@ +// Copyright 2006 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; + +import org.apache.hivemind.impl.InvokeFactoryServiceConstructor; + +/** + * AssemblyInstruction objects play a central role in the "assembly" of a + * core service implementation created by a + * {@link org.apache.hivemind.ServiceImplementationFactory service implementation factory}. They + * correspond to the <assembly> elements which may be added inside the <invoke-factory> + * element. Even though these elements have the same parent element as the service implementation + * factory parameter elements it is important to understand that these are not passed as + * {@link org.apache.hivemind.ServiceImplementationFactoryParameters#getParameters() parameters} to + * the service implementation factory. Likewise the <assembly> element is not + * defined by the service implementation factory's parameters schema. + *

+ * Typically an assembly instruction object will inject dependencies or call an initialization + * method on the core service implementation object. Note that it is possible to declare multiple + * assembly instruction objects (i.e. <assembly> elements) for one service. These will be + * {@link #assemble(Object, AssemblyParameters) called} in order of appearance. + *

+ * In order to get the {@link org.apache.hivemind.schema.SchemaProcessor schema processor} to + * understand the <assembly> elements HiveMind automatically extends any parameters schemas + * with the hivemind.Assembly schema. The + * {@link InvokeFactoryServiceConstructor factory service constructor} calling the schema processor + * will recognize any created AssemblyInstruction instances. This means that it is + * also possible to define custom assembly instruction elements by properly extending the parameters + * schema. + * + * @author Knut Wannheden + * @since 1.2 + */ +public interface AssemblyInstruction +{ + public void assemble(Object service, AssemblyParameters assemblyParameters); +} Added: hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyParameters.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyParameters.java?rev=427127&view=auto ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyParameters.java (added) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/AssemblyParameters.java Mon Jul 31 07:21:27 2006 @@ -0,0 +1,56 @@ +// Copyright 2006 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; + +import org.apache.commons.logging.Log; +import org.apache.hivemind.internal.Module; + +/** + * A wrapper for the parameters needed by {@link org.apache.hivemind.AssemblyInstruction}. As this + * encompasses almost all parameters needed by {@link ServiceImplementationFactory} the + * {@link ServiceImplementationFactoryParameters} interface is a subclass of this interface. + * + * @author Knut Wannheden + * @since 1.2 + */ +public interface AssemblyParameters +{ + /** + * The fully qualified id of the service. + */ + public String getServiceId(); + + /** + * The interface defined for the service. + */ + public Class getServiceInterface(); + + /** + * The log used for any output related to the service (or the construction of the service). + */ + public Log getLog(); + + /** + * An {@link ErrorLog} instance used for reporting recoverable errors related to the service (or + * the construction of the service). + */ + public ErrorLog getErrorLog(); + + /** + * The module containing the service constructor. Primarily used to locate other services (or + * configurations) using simple (non-qualified) ids. + */ + public Module getInvokingModule(); +} Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/ServiceImplementationFactoryParameters.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/ServiceImplementationFactoryParameters.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/ServiceImplementationFactoryParameters.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/ServiceImplementationFactoryParameters.java Mon Jul 31 07:21:27 2006 @@ -16,57 +16,23 @@ import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.hivemind.internal.Module; - /** * A wrapper for the parameters needed by {@link org.apache.hivemind.ServiceImplementationFactory}. * * @author Howard M. Lewis Ship * @since 1.1 */ -public interface ServiceImplementationFactoryParameters +public interface ServiceImplementationFactoryParameters extends AssemblyParameters { /** - * The fully qualified id of the service. - */ - - public String getServiceId(); - - /** - * The interface defined for the service. - */ - public Class getServiceInterface(); - - /** - * The log used for any output related to the service (or the construction of the service). - */ - - public Log getLog(); - - /** - * An {@link ErrorLog} instance used for reporting recoverable errors related to the service (or - * the construction of the service). - */ - - public ErrorLog getErrorLog(); - - /** - * The module containing the service constructor. Primarily used to locate other services (or - * configurations) using simple (non-qualified) ids. - */ - public Module getInvokingModule(); - - /** * The parameters passed to the factory to guide the construction of the service. In most cases, * there will only be a single element in the list. */ public List getParameters(); - + /** - * Returns the first parameter passed to the factory (since most factories - * take exactly one parameter, this is the most common usage). If no parameters exist, - * returns null. + * Returns the first parameter passed to the factory (since most factories take exactly one + * parameter, this is the most common usage). If no parameters exist, returns null. */ public Object getFirstParameter(); Added: hivemind/trunk/framework/src/java/org/apache/hivemind/impl/AssemblyParametersImpl.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/AssemblyParametersImpl.java?rev=427127&view=auto ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/impl/AssemblyParametersImpl.java (added) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/impl/AssemblyParametersImpl.java Mon Jul 31 07:21:27 2006 @@ -0,0 +1,70 @@ +// Copyright 2006 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.impl; + +import org.apache.commons.logging.Log; +import org.apache.hivemind.AssemblyParameters; +import org.apache.hivemind.ErrorLog; +import org.apache.hivemind.internal.Module; +import org.apache.hivemind.internal.ServicePoint; +import org.apache.hivemind.util.Defense; + +/** + * Wrapper around a {@link org.apache.hivemind.internal.ServicePoint} and the + * {@link Module invoking module}, passed to a {@link org.apache.hivemind.AssemblyInstruction}. + * + * @author Knut Wannheden + * @since 1.2 + */ +public class AssemblyParametersImpl implements AssemblyParameters +{ + private ServicePoint _servicePoint; + + private Module _invokingModule; + + public AssemblyParametersImpl(ServicePoint servicePoint, Module invokingModule) + { + Defense.notNull(servicePoint, "servicePoint"); + Defense.notNull(invokingModule, "invokingModule"); + + _servicePoint = servicePoint; + _invokingModule = invokingModule; + } + + public String getServiceId() + { + return _servicePoint.getExtensionPointId(); + } + + public Class getServiceInterface() + { + return _servicePoint.getServiceInterface(); + } + + public Log getLog() + { + return _servicePoint.getLog(); + } + + public ErrorLog getErrorLog() + { + return _servicePoint.getErrorLog(); + } + + public Module getInvokingModule() + { + return _invokingModule; + } +} Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java Mon Jul 31 07:21:27 2006 @@ -14,9 +14,12 @@ package org.apache.hivemind.impl; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import org.apache.hivemind.ApplicationRuntimeException; +import org.apache.hivemind.AssemblyInstruction; import org.apache.hivemind.ErrorLog; import org.apache.hivemind.Occurances; import org.apache.hivemind.ServiceImplementationFactory; @@ -48,7 +51,10 @@ private ServiceImplementationFactory _factory; /** The parameters converted to objects as per the factory's parameter schema. */ - private List _convertedParameters; + private List _convertedFactoryParameters; + + /** The assembly instructions converted to objects as per the factory's parameter schema. */ + private List _convertedAssemblyInstructions; public Object constructCoreServiceImplementation() { @@ -57,9 +63,21 @@ try { ServiceImplementationFactoryParameters factoryParameters = new ServiceImplementationFactoryParametersImpl( - _serviceExtensionPoint, _contributingModule, _convertedParameters); + _serviceExtensionPoint, _contributingModule, _convertedFactoryParameters); + + final Object result = _factory.createCoreServiceImplementation(factoryParameters); + + if (_convertedAssemblyInstructions != null) + { + for (Iterator i = _convertedAssemblyInstructions.iterator(); i.hasNext();) + { + AssemblyInstruction parameter = (AssemblyInstruction) i.next(); - return _factory.createCoreServiceImplementation(factoryParameters); + parameter.assemble(result, factoryParameters); + } + } + + return result; } catch (Exception ex) { @@ -90,18 +108,46 @@ processor.process(_parameters, _contributingModule); - _convertedParameters = processor.getElements(); + _convertedFactoryParameters = processor.getElements(); + + _convertedAssemblyInstructions = extractAssemblyInstructions(_convertedFactoryParameters); checkParameterCounts(errorLog, expected); } } /** + * Extracts and removes the {@link AssemblyInstruction} objects from the converted parameter + * elements. + */ + private List extractAssemblyInstructions(List parameters) + { + List result = null; + + for (Iterator i = parameters.iterator(); i.hasNext();) + { + Object parameter = (Object) i.next(); + + if (parameter instanceof AssemblyInstruction) + { + if (result == null) + result = new ArrayList(); + + result.add(parameter); + + i.remove(); + } + } + + return result; + } + + /** * Checks that the number of parameter elements matches the expected count. */ private void checkParameterCounts(ErrorLog log, Occurances expected) { - int actual = _convertedParameters.size(); + int actual = _convertedFactoryParameters.size(); if (expected.inRange(actual)) return; Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java Mon Jul 31 07:21:27 2006 @@ -41,6 +41,7 @@ import org.apache.hivemind.parse.InterceptorDescriptor; import org.apache.hivemind.parse.ModuleDescriptor; import org.apache.hivemind.parse.ServicePointDescriptor; +import org.apache.hivemind.schema.ElementModel; import org.apache.hivemind.schema.Schema; import org.apache.hivemind.schema.impl.SchemaImpl; import org.apache.hivemind.util.IdUtils; @@ -91,6 +92,8 @@ */ private Map _schemas = new HashMap(); + private ElementModel _assemblyElementModel; + /** * Map of {@link ServicePointImpl} keyed on fully qualified id. */ @@ -284,7 +287,7 @@ point.setServiceInterfaceName(sd.getInterfaceClassName()); - point.setParametersSchema(findSchema(sd.getParametersSchema(), module, sd + point.setParametersSchema(findParametersSchema(sd.getParametersSchema(), module, sd .getParametersSchemaId(), point.getLocation())); point.setParametersCount(sd.getParametersCount()); @@ -337,8 +340,11 @@ point.setModule(module); point.setExpectedCount(cpd.getCount()); - point.setContributionsSchema(findSchema(cpd.getContributionsSchema(), module, cpd - .getContributionsSchemaId(), cpd.getLocation())); + point.setContributionsSchema(findContributionsSchema( + cpd.getContributionsSchema(), + module, + cpd.getContributionsSchemaId(), + cpd.getLocation())); point.setVisibility(cpd.getVisibility()); @@ -466,26 +472,51 @@ } } - private Schema findSchema(SchemaImpl schema, Module module, String schemaId, Location location) + /** + * Finds and returns a service factory parameter schema. The schema is if required first + * extended with the hivemind.Assembly schema. + */ + private Schema findParametersSchema(SchemaImpl schema, Module module, String schemaId, + Location location) { + final SchemaImpl result = findSchema(schema, module, schemaId, location); + + if (result != null && !result.getElementModel().contains(getAssemblyElementModel())) + result.addElementModel(getAssemblyElementModel()); + + return result; + } + + private Schema findContributionsSchema(SchemaImpl schema, Module module, String schemaId, + Location location) + { + return findSchema(schema, module, schemaId, location); + } + + private SchemaImpl findSchema(SchemaImpl schema, Module module, String schemaId, + Location location) + { + SchemaImpl result = null; + if (schema != null) { - schema.setModule(module); - return schema; + result = schema; + result.setModule(module); } + else if (schemaId != null) + { + String moduleId = module.getModuleId(); + String qualifiedId = IdUtils.qualify(moduleId, schemaId); - if (schemaId == null) - return null; - - String moduleId = module.getModuleId(); - String qualifiedId = IdUtils.qualify(moduleId, schemaId); + result = getSchema(qualifiedId, moduleId, location); + } - return getSchema(qualifiedId, moduleId, location); + return result; } - private Schema getSchema(String schemaId, String referencingModule, Location reference) + private SchemaImpl getSchema(String schemaId, String referencingModule, Location reference) { - Schema schema = (Schema) _schemas.get(schemaId); + SchemaImpl schema = (SchemaImpl) _schemas.get(schemaId); if (schema == null) _errorHandler @@ -501,6 +532,19 @@ } return schema; + } + + private ElementModel getAssemblyElementModel() + { + if (_assemblyElementModel == null) + { + final Schema assemblySchema = (Schema) _schemas.get("hivemind.Assembly"); + + if (assemblySchema != null) + _assemblyElementModel = (ElementModel) assemblySchema.getElementModel().get(0); + } + + return _assemblyElementModel; } /** Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ServiceImplementationFactoryParametersImpl.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ServiceImplementationFactoryParametersImpl.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ServiceImplementationFactoryParametersImpl.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/impl/ServiceImplementationFactoryParametersImpl.java Mon Jul 31 07:21:27 2006 @@ -16,9 +16,7 @@ import java.util.List; -import org.apache.commons.logging.Log; import org.apache.hivemind.ServiceImplementationFactoryParameters; -import org.apache.hivemind.ErrorLog; import org.apache.hivemind.internal.Module; import org.apache.hivemind.internal.ServicePoint; import org.apache.hivemind.util.Defense; @@ -30,8 +28,8 @@ * @author Howard M. Lewis Ship * @since 1.1 */ -public class ServiceImplementationFactoryParametersImpl implements - ServiceImplementationFactoryParameters +public class ServiceImplementationFactoryParametersImpl extends AssemblyParametersImpl + implements ServiceImplementationFactoryParameters { private ServicePoint _servicePoint; @@ -42,8 +40,8 @@ public ServiceImplementationFactoryParametersImpl(ServicePoint servicePoint, Module invokingModule, List parameters) { - Defense.notNull(servicePoint, "servicePoint"); - Defense.notNull(invokingModule, "invokingModule"); + super(servicePoint, invokingModule); + Defense.notNull(parameters, "parameters"); _servicePoint = servicePoint; @@ -61,31 +59,6 @@ return _servicePoint == p._servicePoint && _invokingModule == p._invokingModule && _parameters.equals(p._parameters); - } - - public String getServiceId() - { - return _servicePoint.getExtensionPointId(); - } - - public Class getServiceInterface() - { - return _servicePoint.getServiceInterface(); - } - - public Log getLog() - { - return _servicePoint.getLog(); - } - - public ErrorLog getErrorLog() - { - return _servicePoint.getErrorLog(); - } - - public Module getInvokingModule() - { - return _invokingModule; } public List getParameters() Added: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AssemblyInstructionImpl.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AssemblyInstructionImpl.java?rev=427127&view=auto ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AssemblyInstructionImpl.java (added) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/AssemblyInstructionImpl.java Mon Jul 31 07:21:27 2006 @@ -0,0 +1,243 @@ +// Copyright 2006 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.service.impl; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.hivemind.AssemblyInstruction; +import org.apache.hivemind.AssemblyParameters; +import org.apache.hivemind.HiveMind; +import org.apache.hivemind.impl.BaseLocatable; +import org.apache.hivemind.internal.Module; +import org.apache.hivemind.service.EventLinker; +import org.apache.hivemind.util.PropertyUtils; + +/** + * Implements support for explicit and implicit (autowiring) dependency injection, event + * registration, and service initialization for core service implementation objects. Instances + * correspond to the <assembly> element as defined by the "hivemind.Assembly" + * schema. + * + * @author Knut Wannheden + * @since 1.2 + */ +public class AssemblyInstructionImpl extends BaseLocatable implements AssemblyInstruction +{ + private List _properties = new ArrayList(); + + private List _events = new ArrayList(); + + private String _initializeMethod; + + private boolean _autowireServices; + + public void addProperty(BuilderFacet facet) + { + _properties.add(facet); + } + + public List getProperties() + { + return _properties; + } + + public void addEventRegistration(EventRegistration registration) + { + _events.add(registration); + } + + public List getEventRegistrations() + { + return _events; + } + + public String getInitializeMethod() + { + return _initializeMethod; + } + + public void setInitializeMethod(String string) + { + _initializeMethod = string; + } + + public boolean getAutowireServices() + { + return _autowireServices; + } + + public void setAutowireServices(boolean autowireServices) + { + _autowireServices = autowireServices; + } + + public void assemble(Object service, AssemblyParameters assemblyParameters) + { + setProperties(service, assemblyParameters); + + registerForEvents(service, assemblyParameters); + + invokeInitializer(service, assemblyParameters); + } + + private void setProperties(Object service, AssemblyParameters factoryParameters) + { + // Track the writeable properties, removing names as they are wired or autowired. + + Set writeableProperties = new HashSet(PropertyUtils.getWriteableProperties(service)); + + for (Iterator i = _properties.iterator(); i.hasNext();) + { + BuilderFacet facet = (BuilderFacet) i.next(); + + String propertyName = facet.wireProperty(service, factoryParameters); + + if (propertyName != null) + writeableProperties.remove(propertyName); + } + + if (_autowireServices) + { + for (Iterator i = writeableProperties.iterator(); i.hasNext();) + { + String propertyName = (String) i.next(); + + autowireService(service, propertyName, factoryParameters); + } + } + } + + private void autowireService(Object service, String propertyName, + AssemblyParameters factoryParameters) + { + Class propertyType = PropertyUtils.getPropertyType(service, propertyName); + + final Module invokingModule = factoryParameters.getInvokingModule(); + final Log log = factoryParameters.getLog(); + + try + { + // Ignore properties for which there are no corresponding + // service points... + if (invokingModule.containsService(propertyType)) + { + Object collaboratingService = invokingModule.getService(propertyType); + PropertyUtils.write(service, propertyName, collaboratingService); + + if (log.isDebugEnabled()) + { + log.debug("Autowired service property " + propertyName + " to " + + collaboratingService); + } + } + } + catch (Exception ex) + { + invokingModule.getErrorHandler().error( + log, + ServiceMessages.autowirePropertyFailure(propertyName, factoryParameters + .getServiceId(), ex), + getLocation(), + ex); + } + } + + private void registerForEvents(Object result, AssemblyParameters factoryParameters) + { + List eventRegistrations = getEventRegistrations(); + + if (eventRegistrations.isEmpty()) + return; + + EventLinker linker = new EventLinkerImpl(factoryParameters.getErrorLog()); + + Iterator i = eventRegistrations.iterator(); + while (i.hasNext()) + { + EventRegistration er = (EventRegistration) i.next(); + + // Will log any errors to the errorHandler + + linker.addEventListener(er.getProducer(), er.getEventSetName(), result, er + .getLocation()); + } + } + + private void invokeInitializer(Object service, AssemblyParameters factoryParameters) + { + String methodName = getInitializeMethod(); + + boolean allowMissing = HiveMind.isBlank(methodName); + + String searchMethodName = allowMissing ? "initializeService" : methodName; + + try + { + findAndInvokeInitializerMethod(service, searchMethodName, allowMissing); + } + catch (InvocationTargetException ex) + { + Throwable cause = ex.getTargetException(); + + factoryParameters.getErrorLog().error( + ServiceMessages.unableToInitializeService( + factoryParameters.getServiceId(), + searchMethodName, + service.getClass(), + cause), + getLocation(), + cause); + } + catch (Exception ex) + { + factoryParameters.getErrorLog().error( + ServiceMessages.unableToInitializeService( + factoryParameters.getServiceId(), + searchMethodName, + service.getClass(), + ex), + getLocation(), + ex); + } + } + + private void findAndInvokeInitializerMethod(Object service, String methodName, + boolean allowMissing) throws IllegalAccessException, InvocationTargetException, + NoSuchMethodException + { + Class serviceClass = service.getClass(); + + try + { + Method m = serviceClass.getMethod(methodName, null); + + m.invoke(service, null); + } + catch (NoSuchMethodException ex) + { + if (allowMissing) + return; + + throw ex; + } + } +} Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderClassResolverFacet.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderClassResolverFacet.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderClassResolverFacet.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderClassResolverFacet.java Mon Jul 31 07:21:27 2006 @@ -14,8 +14,8 @@ package org.apache.hivemind.service.impl; +import org.apache.hivemind.AssemblyParameters; import org.apache.hivemind.ClassResolver; -import org.apache.hivemind.ServiceImplementationFactoryParameters; /** * {@link org.apache.hivemind.service.impl.BuilderFacet} whose value is the @@ -26,14 +26,12 @@ public class BuilderClassResolverFacet extends BuilderFacet { - public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public Object getFacetValue(AssemblyParameters assemblyParameters, Class targetType) { - return factoryParameters.getInvokingModule().getClassResolver(); + return assemblyParameters.getInvokingModule().getClassResolver(); } - public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public boolean isAssignableToType(AssemblyParameters assemblyParameters, Class targetType) { return targetType == ClassResolver.class; } Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorHandlerFacet.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorHandlerFacet.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorHandlerFacet.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorHandlerFacet.java Mon Jul 31 07:21:27 2006 @@ -14,8 +14,8 @@ package org.apache.hivemind.service.impl; +import org.apache.hivemind.AssemblyParameters; import org.apache.hivemind.ErrorHandler; -import org.apache.hivemind.ServiceImplementationFactoryParameters; /** * Exposes the invoking module's {@link org.apache.hivemind.ErrorHandler} to a service as a @@ -26,14 +26,12 @@ public class BuilderErrorHandlerFacet extends BuilderFacet { - public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public Object getFacetValue(AssemblyParameters assemblyParameters, Class targetType) { - return factoryParameters.getInvokingModule().getErrorHandler(); + return assemblyParameters.getInvokingModule().getErrorHandler(); } - public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public boolean isAssignableToType(AssemblyParameters assemblyParameters, Class targetType) { return targetType == ErrorHandler.class; } Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorLogFacet.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorLogFacet.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorLogFacet.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorLogFacet.java Mon Jul 31 07:21:27 2006 @@ -14,8 +14,8 @@ package org.apache.hivemind.service.impl; +import org.apache.hivemind.AssemblyParameters; import org.apache.hivemind.ErrorLog; -import org.apache.hivemind.ServiceImplementationFactoryParameters; /** * Exposes the service's {@link org.apache.hivemind.internal.ExtensionPoint#getErrorLog() error log} @@ -27,14 +27,12 @@ public class BuilderErrorLogFacet extends BuilderFacet { - public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public Object getFacetValue(AssemblyParameters assemblyParameters, Class targetType) { - return factoryParameters.getErrorLog(); + return assemblyParameters.getErrorLog(); } - public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public boolean isAssignableToType(AssemblyParameters assemblyParameters, Class targetType) { return targetType == ErrorLog.class; } Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java Mon Jul 31 07:21:27 2006 @@ -15,7 +15,7 @@ package org.apache.hivemind.service.impl; import org.apache.commons.logging.Log; -import org.apache.hivemind.ServiceImplementationFactoryParameters; +import org.apache.hivemind.AssemblyParameters; import org.apache.hivemind.impl.BaseLocatable; import org.apache.hivemind.util.PropertyUtils; @@ -23,7 +23,7 @@ * Represents one facet of constructing a service implementation instance. A facet is either a * property to be set on the constructed instance, or a parameter to the instance class' * constructor. Facets are nested properties within - * {@link org.apache.hivemind.service.impl.BuilderParameter}, and are used by + * {@link org.apache.hivemind.service.impl.AssemblyInstructionImpl}, and are additionally used by * {@link org.apache.hivemind.service.impl.BuilderFactory}. * * @author Howard Lewis Ship @@ -36,17 +36,16 @@ * Implemented in subclasses to provide a specific value for the facet (for use as a constructor * parameter, or as a value to set a property to). * - * @param factoryParameters + * @param assemblyParameters * the parameters that define the service point and its environment * @param targetType * the desired property type (extracted from the property type of the property to be * updated, when a property is known) */ - public abstract Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters, - Class targetType); + public abstract Object getFacetValue(AssemblyParameters assemblyParameters, Class targetType); - public abstract boolean isAssignableToType( - ServiceImplementationFactoryParameters factoryParameters, Class targetType); + public abstract boolean isAssignableToType(AssemblyParameters factoryParameters, + Class targetType); public String getPropertyName() { @@ -59,6 +58,49 @@ } /** + * Wire (or auto-wire) the property; return the name of the property actually set (if a property + * is set, which is not always the case). + */ + public String wireProperty(Object service, AssemblyParameters assemblyParameters) + { + try + { + // Autowire the property (if possible). + + String autowirePropertyName = autowire(service, assemblyParameters); + + if (autowirePropertyName != null) + return autowirePropertyName; + + // There will be a facet for log, messages, service-id, etc. even if no + // property name is specified, so we skip it here. In many cases, those + // facets will have just done an autowire. + + if (_propertyName == null) + return null; + + Class targetType = PropertyUtils.getPropertyType(service, _propertyName); + + Object value = getFacetValue(assemblyParameters, targetType); + + PropertyUtils.write(service, _propertyName, value); + + final Log log = assemblyParameters.getLog(); + + if (log.isDebugEnabled()) + log.debug("Set property " + _propertyName + " to " + value); + + return _propertyName; + } + catch (Exception ex) + { + assemblyParameters.getErrorLog().error(ex.getMessage(), getLocation(), ex); + + return null; + } + } + + /** * Attempts to autowire a property of the target. This requires that *

    *
  • The facet type defines a default property name and facet type @@ -71,10 +113,10 @@ * * @param target * The service implementation being constructed - * @param factoryParameters + * @param assemblyParameters * the parameters that define the service point and its environment */ - public String autowire(Object target, ServiceImplementationFactoryParameters factoryParameters) + private String autowire(Object target, AssemblyParameters assemblyParameters) { if (_propertyName != null) return null; @@ -89,13 +131,13 @@ Class propertyType = PropertyUtils.getPropertyType(target, defaultPropertyName); - if (isAssignableToType(factoryParameters, propertyType)) + if (isAssignableToType(assemblyParameters, propertyType)) { - Object facetValue = getFacetValue(factoryParameters, propertyType); + Object facetValue = getFacetValue(assemblyParameters, propertyType); PropertyUtils.write(target, defaultPropertyName, facetValue); - Log log = factoryParameters.getLog(); + Log log = assemblyParameters.getLog(); if (log.isDebugEnabled()) log.debug("Autowired property " + defaultPropertyName + " to " + facetValue); @@ -108,7 +150,7 @@ /** * Returns null. Subclasses can provide the default name for a property used by - * {@link #autowire(Object, ServiceImplementationFactoryParameters)}. + * {@link #autowire(Object, AssemblyParameters)}. */ protected String getDefaultPropertyName() { Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFactoryLogic.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFactoryLogic.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFactoryLogic.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderFactoryLogic.java Mon Jul 31 07:21:27 2006 @@ -15,11 +15,8 @@ package org.apache.hivemind.service.impl; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; @@ -27,16 +24,10 @@ import java.util.List; import java.util.Set; -import org.apache.commons.logging.Log; import org.apache.hivemind.ApplicationRuntimeException; -import org.apache.hivemind.ErrorHandler; -import org.apache.hivemind.HiveMind; -import org.apache.hivemind.Location; import org.apache.hivemind.ServiceImplementationFactoryParameters; import org.apache.hivemind.internal.Module; -import org.apache.hivemind.service.EventLinker; import org.apache.hivemind.util.ConstructorUtils; -import org.apache.hivemind.util.PropertyUtils; /** * Created by {@link org.apache.hivemind.service.impl.BuilderFactory} for each service to be @@ -53,8 +44,6 @@ private BuilderParameter _parameter; - private Log _log; - private Module _contributingModule; public BuilderFactoryLogic(ServiceImplementationFactoryParameters factoryParameters, @@ -63,7 +52,6 @@ _factoryParameters = factoryParameters; _parameter = parameter; - _log = _factoryParameters.getLog(); _serviceId = factoryParameters.getServiceId(); _contributingModule = factoryParameters.getInvokingModule(); } @@ -74,11 +62,7 @@ { Object result = instantiateCoreServiceInstance(); - setProperties(result); - - registerForEvents(result); - - invokeInitializer(result); + _parameter.assemble(result, _factoryParameters); return result; } @@ -90,11 +74,6 @@ } } - private void error(String message, Location location, Throwable cause) - { - _factoryParameters.getErrorLog().error(message, location, cause); - } - private Object instantiateCoreServiceInstance() { Class serviceClass = _contributingModule.resolveType(_parameter.getClassName()); @@ -112,7 +91,9 @@ private Object instantiateExplicitConstructorInstance(Class serviceClass, List builderParameters) { int numberOfParams = builderParameters.size(); - List constructorCandidates = getServiceConstructorsOfLength(serviceClass, numberOfParams); + List constructorCandidates = ConstructorUtils.getConstructorsOfLength( + serviceClass, + numberOfParams); outer: for (Iterator candidates = constructorCandidates.iterator(); candidates.hasNext();) { @@ -139,28 +120,6 @@ _parameter.getLocation(), null); } - private List getServiceConstructorsOfLength(Class serviceClass, int length) - { - List fixedLengthConstructors = new ArrayList(); - - Constructor[] constructors = serviceClass.getDeclaredConstructors(); - - outer: for (int i = 0; i < constructors.length; i++) - { - if (!Modifier.isPublic(constructors[i].getModifiers())) - continue; - - Class[] parameterTypes = constructors[i].getParameterTypes(); - - if (parameterTypes.length != length) - continue; - - fixedLengthConstructors.add(constructors[i]); - } - - return fixedLengthConstructors; - } - private Object instantiateConstructorAutowiredInstance(Class serviceClass) { List serviceConstructorCandidates = getOrderedServiceConstructors(serviceClass); @@ -234,187 +193,6 @@ }); return orderedInterfaceConstructors; - } - - private void invokeInitializer(Object service) - { - String methodName = _parameter.getInitializeMethod(); - - boolean allowMissing = HiveMind.isBlank(methodName); - - String searchMethodName = allowMissing ? "initializeService" : methodName; - - try - { - findAndInvokeInitializerMethod(service, searchMethodName, allowMissing); - } - catch (InvocationTargetException ex) - { - Throwable cause = ex.getTargetException(); - - error(ServiceMessages.unableToInitializeService(_serviceId, searchMethodName, service - .getClass(), cause), _parameter.getLocation(), cause); - } - catch (Exception ex) - { - error(ServiceMessages.unableToInitializeService(_serviceId, searchMethodName, service - .getClass(), ex), _parameter.getLocation(), ex); - } - } - - private void findAndInvokeInitializerMethod(Object service, String methodName, - boolean allowMissing) throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException - { - Class serviceClass = service.getClass(); - - try - { - Method m = serviceClass.getMethod(methodName, null); - - m.invoke(service, null); - } - catch (NoSuchMethodException ex) - { - if (allowMissing) - return; - - throw ex; - } - } - - private void registerForEvents(Object result) - { - List eventRegistrations = _parameter.getEventRegistrations(); - - if (eventRegistrations.isEmpty()) - return; - - EventLinker linker = new EventLinkerImpl(_factoryParameters.getErrorLog()); - - Iterator i = eventRegistrations.iterator(); - while (i.hasNext()) - { - EventRegistration er = (EventRegistration) i.next(); - - // Will log any errors to the errorHandler - - linker.addEventListener(er.getProducer(), er.getEventSetName(), result, er - .getLocation()); - } - } - - private void setProperties(Object service) - { - List properties = _parameter.getProperties(); - int count = properties.size(); - - // Track the writeable properties, removing names as they are wired or autowired. - - Set writeableProperties = new HashSet(PropertyUtils.getWriteableProperties(service)); - - for (int i = 0; i < count; i++) - { - BuilderFacet facet = (BuilderFacet) properties.get(i); - - String propertyName = wireProperty(service, facet); - - if (propertyName != null) - writeableProperties.remove(propertyName); - } - - if (_parameter.getAutowireServices()) - autowireServices(service, writeableProperties); - - } - - /** - * Wire (or auto-wire) the property; return the name of the property actually set (if a property - * is set, which is not always the case). - */ - private String wireProperty(Object service, BuilderFacet facet) - { - String propertyName = facet.getPropertyName(); - - try - { - // Autowire the property (if possible). - - String autowirePropertyName = facet.autowire(service, _factoryParameters); - - if (autowirePropertyName != null) - return autowirePropertyName; - - // There will be a facet for log, messages, service-id, etc. even if no - // property name is specified, so we skip it here. In many cases, those - // facets will have just done an autowire. - - if (propertyName == null) - return null; - - Class targetType = PropertyUtils.getPropertyType(service, propertyName); - - Object value = facet.getFacetValue(_factoryParameters, targetType); - - PropertyUtils.write(service, propertyName, value); - - if (_log.isDebugEnabled()) - _log.debug("Set property " + propertyName + " to " + value); - - return propertyName; - } - catch (Exception ex) - { - error(ex.getMessage(), facet.getLocation(), ex); - - return null; - } - } - - private void autowireServices(Object service, Collection propertyNames) - { - Iterator i = propertyNames.iterator(); - while (i.hasNext()) - { - String propertyName = (String) i.next(); - - autowireProperty(service, propertyName); - } - } - - private void autowireProperty(Object service, String propertyName) - { - Class propertyType = PropertyUtils.getPropertyType(service, propertyName); - - try - { - // Ignore properties for which there are no corresponding - // service points... - if( _contributingModule.containsService( propertyType ) ) - { - Object collaboratingService = _contributingModule.getService(propertyType); - PropertyUtils.write(service, propertyName, collaboratingService); - - if (_log.isDebugEnabled()) - { - _log.debug("Autowired service property " + propertyName + " to " - + collaboratingService); - } - } - } - catch (Exception ex) - { - getErrorHandler().error( - _log, - ServiceMessages.autowirePropertyFailure(propertyName, _serviceId, ex), - _parameter.getLocation(), - ex); - } - } - - private ErrorHandler getErrorHandler() - { - return _contributingModule.getErrorHandler(); } } Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderLogFacet.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderLogFacet.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderLogFacet.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderLogFacet.java Mon Jul 31 07:21:27 2006 @@ -15,7 +15,7 @@ package org.apache.hivemind.service.impl; import org.apache.commons.logging.Log; -import org.apache.hivemind.ServiceImplementationFactoryParameters; +import org.apache.hivemind.AssemblyParameters; /** * Facet whose value is the Log instance for the service (which is based on the @@ -25,14 +25,12 @@ */ public class BuilderLogFacet extends BuilderFacet { - public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public Object getFacetValue(AssemblyParameters assemblyParameters, Class targetType) { - return factoryParameters.getLog(); + return assemblyParameters.getLog(); } - public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public boolean isAssignableToType(AssemblyParameters assemblyParameters, Class targetType) { return targetType == Log.class; } Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderMessagesFacet.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderMessagesFacet.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderMessagesFacet.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderMessagesFacet.java Mon Jul 31 07:21:27 2006 @@ -14,8 +14,8 @@ package org.apache.hivemind.service.impl; +import org.apache.hivemind.AssemblyParameters; import org.apache.hivemind.Messages; -import org.apache.hivemind.ServiceImplementationFactoryParameters; /** * {@link org.apache.hivemind.service.impl.BuilderFacet} whose value is the @@ -26,14 +26,12 @@ public class BuilderMessagesFacet extends BuilderFacet { - public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public Object getFacetValue(AssemblyParameters assemblyParameters, Class targetType) { - return factoryParameters.getInvokingModule().getMessages(); + return assemblyParameters.getInvokingModule().getMessages(); } - public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public boolean isAssignableToType(AssemblyParameters assemblyParameters, Class targetType) { return targetType == Messages.class; } Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderParameter.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderParameter.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderParameter.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderParameter.java Mon Jul 31 07:21:27 2006 @@ -20,11 +20,15 @@ import java.util.List; import java.util.Map; +import org.apache.hivemind.AssemblyParameters; +import org.apache.hivemind.Location; import org.apache.hivemind.ServiceImplementationFactoryParameters; import org.apache.hivemind.impl.BaseLocatable; /** * Parameter object used with {@link org.apache.hivemind.service.impl.BuilderFactory}. + *

    + * A BuilderParameter is a wrapper around an {@link AssemblyInstruction} * * @author Howard Lewis Ship */ @@ -32,18 +36,17 @@ { private String _className; - private List _properties = new ArrayList(); - private List _parameters = new ArrayList(); /** @since 1.1 */ private Map _typeFacetMap = new HashMap(); - private List _events = new ArrayList(); - - private String _initializeMethod; + private AssemblyInstructionImpl _assemblyInstruction = new AssemblyInstructionImpl(); - private boolean _autowireServices; + public void setClassName(String string) + { + _className = string; + } public String getClassName() { @@ -62,12 +65,42 @@ public void addProperty(BuilderFacet facet) { - _properties.add(facet); + _assemblyInstruction.addProperty(facet); } public List getProperties() { - return _properties; + return _assemblyInstruction.getProperties(); + } + + public void addEventRegistration(EventRegistration registration) + { + _assemblyInstruction.addEventRegistration(registration); + } + + public List getEventRegistrations() + { + return _assemblyInstruction.getEventRegistrations(); + } + + public void setInitializeMethod(String string) + { + _assemblyInstruction.setInitializeMethod(string); + } + + public String getInitializeMethod() + { + return _assemblyInstruction.getInitializeMethod(); + } + + public void setAutowireServices(boolean autowireServices) + { + _assemblyInstruction.setAutowireServices(autowireServices); + } + + public boolean getAutowireServices() + { + return _assemblyInstruction.getAutowireServices(); } /** @since 1.1 */ @@ -78,7 +111,7 @@ if (result == null) { - for (Iterator i = _properties.iterator(); i.hasNext();) + for (Iterator i = getProperties().iterator(); i.hasNext();) { BuilderFacet facet = (BuilderFacet) i.next(); @@ -96,39 +129,15 @@ return result; } - public void setClassName(String string) - { - _className = string; - } - - public void addEventRegistration(EventRegistration registration) - { - _events.add(registration); - } - - public List getEventRegistrations() - { - return _events; - } - - public String getInitializeMethod() + public void assemble(Object service, AssemblyParameters assemblyParameters) { - return _initializeMethod; + _assemblyInstruction.assemble(service, assemblyParameters); } - public void setInitializeMethod(String string) - { - _initializeMethod = string; - } - - public boolean getAutowireServices() - { - return _autowireServices; - } - - public void setAutowireServices(boolean autowireServices) + public void setLocation(Location location) { - _autowireServices = autowireServices; + super.setLocation(location); + _assemblyInstruction.setLocation(location); } } Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java Mon Jul 31 07:21:27 2006 @@ -17,8 +17,8 @@ import java.util.HashMap; import java.util.Map; +import org.apache.hivemind.AssemblyParameters; import org.apache.hivemind.Location; -import org.apache.hivemind.ServiceImplementationFactoryParameters; import org.apache.hivemind.internal.Module; import org.apache.hivemind.schema.Translator; import org.apache.hivemind.util.ConstructorUtils; @@ -42,18 +42,17 @@ */ private Map _valuesCache = new HashMap(); - public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public Object getFacetValue(AssemblyParameters assemblyParameters, Class targetType) { Object result = _valuesCache.get(targetType); if (result == null) { - Translator translator = factoryParameters.getInvokingModule().getTranslator( + Translator translator = assemblyParameters.getInvokingModule().getTranslator( _translatorName); result = translator.translate( - factoryParameters.getInvokingModule(), + assemblyParameters.getInvokingModule(), targetType, _literalValue, getLocation()); @@ -64,11 +63,10 @@ return result; } - public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public boolean isAssignableToType(AssemblyParameters assemblyParameters, Class targetType) { // TODO should Translator declare an analoguous isAssignableToType method? - Object facetValue = getFacetValue(factoryParameters, targetType); + Object facetValue = getFacetValue(assemblyParameters, targetType); if (facetValue == null) return !targetType.isPrimitive(); Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderServiceIdFacet.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderServiceIdFacet.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderServiceIdFacet.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/BuilderServiceIdFacet.java Mon Jul 31 07:21:27 2006 @@ -14,7 +14,7 @@ package org.apache.hivemind.service.impl; -import org.apache.hivemind.ServiceImplementationFactoryParameters; +import org.apache.hivemind.AssemblyParameters; /** * {@link org.apache.hivemind.service.impl.BuilderFacet} whose value is the service id of the @@ -25,13 +25,12 @@ public class BuilderServiceIdFacet extends BuilderFacet { - public Object getFacetValue(ServiceImplementationFactoryParameters parameters, Class targetType) + public Object getFacetValue(AssemblyParameters assemblyParameters, Class targetType) { - return parameters.getServiceId(); + return assemblyParameters.getServiceId(); } - public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters, - Class targetType) + public boolean isAssignableToType(AssemblyParameters assemblyParameters, Class targetType) { return targetType == String.class; } Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ObjectTranslator.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ObjectTranslator.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ObjectTranslator.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/service/impl/ObjectTranslator.java Mon Jul 31 07:21:27 2006 @@ -50,7 +50,15 @@ int colonx = inputValue.indexOf(':'); - if (colonx < 1) + if (colonx == -1) + { + return contributingModule.getTranslator("smart").translate( + contributingModule, + propertyType, + inputValue, + location); + } + else if (colonx < 1) { _errorLog.error(ServiceMessages.invalidProviderSelector(inputValue), null, null); Modified: hivemind/trunk/framework/src/java/org/apache/hivemind/util/ConstructorUtils.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/java/org/apache/hivemind/util/ConstructorUtils.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/java/org/apache/hivemind/util/ConstructorUtils.java (original) +++ hivemind/trunk/framework/src/java/org/apache/hivemind/util/ConstructorUtils.java Mon Jul 31 07:21:27 2006 @@ -156,7 +156,7 @@ Constructor[] constructors = clazz.getDeclaredConstructors(); - outer: for (int i = 0; i < constructors.length; i++) + for (int i = 0; i < constructors.length; i++) { if (!Modifier.isPublic(constructors[i].getModifiers())) continue; Modified: hivemind/trunk/framework/src/test/hivemind/test/ant/TestConstructRegistry.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/test/hivemind/test/ant/TestConstructRegistry.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/test/hivemind/test/ant/TestConstructRegistry.java (original) +++ hivemind/trunk/framework/src/test/hivemind/test/ant/TestConstructRegistry.java Mon Jul 31 07:21:27 2006 @@ -20,6 +20,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.LineNumberReader; @@ -112,21 +113,13 @@ p.createPath().setLocation( new File(getFrameworkPath("/test-data/TestConstructRegistry/Symbols.xml"))); - File output = File.createTempFile("testBasic-", ".xml"); - - // Delete the file, to force the task to re-create it. - - output.delete(); - - output.deleteOnExit(); + File output = createTempRegistryFile("testBasic-"); cr.setOutput(output); cr.execute(); - compare( - output, - getFrameworkPath("/test-data/TestConstructRegistry/testBasic.xml.master")); + compare(output, getFrameworkPath("/test-data/TestConstructRegistry/testBasic.xml.master")); } public void testLocalRefs() throws Exception @@ -141,13 +134,7 @@ p.createPath().setLocation( new File(getFrameworkPath("/test-data/TestConstructRegistry/LocalRefs.xml"))); - File output = File.createTempFile("testLocalRefs-", ".xml"); - - // Delete the file, to force the task to re-create it. - - output.delete(); - - output.deleteOnExit(); + File output = createTempRegistryFile("testLocalRefs-"); cr.setOutput(output); @@ -172,13 +159,7 @@ p.createPath().setLocation( new File(getFrameworkPath("/test-data/TestConstructRegistry/Symbols.xml"))); - File output = File.createTempFile("testUptoDate-", ".xml"); - - // Delete the file, to force the task to re-create it. - - output.delete(); - - output.deleteOnExit(); + File output = createTempRegistryFile("testUptoDate-"); cr.setOutput(output); @@ -211,17 +192,26 @@ p.createPath().setLocation( new File(getFrameworkPath("/test-data/TestConstructRegistry/module.jar"))); - File output = File.createTempFile("testJars-", ".xml"); - - output.delete(); - - output.deleteOnExit(); + File output = createTempRegistryFile("testJars-"); cr.setOutput(output); cr.execute(); compare(output, getFrameworkPath("/test-data/TestConstructRegistry/testJars.xml.master")); + } + + private File createTempRegistryFile(String prefix) throws IOException + { + File result = File.createTempFile(prefix, ".xml"); + + // Delete the file, to force the task to re-create it. + + result.delete(); + + result.deleteOnExit(); + + return result; } protected void compare(File actual, String expectedPath) throws Exception Added: hivemind/trunk/framework/src/test/hivemind/test/services/AssemblyInstructions.xml URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/test/hivemind/test/services/AssemblyInstructions.xml?rev=427127&view=auto ============================================================================== --- hivemind/trunk/framework/src/test/hivemind/test/services/AssemblyInstructions.xml (added) +++ hivemind/trunk/framework/src/test/hivemind/test/services/AssemblyInstructions.xml Mon Jul 31 07:21:27 2006 @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Modified: hivemind/trunk/framework/src/test/hivemind/test/services/AutowireTarget.java URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/test/hivemind/test/services/AutowireTarget.java?rev=427127&r1=427126&r2=427127&view=diff ============================================================================== --- hivemind/trunk/framework/src/test/hivemind/test/services/AutowireTarget.java (original) +++ hivemind/trunk/framework/src/test/hivemind/test/services/AutowireTarget.java Mon Jul 31 07:21:27 2006 @@ -21,87 +21,24 @@ import org.apache.hivemind.Messages; /** - * Usesd by the {@link hivemind.test.services.TestBuilderFactory} suite. + * Usesd by the {@link hivemind.test.services.TestAssemblyInstruction} suite. * * @author Howard Lewis Ship * @since 1.0 */ -public class AutowireTarget implements Runnable +public interface AutowireTarget extends Runnable { - private Log _log; + public void setClassResolver(ClassResolver resolver); - private ErrorHandler _errorHandler; + public void setErrorHandler(ErrorHandler handler); - private ClassResolver _classResolver; + public void setLog(Log log); - private String _serviceId; + public void setMessages(Messages messages); - private Messages _messages; - - private ErrorLog _errorLog; - - public ClassResolver getClassResolver() - { - return _classResolver; - } - - public ErrorHandler getErrorHandler() - { - return _errorHandler; - } - - public Log getLog() - { - return _log; - } - - public Messages getMessages() - { - return _messages; - } - - public String getServiceId() - { - return _serviceId; - } - - public void setClassResolver(ClassResolver resolver) - { - _classResolver = resolver; - } - - public void setErrorHandler(ErrorHandler handler) - { - _errorHandler = handler; - } - - public void setLog(Log log) - { - _log = log; - } - - public void setMessages(Messages messages) - { - _messages = messages; - } - - public void setServiceId(String string) - { - _serviceId = string; - } - - public void run() - { - // - } - - public ErrorLog getErrorLog() - { - return _errorLog; - } - - public void setErrorLog(ErrorLog errorLog) - { - _errorLog = errorLog; - } + public void setServiceId(String string); + + public void run(); + + public void setErrorLog(ErrorLog errorLog); }