All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eobjects.metamodel.xml.XmlSaxTableDef Maven / Gradle / Ivy

There is a newer version: 5.3.6
Show newest version
/**
 * eobjects.org MetaModel
 * Copyright (C) 2010 eobjects.org
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.eobjects.metamodel.xml;

import java.io.Serializable;
import java.util.Arrays;

import org.eobjects.metamodel.schema.Table;

/**
 * Defines a table layout for {@link XmlSaxDataContext}. This class is used as
 * an instruction set of xpath expressions for the datacontext to create
 * {@link Table}s.
 * 
 * These types of expressions are allowed in the {@link XmlSaxTableDef}:
 * 
 * 
    *
  • Element selectors: "/path/to/element"
  • *
  • Attribute selectors: "/path/to/element@attribute"
  • *
  • Element index selectors: "index(/path/to)" (can be used to make * cross-references to parent tags)
  • *
* * If, for example, this is your XML document: * *
 * <root>
 * 	<organization type="company">
 * 		<name>Company A</name>
 * 		<employees>
 * 			<employee>
 * 				<name>John Doe</name>
 * 				<gender>M</gender>
 * 			</employee>
 * 			<employee>
 * 				<name>Jane Doe</name>
 * 				<gender>F</gender>
 * 			</employee>
 * 		</employees>
 * 	</organization>
 * 	<organization type="government">
 * 		<name>Company B</name>
 * 		<employees>
 * 			<employee>
 * 				<name>Susan</name>
 * 				<gender>F</gender>
 * 			</employee>
 * 		</employees>
 * 	</organization>
 * </root>
 * 
* * Then if you wanted to extract information about organizations, these xpaths * could work: *
    *
  • Organization row scope: "/root/organization"
  • *
  • Organization name: "/root/organization/name"
  • *
  • Organization type: "/root/organization@type"
  • *
* * Or if you wanted to extract information about employees: *
    *
  • Employee row scope: "/root/organization/employees/employee"
  • *
  • Employee name: "/root/organization/employees/employee/name"
  • *
  • Employee gender: "/root/organization/employees/employee/gender"
  • *
  • Employee organization index: "index(/root/organization)"
  • *
* * @author Kasper Sørensen */ public final class XmlSaxTableDef implements Serializable { private static final long serialVersionUID = 1L; private final String _rowXpath; private final String[] _valueXpaths; /** * Constructs a {@link XmlSaxTableDef} based on an xpath expression for the * row scope and an array of xpath expressions for the individual values * (columns) within a row. * * @param rowXpath * an xpath expression for the scope of a record, eg. * /companies/company/employee * @param valueXpaths * an array of xpath expressions for the individual values * (columns) of a row. eg: [/companies/company/employee/name, * /companies/company/employee/gender, index(/companies/company)] */ public XmlSaxTableDef(String rowXpath, String[] valueXpaths) { _rowXpath = rowXpath; _valueXpaths = valueXpaths; } public String getRowXpath() { return _rowXpath; } public String[] getValueXpaths() { return _valueXpaths; } @Override public int hashCode() { return _rowXpath.hashCode(); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; XmlSaxTableDef other = (XmlSaxTableDef) obj; if (_rowXpath == null) { if (other._rowXpath != null) return false; } else if (!_rowXpath.equals(other._rowXpath)) return false; if (!Arrays.equals(_valueXpaths, other._valueXpaths)) return false; return true; } @Override public String toString() { return "XmlSaxTableDef[rowXpath=" + _rowXpath + ",valueXpaths=" + Arrays.toString(_valueXpaths) + "]"; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy