blob: 993aec7099b8abf13a76a15012b53dcb6d3c7279 [file] [log] [blame]
/*******************************************************************************
* 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 java.util.ArrayList;
import java.util.List;
import org.eclipse.persistence.tools.mapping.AbstractExternalForm;
import org.eclipse.persistence.tools.mapping.orm.ExternalAttributeOverride;
import org.eclipse.persistence.tools.mapping.orm.ExternalEntityColumn;
import org.eclipse.persistence.tools.utility.TextRange;
import org.w3c.dom.Element;
/**
* The external form of an attribute override, which is a child of an embedded mapping.
*
* @see ElementCollectionMapping
* @see EmbeddedIDMapping
* @see EmbeddedMapping
* @see Entity
*
* @version 2.6
*/
final class AttributeOverride extends AbstractExternalForm
implements ExternalAttributeOverride {
/**
* 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>AttributeOverride</code>.
*
* @param parent The parent of this external form
* @param index The position of the external form of the mapping in the list of children
*/
AttributeOverride(AbstractExternalForm parent, int index) {
super(parent);
this.index = index;
}
private EntityColumn buildColumn(int index) {
return new EntityColumn(this, EntityColumn.COLUMN, index);
}
/**
* {@inheritDoc}
*/
@Override
protected List<String> buildElementNamesOrder() {
List<String> names = new ArrayList<String>();
names.add(DESCRIPTION);
return names;
}
/**
* {@inheritDoc}
*/
@Override
protected void calculateInsertionIndex(Element parent, Element child, String elementName) {
index = index(parent, child, elementName);
}
/**
* {@inheritDoc}
*/
@Override
public ExternalEntityColumn getColumn() {
Element element = getChild(EntityColumn.COLUMN, index);
if (element != null) {
return buildColumn(index);
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return getChildTextNode(DESCRIPTION);
}
/**
* {@inheritDoc}
*/
@Override
public Element getElement() {
return getChild(getParent(), getElementName(), index);
}
/**
* {@inheritDoc}
*/
@Override
protected String getElementName() {
return ATTRIBUTE_OVERRIDE;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return getAttribute(NAME);
}
/**
* {@inheritDoc}
*/
@Override
public TextRange getNameTextRange() {
return getAttributeTextRange(NAME);
}
/**
* {@inheritDoc}
*/
@Override
public void removeColumn(int index) {
EntityColumn column = buildColumn(index);
column.removeSelf();
}
/**
* {@inheritDoc}
*/
@Override
public void removeSelf() {
removeChild(getParent(), getElementName(), index);
}
/**
* {@inheritDoc}
*/
@Override
public void setColumn(String name) {
EntityColumn column = buildColumn(index);
if (name == null) {
column.removeSelf();
}
else {
column.setName(name);
}
}
/**
* {@inheritDoc}
*/
@Override
public void setDescription(String description) {
updateChildTextNode(DESCRIPTION, description);
}
/**
* {@inheritDoc}
*/
@Override
public void setName(String name) {
setAttribute(NAME, name);
}
}