You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by hl...@apache.org on 2003/06/04 05:02:32 UTC
cvs commit: jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config ContributeService.xml ServiceHolder.java ContributeSetService.xml TestConfiguration.java
hlship 2003/06/03 20:02:32
Modified: hivemind/src/java/org/apache/commons/hivemind/parse
ServiceDescriptor.java AbstractConfigurator.java
FactoryDescriptor.java DescriptorParser.java
HiveMind_1.0.xsd
AbstractConfigurationDescriptor.java
AbstractServiceDescriptor.java
InstanceBuilderDescriptor.java
InterceptorDescriptor.java
ExpressionDescriptor.java ModuleDescriptor.java
ContributeServiceDescriptor.java
ContributeConfigurationDescriptor.java
ValueDescriptor.java ConfigurationDescriptor.java
CreateInstanceDescriptor.java
hivemind/src/test/hivemind/test HiveMindSuite.java
HiveMindTestCase.java
hivemind/src/test/hivemind/test/services/impl
TrackerFactory.java
hivemind/src/java/org/apache/commons/hivemind/impl
ConfigurationContribution.java
AbstractExtensionPoint.java
FactoryContribution.java
ConfigurationExtensionPoint.java
InterceptorStack.java ServiceExtensionPoint.java
InterceptorContribution.java
hivemind/src/java/org/apache/commons/hivemind
HiveMindMessages.properties
hivemind/src/test/hivemind/test/parse
TestDescriptorParser.java
hivemind/src/test/hivemind/test/config
TestConfiguration.java
Added: hivemind/src/java/org/apache/commons/hivemind/parse
ServiceRefDescriptor.java ExternalParser.java
XMLDescriptor.java
hivemind/src/test/hivemind/test/external Simple.xml
TestExternalParser.java
hivemind/src/java/org/apache/commons/hivemind/impl
Element.java Attribute.java
hivemind/src/java/org/apache/commons/hivemind
IAttribute.java IElement.java
hivemind/src/test/hivemind/test/parse ServiceRef.xml
SetServiceRef.xml
hivemind/src/test/hivemind/test/config ContributeService.xml
ServiceHolder.java ContributeSetService.xml
Log:
Add support for several new elements.
Add support for external XML document parsing.
Revision Changes Path
1.2 +9 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ServiceDescriptor.java
Index: ServiceDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ServiceDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServiceDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ ServiceDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -1,5 +1,6 @@
package org.apache.commons.hivemind.parse;
+import org.apache.commons.lang.builder.ToStringBuilder;
/**
* Defines a service extension point. Corresponds to
@@ -53,6 +54,13 @@
public void setDescription(String string)
{
_description = string;
+ }
+
+ protected void extendDescription(ToStringBuilder builder)
+ {
+ builder.append("id", _id);
+ builder.append("interfaceClassName", _interfaceClassName);
+ builder.append("required", _required);
}
}
1.2 +19 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractConfigurator.java
Index: AbstractConfigurator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractConfigurator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractConfigurator.java 30 May 2003 20:52:01 -0000 1.1
+++ AbstractConfigurator.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -2,6 +2,7 @@
import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.IModule;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.ApplicationRuntimeException;
@@ -21,6 +22,23 @@
private static final Log LOG = LogFactory.getLog(AbstractConfigurator.class);
private String _propertyName;
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+
+ extendDescription(builder);
+
+ builder.append("propertyName", _propertyName);
+ builder.append("location", getLocation());
+
+ return builder.toString();
+ }
+
+ /**
+ * Implemented in subclasses to provide more detail.
+ */
+ protected abstract void extendDescription(ToStringBuilder builder);
public String getPropertyName()
{
1.2 +14 -6 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/FactoryDescriptor.java
Index: FactoryDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/FactoryDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FactoryDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ FactoryDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -4,6 +4,7 @@
import org.apache.commons.hivemind.IFactory;
import org.apache.commons.hivemind.IModule;
import org.apache.commons.hivemind.IRegistry;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.ApplicationRuntimeException;
/**
@@ -27,11 +28,11 @@
_factoryServiceId = string;
}
- /**
- * Obtains the factory service (using the service id) and uses
- * it to create a new instance, which is configured
- * and returned.
- */
+ /**
+ * Obtains the factory service (using the service id) and uses
+ * it to create a new instance, which is configured
+ * and returned.
+ */
public Object provideValue(IModule module)
{
IRegistry registry = module.getRegistry();
@@ -48,6 +49,13 @@
configure(result, module);
return result;
+ }
+
+ protected void extendDescription(ToStringBuilder builder)
+ {
+ builder.append("factoryServiceId", _factoryServiceId);
+
+ super.extendDescription(builder);
}
}
1.2 +35 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java
Index: DescriptorParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DescriptorParser.java 30 May 2003 20:52:01 -0000 1.1
+++ DescriptorParser.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -232,6 +232,40 @@
new String[] { "propertyName", "value" });
result.addSetNext(pattern, "addConfigurator");
+ pattern = "*/service-ref";
+
+ result.addObjectCreate(pattern, ServiceRefDescriptor.class);
+ result.addRule(pattern, setLocationRule);
+ result.addSetLimitedProperties(pattern, "service-id", "serviceId");
+ result.addSetNext(pattern, "addValueProvider");
+
+ pattern = "*/set-service-ref";
+
+ result.addObjectCreate(pattern, ServiceRefDescriptor.class);
+ result.addRule(pattern, setLocationRule);
+ result.addSetLimitedProperties(
+ pattern,
+ new String[] { "property", "service-id" },
+ new String[] { "propertyName", "serviceId" });
+ result.addSetNext(pattern, "addConfigurator");
+
+ pattern = "*/xml";
+
+ result.addObjectCreate(pattern, XMLDescriptor.class);
+ result.addRule(pattern, setLocationRule);
+ result.addSetLimitedProperties(pattern, "path", "path");
+ result.addSetNext(pattern, "addValueProvider");
+
+ pattern = "*/set-xml";
+
+ result.addObjectCreate(pattern, XMLDescriptor.class);
+ result.addRule(pattern, setLocationRule);
+ result.addSetLimitedProperties(
+ pattern,
+ new String[] { "property", "path" },
+ new String[] { "propertyName", "path" });
+ result.addSetNext(pattern, "addConfigurator");
+
pattern = "*/set-expression";
result.addObjectCreate(pattern, ExpressionDescriptor.class);
1.2 +27 -0 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/HiveMind_1.0.xsd
Index: HiveMind_1.0.xsd
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/HiveMind_1.0.xsd,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HiveMind_1.0.xsd 30 May 2003 20:52:01 -0000 1.1
+++ HiveMind_1.0.xsd 4 Jun 2003 03:02:30 -0000 1.2
@@ -107,6 +107,7 @@
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="expression"/>
<xs:element ref="value"/>
+ <xs:element ref="service-ref"/>
<xs:element ref="create-instance"/>
<xs:element ref="factory"/>
</xs:choice>
@@ -125,6 +126,7 @@
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="expression"/>
<xs:element ref="value"/>
+ <xs:element ref="service-ref"/>
<xs:element ref="create-instance"/>
<xs:element ref="factory"/>
</xs:choice>
@@ -203,6 +205,19 @@
</xs:complexContent>
</xs:complexType>
</xs:element>
+ <xs:element name="set-service-ref">
+ <xs:annotation>
+ <xs:documentation>Sets a property of the configured object to a service.</xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:attribute name="service-id" type="qualified-id" use="required">
+ <xs:annotation>
+ <xs:documentation>The fully qualified name of the service to assign to the property.</xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attributeGroup ref="property-setter"/>
+ </xs:complexType>
+ </xs:element>
</xs:choice>
</xs:complexType>
<xs:element name="value" type="xs:string">
@@ -339,4 +354,16 @@
</xs:annotation>
</xs:attribute>
</xs:attributeGroup>
+ <xs:element name="service-ref">
+ <xs:annotation>
+ <xs:documentation>A reference to a service, allowing a service to be directly added to a configuration extension point as an element.</xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:attribute name="service-id" type="qualified-id" use="required">
+ <xs:annotation>
+ <xs:documentation>The fully qualified name of the service to add as a configuration element.</xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
</xs:schema>
1.2 +38 -19 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractConfigurationDescriptor.java
Index: AbstractConfigurationDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractConfigurationDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractConfigurationDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ AbstractConfigurationDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.spec.BaseLocatable;
/**
@@ -14,23 +15,41 @@
*/
public abstract class AbstractConfigurationDescriptor extends BaseLocatable
{
- private List _valueProviders;
-
- public void addValueProvider(IValueProvider provider)
- {
- if (_valueProviders == null)_valueProviders = new ArrayList();
-
- _valueProviders.add(provider);
- }
-
- /**
- * Returns a list of {@link IValueProvider}. May return
- * null if this descriptor has no value providers. The caller
- * should not modify the returned list.
- */
- public List getValueProviders()
- {
- return _valueProviders;
- }
+ private List _valueProviders;
+
+ public void addValueProvider(IValueProvider provider)
+ {
+ if (_valueProviders == null)
+ _valueProviders = new ArrayList();
+
+ _valueProviders.add(provider);
+ }
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+ extendDescription(builder);
+
+ builder.append("valueProviders", _valueProviders);
+ builder.append("location", getLocation());
+
+ return builder.toString();
+ }
+
+ /**
+ * Implemented in subclasses to provide more description; this
+ * implemention does nothing.
+ */
+ protected abstract void extendDescription(ToStringBuilder builder);
+
+ /**
+ * Returns a list of {@link IValueProvider}. May return
+ * null if this descriptor has no value providers. The caller
+ * should not modify the returned list.
+ */
+ public List getValueProviders()
+ {
+ return _valueProviders;
+ }
}
1.2 +20 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractServiceDescriptor.java
Index: AbstractServiceDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractServiceDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractServiceDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ AbstractServiceDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.spec.BaseLocatable;
/**
@@ -17,6 +18,24 @@
{
private InstanceBuilderDescriptor _instanceBuilder;
private List _interceptors;
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+
+ extendDescription(builder);
+
+ builder.append("instanceBuilder", _instanceBuilder);
+ builder.append("interceptors", _interceptors);
+ builder.append("location", getLocation());
+
+ return builder.toString();
+ }
+
+ /**
+ * Implemented in subclasses to provide details about the instance.
+ */
+ protected abstract void extendDescription(ToStringBuilder builder);
public InstanceBuilderDescriptor getInstanceBuilder()
{
1.2 +7 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/InstanceBuilderDescriptor.java
Index: InstanceBuilderDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/InstanceBuilderDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InstanceBuilderDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ InstanceBuilderDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -4,6 +4,7 @@
import java.util.List;
import org.apache.commons.hivemind.IModule;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.Tapestry;
@@ -69,6 +70,11 @@
if (LOG.isDebugEnabled())
LOG.debug("Done configuring: " + object);
+ }
+
+ protected void extendDescription(ToStringBuilder builder)
+ {
+ builder.append("configurators", _configurators);
}
}
1.2 +16 -4 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/InterceptorDescriptor.java
Index: InterceptorDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/InterceptorDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InterceptorDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ InterceptorDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -1,5 +1,6 @@
package org.apache.commons.hivemind.parse;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.spec.BaseLocatable;
/**
@@ -10,9 +11,20 @@
*/
public class InterceptorDescriptor extends BaseLocatable
{
- private int _order;
- private String _serviceId;
-
+ private int _order;
+ private String _serviceId;
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+
+ builder.append("serviceId", _serviceId);
+ builder.append("order", _order);
+ builder.append("location", getLocation());
+
+ return builder.toString();
+ }
+
public int getOrder()
{
return _order;
1.2 +7 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ExpressionDescriptor.java
Index: ExpressionDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ExpressionDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExpressionDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ ExpressionDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -2,6 +2,7 @@
import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.IModule;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.IResourceResolver;
import org.apache.tapestry.util.prop.OgnlUtils;
@@ -15,6 +16,11 @@
public class ExpressionDescriptor extends AbstractConfigurator implements IValueProvider
{
private String _expression;
+
+ protected void extendDescription(ToStringBuilder builder)
+ {
+ builder.append("expression", _expression);
+ }
public void configure(Object object, IModule module)
{
1.2 +18 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ModuleDescriptor.java
Index: ModuleDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ModuleDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ModuleDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ ModuleDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -4,6 +4,7 @@
import java.util.Map;
import org.apache.commons.hivemind.HiveMind;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.spec.BaseLocatable;
/**
@@ -25,6 +26,22 @@
private Map _serviceContributions;
private Map _configurations;
private Map _configurationContributions;
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+
+ builder.append("moduleId", _moduleId);
+ builder.append("moduleClassName", _moduleClassName);
+ builder.append("version", _version);
+ builder.append("services", _services);
+ builder.append("serviceContributions", _serviceContributions);
+ builder.append("configurations", _configurations);
+ builder.append("configurationContributions", _configurationContributions);
+ builder.append("location", getLocation());
+
+ return builder.toString();
+ }
public void addService(ServiceDescriptor service)
{
1.2 +9 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ContributeServiceDescriptor.java
Index: ContributeServiceDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ContributeServiceDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContributeServiceDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ ContributeServiceDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -1,5 +1,7 @@
package org.apache.commons.hivemind.parse;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
/**
* Descriptor for <contribute-service> elements.
*
@@ -19,4 +21,10 @@
{
_serviceId = string;
}
+
+ protected void extendDescription(ToStringBuilder builder)
+ {
+ builder.append("serviceId", _serviceId);
+ }
+
}
1.2 +10 -3 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ContributeConfigurationDescriptor.java
Index: ContributeConfigurationDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ContributeConfigurationDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContributeConfigurationDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ ContributeConfigurationDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -1,5 +1,7 @@
package org.apache.commons.hivemind.parse;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
/**
* Descriptor for <contribute-configuration> element.
*
@@ -8,8 +10,8 @@
*/
public class ContributeConfigurationDescriptor extends AbstractConfigurationDescriptor
{
- private String _configurationId;
-
+ private String _configurationId;
+
public String getConfigurationId()
{
return _configurationId;
@@ -18,6 +20,11 @@
public void setConfigurationId(String string)
{
_configurationId = string;
+ }
+
+ protected void extendDescription(ToStringBuilder builder)
+ {
+ builder.append("configurationId", _configurationId);
}
}
1.2 +7 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ValueDescriptor.java
Index: ValueDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ValueDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ValueDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ ValueDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -1,6 +1,7 @@
package org.apache.commons.hivemind.parse;
import org.apache.commons.hivemind.IModule;
+import org.apache.commons.lang.builder.ToStringBuilder;
/**
* Descriptor for the <value> and
@@ -35,6 +36,11 @@
public void setValue(String string)
{
_value = string;
+ }
+
+ protected void extendDescription(ToStringBuilder builder)
+ {
+ builder.append("value", _value);
}
}
1.2 +14 -6 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ConfigurationDescriptor.java
Index: ConfigurationDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ConfigurationDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigurationDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ ConfigurationDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -1,6 +1,7 @@
package org.apache.commons.hivemind.parse;
import org.apache.commons.hivemind.Occurances;
+import org.apache.commons.lang.builder.ToStringBuilder;
/**
* Descriptor for the <configuration> element, which defines a configuration
@@ -11,11 +12,18 @@
*/
public class ConfigurationDescriptor extends AbstractConfigurationDescriptor
{
- private String _id;
- private String _elementTypeName;
- private Occurances _count = Occurances.UNBOUNDED;
- private String _description;
-
+ private String _id;
+ private String _elementTypeName;
+ private Occurances _count = Occurances.UNBOUNDED;
+ private String _description;
+
+ protected void extendDescription(ToStringBuilder builder)
+ {
+ builder.append("id", _id);
+ builder.append("elementTypeName", _elementTypeName);
+ builder.append("count", _count);
+ }
+
public Occurances getCount()
{
return _count;
1.2 +9 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/CreateInstanceDescriptor.java
Index: CreateInstanceDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/CreateInstanceDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CreateInstanceDescriptor.java 30 May 2003 20:52:01 -0000 1.1
+++ CreateInstanceDescriptor.java 4 Jun 2003 03:02:30 -0000 1.2
@@ -2,6 +2,7 @@
import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.IModule;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.IResourceResolver;
@@ -63,6 +64,13 @@
}
return _instanceClass;
+ }
+
+ protected void extendDescription(ToStringBuilder builder)
+ {
+ builder.append("instanceClassName", _instanceClassName);
+
+ super.extendDescription(builder);
}
}
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ServiceRefDescriptor.java
Index: ServiceRefDescriptor.java
===================================================================
package org.apache.commons.hivemind.parse;
import org.apache.commons.hivemind.IModule;
import org.apache.commons.hivemind.IRegistry;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* A descriptor for the <service-ref> and <set-service-ref>
* elements. Resolves a service and assigns it to a property.
*
* @author Howard Lewis Ship
* @version $Id: ServiceRefDescriptor.java,v 1.1 2003/06/04 03:02:30 hlship Exp $
*/
public class ServiceRefDescriptor extends AbstractConfigurator implements IValueProvider
{
private String _serviceId;
protected void extendDescription(ToStringBuilder builder)
{
builder.append("serviceId", _serviceId);
}
/**
* Invokes {@link #provideValue(IModule)} to get the service,
* and assigns it to the property.
*/
public void configure(Object object, IModule module)
{
Object value = provideValue(module);
configureProperty(object, value, module);
}
/**
* Invokes {@link IRegistry#getService(String, Class)} to retrieve the
* service.
*/
public Object provideValue(IModule module)
{
IRegistry registry = module.getRegistry();
return registry.getService(_serviceId, Object.class);
}
public String getServiceId()
{
return _serviceId;
}
public void setServiceId(String string)
{
_serviceId = string;
}
}
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ExternalParser.java
Index: ExternalParser.java
===================================================================
package org.apache.commons.hivemind.parse;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.IElement;
import org.apache.commons.hivemind.impl.Attribute;
import org.apache.commons.hivemind.impl.Element;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.ILocation;
import org.apache.tapestry.IResourceLocation;
import org.apache.tapestry.Location;
import org.apache.tapestry.util.xml.DocumentParseException;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
/**
* Parser of external XML files (files referenced by a HiveMind module descriptor).
* These are represented as a tree of {@link org.apache.commons.hivemind.IElement}s.
*
* @author Howard Lewis Ship
* @version $Id: ExternalParser.java,v 1.1 2003/06/04 03:02:30 hlship Exp $
*/
public class ExternalParser extends DefaultHandler
{
private static final Log LOG = LogFactory.getLog(ExternalParser.class);
private IResourceLocation _inputLocation;
private int _line = -1;
private int _column = -1;
private List _stack = new ArrayList();
private IElement _root;
private Locator _locator;
private ILocation _location;
private static class StackElement
{
Element _element;
StringBuffer _content;
StackElement(Element e)
{
_element = e;
}
}
protected ILocation getLocation()
{
if (_locator != null)
{
int newLine = _locator.getLineNumber();
int newColumn = _locator.getColumnNumber();
if (_line != newLine || _column != newColumn)
{
_line = newLine;
_column = newColumn;
_location = null;
}
}
if (_location == null)
_location = new Location(_inputLocation, _line, _column);
return _location;
}
public IElement parse(IResourceLocation location) throws DocumentParseException
{
if (LOG.isDebugEnabled())
LOG.debug("Parsing external XML file: " + location);
_inputLocation = location;
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
SAXParser parser = null;
try
{
parser = factory.newSAXParser();
}
catch (ParserConfigurationException ex)
{
throw new ApplicationRuntimeException(ex);
}
catch (SAXException ex)
{
throw new ApplicationRuntimeException(ex);
}
URL url = location.getResourceURL();
if (url == null)
throw new DocumentParseException(
HiveMind.format("ExternalParser.missing-resource", location),
location);
InputSource source = new InputSource(url.toExternalForm());
try
{
parser.parse(source, this);
}
catch (SAXException ex)
{
throw new ApplicationRuntimeException(ex);
}
catch (IOException ex)
{
throw new ApplicationRuntimeException(ex);
}
return _root;
}
protected StackElement peek()
{
int last = _stack.size() - 1;
return (StackElement) _stack.get(last);
}
protected void push(StackElement element)
{
_stack.add(element);
}
protected StackElement pop()
{
int last = _stack.size() - 1;
StackElement result = (StackElement) _stack.get(last);
_stack.remove(last);
return result;
}
/**
* Invokes {@link #fatalError(SAXParseException)}.
*/
public void error(SAXParseException ex) throws SAXException
{
fatalError(ex);
}
/**
* Throws the exception.
*/
public void fatalError(SAXParseException ex) throws SAXException
{
throw ex;
}
/**
* Invokes {@link #fatalError(SAXParseException)}.
*/
public void warning(SAXParseException ex) throws SAXException
{
fatalError(ex);
}
/**
* Adds the characters to the content buffer of the top element on the stack.
*/
public void characters(char[] ch, int start, int length) throws SAXException
{
StackElement e = peek();
if (e._content == null)
e._content = new StringBuffer();
e._content.append(ch, start, length);
}
/**
* Pops the top element off the stack and updates the element's
* content property.
*/
public void endElement(String uri, String localName, String qName) throws SAXException
{
if (LOG.isDebugEnabled())
LOG.debug("endElement " + localName);
StackElement e = pop();
if (e._content == null)
return;
String content = e._content.toString().trim();
if (content.length() > 0)
e._element.setContent(content);
}
public void setDocumentLocator(Locator locator)
{
_locator = locator;
}
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException
{
if (LOG.isDebugEnabled())
LOG.debug("startElement " + localName);
Element e = new Element(qName);
e.setLocation(getLocation());
int count = attributes.getLength();
for (int i = 0; i < count; i++)
{
String name = attributes.getLocalName(i);
String value = attributes.getValue(i);
Attribute a = new Attribute(name, value);
e.addAttribute(a);
}
if (_root == null)
_root = e;
else
peek()._element.addElement(e);
push(new StackElement(e));
}
}
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/XMLDescriptor.java
Index: XMLDescriptor.java
===================================================================
package org.apache.commons.hivemind.parse;
import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.IModule;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.IResourceLocation;
/**
* Descriptor for the <xml> and <set-xml> elements. Used
* to read an external XML file (usually in the same folder as the
* HiveMind module descriptor) in as a tree of {@link org.apache.commons.hivemind.IElement}s.
*
* @author Howard Lewis Ship
* @version $Id: XMLDescriptor.java,v 1.1 2003/06/04 03:02:30 hlship Exp $
*/
public class XMLDescriptor extends AbstractConfigurator implements IValueProvider
{
private String _path;
protected void extendDescription(ToStringBuilder builder)
{
builder.append("path", _path);
}
public Object provideValue(IModule module)
{
IResourceLocation descriptorLocation = module.getLocation().getResourceLocation();
IResourceLocation fileLocation = descriptorLocation.getRelativeLocation(_path);
try
{
return new ExternalParser().parse(fileLocation);
}
catch (Exception ex)
{
throw new ApplicationRuntimeException(
HiveMind.format("XMLDescriptor.unable-to-parse", fileLocation, getLocation(), ex.getMessage()),
getLocation(),
ex);
}
}
public void configure(Object object, IModule module)
{
Object value = provideValue(module);
configureProperty(object, value, module);
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/external/Simple.xml
Index: Simple.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: Simple.xml,v 1.1 2003/06/04 03:02:31 hlship Exp $ -->
<simple gamma="rays" zeta="jones">
<nested depth="1">
nested content
</nested>
simple content
<empty/>
</simple>
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/external/TestExternalParser.java
Index: TestExternalParser.java
===================================================================
package hivemind.test.external;
import hivemind.test.HiveMindTestCase;
import java.net.URL;
import java.util.List;
import java.util.Locale;
import org.apache.commons.hivemind.IAttribute;
import org.apache.commons.hivemind.IElement;
import org.apache.commons.hivemind.parse.ExternalParser;
import org.apache.commons.hivemind.util.URLResourceLocation;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.IResourceLocation;
import org.apache.tapestry.util.xml.DocumentParseException;
/**
* Tests the {@link org.apache.commons.hivemind.impl.ExternalParser} class.
*
* @author Howard Lewis Ship
* @version $Id: TestExternalParser.java,v 1.1 2003/06/04 03:02:31 hlship Exp $
*/
public class TestExternalParser extends HiveMindTestCase
{
public TestExternalParser(String name)
{
super(name);
}
public static class MockResourceLocation implements IResourceLocation
{
public IResourceLocation getLocalization(Locale locale)
{
return this;
}
public String getName()
{
return null;
}
public String getPath()
{
return null;
}
public IResourceLocation getRelativeLocation(String name)
{
return this;
}
public URL getResourceURL()
{
return null;
}
public String toString()
{
return "MockResourceLocation";
}
}
protected IElement parseExternal(String file) throws Exception
{
return parseExternal(getLocation(file));
}
protected IElement parseExternal(IResourceLocation location) throws Exception
{
ExternalParser p = new ExternalParser();
return p.parse(location);
}
public void testSimple() throws Exception
{
IResourceLocation location = getLocation("Simple.xml");
IElement r = parseExternal(location);
assertEquals("simple", r.getElementName());
assertEquals(location, r.getLocation().getResourceLocation());
assertEquals(4, r.getLocation().getLineNumber());
List l = r.getAttributes();
assertEquals(2, l.size());
IAttribute a = (IAttribute) l.get(0);
assertEquals("gamma", a.getName());
assertEquals("rays", a.getValue());
a = (IAttribute) l.get(1);
assertEquals("zeta", a.getName());
assertEquals("jones", a.getValue());
assertEquals("simple content", r.getContent());
l = r.getElements();
assertEquals(2, l.size());
IElement e = (IElement) l.get(0);
assertEquals("nested", e.getElementName());
assertEquals(0, e.getElements().size());
assertEquals("nested content", e.getContent());
List l2 = e.getAttributes();
assertEquals(1, l2.size());
a = (IAttribute) l2.get(0);
assertEquals("depth", a.getName());
assertEquals("1", a.getValue());
e = (IElement) l.get(1);
assertEquals("empty", e.getElementName());
assertEquals(0, e.getAttributes().size());
assertEquals(0, e.getElements().size());
assertEquals("", e.getContent());
assertEquals(location, e.getLocation().getResourceLocation());
assertEquals(9, e.getLocation().getLineNumber());
}
public void testMissing() throws Exception
{
IResourceLocation l = new URLResourceLocation("file://DoesNotExist.xml");
try
{
parseExternal(l);
unreachable();
}
catch (ApplicationRuntimeException ex)
{
checkException(ex, "DoesNotExist.xml");
}
}
public void testNull() throws Exception
{
IResourceLocation l = new MockResourceLocation();
try
{
parseExternal(l);
unreachable();
}
catch (DocumentParseException ex)
{
checkException(ex, "Unable to locate MockResourceLocation");
}
}
}
1.2 +6 -4 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindSuite.java
Index: HiveMindSuite.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindSuite.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HiveMindSuite.java 30 May 2003 20:52:02 -0000 1.1
+++ HiveMindSuite.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -1,6 +1,7 @@
package hivemind.test;
import hivemind.test.config.TestConfiguration;
+import hivemind.test.external.TestExternalParser;
import hivemind.test.parse.TestDescriptorParser;
import hivemind.test.services.TestServices;
import junit.framework.Test;
@@ -12,10 +13,11 @@
{
TestSuite suite = new TestSuite("Master HiveMind Test Suite");
- suite.addTestSuite(TestDescriptorParser.class);
- suite.addTestSuite(TestServices.class);
- suite.addTestSuite(TestConfiguration.class);
-
+ suite.addTestSuite(TestDescriptorParser.class);
+ suite.addTestSuite(TestExternalParser.class);
+ suite.addTestSuite(TestServices.class);
+ suite.addTestSuite(TestConfiguration.class);
+
return suite;
}
1.2 +9 -4 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindTestCase.java
Index: HiveMindTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HiveMindTestCase.java 30 May 2003 20:52:02 -0000 1.1
+++ HiveMindTestCase.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -52,14 +52,19 @@
protected ModuleDescriptor parse(String file) throws Exception
{
+ IResourceLocation location = getLocation(file);
+
+ return _parser.parse(location);
+ }
+
+ protected IResourceLocation getLocation(String file)
+ {
URL url = getClass().getResource(file);
if (url == null)
throw new NullPointerException("No resource named '" + file + "'.");
- IResourceLocation location = new URLResourceLocation(url);
-
- return _parser.parse(location);
+ return new URLResourceLocation(url);
}
protected void checkList(Object[] expected, Object[] actual)
1.2 +0 -2 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/impl/TrackerFactory.java
Index: TrackerFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/impl/TrackerFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TrackerFactory.java 30 May 2003 20:52:05 -0000 1.1
+++ TrackerFactory.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -1,7 +1,5 @@
package hivemind.test.services.impl;
-import hivemind.test.services.impl.CountFactory.CountHandler;
-
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
1.2 +27 -18 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ConfigurationContribution.java
Index: ConfigurationContribution.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ConfigurationContribution.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigurationContribution.java 30 May 2003 20:52:03 -0000 1.1
+++ ConfigurationContribution.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -3,8 +3,8 @@
import org.apache.commons.hivemind.IConfigurationContribution;
import org.apache.commons.hivemind.IModule;
import org.apache.commons.hivemind.parse.IValueProvider;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.ILocation;
-import org.apache.tapestry.spec.BaseLocatable;
/**
* Implements the {@link org.apache.commons.hivemind.IConfigurationContribution} interface,
@@ -16,14 +16,23 @@
*/
public class ConfigurationContribution implements IConfigurationContribution
{
- private IModule _contributingModule;
- private IValueProvider _valueProvider;
-
- public ILocation getLocation()
- {
- return _valueProvider.getLocation();
- }
-
+ private IModule _contributingModule;
+ private IValueProvider _valueProvider;
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+
+ builder.append("valueProvider", _valueProvider);
+
+ return builder.toString();
+ }
+
+ public ILocation getLocation()
+ {
+ return _valueProvider.getLocation();
+ }
+
public IModule getContributingModule()
{
return _contributingModule;
@@ -34,14 +43,14 @@
_contributingModule = module;
}
- /**
- * Invokes {@link IValueProvider#provideValue(IModule)}, passing
- * the module which contributed the value provider.
- */
- public Object getContributedElement()
- {
- return _valueProvider.provideValue(_contributingModule);
- }
+ /**
+ * Invokes {@link IValueProvider#provideValue(IModule)}, passing
+ * the module which contributed the value provider.
+ */
+ public Object getContributedElement()
+ {
+ return _valueProvider.provideValue(_contributingModule);
+ }
public IValueProvider getValueProvider()
{
return _valueProvider;
1.2 +12 -6 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/AbstractExtensionPoint.java
Index: AbstractExtensionPoint.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/AbstractExtensionPoint.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractExtensionPoint.java 30 May 2003 20:52:03 -0000 1.1
+++ AbstractExtensionPoint.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -2,34 +2,40 @@
import org.apache.commons.hivemind.IExtensionPoint;
import org.apache.commons.hivemind.IModule;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.spec.BaseLocatable;
-
public abstract class AbstractExtensionPoint extends BaseLocatable implements IExtensionPoint
{
-
private IModule _module;
private String _extensionPointId;
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+ builder.append("extensionPointId", _extensionPointId);
+
+ return builder.toString();
+ }
+
public void setExtensionPointId(String extensionPointId)
{
_extensionPointId = extensionPointId;
}
- public String getExtensionPointId()
+ public String getExtensionPointId()
{
return _extensionPointId;
}
- public void setModule(IModule module)
+ public void setModule(IModule module)
{
_module = module;
}
- public IModule getModule()
+ public IModule getModule()
{
return _module;
}
-
}
1.2 +10 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/FactoryContribution.java
Index: FactoryContribution.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/FactoryContribution.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FactoryContribution.java 30 May 2003 20:52:03 -0000 1.1
+++ FactoryContribution.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -4,6 +4,7 @@
import org.apache.commons.hivemind.IModule;
import org.apache.commons.hivemind.IServiceExtensionPoint;
import org.apache.commons.hivemind.parse.IValueProvider;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.spec.BaseLocatable;
/**
@@ -20,6 +21,14 @@
private IModule _contributingModule;
private IValueProvider _valueProvider;
private IServiceExtensionPoint _serviceExtensionPoint;
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+ builder.append("valueProvider", _valueProvider);
+
+ return builder.toString();
+ }
public Object createNewInstance()
{
1.2 +13 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ConfigurationExtensionPoint.java
Index: ConfigurationExtensionPoint.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ConfigurationExtensionPoint.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigurationExtensionPoint.java 30 May 2003 20:52:03 -0000 1.1
+++ ConfigurationExtensionPoint.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -8,6 +8,7 @@
import org.apache.commons.hivemind.IConfigurationContribution;
import org.apache.commons.hivemind.IConfigurationExtensionPoint;
import org.apache.commons.hivemind.Occurances;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.IResourceResolver;
@@ -27,6 +28,17 @@
private List _sharedConfigurationContributions;
private Class _elementType;
private String _elementTypeName;
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+
+ builder.append("expectedCount", _expectedCount);
+ builder.append("elementTypeName", _elementTypeName);
+ builder.append("count", getContributionCount());
+
+ return builder.toString();
+ }
public int getContributionCount()
{
1.2 +14 -2 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/InterceptorStack.java
Index: InterceptorStack.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/InterceptorStack.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InterceptorStack.java 30 May 2003 20:52:03 -0000 1.1
+++ InterceptorStack.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -6,6 +6,7 @@
import org.apache.commons.hivemind.IInterceptorStack;
import org.apache.commons.hivemind.IRegistry;
import org.apache.commons.hivemind.IServiceExtensionPoint;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.ApplicationRuntimeException;
@@ -28,6 +29,17 @@
private Object _root;
private Object _top;
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+ builder.append("contribution", _contribution);
+ builder.append("interfaceClass", _interfaceClass);
+ builder.append("root", _root);
+ builder.append("top", _top);
+
+ return builder.toString();
+ }
+
public InterceptorStack(IServiceExtensionPoint sep, Object root)
{
_sep = sep;
@@ -119,7 +131,7 @@
try
{
- _contribution = contribution;
+ _contribution = contribution;
factory.createInterceptor(this);
}
1.2 +13 -3 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ServiceExtensionPoint.java
Index: ServiceExtensionPoint.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ServiceExtensionPoint.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServiceExtensionPoint.java 30 May 2003 20:52:03 -0000 1.1
+++ ServiceExtensionPoint.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -8,12 +8,11 @@
import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.IFactoryContribution;
import org.apache.commons.hivemind.IInterceptorContribution;
-import org.apache.commons.hivemind.IModule;
import org.apache.commons.hivemind.IRegistry;
import org.apache.commons.hivemind.IServiceExtensionPoint;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.IResourceResolver;
-import org.apache.tapestry.spec.BaseLocatable;
/**
* Implementation of {@link org.apache.commons.hivemind.IServiceExtensionPoint}.
@@ -29,6 +28,17 @@
private List _interceptorContributions;
private List _sortedInterceptorContributions;
private boolean _required;
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+ builder.append("serviceIntrerfaceName", _serviceInterfaceName);
+ builder.append("required", _required);
+ builder.append("factoryContribution", _factoryContribution);
+ builder.append("interceptorContributions", _interceptorContributions);
+
+ return builder.toString();
+ }
/**
* Used for sorting interceptor contributions into ascending
1.2 +11 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/InterceptorContribution.java
Index: InterceptorContribution.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/InterceptorContribution.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InterceptorContribution.java 30 May 2003 20:52:03 -0000 1.1
+++ InterceptorContribution.java 4 Jun 2003 03:02:31 -0000 1.2
@@ -3,6 +3,7 @@
import org.apache.commons.hivemind.IInterceptorContribution;
import org.apache.commons.hivemind.IModule;
import org.apache.commons.hivemind.IServiceExtensionPoint;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.spec.BaseLocatable;
/**
@@ -18,6 +19,15 @@
private String _factoryId;
private int _order;
private IServiceExtensionPoint _serviceExtensionPoint;
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+ builder.append("factoryId", _factoryId);
+ builder.append("order", _order);
+
+ return builder.toString();
+ }
public IModule getContributingModule()
{
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/Element.java
Index: Element.java
===================================================================
package org.apache.commons.hivemind.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.hivemind.IAttribute;
import org.apache.commons.hivemind.IElement;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.tapestry.spec.BaseLocatable;
/**
* Implementation of {@link org.apache.commons.hivemind.IElement}.
*
* @author Howard Lewis Ship
* @version $Id: Element.java,v 1.1 2003/06/04 03:02:31 hlship Exp $
*/
public class Element extends BaseLocatable implements IElement
{
private String _elementName;
private String _content;
private List _elements;
private List _safeElements;
private List _attributes;
private List _safeAttributes;
public Element(String elementName)
{
_elementName = elementName;
}
public String getElementName()
{
return _elementName;
}
public void addAttribute(IAttribute attribute)
{
if (_attributes == null)
_attributes = new ArrayList();
_attributes.add(attribute);
}
public void addElement(IElement element)
{
if (_elements == null)
_elements = new ArrayList();
_elements.add(element);
}
public synchronized List getAttributes()
{
if (_attributes == null)
return Collections.EMPTY_LIST;
if (_safeAttributes == null)
_safeAttributes = Collections.unmodifiableList(_attributes);
return _safeAttributes;
}
public String getContent()
{
if (_content == null)
return "";
return _content;
}
public synchronized List getElements()
{
if (_elements == null)
return Collections.EMPTY_LIST;
if (_safeElements == null)
_safeElements = Collections.unmodifiableList(_elements);
return _safeElements;
}
public boolean isEmpty()
{
return _elements == null || _elements.size() == 0;
}
public void setContent(String string)
{
_content = string;
}
public String toString()
{
ToStringBuilder builder = new ToStringBuilder(this);
builder.append("elementName", _elementName);
builder.append("attributes", _attributes);
builder.append("elements", _elements);
builder.append("content", _content);
builder.append("location", getLocation());
return builder.toString();
}
}
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/Attribute.java
Index: Attribute.java
===================================================================
package org.apache.commons.hivemind.impl;
import org.apache.commons.hivemind.IAttribute;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* Implementation of {@link org.apache.commons.hivemind.IAttribute}.
*
* @author Howard Lewis Ship
* @version $Id: Attribute.java,v 1.1 2003/06/04 03:02:31 hlship Exp $
*/
public class Attribute implements IAttribute
{
private String _name;
private String _value;
public Attribute(String name, String value)
{
_name = name;
_value = value;
}
public String getName()
{
return _name;
}
public String getValue()
{
return _value;
}
public String toString()
{
ToStringBuilder builder = new ToStringBuilder(this);
builder.append("name", _name);
builder.append("value", _value);
return builder.toString();
}
}
1.2 +5 -1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/HiveMindMessages.properties
Index: HiveMindMessages.properties
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/HiveMindMessages.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HiveMindMessages.properties 30 May 2003 20:52:03 -0000 1.1
+++ HiveMindMessages.properties 4 Jun 2003 03:02:32 -0000 1.2
@@ -26,6 +26,8 @@
DescriptorParser.error-reading-descriptor=Unable to read descriptor {0}: {1}
DescriptorParser.unable-to-set-feature=Error setting SAXParser feature {0} to {1}: {2}
+ExternalParser.missing-resource=Unable to locate {0}.
+
ServiceExtensionPoint.bad-interface=Unable to find interface {0} (for service {1}).
ServiceExtensionPoint.interface-required=Service extension points must provide an interface type: {0} is a class (for service {1}).
@@ -55,3 +57,5 @@
ExpressionDescriptor.unable-to-evaluate=Unable to evaluate expression ''{0}'' for {1}: {2}
FactoryDescriptor.factory-is-null=Factory service {0} is null.
+
+XMLDescriptor.unable-to-parse=Unable to parse {0} (referenced at {1}): {2}
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/IAttribute.java
Index: IAttribute.java
===================================================================
package org.apache.commons.hivemind;
/**
* An attribute that may be attached to a {@link org.apache.commons.hivemind.IElement}.
* Namespaces not (yet) supported.
*
* @author Howard Lewis Ship
* @version $Id: IAttribute.java,v 1.1 2003/06/04 03:02:32 hlship Exp $
*/
public interface IAttribute
{
/**
* Returns the name of the attribute.
*/
public String getName();
/**
* Returns the value of the attribute.
*/
public String getValue();
}
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/IElement.java
Index: IElement.java
===================================================================
package org.apache.commons.hivemind;
import java.util.List;
import org.apache.tapestry.ILocatable;
/**
* Simplified read-only thread safe DOM.
* Currently, no support for namespaces, but that may come.
*
* @author Howard Lewis Ship
* @version $Id: IElement.java,v 1.1 2003/06/04 03:02:32 hlship Exp $
*/
public interface IElement extends ILocatable
{
public String getElementName();
/**
* Returns an unmodifiable list of {@link IAttribute} for this element.
* May return an empty list, but won't return null. The attributes
* are in no specific order.
*/
public List getAttributes();
/**
* Returns true if this element contains no other elements.
*/
public boolean isEmpty();
/**
* Returns an unmodifiable list of {@link IElement} directly contained
* by this element. May return an empty list, but won't return null.
* The elements are returned in the order in which they were encountered
* in the XML.
*/
public List getElements();
/**
* Returns the content of the element. This is a concatination of
* all the text directly enclosed by the element. Ignorable whitespace
* is ignored. The content is trimmed of leading and trailing whitespace.
*/
public String getContent();
}
1.2 +36 -0 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestDescriptorParser.java
Index: TestDescriptorParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestDescriptorParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestDescriptorParser.java 30 May 2003 20:52:04 -0000 1.1
+++ TestDescriptorParser.java 4 Jun 2003 03:02:32 -0000 1.2
@@ -15,6 +15,7 @@
import org.apache.commons.hivemind.parse.InterceptorDescriptor;
import org.apache.commons.hivemind.parse.ModuleDescriptor;
import org.apache.commons.hivemind.parse.ServiceDescriptor;
+import org.apache.commons.hivemind.parse.ServiceRefDescriptor;
import org.apache.commons.hivemind.parse.ValueDescriptor;
import org.apache.tapestry.Tapestry;
@@ -319,4 +320,39 @@
assertEquals("package.foo.FooInterceptor", id.getServiceId());
assertEquals(1000, id.getOrder());
}
+
+ public void testServiceRef() throws Exception
+ {
+ ModuleDescriptor md = parse("ServiceRef.xml");
+
+ ConfigurationDescriptor cd = md.getConfiguration("Blat");
+ List l = cd.getValueProviders();
+ assertEquals(1, l.size());
+
+ ServiceRefDescriptor d = (ServiceRefDescriptor) l.get(0);
+
+ assertEquals("foo.bar.Boom", d.getServiceId());
+ }
+
+ public void testSetServiceRef() throws Exception
+ {
+ ModuleDescriptor md = parse("SetServiceRef.xml");
+
+ ConfigurationDescriptor cd = md.getConfiguration("Blat");
+ List l = cd.getValueProviders();
+ assertEquals(1, l.size());
+
+ CreateInstanceDescriptor cid = (CreateInstanceDescriptor) l.get(0);
+
+ assertEquals("zip.zap.Zoom", cid.getInstanceClassName());
+
+ l = cid.getConfigurators();
+ assertEquals(1, l.size());
+
+ ServiceRefDescriptor d = (ServiceRefDescriptor) l.get(0);
+
+ assertEquals("gamma", d.getPropertyName());
+ assertEquals("foo.bar.Boom", d.getServiceId());
+ }
+
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/ServiceRef.xml
Index: ServiceRef.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: ServiceRef.xml,v 1.1 2003/06/04 03:02:32 hlship Exp $ -->
<module
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://jakarta.apache.org/commons/hivemind/schema/HiveMind_1.0.xsd"
id="package.configuration"
version="0.0.2">
<configuration id="Blat" element-type="java.lang.Object">
<service-ref service-id="foo.bar.Boom"/>
</configuration>
</module>
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/SetServiceRef.xml
Index: SetServiceRef.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: SetServiceRef.xml,v 1.1 2003/06/04 03:02:32 hlship Exp $ -->
<module
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://jakarta.apache.org/commons/hivemind/schema/HiveMind_1.0.xsd"
id="package.configuration"
version="0.0.2">
<configuration id="Blat" element-type="java.lang.Object">
<create-instance class="zip.zap.Zoom">
<set-service-ref property="gamma" service-id="foo.bar.Boom"/>
</create-instance>
</configuration>
</module>
1.2 +24 -0 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/TestConfiguration.java
Index: TestConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/TestConfiguration.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestConfiguration.java 30 May 2003 20:52:02 -0000 1.1
+++ TestConfiguration.java 4 Jun 2003 03:02:32 -0000 1.2
@@ -1,6 +1,7 @@
package hivemind.test.config;
import hivemind.test.HiveMindTestCase;
+import hivemind.test.services.ISimpleService;
import java.util.List;
import java.util.Locale;
@@ -196,5 +197,28 @@
assertEquals("built by factory", e.getTitle());
assertEquals(21, e.getOrder());
assertEquals(new Locale("fr"), e.getLocale());
+ }
+
+ public void testContributeService() throws Exception
+ {
+ IRegistry r = buildRegistry("ContributeService.xml");
+ List c = r.getConfiguration("hivemind.test.config.SimpleConf");
+ assertEquals(1, c.size());
+
+ ISimpleService s = (ISimpleService) c.get(0);
+
+ assertEquals(5, s.add(2, 3));
+ }
+
+ public void testContributeSetService() throws Exception
+ {
+ IRegistry r = buildRegistry("ContributeSetService.xml");
+ List c = r.getConfiguration("hivemind.test.config.SimpleConf");
+ assertEquals(1, c.size());
+
+ ServiceHolder h = (ServiceHolder) c.get(0);
+
+ assertEquals(100, h.getOrder());
+ assertEquals(7, h.getService().add(4, 3));
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/ContributeService.xml
Index: ContributeService.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: ContributeService.xml,v 1.1 2003/06/04 03:02:32 hlship Exp $ -->
<module
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://jakarta.apache.org/commons/hivemind/schema/HiveMind_1.0.xsd"
id="hivemind.test.config"
version="1.0.0">
<service id="Simple" interface="hivemind.test.services.ISimpleService">
<create-instance class="hivemind.test.services.impl.SimpleService"/>
</service>
<configuration id="SimpleConf" element-type="hivemind.test.services.ISimpleService">
<service-ref service-id="hivemind.test.config.Simple"/>
</configuration>
</module>
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/ServiceHolder.java
Index: ServiceHolder.java
===================================================================
package hivemind.test.config;
import hivemind.test.services.ISimpleService;
/**
* Used to test the <set-service-ref> element.
*
* @author Howard Lewis Ship
* @version $Id: ServiceHolder.java,v 1.1 2003/06/04 03:02:32 hlship Exp $
*/
public class ServiceHolder
{
private int _order;
private ISimpleService _service;
public int getOrder()
{
return _order;
}
public ISimpleService getService()
{
return _service;
}
public void setOrder(int i)
{
_order = i;
}
public void setService(ISimpleService service)
{
_service = service;
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/ContributeSetService.xml
Index: ContributeSetService.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: ContributeSetService.xml,v 1.1 2003/06/04 03:02:32 hlship Exp $ -->
<module
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://jakarta.apache.org/commons/hivemind/schema/HiveMind_1.0.xsd"
id="hivemind.test.config"
version="1.0.0">
<service id="Simple" interface="hivemind.test.services.ISimpleService">
<create-instance class="hivemind.test.services.impl.SimpleService"/>
</service>
<configuration id="SimpleConf" element-type="hivemind.test.config.ServiceHolder">
<create-instance class="hivemind.test.config.ServiceHolder">
<set property="order" value="100"/>
<set-service-ref property="service" service-id="hivemind.test.config.Simple"/>
</create-instance>
</configuration>
</module>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org