| /******************************************************************************* |
| * Copyright (c) 2006, 2013 Oracle and/or its affiliates. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
| * which accompanies this distribution. |
| * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| * and the Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * Oracle - initial API and implementation |
| * |
| ******************************************************************************/ |
| package org.eclipse.persistence.tools.mapping.orm.dom; |
| |
| import org.eclipse.persistence.tools.mapping.AbstractExternalForm; |
| import org.eclipse.persistence.tools.mapping.orm.ExternalConverter; |
| import org.eclipse.persistence.tools.utility.TextRange; |
| import org.w3c.dom.Element; |
| |
| /** |
| * The abstract definition of an external class converter. |
| * |
| * @version 2.6 |
| */ |
| abstract class AbstractConverter extends AbstractExternalForm |
| implements ExternalConverter { |
| |
| /** |
| * The position of the element within the list of children with the same type owned by the parent. |
| */ |
| private int index; |
| |
| /** |
| * Creates a new <code>AbstractConverter</code>. |
| * |
| * @param parent The parent of this external form |
| * @param index The position of the element within the list of children with the same type owned by the parent |
| */ |
| AbstractConverter(AbstractExternalForm parent, int index) { |
| super(parent); |
| this.index = index; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| protected final void calculateInsertionIndex(Element parent, Element child, String elementName) { |
| if (elementName == getElementName()) { |
| index = index(parent, child, elementName); |
| } |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public final Element getElement() { |
| |
| if (index == -1) { |
| return super.getElement(); |
| } |
| |
| return getChild(getParent(), getElementName(), index); |
| } |
| |
| @Override |
| @Deprecated |
| public final int getIndex() { |
| return index; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public final String getName() { |
| return getAttribute(NAME); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public final TextRange getNameTextRange() { |
| return getAttributeTextRange(NAME); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public final void removeSelf() { |
| |
| if (index == -1) { |
| super.removeSelf(); |
| } |
| else { |
| removeChild(getParent(), getElementName(), index); |
| } |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public final void setName(String name) { |
| setAttribute(NAME, name); |
| } |
| } |