hlship 2004/07/25 15:12:52
Modified: examples/src/java/org/apache/hivemind/examples
CalculatorMain.java
framework/src/java/org/apache/hivemind/impl
InvokeFactoryServiceConstructor.java
ConfigurationPointImpl.java ServicePointImpl.java
SchemaProcessorImpl.java
ServiceInterceptorContributionImpl.java
framework/src/java/org/apache/hivemind/internal
ServicePoint.java
examples/src/documentation/content/xdocs/hivemind-examples
panorama.xml
examples/src/java/com/panorama/startup/impl
TaskExecutor.java
framework/src/java/org/apache/hivemind/service/impl
BuilderFactory.java
framework/src/test/org/apache/hivemind/impl
TestSchemaProcessor.java
examples/src/conf log4j.properties
framework/src/test/hivemind/test/config
TestConfigurationPoint.java
examples build.xml
Added: examples/src/java/org/apache/hivemind/examples
ExampleUtils.java
examples/src/java/com/panorama/startup PanoramaMain.java
Log:
Change Schema Processing (for contributions and parameters) to use a logger
related to the configuration or service.
Update example code and documentation.
Revision Changes Path
1.2 +12 -34
jakarta-hivemind/examples/src/java/org/apache/hivemind/examples/CalculatorMain.java
Index: CalculatorMain.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/examples/src/java/org/apache/hivemind/examples/CalculatorMain.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CalculatorMain.java 24 Jul 2004 22:18:13 -0000 1.1
+++ CalculatorMain.java 25 Jul 2004 22:12:51 -0000 1.2
@@ -14,14 +14,14 @@
package org.apache.hivemind.examples;
-import java.util.Locale;
-
-import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.Registry;
-import org.apache.hivemind.impl.DefaultClassResolver;
-import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.util.FileResource;
+/**
+ * Runs through the methods of the [EMAIL PROTECTED]
org.apache.hivemind.examples.Calculator} with
+ * a pair of argument values parsed from the command line.
+ *
+ * @author Howard Lewis Ship
+ */
public class CalculatorMain
{
public static void main(String[] args)
@@ -29,41 +29,19 @@
double arg0 = Double.parseDouble(args[0]);
double arg1 = Double.parseDouble(args[1]);
- Registry registry = buildRegistry();
-
+ Registry registry = ExampleUtils.buildRegistry("examples.sdl");
+
// Since we know there's exactly *one* service-point implementing
Calculator,
// we can get it this way, and never have to know its service id.
-
+
Calculator calculator = (Calculator)
registry.getService(Calculator.class);
-
+
System.out.println("Inputs: " + arg0 + " and " + arg1);
System.out.println("Add: " + calculator.add(arg0, arg1));
System.out.println("Subtract: " + calculator.subtract(arg0, arg1));
System.out.println("Multiply: " + calculator.multiply(arg0, arg1));
System.out.println("Divide: " + calculator.divide(arg0, arg1));
- }
-
- private static Registry buildRegistry()
- {
- // The examples package is structured oddly (so that it doesn't
interfere with
- // the main HiveMind framework tests), so we have to go through some
gyrations
- // here that aren't necessary in an ordinary HiveMind application.
-
- String projectRoot = System.getProperty("PROJECT_ROOT");
- String path = projectRoot +
"/examples/src/descriptor/META-INF/examples.sdl";
-
- RegistryBuilder builder = new RegistryBuilder();
- ClassResolver resolver = new DefaultClassResolver();
-
- // Process standard files, on the classpath.
-
- builder.processModules(resolver);
-
- // Process the examples.sdl file, which (given its non-standard
name)
- // is not visible.
-
- builder.processModule(resolver, new FileResource(path));
-
- return builder.constructRegistry(Locale.getDefault());
+
+ registry.shutdown();
}
}
1.1
jakarta-hivemind/examples/src/java/org/apache/hivemind/examples/ExampleUtils.java
Index: ExampleUtils.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.examples;
import java.util.Locale;
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.Registry;
import org.apache.hivemind.impl.DefaultClassResolver;
import org.apache.hivemind.impl.RegistryBuilder;
import org.apache.hivemind.util.FileResource;
/**
* Utilities needed by the examples.
*
* @author Howard Lewis Ship
*/
public class ExampleUtils
{
/**
* Builds a Registry for a file stored in the src/descriptor/META-INF
directory.
*
* @param fileName -- the name of the module descriptor file.
*/
public static Registry buildRegistry(String fileName)
{
// The examples package is structured oddly (so that it doesn't
interfere with
// the main HiveMind framework tests), so we have to go through some
gyrations
// here that aren't necessary in an ordinary HiveMind application.
String projectRoot = System.getProperty("PROJECT_ROOT");
String path = projectRoot + "/examples/src/descriptor/META-INF/" +
fileName;
RegistryBuilder builder = new RegistryBuilder();
ClassResolver resolver = new DefaultClassResolver();
// Process standard files, on the classpath.
builder.processModules(resolver);
// Process the examples.sdl file, which (given its non-standard name)
// is not visible.
builder.processModule(resolver, new FileResource(path));
return builder.constructRegistry(Locale.getDefault());
}
}
1.1
jakarta-hivemind/examples/src/java/com/panorama/startup/PanoramaMain.java
Index: PanoramaMain.java
===================================================================
// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.panorama.startup;
import org.apache.hivemind.Registry;
import org.apache.hivemind.examples.ExampleUtils;
/**
* Builds the Registry for Panorama, then exits. Demonstrates how the
* MDDs are parsed and the startup logic executed.
*
* @author Howard Lewis Ship
*/
public class PanoramaMain
{
public static void main(String[] args)
{
Registry registry = ExampleUtils.buildRegistry("panorama.sdl");
registry.shutdown();
}
}
1.7 +10 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java
Index: InvokeFactoryServiceConstructor.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/InvokeFactoryServiceConstructor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- InvokeFactoryServiceConstructor.java 16 Jul 2004 23:15:40 -0000
1.6
+++ InvokeFactoryServiceConstructor.java 25 Jul 2004 22:12:51 -0000
1.7
@@ -59,8 +59,17 @@
Schema schema = factoryPoint.getParametersSchema();
+ // Note: it's kind of a toss up whether logging should
occur using the
+ // id of the service being constructed, or of the
factory being invoked.
+ // Here, we're using the constructed service ... with
the intent being that
+ // users will enable debugging for the service (or
search the logs for the service)
+ // if it fails to build properly.
+
SchemaProcessorImpl processor =
- new
SchemaProcessorImpl(_contributingModule.getErrorHandler(), schema);
+ new SchemaProcessorImpl(
+ _contributingModule.getErrorHandler(),
+ _serviceExtensionPoint.getServiceLog(),
+ schema);
processor.process(_parameters, _contributingModule);
1.6 +4 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java
Index: ConfigurationPointImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ConfigurationPointImpl.java 17 Jun 2004 15:16:11 -0000 1.5
+++ ConfigurationPointImpl.java 25 Jul 2004 22:12:51 -0000 1.6
@@ -186,7 +186,10 @@
return Collections.EMPTY_LIST;
SchemaProcessorImpl processor =
- new SchemaProcessorImpl(getModule().getErrorHandler(),
_contributionsSchema);
+ new SchemaProcessorImpl(
+ getModule().getErrorHandler(),
+ LogFactory.getLog(getExtensionPointId()),
+ _contributionsSchema);
int count = _contributions.size();
1.5 +4 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ServicePointImpl.java
Index: ServicePointImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ServicePointImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServicePointImpl.java 17 Jun 2004 15:16:12 -0000 1.4
+++ ServicePointImpl.java 25 Jul 2004 22:12:51 -0000 1.5
@@ -272,4 +272,8 @@
_serviceModelObject.instantiateService();
}
+ public Log getServiceLog()
+ {
+ return LogFactory.getLog(getExtensionPointId());
+ }
}
1.7 +4 -4
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/SchemaProcessorImpl.java
Index: SchemaProcessorImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/SchemaProcessorImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SchemaProcessorImpl.java 10 Jun 2004 19:49:39 -0000 1.6
+++ SchemaProcessorImpl.java 25 Jul 2004 22:12:51 -0000 1.7
@@ -39,9 +39,8 @@
*/
public final class SchemaProcessorImpl implements SchemaProcessor
{
- private static final Log LOG =
LogFactory.getLog(SchemaProcessorImpl.class);
-
private ErrorHandler _errorHandler;
+ private Log _log;
private Schema _schema;
/**
@@ -62,9 +61,10 @@
*/
private List _elementStack = new ArrayList();
- public SchemaProcessorImpl(ErrorHandler errorHandler, Schema schema)
+ public SchemaProcessorImpl(ErrorHandler errorHandler, Log log, Schema
schema)
{
_errorHandler = errorHandler;
+ _log = log;
_schema = schema;
_stack.add(this);
@@ -191,7 +191,7 @@
if (schemaElement == null)
_errorHandler.error(
- LOG,
+ _log,
ImplMessages.unknownElement(this, element),
element.getLocation(),
null);
1.7 +4 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ServiceInterceptorContributionImpl.java
Index: ServiceInterceptorContributionImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ServiceInterceptorContributionImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ServiceInterceptorContributionImpl.java 17 Jun 2004 15:16:11 -0000
1.6
+++ ServiceInterceptorContributionImpl.java 25 Jul 2004 22:12:51 -0000
1.7
@@ -85,7 +85,10 @@
Schema schema = factoryPoint.getParametersSchema();
SchemaProcessorImpl processor =
- new
SchemaProcessorImpl(_contributingModule.getErrorHandler(), schema);
+ new SchemaProcessorImpl(
+ _contributingModule.getErrorHandler(),
+ factoryPoint.getServiceLog(),
+ schema);
processor.process(_parameters, _contributingModule);
1.4 +7 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ServicePoint.java
Index: ServicePoint.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ServicePoint.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ServicePoint.java 25 Jun 2004 20:20:01 -0000 1.3
+++ ServicePoint.java 25 Jul 2004 22:12:51 -0000 1.4
@@ -14,6 +14,7 @@
package org.apache.hivemind.internal;
+import org.apache.commons.logging.Log;
import org.apache.hivemind.schema.Schema;
/**
@@ -69,5 +70,11 @@
*/
public void forceServiceInstantiation();
+
+ /**
+ * Returns the Log instance for this service point.
+ */
+
+ public Log getServiceLog();
}
1.2 +2 -1
jakarta-hivemind/examples/src/documentation/content/xdocs/hivemind-examples/panorama.xml
Index: panorama.xml
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/examples/src/documentation/content/xdocs/hivemind-examples/panorama.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- panorama.xml 24 Jul 2004 22:18:13 -0000 1.1
+++ panorama.xml 25 Jul 2004 22:12:51 -0000 1.2
@@ -443,6 +443,8 @@
*/
public void run()
{
+ long startTime = System.currentTimeMillis();
+
Orderer orderer = new Orderer(_log, _errorHandler, task());
Iterator i = _tasks.iterator();
@@ -456,7 +458,6 @@
List orderedTasks = orderer.getOrderedObjects();
int failures = 0;
- long startTime = System.currentTimeMillis();
i = orderedTasks.iterator();
while (i.hasNext())
1.4 +2 -1
jakarta-hivemind/examples/src/java/com/panorama/startup/impl/TaskExecutor.java
Index: TaskExecutor.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/examples/src/java/com/panorama/startup/impl/TaskExecutor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TaskExecutor.java 24 Jul 2004 22:18:13 -0000 1.3
+++ TaskExecutor.java 25 Jul 2004 22:12:51 -0000 1.4
@@ -41,6 +41,8 @@
*/
public void run()
{
+ long startTime = System.currentTimeMillis();
+
Orderer orderer = new Orderer(_log, _errorHandler, task());
Iterator i = _tasks.iterator();
@@ -54,7 +56,6 @@
List orderedTasks = orderer.getOrderedObjects();
int failures = 0;
- long startTime = System.currentTimeMillis();
i = orderedTasks.iterator();
while (i.hasNext())
1.14 +4 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactory.java
Index: BuilderFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactory.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- BuilderFactory.java 18 Jul 2004 00:37:11 -0000 1.13
+++ BuilderFactory.java 25 Jul 2004 22:12:51 -0000 1.14
@@ -51,6 +51,10 @@
BuilderParameter parameter = (BuilderParameter) parameters.get(0);
+ // Hm. Ideally, either the ServicePoint should pass in the Log
instance, or
+ // the ServicePoint itself should be passed in --- this
duplicates (trivial)
+ // logic inside AbstractServicePoint.
+
BuilderFactoryLogic logic =
new BuilderFactoryLogic(
invokingModule,
1.4 +4 -3
jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
Index: TestSchemaProcessor.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestSchemaProcessor.java 21 Jun 2004 14:25:44 -0000 1.3
+++ TestSchemaProcessor.java 25 Jul 2004 22:12:52 -0000 1.4
@@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
+import org.apache.commons.logging.Log;
import org.apache.hivemind.Element;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.schema.impl.AttributeModelImpl;
@@ -61,7 +62,7 @@
SchemaImpl schema = new SchemaImpl();
schema.addElementModel(em);
- SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);
+ SchemaProcessorImpl p = new SchemaProcessorImpl(null, null, schema);
ElementImpl element = new ElementImpl();
element.setElementName("fred");
@@ -114,7 +115,7 @@
SchemaImpl schema = new SchemaImpl();
schema.addElementModel(em);
- SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);
+ SchemaProcessorImpl p = new SchemaProcessorImpl(null, null, schema);
ElementImpl element = new ElementImpl();
element.setElementName("fred");
@@ -169,7 +170,7 @@
SchemaImpl schema = new SchemaImpl();
schema.addElementModel(em);
- SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);
+ SchemaProcessorImpl p = new SchemaProcessorImpl(null, null, schema);
ElementImpl element = new ElementImpl();
element.setElementName("fred");
1.3 +1 -1 jakarta-hivemind/examples/src/conf/log4j.properties
Index: log4j.properties
===================================================================
RCS file: /home/cvs/jakarta-hivemind/examples/src/conf/log4j.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- log4j.properties 24 Jul 2004 22:18:13 -0000 1.2
+++ log4j.properties 25 Jul 2004 22:12:52 -0000 1.3
@@ -22,7 +22,7 @@
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%c{1} [%p] %m%n
-log4j.category.panorama=info
+log4j.category.panorama=debug
log4j.category.examples=debug
1.17 +1 -1
jakarta-hivemind/framework/src/test/hivemind/test/config/TestConfigurationPoint.java
Index: TestConfigurationPoint.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/config/TestConfigurationPoint.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- TestConfigurationPoint.java 17 Jul 2004 23:50:38 -0000 1.16
+++ TestConfigurationPoint.java 25 Jul 2004 22:12:52 -0000 1.17
@@ -378,7 +378,7 @@
{
Registry r = buildFrameworkRegistry("BadElement.xml");
- interceptLogging(SchemaProcessorImpl.class.getName());
+ interceptLogging("hivemind.test.config");
List l = r.getConfiguration("hivemind.test.config.BadElement");
1.4 +7 -1 jakarta-hivemind/examples/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-hivemind/examples/build.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- build.xml 24 Jul 2004 22:18:13 -0000 1.3
+++ build.xml 25 Jul 2004 22:12:52 -0000 1.4
@@ -61,11 +61,17 @@
<hivedoc-report doc-path-id="hivedoc.classpath"
taskdef-path-id="hivedoc.taskdef.classpath"/>
<clover-report/>
</target>
- <target name="run-calculator" description="Execute the calculator
example.">
+ <target name="run-calculator" description="Execute the Calculator
example.">
<java classname="org.apache.hivemind.examples.CalculatorMain">
<classpath refid="runtime.classpath"/>
<sysproperty key="PROJECT_ROOT" value="${project.dir}"/>
<arg line="28 4.75"/>
+ </java>
+ </target>
+ <target name="run-panorama" description="Execute the Panorama example.">
+ <java classname="com.panorama.startup.PanoramaMain">
+ <classpath refid="runtime.classpath"/>
+ <sysproperty key="PROJECT_ROOT" value="${project.dir}"/>
</java>
</target>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]