hlship 2003/08/01 12:05:24 Modified: hivemind/src/java/org/apache/commons/hivemind HiveMindMessages.properties hivemind/xdocs descriptor.xml hivemind/src/test/hivemind/test/parse GenericModule.xml TestDescriptorParser.java hivemind/src/java/org/apache/commons/hivemind/parse DescriptorParser.java Added: hivemind/src/test/hivemind/test/parse SchemaRef.xml Log: Add id and ref-id to <schema> and <parameters-schema> to allow shared schemas (within the same module). Revision Changes Path 1.16 +2 -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.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- HiveMindMessages.properties 31 Jul 2003 21:06:25 -0000 1.15 +++ HiveMindMessages.properties 1 Aug 2003 19:05:23 -0000 1.16 @@ -39,6 +39,7 @@ DescriptorParser.invalid-attribute-value=''{0}'' is not a valid value for attribute ''{1}'' of {2} (at {3}). DescriptorParser.invalid-numeric-value=''{0}'' (attribute ''{1}'' of {2}, at {3}) can not be converted to a numeric value. DescriptorParser.bad-translator=Unable to create translator ''{0}'' (at {1}): {2} +DescriptorParser.unknown-schema-id=Element {0} (at {1}) references unknown schema ''{2}''. ExternalParser.missing-resource=Unable to locate {0}. 1.16 +31 -1 jakarta-commons-sandbox/hivemind/xdocs/descriptor.xml Index: descriptor.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/descriptor.xml,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- descriptor.xml 1 Aug 2003 14:21:38 -0000 1.15 +++ descriptor.xml 1 Aug 2003 19:05:24 -0000 1.16 @@ -333,6 +333,36 @@ an &extension-point;. The &_parameters-schema; element is identical, and is used to specify the format of XML parameters to a service implementation factory service.</p> + <table> + <tr> + <th>Attribute</th> + <th>Type</th> + <th>Required ?</th> + <th>Description</th> + </tr> + + <tr> + <td>id</td> + <td>string</td> + <td>no</td> + <td>Assigns a local id to the schema that may be referenced elsewhere within the <em>same</em> + module.</td> + </tr> + + <tr> + <td>ref-id</td> + <td>string</td> + <td>no</td> + <td> + If given, the &_schema; (or &_parameters-schema;) is a reference to a + previously defined &_schema; (or &_parameters-schema;) within the same module. + This is used to eliminate redundant schemas. If <code>ref-id</code> + is specified, the current element must be empty. + </td> + </tr> + + </table> + <p> At a future time, the &_schema; element will be extended to provide more options, to provide more precise control over the elements that may be provided in an &_extension;. 1.4 +2 -0 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/GenericModule.xml Index: GenericModule.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/GenericModule.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- GenericModule.xml 31 Jul 2003 21:06:25 -0000 1.3 +++ GenericModule.xml 1 Aug 2003 19:05:24 -0000 1.4 @@ -1,3 +1,5 @@ +<?xml version="1.0"?> +<!-- $Id$ --> <module id="hivemind.test.parse" version="1.0.0"> <description>Description of the Module.</description> 1.17 +11 -1 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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- TestDescriptorParser.java 31 Jul 2003 21:06:25 -0000 1.16 +++ TestDescriptorParser.java 1 Aug 2003 19:05:24 -0000 1.17 @@ -322,4 +322,14 @@ assertEquals("myParameter", em.getElementName()); } + + public void testSchemaRef() throws Exception + { + ModuleDescriptor md = parse("SchemaRef.xml"); + + Schema schema1 = md.getExtensionPoint("One").getSchema(); + Schema schema2 = md.getExtensionPoint("Two").getSchema(); + + assertSame(schema1, schema2); + } } 1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/SchemaRef.xml Index: SchemaRef.xml =================================================================== <?xml version="1.0"?> <module id="hivemind.test.parse" version="1.0.0"> <extension-point id="One"> <schema id="the-schema"> <element name="the-element"/> </schema> </extension-point> <extension-point id="Two"> <schema ref-id="the-schema"/> </extension-point> </module> 1.17 +69 -8 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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- DescriptorParser.java 1 Aug 2003 14:21:38 -0000 1.16 +++ DescriptorParser.java 1 Aug 2003 19:05:24 -0000 1.17 @@ -133,6 +133,11 @@ private ModuleDescriptor _moduleDescriptor; /** + * Used to resolve schema references during the parse. + */ + private Map _schemas = new HashMap(); + + /** * States used while parsing the document. Most states * correspond to a particular XML element in the document. * STATE_START is the initial state, before the <module> @@ -274,6 +279,16 @@ INVOKE_FACTORY_ATTRIBUTES.put("service-id", Boolean.TRUE); } + /** + * Applies to schema and parameter-schema elements. + */ + private static final Map SCHEMA_ATTRIBUTES = new HashMap(); + + static { + SCHEMA_ATTRIBUTES.put("id", Boolean.FALSE); + SCHEMA_ATTRIBUTES.put("ref-id", Boolean.FALSE); + } + private static final Map OCCURS_MAP = new HashMap(); static { @@ -443,6 +458,7 @@ _top = null; _moduleDescriptor = null; _attributes.clear(); + _schemas.clear(); } } @@ -876,11 +892,7 @@ if (elementName.equals("schema")) { - SchemaImpl schema = new SchemaImpl(); - - push(elementName, schema, STATE_SCHEMA); - - checkAttributes(null); + SchemaImpl schema = enterSchema(elementName); epd.setSchema(schema); @@ -890,6 +902,56 @@ unexpectedElement(elementName); } + private SchemaImpl enterSchema(String elementName) + { + SchemaImpl result = new SchemaImpl(); + + // For error reporting reasons, its best to push() first and + // check attribute second. + + push(elementName, result, STATE_SCHEMA); + + checkAttributes(SCHEMA_ATTRIBUTES); + + String refId = getAttribute("ref-id"); + + if (refId != null) + { + SchemaImpl reffed = (SchemaImpl) _schemas.get(refId); + + if (result == null) + LOG.error( + HiveMind.format( + "DescriptorParser.unknown-schema-id", + getElementPath(), + getLocation(), + refId)); + else + { + + result = reffed; + + Item top = peek(); + + // Change out mind about the state ... if using a ref-id, then + // no content is allowed. + top._object = reffed; + top._state = STATE_NO_CONTENT; + } + + return result; + } + + String id = getAttribute("id"); + + // TODO: Check that id is unique + + if (id != null) + _schemas.put(id, result); + + return result; + } + private void beginExtension(String elementName) { // This is where things get tricky, the point where we outgrew Jakarta Digester. @@ -941,9 +1003,8 @@ if (elementName.equals("parameters-schema")) { ServiceDescriptor sd = (ServiceDescriptor) peekObject(); - SchemaImpl schema = new SchemaImpl(); - push(elementName, schema, STATE_SCHEMA); + SchemaImpl schema = enterSchema(elementName); sd.setParametersSchema(schema); return;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]