Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 1169

Nested Elements not parsed for my own extension

$
0
0
I am trying to create my own extension for Liquibase. The changeLog looks something like this:

  1. <databaseChangeLog
  2.     xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
  3.     xmlns:my-ext="http://www.liquibase.org/xml/ns/my-ext"
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.     xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
  6.                         http://www.liquibase.org/xml/ns/my-ext my-ext.xsd">
  7.   <changeSet author="tkellerer" id="1">
  8.     <my-ext:createFoo name="Bar">
  9.       <my-ext:attributes>
  10.         <my-ext:attribute name="a1" dataType="integer"/>
  11.         <my-ext:attribute name="a2" dataType="integer"/>
  12.       </my-ext:attributes>
  13.     </my-ext:createFoo>
  14.   </changeSet>
  15. </databaseChangeLog>

The corresponding XSD looks like this:

  1. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  2.             targetNamespace="http://www.liquibase.org/xml/ns/my-ext"
  3.             xmlns="http://www.liquibase.org/xml/ns/my-ext"
  4.             elementFormDefault="qualified">
  5.     <xsd:element name="createFoo">
  6.     <xsd:complexType>
  7.         <xsd:sequence>
  8.           <xsd:element name="attributes" minOccurs="0" maxOccurs="1">
  9.             <xsd:complexType>
  10.               <xsd:sequence>
  11.                 <xsd:element name="attribute" minOccurs="1" maxOccurs="unbounded">
  12.                   <xsd:complexType>
  13.                     <xsd:attribute name="name" type="xsd:string" use="required"/>
  14.                     <xsd:attribute name="dataType" type="xsd:string" use="required"/>
  15.                   </xsd:complexType>
  16.                 </xsd:element>
  17.               </xsd:sequence>
  18.             </xsd:complexType>
  19.           </xsd:element>
  20.         </xsd:sequence>
  21.       <xsd:attribute name="name" type="xsd:string" use="required"/>
  22.     </xsd:complexType>
  23.   </xsd:element>
  24. </xsd:schema>

Then I have a Change implementation that contains the following getters and setters:

  1. @DatabaseChange(name = "createFoo", priority = ChangeMetaData.PRIORITY_DEFAULT)
  2. public class CreateFoo
  3.     extends AbstractChange {
  4.     ....
  5.    
  6.     public void addAttribute(Attribute attr) {
  7.         attributes.add(attr);
  8.     }
  9.    
  10.     @DatabaseChangeProperty
  11.     public List<Attribute> getAttributes() {
  12.         return attributes;
  13.     }
  14.     public void setAttributes(List<Attribute> attributeList) {
  15.         logger.info("Attributes set: " + attributeList);
  16.         this.attributes.clear();
  17.         if (attributeList != null) {
  18.             this.attributes.addAll(attributeList);
  19.         }
  20.     }
  21.     @Override
  22.     public String getSerializableFieldNamespace(String field) {
  23.         return "http://www.liquibase.org/xml/ns/my-ext";
  24.     }
  25.     @Override
  26.     public String getSerializedObjectNamespace() {
  27.         return "http://www.liquibase.org/xml/ns/my-ext";
  28.     }
  29.    ....
  30. }


The class Attribute extends AbstractLiquibaseSerializable and contains a bunch of getters and setters and returns the same namespace value in getSerializedObjectNamespace()

Liquibase parses my changeLog and processes my createFoo tag, but it never calls setAttributes() or addAttribute() so my Change is not populated completely.

I debugged the load() method of my Change implementation and the ParsedNode instance that is passed to it, does not contain an "attributes" child nor any "attribute" children.  I also tried a XSD version where the intermediate <attributes> was removed, but that didn't work either? 

XMLChangeLogSAXHandler.startElement() is never called for the nested tags, only for my createFoo tag.

I suspect that this has something to do with XML namespaces, but I'm unsure what exactly. My CreateFoo class implements

What am I missing?


Viewing all articles
Browse latest Browse all 1169

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>