You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by hl...@apache.org on 2004/09/27 16:36:35 UTC
cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind/parse SchemaInjector.java ParseStrings.properties ParseMessages.java DescriptorParser.java DescriptorParser.properties
hlship 2004/09/27 07:36:35
Modified: framework/src/java/org/apache/hivemind/parse
ParseStrings.properties ParseMessages.java
DescriptorParser.java DescriptorParser.properties
Added: framework/src/java/org/apache/hivemind/parse
SchemaInjector.java
Log:
HIVEMIND-58: Add visibility attribute to the <schema> element.
Revision Changes Path
1.9 +3 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseStrings.properties
Index: ParseStrings.properties
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseStrings.properties,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ParseStrings.properties 12 Sep 2004 19:55:11 -0000 1.8
+++ ParseStrings.properties 27 Sep 2004 14:36:35 -0000 1.9
@@ -33,4 +33,6 @@
invalid-attribute-format=Attribute {0} ({1}) of element {2} is improperly formatted. {3}
module-id-format=Module identifiers should consist of a period-seperated series of names, like a Java package.
id-format=Schema and extension point ids should be simple names with no punctuation.
-version-format=Version numbers should be a sequence of three numbers seperated by periods.
\ No newline at end of file
+version-format=Version numbers should be a sequence of three numbers seperated by periods.
+
+schema-not-visible=Schema ''{0}'' is not visible to module {1}.
\ No newline at end of file
1.11 +24 -21 jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseMessages.java
Index: ParseMessages.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseMessages.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ParseMessages.java 12 Sep 2004 19:55:11 -0000 1.10
+++ ParseMessages.java 27 Sep 2004 14:36:35 -0000 1.11
@@ -20,25 +20,25 @@
import org.apache.hivemind.Resource;
import org.apache.hivemind.impl.MessageFormatter;
import org.apache.hivemind.schema.ElementModel;
+import org.apache.hivemind.schema.Schema;
/**
* Messages for the parse package.
- *
+ *
* @author Howard Lewis Ship
*/
final class ParseMessages
{
- private static final MessageFormatter _formatter =
- new MessageFormatter(ParseMessages.class, "ParseStrings");
+ private static final MessageFormatter _formatter = new MessageFormatter(ParseMessages.class,
+ "ParseStrings");
- public static String dupeAttributeMapping(
- AttributeMappingDescriptor newDescriptor,
- AttributeMappingDescriptor existingDescriptor)
+ public static String dupeAttributeMapping(AttributeMappingDescriptor newDescriptor,
+ AttributeMappingDescriptor existingDescriptor)
{
return _formatter.format(
- "dupe-attribute-mapping",
- newDescriptor.getAttributeName(),
- existingDescriptor.getLocation());
+ "dupe-attribute-mapping",
+ newDescriptor.getAttributeName(),
+ existingDescriptor.getLocation());
}
public static String extraMappings(Collection extraNames, ElementModel model)
@@ -73,18 +73,21 @@
public static String booleanAttribute(String value, String name, String path)
{
- return _formatter.format("boolean-attribute", new Object[] { value, name, path });
+ return _formatter.format("boolean-attribute", new Object[]
+ { value, name, path });
}
public static String invalidAttributeValue(String value, String name, String path)
{
- return _formatter.format("invalid-attribute-value", new Object[] { value, name, path });
+ return _formatter.format("invalid-attribute-value", new Object[]
+ { value, name, path });
}
public static String invalidNumericValue(String value, String name, String path)
{
- return _formatter.format("invalid-numeric-value", new Object[] { value, name, path });
+ return _formatter.format("invalid-numeric-value", new Object[]
+ { value, name, path });
}
public static String unableToInitialize(Throwable cause)
@@ -112,17 +115,17 @@
return _formatter.format("unexpected-element", elementName, elementPath);
}
- public static String invalidAttributeFormat(
- String attributeName,
- String value,
- String elementPath,
- String formatKey)
+ public static String invalidAttributeFormat(String attributeName, String value,
+ String elementPath, String formatKey)
{
String inputValueFormat = _formatter.getMessage(formatKey);
- return _formatter.format(
- "invalid-attribute-format",
- new Object[] { attributeName, value, elementPath, inputValueFormat });
+ return _formatter.format("invalid-attribute-format", new Object[]
+ { attributeName, value, elementPath, inputValueFormat });
}
-}
+ public static String schemaNotVisible(String schemaId, String moduleId)
+ {
+ return _formatter.format("schema-not-visible", schemaId, moduleId);
+ }
+}
\ No newline at end of file
1.36 +17 -66 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.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- DescriptorParser.java 25 Sep 2004 17:08:35 -0000 1.35
+++ DescriptorParser.java 27 Sep 2004 14:36:35 -0000 1.36
@@ -76,50 +76,6 @@
{
private static final String DEFAULT_SERVICE_MODEL = "singleton";
- private class SchemaRelinker implements Runnable
- {
- private Object _container;
-
- private String _propertyName;
-
- private Location _referenceLocation;
-
- private RegistryAssembly _registryAssembly;
-
- private String _schemaId;
-
- SchemaRelinker(String schemaId, Object container, String propertyName,
- RegistryAssembly assembly, Location referenceLocation)
- {
- _schemaId = schemaId;
- _container = container;
- _propertyName = propertyName;
- _registryAssembly = assembly;
- _referenceLocation = referenceLocation;
- }
-
- public void run()
- {
- Schema s = _registryAssembly.getSchema(_schemaId);
-
- if (s == null)
- _errorHandler.error(
- LOG,
- ParseMessages.unableToResolveSchema(_schemaId),
- _referenceLocation,
- null);
-
- try
- {
- PropertyUtils.write(_container, _propertyName, s);
- }
- catch (Exception ex)
- {
- _errorHandler.error(LOG, ex.getMessage(), _referenceLocation, ex);
- }
- }
- }
-
private static final Log LOG = LogFactory.getLog(DescriptorParser.class);
/**
@@ -778,9 +734,7 @@
if (visibility != null)
cpd.setVisibility(visibility);
- Schema s = obtainSchema(getAttribute("schema-id"), cpd, "contributionsSchema");
-
- cpd.setContributionsSchema(s);
+ injectSchema(getAttribute("schema-id"), cpd, "contributionsSchema");
md.addConfigurationPoint(cpd);
}
@@ -1035,12 +989,19 @@
{
SchemaImpl schema = new SchemaImpl();
+ schema.setModuleId(_moduleDescriptor.getModuleId());
+
push(elementName, schema, STATE_SCHEMA);
checkAttributes();
String id = getValidatedAttribute("id", ID_PATTERN, "id-format");
+ Visibility visibility = (Visibility) getEnumAttribute("visibility", VISIBILITY_MAP);
+
+ if (visibility != null)
+ schema.setVisibility(visibility);
+
// TODO: check for duplicate name!
_registryAssembly.addSchema(qualify(id), schema);
@@ -1059,9 +1020,7 @@
spd.setId(getValidatedAttribute("id", ID_PATTERN, "id-format"));
spd.setInterfaceClassName(getAttribute("interface"));
- Schema s = obtainSchema(getAttribute("parameters-schema-id"), spd, "parametersSchema");
-
- spd.setParametersSchema(s);
+ injectSchema(getAttribute("parameters-schema-id"), spd, "parametersSchema");
Occurances count = (Occurances) getEnumAttribute("parameters-occurs", OCCURS_MAP);
@@ -1412,30 +1371,22 @@
* {@link ServicePointDescriptor}) that will contain the schema
* @param propertyName
* property of the container to update once the schema is known
- * @return the Schema (if known), or null (if the schema will be located later)
*/
- private Schema obtainSchema(String schemaId, Object container, String propertyName)
+ private void injectSchema(String schemaId, Object container, String propertyName)
{
if (schemaId == null)
- return null;
+ return;
+ String moduleId = _moduleDescriptor.getModuleId();
String fullId = qualify(schemaId);
- Schema reffed = _registryAssembly.getSchema(fullId);
-
- if (reffed != null)
- return reffed;
- // Not found! We don't know what order modules are parsed in,
- // so this is not necessarily an error (it could even be a forward
- // reference within the same module). In any case, set up to relink
- // to the resolved Schema object after all modules are parsed.
-
- Runnable r = new SchemaRelinker(fullId, container, propertyName, _registryAssembly,
- getLocation());
+ Runnable r = new SchemaInjector(_errorHandler, LOG, fullId, moduleId, container,
+ propertyName, _registryAssembly, getLocation());
- _registryAssembly.addPostProcessor(r);
+ // Run it now; if it works, then the property of the container is updated immediately.
+ // If the schema is not located, then the injector will queue itself for later execution.
- return null;
+ r.run();
}
/**
1.14 +1 -0 jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties
Index: DescriptorParser.properties
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DescriptorParser.properties 25 Sep 2004 17:08:35 -0000 1.13
+++ DescriptorParser.properties 27 Sep 2004 14:36:35 -0000 1.14
@@ -69,6 +69,7 @@
required.invoke-factory.model=false
required.schema.id=true
+required.schema.visibility=false
required.set-module.property=true
1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/SchemaInjector.java
Index: SchemaInjector.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.parse;
import org.apache.commons.logging.Log;
import org.apache.hivemind.ErrorHandler;
import org.apache.hivemind.Location;
import org.apache.hivemind.impl.RegistryAssembly;
import org.apache.hivemind.schema.Schema;
import org.apache.hivemind.util.PropertyUtils;
/**
* Used by {@link org.apache.hivemind.parse.DescriptorParser}to locate and inject a
* {@link org.apache.hivemind.schema.Schema}into another object. Designed to be invoked immediately
* from the parser, but if the schema is not known (quite possibly, since schemas can be referenced
* by other modules, and parse order is not known) then the injector adds itself to the
* {@link org.apache.hivemind.impl.RegistryAssembly}for later execution as a post-processor (after
* all modules are parsed).
*
* @author Howard Lewis Ship
* @since 1.1
*/
class SchemaInjector implements Runnable
{
private ErrorHandler _errorHandler;
private Log _log;
/**
* Module id of referencing module (used for visibility check).
*/
private String _moduleId;
/**
* Descriptor object whose property is to be set.
*/
private Object _container;
/**
* Name of property of container to set.
*/
private String _propertyName;
/**
* Reference location (used when reporting errors).
*/
private Location _referenceLocation;
/**
* RegistryAssembly helper service.
*/
private RegistryAssembly _registryAssembly;
/**
* Fully qualified schema id.
*/
private String _schemaId;
/**
* True once the injector is queued as a post-processor.
*/
private boolean _queued = false;
public SchemaInjector(ErrorHandler errorHandler, Log log, String schemaId, String moduleId,
Object container, String propertyName, RegistryAssembly assembly,
Location referenceLocation)
{
_errorHandler = errorHandler;
_log = log;
_schemaId = schemaId;
_moduleId = moduleId;
_container = container;
_propertyName = propertyName;
_registryAssembly = assembly;
_referenceLocation = referenceLocation;
}
public void run()
{
Schema s = _registryAssembly.getSchema(_schemaId);
if (s == null)
{
if (!_queued)
{
_queued = true;
_registryAssembly.addPostProcessor(this);
// Return now, this will be re-invoked later to finish the job
// or report the final error.
return;
}
_errorHandler.error(
_log,
ParseMessages.unableToResolveSchema(_schemaId),
_referenceLocation,
null);
return;
}
if (!validateSchemaIsVisible(s))
return;
try
{
PropertyUtils.write(_container, _propertyName, s);
}
catch (Exception ex)
{
_errorHandler.error(_log, ex.getMessage(), _referenceLocation, ex);
}
}
/**
* Validates that the schema is visible to the referencing module; notes an error if not.
*
* @since 1.1
*/
private boolean validateSchemaIsVisible(Schema schema)
{
if (schema.visibleToModule(_moduleId))
return true;
_errorHandler.error(
_log,
ParseMessages.schemaNotVisible(_schemaId, _moduleId),
_referenceLocation,
null);
return false;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org