package org.jboss.loom.migrators._ext;


import java.io.File;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.oxm.annotations.XmlLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Locator;

/**
 *
 *  @author Ondrej Zizka, ozizka at redhat.com
 */
@XmlRootElement( name="migrator" )
@XmlAccessorType( XmlAccessType.NONE )
public class MigratorDefinition extends ContainerOfStackableDefs {
    private static final Logger log = LoggerFactory.getLogger( MigratorDefinition.class );
    
    @XmlAttribute
    String name;

    //@XmlElementWrapper(name = "jaxbBeans")
    @XmlElement(name = "jaxbBean")
    //@XmlPath("jaxbBean/@file")
    List<JaxbClassDef> jaxbBeansClasses;
    
    @XmlElement(name = "xmlQuery")
    List<XmlFileQueryDef> xmlQueries;
    
    @XmlElement(name = "propQuery")
    List<PropFileQueryDef> propQueries;
    
    //@XmlElement(name = "action")
    //List<ActionDef> actions;
    
    //File fileOfOrigin;
    
    @XmlLocation Locator location;
    public Locator getLocation() { return location; }

    
    // === Subelement classes === //
    
    
    @XmlRootElement
    @XmlAccessorType( XmlAccessType.NONE )
    public static class JaxbClassDef {
        @XmlAttribute(name = "file")
        //@XmlJavaTypeAdapter( StringToFileAdapter.class )
        public File file;
    }
    

    @XmlRootElement
    public static class ActionDef extends ContainerOfStackableDefs {
        @XmlAttribute
        public String type;
        
        //public List<PropertyBean> properties;
        @XmlAnyAttribute
        public Map<String, String> attribs;
    }
    
    @XmlRootElement
    public static class ForEachDef extends ContainerOfStackableDefs {
        
        @XmlAttribute(name = "query")
        public String queryName;
        
        @XmlAttribute(name = "var")
        public String variableName;
    }

    
    @XmlRootElement
    public static class XmlFileQueryDef extends FileQueryBase {
        public Class jaxbBean;
        public String xpath;
    }

    @XmlRootElement
    public static class PropFileQueryDef extends FileQueryBase {
        public String propNameMask;
    }
    
    
    private static class FileQueryBase extends QueryBase {
        public String pathMask;     // Path mask of the files to load.
    }
    
    private static class QueryBase {
        public String id;           // Id under which the result will be stored.
        public String subjectLabel; // What's being loaded - for exceptions and logging.
    }
    
}// class

@@ -404,54 +404,34 @@
 org.
-eclipse.persistence.oxm.annotations.XmlLocatio
+jboss.loom.migrators.Origi
 n;%0Ai
@@ -489,36 +489,8 @@
 ory;
-%0Aimport org.xml.sax.Locator;
 %0A%0A/*
@@ -680,24 +680,47 @@
 ackableDefs 
+implements Origin.Wise 
 %7B%0A    privat
@@ -1255,28 +1255,26 @@
 Origin;%0A    
-%0A   
+//
  @XmlLocatio
@@ -1279,76 +1279,239 @@
 ion 
-Locator location;%0A    public Locator getLocation() %7B return location
+wouldn't work if loaded through Node.%0A    %0A    private Origin origin;%0A    @Override public Origin getOrigin() %7B return origin; %7D%0A    @Override public MigratorDefinition setOrigin( Origin origin ) %7B this.origin = origin; return this
 ; %7D%0A

Use Origin in MigrationDefinition as @XmlLocation doesn't work from XmlUtils.unmarshallBeans() ... :(