package org.openestate.io.immoxml.xml;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Generated;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlMixed;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.jvnet.jaxb2_commons.lang.CopyStrategy2;
import org.jvnet.jaxb2_commons.lang.CopyTo2;
import org.jvnet.jaxb2_commons.lang.Equals2;
import org.jvnet.jaxb2_commons.lang.EqualsStrategy2;
import org.jvnet.jaxb2_commons.lang.JAXBCopyStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBEqualsStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBToStringStrategy;
import org.jvnet.jaxb2_commons.lang.ToString2;
import org.jvnet.jaxb2_commons.lang.ToStringStrategy2;
import org.jvnet.jaxb2_commons.locator.ObjectLocator;
import org.jvnet.jaxb2_commons.locator.util.LocatorUtils;
import org.w3c.dom.Element;

/**
 * Java class for <user_defined_anyfield> element.
 *
 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "content"
})
@XmlRootElement(name = "user_defined_anyfield")
@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
public class UserDefinedAnyfield implements Serializable, Cloneable, CopyTo2, Equals2, ToString2
{

    @XmlMixed
    @XmlAnyElement(lax = true)
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    protected List<Object> content;

    /**
     * Gets the value of the content property.
     *
     *

     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a set method for the content property.
     *
     *

     * For example, to add a new item, do as follows:
     *

     *    getContent().add(newItem);
     *

     *
     *
     *

     * Objects of the following type(s) are allowed in the list
     * {@link Element }
     * {@link Object }
     * {@link String }
     *
     *
     */
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public List<Object> getContent() {
        if (content == null) {
            content = new ArrayList<Object>();
        }
        return this.content;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public String toString() {
        final ToStringStrategy2 strategy = JAXBToStringStrategy.INSTANCE;
        final StringBuilder buffer = new StringBuilder();
        append(null, buffer, strategy);
        return buffer.toString();
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public StringBuilder append(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) {
        strategy.appendStart(locator, this, buffer);
        appendFields(locator, buffer, strategy);
        strategy.appendEnd(locator, this, buffer);
        return buffer;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) {
        {
            List<Object> theContent;
            theContent = (((this.content!= null)&&(!this.content.isEmpty()))?this.getContent():null);
            strategy.appendField(locator, this, "content", buffer, theContent, ((this.content!= null)&&(!this.content.isEmpty())));
        }
        return buffer;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public Object clone() {
        return copyTo(createNewInstance());
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public Object copyTo(Object target) {
        final CopyStrategy2 strategy = JAXBCopyStrategy.INSTANCE;
        return copyTo(null, target, strategy);
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy) {
        final Object draftCopy = ((target == null)?createNewInstance():target);
        if (draftCopy instanceof UserDefinedAnyfield) {
            final UserDefinedAnyfield copy = ((UserDefinedAnyfield) draftCopy);
            {
                Boolean contentShouldBeCopiedAndSet = strategy.shouldBeCopiedAndSet(locator, ((this.content!= null)&&(!this.content.isEmpty())));
                if (contentShouldBeCopiedAndSet == Boolean.TRUE) {
                    List<Object> sourceContent;
                    sourceContent = (((this.content!= null)&&(!this.content.isEmpty()))?this.getContent():null);
                    @SuppressWarnings("unchecked")
                    List<Object> copyContent = ((List<Object> ) strategy.copy(LocatorUtils.property(locator, "content", sourceContent), sourceContent, ((this.content!= null)&&(!this.content.isEmpty()))));
                    copy.content = null;
                    if (copyContent!= null) {
                        List<Object> uniqueContentl = copy.getContent();
                        uniqueContentl.addAll(copyContent);
                    }
                } else {
                    if (contentShouldBeCopiedAndSet == Boolean.FALSE) {
                        copy.content = null;
                    }
                }
            }
        }
        return draftCopy;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public Object createNewInstance() {
        return new UserDefinedAnyfield();
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) {
        if ((object == null)||(this.getClass()!= object.getClass())) {
            return false;
        }
        if (this == object) {
            return true;
        }
        final UserDefinedAnyfield that = ((UserDefinedAnyfield) object);
        {
            List<Object> lhsContent;
            lhsContent = (((this.content!= null)&&(!this.content.isEmpty()))?this.getContent():null);
            List<Object> rhsContent;
            rhsContent = (((that.content!= null)&&(!that.content.isEmpty()))?that.getContent():null);
            if (!strategy.equals(LocatorUtils.property(thisLocator, "content", lhsContent), LocatorUtils.property(thatLocator, "content", rhsContent), lhsContent, rhsContent, ((this.content!= null)&&(!this.content.isEmpty())), ((that.content!= null)&&(!that.content.isEmpty())))) {
                return false;
            }
        }
        return true;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public boolean equals(Object object) {
        final EqualsStrategy2 strategy = JAXBEqualsStrategy.INSTANCE;
        return equals(null, null, object, strategy);
    }

}


/*
 * Copyright 2015-2018 OpenEstate.org.
 *
 * 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.openestate.io.filemaker;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.openestate.io.filemaker.xml.result.FMPXMLRESULT;
import org.openestate.io.filemaker.xml.result.MetaDataType;
import org.openestate.io.filemaker.xml.result.ResultSetType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class provides high level read access to fields and values from a
 * {@link FMPXMLRESULT}.
 *
 * @author Andreas Rudolph
 * @since 1.0
 */
@SuppressWarnings("WeakerAccess")
public class FilemakerResultMapping {
    @SuppressWarnings("unused")
    private final static Logger LOGGER = LoggerFactory.getLogger(FilemakerResultMapping.class);
    private final List<MetaDataType.FIELD> fields;
    private final List<Row> rows;

    /**
     * Create from a {@link FMPXMLRESULT}.
     *
     * @param result the object to create from
     */
    public FilemakerResultMapping(FMPXMLRESULT result) {
        if (result.getMETADATA() == null || result.getMETADATA().getFIELD().isEmpty()) {
            throw new IllegalArgumentException("No metadata is present in the xml result!");
        }
        this.fields = new ArrayList<>();
        this.fields.addAll(result.getMETADATA().getFIELD());

        this.rows = new ArrayList<>();
        if (result.getRESULTSET() != null) {
            for (ResultSetType.ROW row : result.getRESULTSET().getROW()) {
                this.rows.add(new Row(row.getRECORDID(), row.getMODID(), row, this.fields));
            }
        }
    }

    /**
     * Returns the field definition at a certain position.
     *
     * @param index position of the field within the {@link FMPXMLRESULT}, starting with 0
     * @return field definition at the provided index position, or null if not found
     */
    @SuppressWarnings("unused")
    public MetaDataType.FIELD getField(int index) {
        return this.fields.get(index);
    }

    /**
     * Returns the number of specified fields.
     *
     * @return number of fields
     */
    public int getFieldCount() {
        return this.fields.size();
    }

    /**
     * Returns the names of specified fields.
     *
     * @return names of the fields
     */
    public String[] getFieldNames() {
        List<String> names = new ArrayList<>();
        for (MetaDataType.FIELD field : this.fields) {
            names.add(field.getNAME());
        }
        return names.toArray(new String[0]);
    }

    /**
     * Returns the specified fields.
     *
     * @return fields
     */
    @SuppressWarnings("unused")
    public MetaDataType.FIELD[] getFields() {
        return this.fields.toArray(new MetaDataType.FIELD[0]);
    }

    /**
     * Returns the row with its values at a certain position.
     *
     * @param index position of the row within the {@link FMPXMLRESULT}, starting with 0
     * @return row at the provided index position, or null if not found
     */
    public Row getRow(int index) {
        return this.rows.get(index);
    }

    /**
     * Returns the number of available rows.
     *
     * @return number of rows
     */
    public int getRowCount() {
        return this.rows.size();
    }

    /**
     * Returns the specified rows.
     *
     * @return rows
     */
    @SuppressWarnings("unused")
    public Row[] getRows() {
        return this.rows.toArray(new Row[0]);
    }

    /**
     * This class contains the data from a column of a certain row.
     */
    public final static class Column {
        private final MetaDataType.FIELD field;
        private final List<String> data;

        private Column(MetaDataType.FIELD field, List<String> data) {
            this.field = field;
            this.data = data;
        }

        /**
         * Returns the field definition for the column.
         *
         * @return field definition
         */
        public MetaDataType.FIELD getField() {
            return this.field;
        }

        /**
         * Returns the first value within the column.
         *
         * @return first value
         */
        public String getValue() {
            return (!this.data.isEmpty()) ? this.data.get(0) : null;
        }

        /**
         * Returns all values within the column.
         *
         * @return all values
         */
        public String[] getValues() {
            return this.data.toArray(new String[0]);
        }
    }

    /**
     * This class contains the data of a certain row.
     */
    public final static class Row {
        private final long recordId;
        private final long modId;
        private final Map<String, Column> columns;

        private Row(BigInteger recordId, BigInteger modId, ResultSetType.ROW row, List<MetaDataType.FIELD> fields) {
            this.recordId = (recordId != null) ? recordId.longValue() : 0;
            this.modId = (modId != null) ? modId.longValue() : 0;
            this.columns = new HashMap<>();

            int i = 0;
            for (ResultSetType.ROW.COL col : row.getCOL()) {
                MetaDataType.FIELD field = fields.get(i);
                if (field == null) {
                    LOGGER.warn("Can't find a field definition for column " + i + "!");
                    continue;
                }
                this.columns.put(field.getNAME(), new Column(field, col.getDATA()));
                i++;
            }
        }

        /**
         * Returns the column for a certain field name.
         *
         * @param name name of the field
         * @return column for the provided field, or null if not found
         */
        @SuppressWarnings("unused")
        public Column getColumn(String name) {
            return this.columns.get(name);
        }

        /**
         * Returns the definition for a certain field name.
         *
         * @param name name of the field
         * @return definition for the provided field, or null if not found
         */
        @SuppressWarnings("unused")
        public MetaDataType.FIELD getField(String name) {
            Column col = this.columns.get(name);
            return (col != null) ? col.getField() : null;
        }

        /**
         * Returns the field names within the row.
         *
         * @return field names
         */
        public String[] getFieldNames() {
            return this.columns.keySet().toArray(new String[0]);
        }

        /**
         * Returns the MODID value of the row.
         *
         * @return MODID value
         */
        public long getModId() {
            return this.modId;
        }

        /**
         * Returns the RECORDID value of the row.
         *
         * @return RECORDID value
         */
        public long getRecordId() {
            return this.recordId;
        }

        /**
         * Returns the first value for a certain field name.
         *
         * @param name name of the field
         * @return first value for the provided field, or null if not found
         */
        public String getValue(String name) {
            Column col = this.columns.get(name);
            return (col != null) ? col.getValue() : null;
        }

        /**
         * Returns all values for a certain field name.
         *
         * @param name name of the field
         * @return all values for the provided field, or null if not found
         */
        public String[] getValues(String name) {
            Column col = this.columns.get(name);
            return (col != null) ? col.getValues() : null;
        }
    }
}


package org.openestate.io.openimmo.xml;

import java.io.Serializable;
import javax.annotation.Generated;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.jvnet.jaxb2_commons.lang.CopyStrategy2;
import org.jvnet.jaxb2_commons.lang.CopyTo2;
import org.jvnet.jaxb2_commons.lang.Equals2;
import org.jvnet.jaxb2_commons.lang.EqualsStrategy2;
import org.jvnet.jaxb2_commons.lang.JAXBCopyStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBEqualsStrategy;
import org.jvnet.jaxb2_commons.lang.JAXBToStringStrategy;
import org.jvnet.jaxb2_commons.lang.ToString2;
import org.jvnet.jaxb2_commons.lang.ToStringStrategy2;
import org.jvnet.jaxb2_commons.locator.ObjectLocator;
import org.jvnet.jaxb2_commons.locator.util.LocatorUtils;

/**
 * Java class for <ausblick> element.
 *
 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "ausblick")
@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
public class Ausblick implements Serializable, Cloneable, CopyTo2, Equals2, ToString2
{

    @XmlAttribute(name = "blick")
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    protected Ausblick.Blick blick;

    /**
     * Gets the value of the blick property.
     *
     * @return
     *     possible object is
     *     {@link Ausblick.Blick }
     *
     */
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public Ausblick.Blick getBlick() {
        return blick;
    }

    /**
     * Sets the value of the blick property.
     *
     * @param value
     *     allowed object is
     *     {@link Ausblick.Blick }
     *
     */
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public void setBlick(Ausblick.Blick value) {
        this.blick = value;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public String toString() {
        final ToStringStrategy2 strategy = JAXBToStringStrategy.INSTANCE;
        final StringBuilder buffer = new StringBuilder();
        append(null, buffer, strategy);
        return buffer.toString();
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public StringBuilder append(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) {
        strategy.appendStart(locator, this, buffer);
        appendFields(locator, buffer, strategy);
        strategy.appendEnd(locator, this, buffer);
        return buffer;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) {
        {
            Ausblick.Blick theBlick;
            theBlick = this.getBlick();
            strategy.appendField(locator, this, "blick", buffer, theBlick, (this.blick!= null));
        }
        return buffer;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public Object clone() {
        return copyTo(createNewInstance());
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public Object copyTo(Object target) {
        final CopyStrategy2 strategy = JAXBCopyStrategy.INSTANCE;
        return copyTo(null, target, strategy);
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy) {
        final Object draftCopy = ((target == null)?createNewInstance():target);
        if (draftCopy instanceof Ausblick) {
            final Ausblick copy = ((Ausblick) draftCopy);
            {
                Boolean blickShouldBeCopiedAndSet = strategy.shouldBeCopiedAndSet(locator, (this.blick!= null));
                if (blickShouldBeCopiedAndSet == Boolean.TRUE) {
                    Ausblick.Blick sourceBlick;
                    sourceBlick = this.getBlick();
                    Ausblick.Blick copyBlick = ((Ausblick.Blick) strategy.copy(LocatorUtils.property(locator, "blick", sourceBlick), sourceBlick, (this.blick!= null)));
                    copy.setBlick(copyBlick);
                } else {
                    if (blickShouldBeCopiedAndSet == Boolean.FALSE) {
                        copy.blick = null;
                    }
                }
            }
        }
        return draftCopy;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public Object createNewInstance() {
        return new Ausblick();
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) {
        if ((object == null)||(this.getClass()!= object.getClass())) {
            return false;
        }
        if (this == object) {
            return true;
        }
        final Ausblick that = ((Ausblick) object);
        {
            Ausblick.Blick lhsBlick;
            lhsBlick = this.getBlick();
            Ausblick.Blick rhsBlick;
            rhsBlick = that.getBlick();
            if (!strategy.equals(LocatorUtils.property(thisLocator, "blick", lhsBlick), LocatorUtils.property(thatLocator, "blick", rhsBlick), lhsBlick, rhsBlick, (this.blick!= null), (that.blick!= null))) {
                return false;
            }
        }
        return true;
    }

    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public boolean equals(Object object) {
        final EqualsStrategy2 strategy = JAXBEqualsStrategy.INSTANCE;
        return equals(null, null, object, strategy);
    }

    /**
     *
     *                     Java enum for blick attribute in <ausblick> elements.
     *
     *
Java class for null.
     *
     *
The following schema fragment specifies the expected content contained within this class.
     *

     *

     * <simpleType>
     *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
     *     <enumeration value="FERNE"/>
     *     <enumeration value="SEE"/>
     *     <enumeration value="BERGE"/>
     *     <enumeration value="MEER"/>
     *   </restriction>
     * </simpleType>
     *

     *
     */
    @XmlType(name = "")
    @XmlEnum
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public enum Blick {

        FERNE,
        SEE,
        BERGE,
        MEER;

        public String value() {
            return name();
        }

        public static Ausblick.Blick fromValue(String v) {
            return valueOf(v);
        }

    }

}