You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by kn...@apache.org on 2004/10/04 17:16:05 UTC
cvs commit: jakarta-hivemind/framework/src/test/hivemind/test/parse TestToString.java
knut 2004/10/04 08:16:05
Modified: framework/src/test/hivemind/test FrameworkTestCase.java
TestRegistryBuilder.java
framework/src/java/org/apache/hivemind/parse
ConversionDescriptor.java DescriptorParser.java
framework/src/java/org/apache/hivemind/impl
ImplStrings.properties ImplMessages.java
RegistryInfrastructureConstructor.java
. status.xml
framework/src/test/hivemind/test/parse TestToString.java
Log:
RegistryInfrastructureConstructor now detects duplicate extension points and reports error (HIVEMIND-64)
Revision Changes Path
1.14 +31 -0 jakarta-hivemind/framework/src/test/hivemind/test/FrameworkTestCase.java
Index: FrameworkTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/FrameworkTestCase.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- FrameworkTestCase.java 13 Sep 2004 12:44:35 -0000 1.13
+++ FrameworkTestCase.java 4 Oct 2004 15:16:03 -0000 1.14
@@ -19,9 +19,11 @@
import org.apache.hivemind.impl.DefaultClassResolver;
import org.apache.hivemind.impl.DefaultErrorHandler;
import org.apache.hivemind.impl.RegistryAssemblyImpl;
+import org.apache.hivemind.parse.ConfigurationPointDescriptor;
import org.apache.hivemind.parse.DependencyDescriptor;
import org.apache.hivemind.parse.DescriptorParser;
import org.apache.hivemind.parse.ModuleDescriptor;
+import org.apache.hivemind.parse.ServicePointDescriptor;
import org.apache.hivemind.test.HiveMindTestCase;
/**
@@ -70,6 +72,7 @@
result.setModuleId(moduleId);
result.setVersion(version);
+ result.setClassResolver(new DefaultClassResolver());
result.setLocation(fabricateLocation(0));
return result;
@@ -86,6 +89,34 @@
result.setVersion(version);
result.setLocation(fabricateLocation(0));
+ return result;
+ }
+
+ /**
+ * Convenience method for creating a {@link ServicePointDescriptor}.
+ */
+ protected ServicePointDescriptor createServicePointDescriptor(String pointId,
+ Class serviceInterface)
+ {
+ ServicePointDescriptor result = new ServicePointDescriptor();
+
+ result.setId(pointId);
+ result.setInterfaceClassName(serviceInterface.getName());
+ result.setLocation(fabricateLocation(0));
+
+ return result;
+ }
+
+ /**
+ * Convenience method for creating a {@link ConfigurationPointDescriptor}.
+ */
+ protected ConfigurationPointDescriptor createConfigurationPointDescriptor(String pointId)
+ {
+ ConfigurationPointDescriptor result = new ConfigurationPointDescriptor();
+
+ result.setId(pointId);
+ result.setLocation(fabricateLocation(0));
+
return result;
}
1.20 +24 -0 jakarta-hivemind/framework/src/test/hivemind/test/TestRegistryBuilder.java
Index: TestRegistryBuilder.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/TestRegistryBuilder.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- TestRegistryBuilder.java 28 Sep 2004 10:24:02 -0000 1.19
+++ TestRegistryBuilder.java 4 Oct 2004 15:16:03 -0000 1.20
@@ -101,4 +101,28 @@
assertLoggedMessagePattern("Module " + duplicateModuleId + " is duplicated!");
}
+ public void testDuplicateExtensionPoints() throws Exception
+ {
+ ModuleDescriptor testModule = createModuleDescriptor("hivemind.test", null);
+
+ testModule.addServicePoint(createServicePointDescriptor("MyService", Comparable.class));
+ testModule.addServicePoint(createServicePointDescriptor("MyService", Comparable.class));
+
+ testModule.addConfigurationPoint(createConfigurationPointDescriptor("MyConfig"));
+ testModule.addConfigurationPoint(createConfigurationPointDescriptor("MyConfig"));
+
+ SimpleModuleDescriptorProvider provider = new SimpleModuleDescriptorProvider();
+ provider.addModuleDescriptor(testModule);
+
+ interceptLogging();
+
+ buildFrameworkRegistry(provider);
+
+ List interceptedEvents = getInterceptedLogEvents();
+
+ assertLoggedMessagePattern("Extension point hivemind\\.test\\.MyService "
+ + "conflicts with definition at .* and has been ignored\\.", interceptedEvents);
+ assertLoggedMessagePattern("Extension point hivemind\\.test\\.MyConfig "
+ + "conflicts with definition at .* and has been ignored\\.", interceptedEvents);
+ }
}
1.11 +25 -36 jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ConversionDescriptor.java
Index: ConversionDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ConversionDescriptor.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ConversionDescriptor.java 19 Aug 2004 22:24:00 -0000 1.10
+++ ConversionDescriptor.java 4 Oct 2004 15:16:03 -0000 1.11
@@ -21,7 +21,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.Location;
import org.apache.hivemind.impl.BaseLocatable;
import org.apache.hivemind.schema.AttributeModel;
import org.apache.hivemind.schema.impl.ElementModelImpl;
@@ -31,7 +30,7 @@
/**
* Descriptor for the <conversion> module descriptor element.
- *
+ *
* @author Howard Lewis Ship
*/
public class ConversionDescriptor extends BaseLocatable
@@ -39,43 +38,40 @@
private static final Log LOG = LogFactory.getLog(ConversionDescriptor.class);
private ErrorHandler _errorHandler;
+
private ElementModelImpl _elementModel;
private String _className;
+
private String _parentMethodName = "addElement";
+
private Map _attributeMappings = new HashMap();
- public ConversionDescriptor(
- ErrorHandler errorHandler,
- ElementModelImpl elementModel,
- Location location)
+ public ConversionDescriptor(ErrorHandler errorHandler, ElementModelImpl elementModel)
{
_errorHandler = errorHandler;
_elementModel = elementModel;
-
- setLocation(location);
}
/**
- * Adds a mapping for an attribute; these come from <map>
- * elements nested within the <conversion> element. A check
- * for duplicate attribute mappings (that is, duplicated attribute name),
- * and an error is logged (and the duplicate ignored).
+ * Adds a mapping for an attribute; these come from <map> elements nested within the
+ * <conversion> element. A check for duplicate attribute mappings (that is, duplicated
+ * attribute name), and an error is logged (and the duplicate ignored).
*/
public void addAttributeMapping(AttributeMappingDescriptor descriptor)
{
String attributeName = descriptor.getAttributeName();
- AttributeMappingDescriptor existing =
- (AttributeMappingDescriptor) _attributeMappings.get(attributeName);
+ AttributeMappingDescriptor existing = (AttributeMappingDescriptor) _attributeMappings
+ .get(attributeName);
if (existing != null)
{
_errorHandler.error(
- LOG,
- ParseMessages.dupeAttributeMapping(descriptor, existing),
- descriptor.getLocation(),
- null);
+ LOG,
+ ParseMessages.dupeAttributeMapping(descriptor, existing),
+ descriptor.getLocation(),
+ null);
return;
}
@@ -95,8 +91,7 @@
/**
* Invoked once all <map> elements have been processed; this creates
- * {@link org.apache.hivemind.schema.Rule}s that are added
- * to the {@link ElementModelImpl}.
+ * {@link org.apache.hivemind.schema.Rule}s that are added to the {@link ElementModelImpl}.
*/
public void addRulesForModel()
{
@@ -116,17 +111,13 @@
AttributeModel am = (AttributeModel) i.next();
String attributeName = am.getName();
- AttributeMappingDescriptor amd =
- (AttributeMappingDescriptor) _attributeMappings.get(attributeName);
+ AttributeMappingDescriptor amd = (AttributeMappingDescriptor) _attributeMappings
+ .get(attributeName);
if (amd == null)
{
- _elementModel.addRule(
- new ReadAttributeRule(
- attributeName,
- constructPropertyName(attributeName),
- null,
- getLocation()));
+ _elementModel.addRule(new ReadAttributeRule(attributeName,
+ constructPropertyName(attributeName), null, getLocation()));
}
else
{
@@ -134,19 +125,17 @@
if (propertyName == null)
propertyName = constructPropertyName(attributeName);
- _elementModel.addRule(
- new ReadAttributeRule(attributeName, propertyName, null, amd.getLocation()));
+ _elementModel.addRule(new ReadAttributeRule(attributeName, propertyName, null, amd
+ .getLocation()));
_attributeMappings.remove(attributeName);
}
}
if (!_attributeMappings.isEmpty())
- _errorHandler.error(
- LOG,
- ParseMessages.extraMappings(_attributeMappings.keySet(), _elementModel),
- _elementModel.getLocation(),
- null);
+ _errorHandler.error(LOG, ParseMessages.extraMappings(
+ _attributeMappings.keySet(),
+ _elementModel), _elementModel.getLocation(), null);
}
private String constructPropertyName(String attributeName)
@@ -181,4 +170,4 @@
return buffer.toString();
}
-}
+}
\ No newline at end of file
1.37 +2 -4 jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java
Index: DescriptorParser.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- DescriptorParser.java 27 Sep 2004 14:36:35 -0000 1.36
+++ DescriptorParser.java 4 Oct 2004 15:16:03 -0000 1.37
@@ -35,7 +35,6 @@
import org.apache.hivemind.Attribute;
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.Location;
import org.apache.hivemind.Occurances;
import org.apache.hivemind.Resource;
import org.apache.hivemind.impl.AttributeImpl;
@@ -56,11 +55,11 @@
import org.apache.hivemind.schema.rules.SetModuleRule;
import org.apache.hivemind.schema.rules.SetParentRule;
import org.apache.hivemind.schema.rules.SetPropertyRule;
-import org.apache.hivemind.util.PropertyUtils;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
+import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -758,8 +757,7 @@
{
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
- ConversionDescriptor cd = new ConversionDescriptor(_errorHandler, elementModel,
- getLocation());
+ ConversionDescriptor cd = new ConversionDescriptor(_errorHandler, elementModel);
push(elementName, cd, STATE_CONVERSION);
1.13 +1 -0 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
Index: ImplStrings.properties
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ImplStrings.properties 25 Sep 2004 17:08:34 -0000 1.12
+++ ImplStrings.properties 4 Oct 2004 15:16:05 -0000 1.13
@@ -32,6 +32,7 @@
unable-to-parse=Unable to parse module deployment descriptor {0}: {1}
unable-to-find-modules=Unable to locate HiveMind module deployment descriptors in {0}: {1}
duplicate-module-id=Module {0} is duplicated! Definition in {2} has been ignored in favor of existing definition from {1}.
+duplicate-extension-point=Extension point {0} conflicts with definition at {1} and has been ignored.
unknown-configuration-extension-point=Module {0} has contributed to unknown configuration point {1}. The contribution has been ignored.
unknown-service-extension-point=Module {0} contributed to unknown service point {1}. The contribution has been ignored.
missing-service=No module has contributed a service constructor for service point {0}.
1.20 +9 -4 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
Index: ImplMessages.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ImplMessages.java 25 Sep 2004 17:08:34 -0000 1.19
+++ ImplMessages.java 4 Oct 2004 15:16:05 -0000 1.20
@@ -26,6 +26,7 @@
import org.apache.hivemind.Resource;
import org.apache.hivemind.events.RegistryShutdownListener;
import org.apache.hivemind.internal.ConfigurationPoint;
+import org.apache.hivemind.internal.ExtensionPoint;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.internal.ServiceInterceptorContribution;
import org.apache.hivemind.internal.ServicePoint;
@@ -139,6 +140,11 @@
descriptor.getLocation().getResource());
}
+ public static String duplicateExtensionPointId(String pointId, ExtensionPoint existingPoint)
+ {
+ return _formatter.format("duplicate-extension-point", pointId, existingPoint.getLocation());
+ }
+
public static String unknownConfigurationPoint(String moduleId,
ContributionDescriptor descriptor)
{
@@ -374,13 +380,12 @@
point.getExtensionPointId(),
contributingModule.getModuleId());
}
-
- public static String servicePointNotVisible(ServicePoint point,
- Module contributingModule)
+
+ public static String servicePointNotVisible(ServicePoint point, Module contributingModule)
{
return _formatter.format(
"service-point-not-visible",
point.getExtensionPointId(),
contributingModule.getModuleId());
- }
+ }
}
1.3 +23 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java
Index: RegistryInfrastructureConstructor.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RegistryInfrastructureConstructor.java 27 Sep 2004 13:51:37 -0000 1.2
+++ RegistryInfrastructureConstructor.java 4 Oct 2004 15:16:05 -0000 1.3
@@ -26,8 +26,10 @@
import org.apache.hivemind.ErrorHandler;
import org.apache.hivemind.Occurances;
import org.apache.hivemind.ShutdownCoordinator;
+import org.apache.hivemind.internal.ConfigurationPoint;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.internal.RegistryInfrastructure;
+import org.apache.hivemind.internal.ServicePoint;
import org.apache.hivemind.parse.ConfigurationPointDescriptor;
import org.apache.hivemind.parse.ContributionDescriptor;
import org.apache.hivemind.parse.DependencyDescriptor;
@@ -42,7 +44,6 @@
* Fed a series of {@link org.apache.hivemind.parse.ModuleDescriptor}s, this class will assemble
* them into a final {@link org.apache.hivemind.internal.RegistryInfrastructure}as well as perform
* some validations.
- *
* <p>
* This class was extracted from {@link org.apache.hivemind.impl.RegistryBuilder}.
*
@@ -249,6 +250,16 @@
String pointId = moduleId + "." + sd.getId();
+ ServicePoint existingPoint = (ServicePoint) _servicePoints.get(pointId);
+
+ if (existingPoint != null)
+ {
+ _errorHandler.error(_log, ImplMessages.duplicateExtensionPointId(
+ pointId,
+ existingPoint), sd.getLocation(), null);
+ continue;
+ }
+
if (_log.isDebugEnabled())
_log.debug("Creating service point " + pointId);
@@ -292,6 +303,17 @@
ConfigurationPointDescriptor cpd = (ConfigurationPointDescriptor) points.get(i);
String pointId = moduleId + "." + cpd.getId();
+
+ ConfigurationPoint existingPoint = (ConfigurationPoint) _configurationPoints
+ .get(pointId);
+
+ if (existingPoint != null)
+ {
+ _errorHandler.error(_log, ImplMessages.duplicateExtensionPointId(
+ pointId,
+ existingPoint), cpd.getLocation(), null);
+ continue;
+ }
if (_log.isDebugEnabled())
_log.debug("Creating configuration point " + pointId);
1.66 +4 -1 jakarta-hivemind/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/jakarta-hivemind/status.xml,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- status.xml 1 Oct 2004 21:34:05 -0000 1.65
+++ status.xml 4 Oct 2004 15:16:05 -0000 1.66
@@ -40,8 +40,11 @@
<action type="add" dev="HLS" fixes-bug="HIVEMIND-58">
Add visibility (public or private) to configuration points, service points and schemas.
</action>
- <action type="fix" dev="KW" fixes-bug="HIVEMIND-63">
+ <action type="add" dev="KW" fixes-bug="HIVEMIND-63">
Add <null> constructor parameter element to BuilderFactory service.
+ </action>
+ <action type="fix" dev="KW" fixes-bug="HIVEMIND-64">
+ Report error if module descriptors define conflicting service or configuration points.
</action>
</release>
1.17 +4 -0 jakarta-hivemind/framework/src/test/hivemind/test/parse/TestToString.java
Index: TestToString.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/parse/TestToString.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- TestToString.java 25 Sep 2004 17:08:34 -0000 1.16
+++ TestToString.java 4 Oct 2004 15:16:05 -0000 1.17
@@ -31,11 +31,13 @@
import org.apache.hivemind.parse.ConfigurationPointDescriptor;
import org.apache.hivemind.parse.ContributionDescriptor;
import org.apache.hivemind.parse.CreateInstanceDescriptor;
+import org.apache.hivemind.parse.DependencyDescriptor;
import org.apache.hivemind.parse.ImplementationDescriptor;
import org.apache.hivemind.parse.InterceptorDescriptor;
import org.apache.hivemind.parse.InvokeFactoryDescriptor;
import org.apache.hivemind.parse.ModuleDescriptor;
import org.apache.hivemind.parse.ServicePointDescriptor;
+import org.apache.hivemind.parse.SubModuleDescriptor;
import org.easymock.MockControl;
/**
@@ -59,6 +61,8 @@
new CreateInstanceDescriptor().toString();
new InvokeFactoryDescriptor().toString();
new ModuleDescriptor().toString();
+ new SubModuleDescriptor().toString();
+ new DependencyDescriptor().toString();
new ServicePointDescriptor().toString();
new InterceptorDescriptor().toString();
new ModuleImpl().toString();
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org