You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by ah...@apache.org on 2006/06/12 23:44:58 UTC
svn commit: r413747 [4/4] - in /jakarta/hivemind/branches/branch-2-0-annot:
./ examples/src/java/org/apache/examples/
framework/src/descriptor/META-INF/ framework/src/java/org/apache/hivemind/
framework/src/java/org/apache/hivemind/ant/ framework/src/j...
Added: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/TranslatorManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/TranslatorManagerImpl.java?rev=413747&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/TranslatorManagerImpl.java (added)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/TranslatorManagerImpl.java Mon Jun 12 14:44:52 2006
@@ -0,0 +1,217 @@
+// Copyright 2004, 2005 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 java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.ErrorHandler;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.TranslatorManager;
+import org.apache.hivemind.internal.RegistryInfrastructure;
+import org.apache.hivemind.schema.Translator;
+import org.apache.hivemind.schema.rules.ClassTranslator;
+import org.apache.hivemind.schema.rules.InstanceTranslator;
+import org.apache.hivemind.schema.rules.ServiceTranslator;
+import org.apache.hivemind.schema.rules.SmartTranslator;
+
+/**
+ * Manages translators for {@link org.apache.hivemind.impl.RegistryInfrastructureImpl}.
+ * Translators may be a shared, cached instance.
+ * (Translators should be stateless). Translators are identified by a constructor, which may be
+ * the name of a translator defined in the <code>hivemind.Translators</code> extension point
+ * (a single builtin translator, <code>class</code>, is hardcoded). Alternately, the name may
+ * consist of a translator name, a comma, and an initializer string for the service (example:
+ * <code>int,min=5</code>).
+ *
+ * @author Howard Lewis Ship
+ */
+public class TranslatorManagerImpl implements TranslatorManager
+{
+ static final Log LOG = LogFactory.getLog(TranslatorManagerImpl.class);
+
+ public static final String TRANSLATORS_CONFIGURATION_ID = "hivemind.Translators";
+
+ private ErrorHandler _errorHandler;
+
+ private RegistryInfrastructure _registry;
+
+ /**
+ * Map of Class, keyed on translator name, used to instantiate new
+ * {@link org.apache.hivemind.schema.Translator}s. Loaded from the
+ * <code>hivemind.Translators</code> configuration point;
+ */
+ private Map _translatorClasses = new HashMap();
+
+ private Map _translatorsCache = new HashMap();
+
+ private boolean _translatorsLoaded;
+
+ public TranslatorManagerImpl(RegistryInfrastructure registry, ErrorHandler errorHandler)
+ {
+ _registry = registry;
+ _errorHandler = errorHandler;
+
+ // Seed the basic translators used to "bootstrap" the
+ // processing of the hivemind.Translators configuration point.
+
+ _translatorsCache.put("class", new ClassTranslator());
+ _translatorsCache.put("service", new ServiceTranslator());
+ _translatorsCache.put("smart", new SmartTranslator());
+ _translatorsCache.put("instance", new InstanceTranslator());
+
+ // smart may take an initializer, so we need to put it into the classes as
+ // well.
+
+ _translatorClasses.put("smart", SmartTranslator.class);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.hivemind.impl.TranslatorManager#getTranslator(java.lang.String)
+ */
+ public synchronized Translator getTranslator(String constructor)
+ {
+ // The cache is preloaded with the hardcoded translators.
+
+ if (!_translatorsLoaded && !_translatorsCache.containsKey(constructor))
+ loadTranslators();
+
+ Translator result = (Translator) _translatorsCache.get(constructor);
+
+ if (result == null)
+ {
+ result = constructTranslator(constructor);
+ _translatorsCache.put(constructor, result);
+ }
+
+ return result;
+ }
+
+ private Translator constructTranslator(String constructor)
+ {
+ String name = constructor;
+ String initializer = null;
+
+ int commax = constructor.indexOf(',');
+
+ if (commax > 0)
+ {
+ name = constructor.substring(0, commax);
+ initializer = constructor.substring(commax + 1);
+ }
+
+ Class translatorClass = findTranslatorClass(name);
+
+ // TODO: check for null class, meaning that the translator is a service.
+
+ return createTranslator(translatorClass, initializer);
+ }
+
+ private Translator createTranslator(Class translatorClass, String initializer)
+ {
+ try
+ {
+
+ if (initializer == null)
+ return (Translator) translatorClass.newInstance();
+
+ Constructor c = translatorClass.getConstructor(new Class[]
+ { String.class });
+
+ return (Translator) c.newInstance(new Object[]
+ { initializer });
+ }
+ catch (Exception ex)
+ {
+ throw new ApplicationRuntimeException(ImplMessages.translatorInstantiationFailure(
+ translatorClass,
+ ex), ex);
+ }
+ }
+
+ private Class findTranslatorClass(String translatorName)
+ {
+ Class result = (Class) _translatorClasses.get(translatorName);
+
+ if (result == null)
+ throw new ApplicationRuntimeException(ImplMessages.unknownTranslatorName(
+ translatorName,
+ TRANSLATORS_CONFIGURATION_ID));
+
+ return result;
+ }
+
+ private void loadTranslators()
+ {
+ // Prevent endless recursion!
+
+ _translatorsLoaded = true;
+
+ List contributions = (List) _registry.getConfiguration(TRANSLATORS_CONFIGURATION_ID, null);
+
+ Map locations = new HashMap();
+ locations.put("class", null);
+
+ Iterator i = contributions.iterator();
+ while (i.hasNext())
+ {
+ TranslatorContribution c = (TranslatorContribution) i.next();
+
+ String name = c.getName();
+ Location oldLocation = (Location) locations.get(name);
+
+ if (oldLocation != null)
+ {
+ _errorHandler.error(LOG, ImplMessages.duplicateTranslatorName(name, oldLocation), c
+ .getLocation(), null);
+
+ continue;
+ }
+
+ locations.put(name, c.getLocation());
+
+ Translator t = c.getTranslator();
+
+ if (t != null)
+ {
+ _translatorsCache.put(name, t);
+ continue;
+ }
+
+ Class tClass = c.getTranslatorClass();
+
+ if (tClass == null)
+ {
+ _errorHandler.error(
+ LOG,
+ ImplMessages.incompleteTranslator(c),
+ c.getLocation(),
+ null);
+ continue;
+ }
+
+ _translatorClasses.put(name, tClass);
+ }
+
+ }
+
+}
\ No newline at end of file
Added: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlConfigurationConstructor.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlConfigurationConstructor.java?rev=413747&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlConfigurationConstructor.java (added)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlConfigurationConstructor.java Mon Jun 12 14:44:52 2006
@@ -0,0 +1,45 @@
+package org.apache.hivemind.impl;
+
+import org.apache.hivemind.Location;
+import org.apache.hivemind.internal.ConfigurationConstructor;
+import org.apache.hivemind.internal.Module;
+import org.apache.hivemind.util.Defense;
+import org.apache.hivemind.util.InstanceCreationUtils;
+
+public class XmlConfigurationConstructor implements ConfigurationConstructor
+{
+ private String _containerClassName;
+
+ private Location _location;
+
+ public XmlConfigurationConstructor(Location location)
+ {
+ _location = location;
+ }
+
+ public Object constructConfigurationContainer(Module contributingModule)
+ {
+ Defense.notNull(_containerClassName, "_containerClassName");
+
+ return InstanceCreationUtils.createInstance(
+ contributingModule,
+ _containerClassName,
+ getLocation());
+ }
+
+ public Location getLocation()
+ {
+ return _location;
+ }
+
+ public String getContainerClassName()
+ {
+ return _containerClassName;
+ }
+
+ public void setContainerClassName(String containerClassName)
+ {
+ _containerClassName = containerClassName;
+ }
+
+}
Added: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java?rev=413747&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java (added)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java Mon Jun 12 14:44:52 2006
@@ -0,0 +1,472 @@
+package org.apache.hivemind.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.ErrorHandler;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.conditional.EvaluationContextImpl;
+import org.apache.hivemind.conditional.Node;
+import org.apache.hivemind.conditional.Parser;
+import org.apache.hivemind.definition.ConfigurationPointDefinition;
+import org.apache.hivemind.definition.ContributionDefinition;
+import org.apache.hivemind.definition.ModuleDefinition;
+import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.definition.ServiceImplementationDefinition;
+import org.apache.hivemind.definition.ServiceInterceptorDefinition;
+import org.apache.hivemind.definition.ServicePointDefinition;
+import org.apache.hivemind.impl.natures.XmlConfigurationPointNature;
+import org.apache.hivemind.impl.natures.XmlRegistryNature;
+import org.apache.hivemind.impl.natures.XmlServicePointNature;
+import org.apache.hivemind.parse.ConfigurationPointDescriptor;
+import org.apache.hivemind.parse.ContributionDescriptor;
+import org.apache.hivemind.parse.DependencyDescriptor;
+import org.apache.hivemind.parse.ImplementationDescriptor;
+import org.apache.hivemind.parse.InstanceBuilder;
+import org.apache.hivemind.parse.InterceptorDescriptor;
+import org.apache.hivemind.parse.ModuleDescriptor;
+import org.apache.hivemind.parse.ServicePointDescriptor;
+import org.apache.hivemind.schema.Schema;
+import org.apache.hivemind.schema.impl.SchemaImpl;
+import org.apache.hivemind.util.IdUtils;
+
+/**
+ * Adds the modules held by instances of {@link org.apache.hivemind.parse.ModuleDescriptor}
+ * to a {@link org.apache.hivemind.definition.RegistryDefinition}.
+ * That is the xml specific module definition is converted to the structure
+ * defined in package {@link org.apache.hivemind.definition}.
+ *
+ * @author Achim Huegen
+ */
+public class XmlModuleDescriptorProcessor
+{
+ private static final Log _log = LogFactory.getLog(XmlModuleDescriptorProcessor.class);
+
+ private ErrorHandler _errorHandler;
+
+ private RegistryDefinition _registryDefinition;
+
+ private Parser _conditionalExpressionParser;
+
+ /**
+ * Map of {@link ModuleDescriptor} keyed on module id.
+ */
+ private Map _moduleDescriptors = new HashMap();
+
+ public XmlModuleDescriptorProcessor(RegistryDefinition registryDefinition, ErrorHandler errorHandler)
+ {
+ _registryDefinition = registryDefinition;
+ _errorHandler = errorHandler;
+ _registryDefinition.addPostProcessor(new XmlPostProcessor());
+ initXmlRegistryNature();
+ }
+
+ public void processModuleDescriptor(ModuleDescriptor md)
+ {
+ String id = md.getModuleId();
+
+ if (_log.isDebugEnabled())
+ _log.debug("Processing module " + id);
+
+ _moduleDescriptors.put(id, md);
+
+ ModuleDefinition module = new ModuleDefinition(id, md.getLocation(), md.getClassResolver(), md.getPackageName());
+
+ addSchemas(module, md);
+
+ addServicePoints(module, md);
+
+ addConfigurationPoints(module, md);
+
+ addImplementations(module, md);
+
+ addContributions(module, md);
+
+ addDependencies(module, md);
+
+ _registryDefinition.addModule(module);
+
+ }
+
+ /**
+ * Check if XmlRegistryNature has been established already by an earlier call
+ * of this method or by another instance of this class.
+ * If not then create a new nature and register ist.
+ */
+ private void initXmlRegistryNature()
+ {
+ if (getXmlRegistryNature() == null) {
+ _registryDefinition.addNature(XmlRegistryNature.class, new XmlRegistryNature(_errorHandler));
+ }
+ }
+
+ private void addDependencies(ModuleDefinition module, ModuleDescriptor md)
+ {
+ int count = size(md.getDependencies());
+ for (int i = 0; i < count; i++)
+ {
+ DependencyDescriptor dependency = (DependencyDescriptor) md.getDependencies().get(i);
+ // TODO: DependencyDefinition mit Location , dependency.getLocation()
+ module.addDependency(dependency.getModuleId());
+ }
+ }
+
+ private XmlRegistryNature getXmlRegistryNature()
+ {
+ return (XmlRegistryNature) _registryDefinition.getNature(XmlRegistryNature.class);
+ }
+
+ private void addSchemas(ModuleDefinition module, ModuleDescriptor md)
+ {
+ for (Iterator schemas = md.getSchemas().iterator(); schemas.hasNext();)
+ {
+ SchemaImpl schema = (SchemaImpl) schemas.next();
+
+ String schemaId = IdUtils.qualify(module.getId(), schema.getId());
+
+ getXmlRegistryNature().addSchema(schemaId, schema);
+ }
+ }
+
+ private void addServicePoints(ModuleDefinition module, ModuleDescriptor md)
+ {
+ List services = md.getServicePoints();
+ int count = size(services);
+
+ for (int i = 0; i < count; i++)
+ {
+ ServicePointDescriptor sd = (ServicePointDescriptor) services.get(i);
+ ServicePointDefinition servicePoint = new ServicePointDefinition(sd.getId(), sd.getLocation(), sd.getVisibility(), sd.getInterfaceClassName());
+ module.addServicePoint(servicePoint);
+
+ // Add the xml nature for the storage of the schema
+ XmlServicePointNature xmlNature = new XmlServicePointNature();
+ servicePoint.addNature(XmlServicePointNature.class, xmlNature);
+
+ // Store the schema in the nature
+ // Schemas are for service factories only
+ if (sd.getParametersSchema() != null) {
+ xmlNature.setParametersSchema(sd.getParametersSchema());
+ xmlNature.setParametersCount(sd.getParametersCount());
+ }
+
+ addInternalImplementations(module, servicePoint, sd);
+ }
+ }
+
+ private void addImplementations(ModuleDefinition module, ModuleDescriptor md)
+ {
+ String moduleId = md.getModuleId();
+
+ List implementations = md.getImplementations();
+ int count = size(implementations);
+
+ for (int i = 0; i < count; i++)
+ {
+ ImplementationDescriptor impl = (ImplementationDescriptor) implementations.get(i);
+
+ if (!includeContribution(impl.getConditionalExpression(), module, impl
+ .getLocation()))
+ continue;
+
+ String pointId = impl.getServiceId();
+ String qualifiedId = IdUtils.qualify(moduleId, pointId);
+
+ addImplementationAndInterceptors(module, qualifiedId, impl);
+ }
+
+ }
+
+ /**
+ * Adds ordinary service contributions.
+ */
+ private void addImplementationAndInterceptors(ModuleDefinition sourceModule, String qualifiedPointId, ImplementationDescriptor id)
+ {
+ InstanceBuilder builder = id.getInstanceBuilder();
+ List interceptors = id.getInterceptors();
+
+ if (builder != null) {
+ ServiceImplementationDefinition implementation = new ServiceImplementationDefinition(
+ builder.getLocation(), builder.createConstructor(sourceModule.getId()),
+ builder.getServiceModel(), false);
+ _registryDefinition.addServiceImplementation(qualifiedPointId, implementation);
+ }
+
+ int count = size(interceptors);
+ for (int i = 0; i < count; i++)
+ {
+ InterceptorDescriptor ind = (InterceptorDescriptor) interceptors.get(i);
+
+ addInterceptor(sourceModule.getId(), qualifiedPointId, ind);
+ }
+ }
+
+ /**
+ * Adds internal service contributions; the contributions provided inplace with the service
+ * definition.
+ */
+ private void addInternalImplementations(ModuleDefinition module, ServicePointDefinition point,
+ ServicePointDescriptor spd)
+ {
+ InstanceBuilder builder = spd.getInstanceBuilder();
+ List interceptors = spd.getInterceptors();
+ String pointId = point.getId();
+
+ if (builder == null && interceptors == null)
+ return;
+
+ if (builder != null) {
+ ServiceImplementationDefinition implementation = new ServiceImplementationDefinition(
+ builder.getLocation(), builder.createConstructor(module.getId()),
+ builder.getServiceModel(), false);
+ point.addImplementation(implementation);
+ }
+ if (interceptors == null)
+ return;
+
+ int count = size(interceptors);
+
+ for (int i = 0; i < count; i++)
+ {
+ InterceptorDescriptor id = (InterceptorDescriptor) interceptors.get(i);
+ String qualifiedId = IdUtils.qualify(module.getId(), pointId);
+ addInterceptor(module.getId(), qualifiedId, id);
+ }
+ }
+
+ private void addConfigurationPoints(ModuleDefinition module, ModuleDescriptor md)
+ {
+ List points = md.getConfigurationPoints();
+ int count = size(points);
+
+ for (int i = 0; i < count; i++)
+ {
+ ConfigurationPointDescriptor cpd = (ConfigurationPointDescriptor) points.get(i);
+
+ XmlConfigurationConstructor constructor = new XmlConfigurationConstructor(
+ cpd.getLocation());
+
+ ConfigurationPointDefinition configurationPoint = new ConfigurationPointDefinition(
+ cpd.getId(), cpd.getLocation(), cpd.getVisibility(),
+ constructor, cpd.getContainerClassName(), cpd.getCount());
+ module.addConfigurationPoint(configurationPoint);
+
+ // Add the xml nature
+ XmlConfigurationPointNature xmlNature = new XmlConfigurationPointNature();
+ configurationPoint.addNature(XmlConfigurationPointNature.class, xmlNature);
+
+ // If schema is embedded we can process it now, otherwise it must
+ // be resolved and processed later
+ if (cpd.getContributionsSchema() != null) {
+ constructor.setContainerClassName(cpd.getContributionsSchema().getRootElementClassName());
+ xmlNature.setSchema(cpd.getContributionsSchema());
+ }
+ }
+ }
+
+ private void addContributions(ModuleDefinition module, ModuleDescriptor md)
+ {
+ String moduleId = md.getModuleId();
+
+ List contributions = md.getContributions();
+ int count = size(contributions);
+
+ for (int i = 0; i < count; i++)
+ {
+ ContributionDescriptor cd = (ContributionDescriptor) contributions.get(i);
+
+ if (!includeContribution(cd.getConditionalExpression(), module, cd.getLocation()))
+ continue;
+
+ String pointId = cd.getConfigurationId();
+ String qualifiedId = IdUtils.qualify(moduleId, pointId);
+
+ ContributionDefinition contribution = new ContributionDefinition(cd.getLocation(),
+ new ContributionImpl(moduleId, cd.getElements()));
+ _registryDefinition.addContribution(qualifiedId, contribution);
+
+ }
+ }
+
+ private void addInterceptor(String contributingModuleId, String qualifiedPointId, InterceptorDescriptor id)
+ {
+ if (_log.isDebugEnabled())
+ _log.debug("Adding " + id + " to service extension point " + qualifiedPointId);
+
+ // TODO annotations: generic container for parameter
+ InvokeFactoryInterceptorConstructor constructor = new InvokeFactoryInterceptorConstructor();
+ constructor.setFactoryServiceId(id.getFactoryServiceId());
+ constructor.setParameters(id.getParameters());
+ constructor.setContributingModuleId(contributingModuleId);
+ ServiceInterceptorDefinition interceptor = new ServiceInterceptorDefinition(
+ id.getLocation(), constructor);
+ _registryDefinition.addServiceInterceptor(qualifiedPointId, interceptor);
+ }
+
+ /**
+ * Resolves schema references via id from contributions and services.
+ * All added module descriptors are processed.
+ */
+ public void resolveSchemas()
+ {
+ for (Iterator i = _moduleDescriptors.values().iterator(); i.hasNext();)
+ {
+ ModuleDescriptor md = (ModuleDescriptor) i.next();
+
+ resolveConfigurationPointSchemas(md);
+ resolveServicePointSchemas(md);
+ }
+ }
+
+ private void resolveConfigurationPointSchemas(ModuleDescriptor md)
+ {
+ ModuleDefinition sourceModule = _registryDefinition.getModule(md.getModuleId());
+
+ List points = md.getConfigurationPoints();
+ int count = size(points);
+
+ for (int i = 0; i < count; i++)
+ {
+ ConfigurationPointDescriptor cpd = (ConfigurationPointDescriptor) points.get(i);
+
+ if (cpd.getContributionsSchemaId() != null) {
+ ConfigurationPointDefinition point = sourceModule.getConfigurationPoint(cpd.getId());
+
+ XmlConfigurationPointNature xmlNature = (XmlConfigurationPointNature) point.getNature(XmlConfigurationPointNature.class);
+ // Store the schema in the nature
+ Schema schema = findSchema(sourceModule, cpd.getContributionsSchemaId(), cpd.getLocation());
+
+ if (schema == null) {
+ // TODO annotations: Exceptionhandling, errorHandler benutzen
+ throw new ApplicationRuntimeException("Schema could not be resolved");
+ } else {
+ xmlNature.setSchema(schema);
+ XmlConfigurationConstructor constructor = (XmlConfigurationConstructor) point.getConstructor();
+ // store the root-element-classname in the constructor
+ constructor.setContainerClassName(schema.getRootElementClassName());
+ }
+ }
+ }
+ }
+
+ private void resolveServicePointSchemas(ModuleDescriptor md)
+ {
+ ModuleDefinition sourceModule = _registryDefinition.getModule(md.getModuleId());
+
+ List points = md.getServicePoints();
+ int count = size(points);
+
+ for (int i = 0; i < count; i++)
+ {
+ ServicePointDescriptor spd = (ServicePointDescriptor) points.get(i);
+
+ if (spd.getParametersSchemaId() != null) {
+ ServicePointDefinition point = sourceModule.getServicePoint(spd.getId());
+
+ XmlServicePointNature xmlNature = (XmlServicePointNature) point.getNature(XmlServicePointNature.class);
+ // Store the schema in the nature
+ Schema schema = findSchema(sourceModule, spd.getParametersSchemaId(), spd.getLocation());
+ if (schema == null) {
+ // TODO annotations: Exceptionhandling, errorHandler benutzen
+ throw new ApplicationRuntimeException("Schema could not be resolved");
+ } else {
+ xmlNature.setParametersSchema(schema);
+ xmlNature.setParametersCount(spd.getParametersCount());
+ }
+ }
+ }
+ }
+
+ private Schema findSchema(ModuleDefinition module, String schemaId, Location location)
+ {
+ if (schemaId == null)
+ return null;
+
+ String moduleId = module.getId();
+ String qualifiedId = IdUtils.qualify(moduleId, schemaId);
+
+ return getSchema(qualifiedId, moduleId, location);
+ }
+
+ /**
+ * Schemas are held locally. Todo: Move to XMLRegistryNature
+ * @param schemaId
+ * @param referencingModule
+ * @param reference
+ * @return
+ */
+ private Schema getSchema(String schemaId, String referencingModule, Location reference)
+ {
+ Schema schema = (Schema) getXmlRegistryNature().getSchema(schemaId);
+
+ if (schema == null)
+ _errorHandler
+ .error(_log, ImplMessages.unableToResolveSchema(schemaId), reference, null);
+ else if (!schema.visibleToModule(referencingModule))
+ {
+ _errorHandler.error(
+ _log,
+ ImplMessages.schemaNotVisible(schemaId, referencingModule),
+ reference,
+ null);
+ schema = null;
+ }
+
+ return schema;
+ }
+
+ /**
+ * Filters a contribution based on an expression. Returns true if the expression is null, or
+ * evaluates to true. Returns false if the expression if non-null and evaluates to false, or an
+ * exception occurs evaluating the expression.
+ *
+ * @param expression
+ * to parse and evaluate
+ * @param location
+ * of the expression (used if an error is reported)
+ */
+
+ private boolean includeContribution(String expression, ModuleDefinition module, Location location)
+ {
+ if (expression == null)
+ return true;
+
+ if (_conditionalExpressionParser == null)
+ _conditionalExpressionParser = new Parser();
+
+ try
+ {
+ Node node = _conditionalExpressionParser.parse(expression);
+
+ return node.evaluate(new EvaluationContextImpl(module.getClassResolver()));
+ }
+ catch (RuntimeException ex)
+ {
+ _errorHandler.error(_log, ex.getMessage(), location, ex);
+
+ return false;
+ }
+ }
+
+ private static int size(Collection c)
+ {
+ return c == null ? 0 : c.size();
+ }
+
+
+ class XmlPostProcessor implements RegistryPostProcessor
+ {
+ public void postprocess(RegistryDefinition registryDefinition, ErrorHandler errorHandler)
+ {
+ // resolve extension which were referenced by id
+ resolveSchemas();
+ }
+ }
+
+}
Added: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleReader.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleReader.java?rev=413747&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleReader.java (added)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleReader.java Mon Jun 12 14:44:52 2006
@@ -0,0 +1,105 @@
+package org.apache.hivemind.impl;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.ClassResolver;
+import org.apache.hivemind.ErrorHandler;
+import org.apache.hivemind.HiveMind;
+import org.apache.hivemind.Resource;
+import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.parse.ModuleDescriptor;
+import org.apache.hivemind.parse.SubModuleDescriptor;
+import org.apache.hivemind.parse.XmlResourceProcessor;
+import org.apache.hivemind.util.ClasspathResource;
+
+public class XmlModuleReader
+{
+ private static final Log LOG = LogFactory.getLog(XmlModuleReader.class);
+
+ private RegistryDefinition _registryDefinition;
+
+ /**
+ * Parser instance used by all parsing of module descriptors.
+ */
+ private XmlResourceProcessor _parser;
+
+ private XmlModuleDescriptorProcessor _processor;
+
+ private ErrorHandler _errorHandler;
+
+ private ClassResolver _classResolver;
+
+ public XmlModuleReader(RegistryDefinition registryDefinition)
+ {
+ this(registryDefinition, new DefaultClassResolver(), new DefaultErrorHandler());
+ }
+
+ public XmlModuleReader(RegistryDefinition registryDefinition, ClassResolver classResolver,
+ ErrorHandler errorHandler)
+ {
+ _registryDefinition = registryDefinition;
+ _classResolver = classResolver;
+ _errorHandler = errorHandler;
+ _processor = new XmlModuleDescriptorProcessor(_registryDefinition, _errorHandler);
+ _parser = new XmlResourceProcessor(_classResolver, _errorHandler);
+ }
+
+ public void readModule(Resource moduleResource)
+ {
+ processResource(moduleResource);
+ }
+
+ public void readClassPathModule(String moduleResourceFileName)
+ {
+ readModule(new ClasspathResource(_classResolver, moduleResourceFileName));
+ }
+
+ private void processResource(Resource resource)
+ {
+ try
+ {
+ ModuleDescriptor md = _parser.processResource(resource);
+
+ _processor.processModuleDescriptor(md);
+
+ // After parsing a module, parse any additional modules identified
+ // within the module (using the <sub-module> element) recursively.
+ processSubModules(md);
+ }
+ catch (RuntimeException ex)
+ {
+ _errorHandler.error(LOG, ex.getMessage(), HiveMind.getLocation(ex), ex);
+ }
+ }
+
+ private void processSubModules(ModuleDescriptor moduleDescriptor)
+ {
+ List subModules = moduleDescriptor.getSubModules();
+
+ if (subModules == null)
+ return;
+
+ for (Iterator i = subModules.iterator(); i.hasNext();)
+ {
+ SubModuleDescriptor smd = (SubModuleDescriptor) i.next();
+
+ Resource descriptorResource = smd.getDescriptor();
+
+ if (descriptorResource.getResourceURL() == null)
+ {
+ _errorHandler.error(
+ LOG,
+ ImplMessages.subModuleDoesNotExist(descriptorResource),
+ smd.getLocation(),
+ null);
+ continue;
+ }
+
+ processResource(smd.getDescriptor());
+ }
+ }
+
+}
Added: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlRegistryProvider.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlRegistryProvider.java?rev=413747&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlRegistryProvider.java (added)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlRegistryProvider.java Mon Jun 12 14:44:52 2006
@@ -0,0 +1,75 @@
+package org.apache.hivemind.impl;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.ClassResolver;
+import org.apache.hivemind.ErrorHandler;
+import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.util.URLResource;
+
+public class XmlRegistryProvider implements RegistryProvider
+{
+ private static final Log LOG = LogFactory.getLog(RegistryBuilder.class);
+
+ /**
+ * The default path, within a JAR or the classpath, to the XML HiveMind module deployment
+ * descriptor: <code>META-INF/hivemodule.xml</code>. Use this constant with the
+ * {@link #XmlRegistryProvider(ClassResolver, String)} constructor.
+ */
+ public static final String HIVE_MODULE_XML = "META-INF/hivemodule.xml";
+
+ private ClassResolver _classResolver;
+
+ private String _resourcePath;
+
+ public XmlRegistryProvider()
+ {
+ this(new DefaultClassResolver(), HIVE_MODULE_XML);
+ }
+
+ public XmlRegistryProvider(ClassResolver classResolver, String resourcePath)
+ {
+ _classResolver = classResolver;
+ _resourcePath = resourcePath;
+ }
+
+ public void process(RegistryDefinition registryDefinition, ErrorHandler errorHandler)
+ {
+ XmlModuleReader xmlModuleReader = new XmlModuleReader(registryDefinition, _classResolver,
+ errorHandler);
+ findModules(xmlModuleReader);
+ }
+
+ private void findModules(XmlModuleReader xmlModuleReader)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Processing modules visible to " + _classResolver);
+
+ ClassLoader loader = _classResolver.getClassLoader();
+ Enumeration e = null;
+
+ try
+ {
+ e = loader.getResources(_resourcePath);
+ }
+ catch (IOException ex)
+ {
+ throw new ApplicationRuntimeException(ImplMessages.unableToFindModules(_classResolver, ex),
+ ex);
+ }
+
+ while (e.hasMoreElements())
+ {
+ URL descriptorURL = (URL) e.nextElement();
+
+ xmlModuleReader.readModule(new URLResource(descriptorURL));
+ }
+
+ }
+
+}
Added: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlConfigurationPointNature.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlConfigurationPointNature.java?rev=413747&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlConfigurationPointNature.java (added)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlConfigurationPointNature.java Mon Jun 12 14:44:52 2006
@@ -0,0 +1,19 @@
+package org.apache.hivemind.impl.natures;
+
+import org.apache.hivemind.schema.Schema;
+
+public class XmlConfigurationPointNature
+{
+ private Schema _schema;
+
+ public Schema getSchema()
+ {
+ return _schema;
+ }
+
+ public void setSchema(Schema schema)
+ {
+ this._schema = schema;
+ }
+
+}
Added: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlRegistryNature.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlRegistryNature.java?rev=413747&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlRegistryNature.java (added)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlRegistryNature.java Mon Jun 12 14:44:52 2006
@@ -0,0 +1,58 @@
+package org.apache.hivemind.impl.natures;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hivemind.ErrorHandler;
+import org.apache.hivemind.TranslatorManager;
+import org.apache.hivemind.definition.RegistryNature;
+import org.apache.hivemind.impl.TranslatorManagerImpl;
+import org.apache.hivemind.internal.RegistryInfrastructure;
+import org.apache.hivemind.schema.Schema;
+
+public class XmlRegistryNature implements RegistryNature
+{
+ private TranslatorManager _translationManager;
+ private ErrorHandler _errorHandler;
+ private RegistryInfrastructure _registry;
+
+ /**
+ * Map of {@link Schema} keyed on fully qualified module id.
+ */
+ private Map _schemas = new HashMap();
+
+ public XmlRegistryNature(ErrorHandler handler)
+ {
+ _errorHandler = handler;
+ }
+
+ public TranslatorManager getTranslationManager()
+ {
+ if (_translationManager == null) {
+ // TODO: Referenz auf Infrastructure besorgen
+ _translationManager = new TranslatorManagerImpl(_registry, _errorHandler);
+ }
+
+ return _translationManager;
+ }
+
+ public void setTranslationManager(TranslatorManager translationManager)
+ {
+ _translationManager = translationManager;
+ }
+
+ public void addSchema(String qualifiedSchemaId, Schema schema)
+ {
+ _schemas.put(qualifiedSchemaId, schema);
+ }
+
+ public Schema getSchema(String qualifiedSchemaId)
+ {
+ return (Schema) _schemas.get(qualifiedSchemaId);
+ }
+
+ public void setRegistry(RegistryInfrastructure registry)
+ {
+ _registry = registry;
+ }
+}
Added: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlServicePointNature.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlServicePointNature.java?rev=413747&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlServicePointNature.java (added)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/natures/XmlServicePointNature.java Mon Jun 12 14:44:52 2006
@@ -0,0 +1,39 @@
+package org.apache.hivemind.impl.natures;
+
+import org.apache.hivemind.Occurances;
+import org.apache.hivemind.schema.Schema;
+
+public class XmlServicePointNature
+{
+ private Schema _parametersSchema;
+ private Occurances _parametersCount = Occurances.REQUIRED;
+
+ /**
+ * Returns the {@link Schema} used to process any parameters passed to the service. Service
+ * implementation factories and service interceptor factories allow parameters.
+ */
+ public Schema getParametersSchema()
+ {
+ return _parametersSchema;
+ }
+
+ public void setParametersSchema(Schema schema)
+ {
+ this._parametersSchema = schema;
+ }
+
+ /**
+ * Returns the number of parameter object expected; generally this is the default of exactly one (
+ * {@link Occurances#REQUIRED}).
+ */
+ public Occurances getParametersCount()
+ {
+ return _parametersCount;
+ }
+
+ public void setParametersCount(Occurances parametersCount)
+ {
+ this._parametersCount = parametersCount;
+ }
+
+}
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/ConfigurationPointDescriptor.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/ConfigurationPointDescriptor.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/ConfigurationPointDescriptor.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/ConfigurationPointDescriptor.java Mon Jun 12 14:44:52 2006
@@ -39,6 +39,12 @@
/** @since 1.1 */
private Visibility _visibility = Visibility.PUBLIC;
+ /**
+ * Implementation class that holds the configuration data.
+ * @since 1.2
+ */
+ private String _containerClassName;
+
public String toString()
{
ToStringBuilder builder = new ToStringBuilder(this);
@@ -108,5 +114,15 @@
public void setVisibility(Visibility visibility)
{
_visibility = visibility;
+ }
+
+ public String getContainerClassName()
+ {
+ return _containerClassName;
+ }
+
+ public void setContainerClassName(String containerClassName)
+ {
+ _containerClassName = containerClassName;
}
}
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/ConversionDescriptor.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/ConversionDescriptor.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/ConversionDescriptor.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/ConversionDescriptor.java Mon Jun 12 14:44:52 2006
@@ -44,13 +44,15 @@
*/
public class ConversionDescriptor extends BaseRule
{
+ private static final String DEFAULT_PARENT_METHOD_NAME = "add";
+
private static final Log LOG = LogFactory.getLog(ConversionDescriptor.class);
private ErrorHandler _errorHandler;
private String _className;
- private String _parentMethodName = "addElement";
+ private String _parentMethodName = DEFAULT_PARENT_METHOD_NAME;
private Map _attributeNameMappingMap = new HashMap();
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/CreateInstanceDescriptor.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/CreateInstanceDescriptor.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/CreateInstanceDescriptor.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/CreateInstanceDescriptor.java Mon Jun 12 14:44:52 2006
@@ -16,8 +16,6 @@
import org.apache.hivemind.impl.BaseLocatable;
import org.apache.hivemind.impl.CreateClassServiceConstructor;
-import org.apache.hivemind.internal.Module;
-import org.apache.hivemind.internal.ServicePoint;
import org.apache.hivemind.internal.ServiceImplementationConstructor;
import org.apache.hivemind.util.ToStringBuilder;
@@ -43,13 +41,12 @@
}
public ServiceImplementationConstructor createConstructor(
- ServicePoint point,
- Module contributingModule)
+ String contributingModuleId)
{
CreateClassServiceConstructor result = new CreateClassServiceConstructor();
result.setLocation(getLocation());
- result.setContributingModule(contributingModule);
+ result.setContributingModuleId(contributingModuleId);
result.setInstanceClassName(_instanceClassName);
return result;
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/DescriptorParser.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/DescriptorParser.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/DescriptorParser.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/DescriptorParser.java Mon Jun 12 14:44:52 2006
@@ -17,9 +17,11 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -733,10 +735,10 @@
checkAttributes();
attributeModel.setName(getAttribute("name"));
- attributeModel.setDefault(getAttribute("default"));
attributeModel.setRequired(getBooleanAttribute("required", false));
attributeModel.setUnique(getBooleanAttribute("unique", false));
attributeModel.setTranslator(getAttribute("translator", "smart"));
+ attributeModel.setDefault(getAttribute("default"));
elementModel.addAttributeModel(attributeModel);
}
@@ -751,7 +753,8 @@
checkAttributes();
- cpd.setId(getValidatedAttribute("id", ID_PATTERN, "id-format"));
+ String id = getValidatedAttribute("id", ID_PATTERN, "id-format");
+ cpd.setId(id);
Occurances count = (Occurances) getEnumAttribute("occurs", OCCURS_MAP);
@@ -765,6 +768,18 @@
cpd.setContributionsSchemaId(getAttribute("schema-id"));
+ // Get the type of the configuration container
+ // For backward compatibility, List is the default
+ String containerClassName = getAttribute("container-class", List.class.getName());
+
+ // Qualify the interface name with the defined package name (which will
+ // often implicitly or explicitly match the module id).
+
+ String fullContainerTypeName = IdUtils.qualify(
+ _moduleDescriptor.getPackageName(),
+ containerClassName);
+ cpd.setContainerClassName(fullContainerTypeName);
+
md.addConfigurationPoint(cpd);
}
@@ -859,7 +874,7 @@
*/
private ElementModel enterElement(String elementName)
{
- ElementModelImpl result = new ElementModelImpl();
+ ElementModelImpl result = new ElementModelImpl(_moduleDescriptor.getModuleId());
push(elementName, result, STATE_ELEMENT);
@@ -876,7 +891,19 @@
{
ConfigurationPointDescriptor cpd = (ConfigurationPointDescriptor) peekObject();
- SchemaImpl schema = new SchemaImpl();
+ SchemaImpl schema = new SchemaImpl(_moduleDescriptor.getModuleId());
+
+ // Get the type of the root element
+ // For backward compatibility, ArrayList is the default
+ String rootElementClassName = getAttribute("root-element-class", ArrayList.class.getName());
+
+ // Qualify the interface name with the defined package name (which will
+ // often implicitly or explicitly match the module id).
+
+ String fullRootElementClassName = IdUtils.qualify(
+ _moduleDescriptor.getPackageName(),
+ rootElementClassName);
+ schema.setRootElementClassName(fullRootElementClassName);
push(elementName, schema, STATE_SCHEMA);
@@ -896,7 +923,7 @@
private void enterParametersSchema(String elementName)
{
ServicePointDescriptor spd = (ServicePointDescriptor) peekObject();
- SchemaImpl schema = new SchemaImpl();
+ SchemaImpl schema = new SchemaImpl(_moduleDescriptor.getModuleId());
push(elementName, schema, STATE_SCHEMA);
@@ -978,6 +1005,10 @@
checkAttributes();
rule.setMethodName(getAttribute("method"));
+
+ if (_attributes.containsKey("parameter-count")) {
+ rule.setParameterCount(getIntAttribute("parameter-count"));
+ }
if (_attributes.containsKey("depth"))
rule.setDepth(getIntAttribute("depth"));
@@ -1026,7 +1057,7 @@
private void enterSchema(String elementName)
{
- SchemaImpl schema = new SchemaImpl();
+ SchemaImpl schema = new SchemaImpl(_moduleDescriptor.getModuleId());
push(elementName, schema, STATE_SCHEMA);
@@ -1040,6 +1071,18 @@
if (visibility != null)
schema.setVisibility(visibility);
+
+ // Get the type of the root element
+ // For backward compatibility, ArrayList is the default
+ String rootElementClassName = getAttribute("root-element-class", ArrayList.class.getName());
+
+ // Qualify the interface name with the defined package name (which will
+ // often implicitly or explicitly match the module id).
+
+ String fullRootElementClassName = IdUtils.qualify(
+ _moduleDescriptor.getPackageName(),
+ rootElementClassName);
+ schema.setRootElementClassName(fullRootElementClassName);
_moduleDescriptor.addSchema(schema);
}
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/DescriptorParser.properties
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/DescriptorParser.properties?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/DescriptorParser.properties (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/DescriptorParser.properties Mon Jun 12 14:44:52 2006
@@ -23,6 +23,7 @@
required.configuration-point.occurs=false
required.configuration-point.schema-id=false
required.configuration-point.visibility=false
+required.configuration-point.container-class=false
required.service-point.id=true
required.service-point.interface=false
@@ -42,7 +43,6 @@
required.interceptor.service-id=true
required.element.name=true
-required.element.key-attribute=false
required.element.content-translator=false
required.attribute.name=true
@@ -55,6 +55,7 @@
required.invoke-parent.method=true
required.invoke-parent.depth=false
+required.invoke-parent.parameter-count=false
required.set-parent.property=true
@@ -70,6 +71,8 @@
required.schema.id=true
required.schema.visibility=false
+required.schema.root-element-class=false
+required.schema{embedded}.root-element-class=false
required.set-module.property=true
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/InstanceBuilder.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/InstanceBuilder.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/InstanceBuilder.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/InstanceBuilder.java Mon Jun 12 14:44:52 2006
@@ -15,8 +15,6 @@
package org.apache.hivemind.parse;
import org.apache.hivemind.Locatable;
-import org.apache.hivemind.internal.Module;
-import org.apache.hivemind.internal.ServicePoint;
import org.apache.hivemind.internal.ServiceImplementationConstructor;
/**
@@ -37,6 +35,5 @@
* that will ultimately create the service implementation instance.
*/
public ServiceImplementationConstructor createConstructor(
- ServicePoint point,
- Module contributingModule);
+ String contributingModuleId);
}
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/InvokeFactoryDescriptor.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/InvokeFactoryDescriptor.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/InvokeFactoryDescriptor.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/parse/InvokeFactoryDescriptor.java Mon Jun 12 14:44:52 2006
@@ -15,8 +15,6 @@
package org.apache.hivemind.parse;
import org.apache.hivemind.impl.InvokeFactoryServiceConstructor;
-import org.apache.hivemind.internal.Module;
-import org.apache.hivemind.internal.ServicePoint;
import org.apache.hivemind.internal.ServiceImplementationConstructor;
import org.apache.hivemind.util.ToStringBuilder;
@@ -32,16 +30,14 @@
private String _serviceModel;
public ServiceImplementationConstructor createConstructor(
- ServicePoint point,
- Module contributingModule)
+ String contributingModuleId)
{
InvokeFactoryServiceConstructor result = new InvokeFactoryServiceConstructor();
result.setLocation(getLocation());
- result.setContributingModule(contributingModule);
+ result.setContributingModuleId(contributingModuleId);
result.setParameters(getParameters());
result.setFactoryServiceId(getFactoryServiceId());
- result.setServiceExtensionPoint(point);
return result;
}
Copied: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/Schema.java (from r413141, jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/schema/Schema.java)
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/Schema.java?p2=jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/Schema.java&p1=jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/schema/Schema.java&r1=413141&r2=413747&rev=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/schema/Schema.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/Schema.java Mon Jun 12 14:44:52 2006
@@ -17,7 +17,6 @@
import java.util.List;
import org.apache.hivemind.Locatable;
-import org.apache.hivemind.internal.Module;
import org.apache.hivemind.parse.AnnotationHolder;
/**
@@ -73,5 +72,7 @@
*
*/
- public Module getDefiningModule();
+ public String getDefiningModuleId();
+
+ public String getRootElementClassName();
}
Copied: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/SchemaProcessor.java (from r413141, jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/schema/SchemaProcessor.java)
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/SchemaProcessor.java?p2=jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/SchemaProcessor.java&p1=jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/schema/SchemaProcessor.java&r1=413141&r2=413747&rev=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/schema/SchemaProcessor.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/SchemaProcessor.java Mon Jun 12 14:44:52 2006
@@ -24,13 +24,6 @@
*/
public interface SchemaProcessor
{
- /**
- * The SchemaProcessor is always the bottom (deepest) object on the stack. Top level objects
- * (contained by a schema, not another element) can use an
- * {@link org.apache.hivemind.schema.rules.InvokeParentRule} to add themselves to the list of
- * elements for the {@link org.apache.hivemind.internal.ConfigurationPoint} being constructed.
- */
- public void addElement(Object element);
/**
* Pushes an object onto the processor's stack.
@@ -65,8 +58,10 @@
* Return the module which defined the schema.
*
* @since 1.1
- */
+ */
+ public String getDefiningModuleId();
+
public Module getDefiningModule();
/**
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/impl/ElementModelImpl.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/impl/ElementModelImpl.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/impl/ElementModelImpl.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/impl/ElementModelImpl.java Mon Jun 12 14:44:52 2006
@@ -44,6 +44,11 @@
private String _contentTranslator;
+ public ElementModelImpl(String moduleId)
+ {
+ super(moduleId);
+ }
+
public String getElementName()
{
return _elementName;
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/impl/SchemaImpl.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/impl/SchemaImpl.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/impl/SchemaImpl.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/impl/SchemaImpl.java Mon Jun 12 14:44:52 2006
@@ -20,7 +20,6 @@
import java.util.List;
import org.apache.hivemind.ApplicationRuntimeException;
-import org.apache.hivemind.internal.Module;
import org.apache.hivemind.internal.Visibility;
import org.apache.hivemind.parse.BaseAnnotationHolder;
import org.apache.hivemind.schema.AttributeModel;
@@ -42,17 +41,24 @@
private Visibility _visibility = Visibility.PUBLIC;
/** @since 1.1 */
- private Module _module;
+ private String _moduleId;
/** @since 1.1 */
private String _id;
+
+ private String _rootElementClassName;
+
+ public SchemaImpl(String moduleId)
+ {
+ _moduleId = moduleId;
+ }
/**
* @since 1.1
*/
public String getModuleId()
{
- return _module.getModuleId();
+ return _moduleId;
}
/**
@@ -153,23 +159,23 @@
/**
* @since 1.1
*/
- public void setModule(Module module)
+ public void setId(String id)
{
- _module = module;
+ _id = id;
}
- /**
- * @since 1.1
- */
- public void setId(String id)
+ public String getDefiningModuleId()
{
- _id = id;
+ return _moduleId;
}
- /** @since 1.1 */
+ public String getRootElementClassName()
+ {
+ return _rootElementClassName;
+ }
- public Module getDefiningModule()
+ public void setRootElementClassName(String rootElementClassName)
{
- return _module;
+ _rootElementClassName = rootElementClassName;
}
}
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/ConfigurationTranslator.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/ConfigurationTranslator.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/ConfigurationTranslator.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/ConfigurationTranslator.java Mon Jun 12 14:44:52 2006
@@ -14,8 +14,6 @@
package org.apache.hivemind.schema.rules;
-import java.util.Map;
-
import org.apache.hivemind.HiveMind;
import org.apache.hivemind.Location;
import org.apache.hivemind.internal.Module;
@@ -34,9 +32,6 @@
{
if (HiveMind.isBlank(inputValue))
return null;
-
- if (propertyType == Map.class && contributingModule.isConfigurationMappable(inputValue))
- return contributingModule.getConfigurationAsMap(inputValue);
return contributingModule.getConfiguration(inputValue);
}
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/InvokeParentRule.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/InvokeParentRule.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/InvokeParentRule.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/InvokeParentRule.java Mon Jun 12 14:44:52 2006
@@ -15,6 +15,7 @@
package org.apache.hivemind.schema.rules;
import java.lang.reflect.Method;
+import java.util.List;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Element;
@@ -33,6 +34,7 @@
private String _methodName;
private int _depth = 1;
+ private int _parameterCount = 1;
public InvokeParentRule()
{
@@ -49,16 +51,29 @@
*/
public void begin(SchemaProcessor processor, Element element)
{
- Object child = processor.peek();
- Class childClass = child == null ? null : child.getClass();
- Object parent = processor.peek(_depth);
+ // Get all parameters from the stack in the order they where pushed on it
+ Object[] parameters = new Object[_parameterCount];
+ Class[] parameterTypes = new Class[_parameterCount];
+ for (int i = 0; i < parameters.length; i++)
+ {
+ parameters[i] = processor.peek(_parameterCount - i - 1);
+ if (parameterTypes[i] != null)
+ parameterTypes[i] = parameters[i].getClass();
+ }
+
+ Object parent = processor.peek(_parameterCount + _depth - 1);
+
+ // For Backward compatiblity: If parent is a list and the method is 'addElement'
+ // then change it to add
+ if (parent instanceof List && "addElement".equals(_methodName) ) {
+ _methodName = "add";
+ }
try
{
- Method m = findMethod(parent, _methodName, childClass);
+ Method m = findMethod(parent, _methodName, parameterTypes);
- m.invoke(parent, new Object[]
- { child });
+ m.invoke(parent, parameters);
}
catch (Exception ex)
{
@@ -103,7 +118,7 @@
* @throws NoSuchMethodException
* if a method can't be found
*/
- private Method findMethod(Object target, String name, Class parameterType)
+ private Method findMethod(Object target, String name, Class[] parameterTypes)
throws NoSuchMethodException
{
Method[] methods = target.getClass().getMethods();
@@ -111,19 +126,40 @@
for (int i = 0; i < methods.length; i++)
{
Method m = methods[i];
- Class[] parameterTypes = m.getParameterTypes();
+ Class[] actualParameterTypes = m.getParameterTypes();
- if (parameterTypes.length != 1)
+ if (actualParameterTypes.length != parameterTypes.length)
continue;
if (!m.getName().equals(name))
continue;
- if ((parameterType != null && parameterTypes[0].isAssignableFrom(parameterType))
- || (parameterType == null && !parameterTypes[0].isPrimitive()))
- return m;
+ for (int j = 0; j < actualParameterTypes.length; j++)
+ {
+ Class actualParameterType = actualParameterTypes[j];
+ Class expectedParameterType = parameterTypes[j];
+ if ((expectedParameterType != null && actualParameterType.isAssignableFrom(expectedParameterType))
+ || (expectedParameterType == null && !actualParameterType.isPrimitive()))
+ return m;
+
+ }
}
throw new NoSuchMethodException(name);
+ }
+
+ public int getParameterCount()
+ {
+ return _parameterCount;
+ }
+
+ /**
+ * Sets the number of parameters that are passed to the invoked method. The default is 1.
+ *
+ * @param parameterCount
+ */
+ public void setParameterCount(int parameterCount)
+ {
+ _parameterCount = parameterCount;
}
}
Modified: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/RuleUtils.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/RuleUtils.java?rev=413747&r1=413141&r2=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/RuleUtils.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/schema/rules/RuleUtils.java Mon Jun 12 14:44:52 2006
@@ -24,6 +24,8 @@
import org.apache.hivemind.Element;
import org.apache.hivemind.ErrorHandler;
import org.apache.hivemind.HiveMind;
+import org.apache.hivemind.TranslatorManager;
+import org.apache.hivemind.impl.natures.XmlRegistryNature;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.schema.SchemaProcessor;
import org.apache.hivemind.schema.Translator;
@@ -149,7 +151,10 @@
{
if (translator == null)
return new NullTranslator();
+
+ XmlRegistryNature xmlNature = (XmlRegistryNature) processor.getContributingModule().getRegistryNature(XmlRegistryNature.class);
+ TranslatorManager translatorManager = xmlNature.getTranslationManager();
- return processor.getContributingModule().getTranslator(translator);
+ return translatorManager.getTranslator(translator);
}
}
Copied: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java (from r413141, jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java)
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java?p2=jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java&p1=jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java&r1=413141&r2=413747&rev=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.java Mon Jun 12 14:44:52 2006
@@ -19,6 +19,8 @@
import org.apache.hivemind.Location;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
+import org.apache.hivemind.TranslatorManager;
+import org.apache.hivemind.impl.natures.XmlRegistryNature;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.schema.Translator;
import org.apache.hivemind.util.ConstructorUtils;
@@ -49,8 +51,9 @@
if (result == null)
{
- Translator translator = factoryParameters.getInvokingModule().getTranslator(
- _translatorName);
+ XmlRegistryNature xmlNature = (XmlRegistryNature) factoryParameters.getInvokingModule().getRegistryNature(XmlRegistryNature.class);
+ TranslatorManager translatorManager = xmlNature.getTranslationManager();
+ Translator translator = translatorManager.getTranslator(_translatorName);
result = translator.translate(
factoryParameters.getInvokingModule(),
Copied: jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/ConfigurationObjectProvider.java (from r413141, jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/service/impl/ConfigurationObjectProvider.java)
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/ConfigurationObjectProvider.java?p2=jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/ConfigurationObjectProvider.java&p1=jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/service/impl/ConfigurationObjectProvider.java&r1=413141&r2=413747&rev=413747&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/service/impl/ConfigurationObjectProvider.java (original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/service/impl/ConfigurationObjectProvider.java Mon Jun 12 14:44:52 2006
@@ -14,8 +14,6 @@
package org.apache.hivemind.service.impl;
-import java.util.Map;
-
import org.apache.hivemind.Location;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.service.ObjectProvider;
@@ -35,9 +33,6 @@
public Object provideObject(Module contributingModule, Class propertyType, String locator,
Location location)
{
- if (propertyType == Map.class && contributingModule.isConfigurationMappable(locator))
- return contributingModule.getConfigurationAsMap(locator);
-
return contributingModule.getConfiguration(locator);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org