blob: 0ed2a612af894a4707909d93087c8c57246bf8fd [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.ExternalPrimaryKeyJoinColumn;
import org.eclipse.persistence.tools.utility.TextRange;
import org.w3c.dom.Element;
/**
* The external form for primary key join column.
*
* @see Entity
* @see OneToOneMapping
* @see SecondaryTable
*
* @version 2.6
*/
final class PrimaryKeyJoinColumn extends AbstractExternalForm
implements ExternalPrimaryKeyJoinColumn {
/**
* 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>PrimaryKeyJoinColumn</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
*/
PrimaryKeyJoinColumn(AbstractExternalForm parent, int index) {
super(parent);
this.index = index;
}
/**
* {@inheritDoc}
*/
@Override
protected List<String> buildAttributeNamesOrder() {
List<String> names = new ArrayList<String>();
names.add(NAME);
names.add(REFERENCED_COLUMN_NAME);
names.add(COLUMN_DEFINITION);
return names;
}
/**
* {@inheritDoc}
*/
@Override
protected void calculateInsertionIndex(Element parent, Element child, String elementName) {
index = index(parent, child, elementName);
}
/**
* {@inheritDoc}
*/
@Override
public String getColumnDefinition() {
return getAttribute(COLUMN_DEFINITION);
}
/**
* {@inheritDoc}
*/
@Override
public TextRange getColumnDefinitionTextRange() {
return getAttributeTextRange(COLUMN_DEFINITION);
}
/**
* {@inheritDoc}
*/
@Override
public Element getElement() {
return getChild(getParent(), getElementName(), index);
}
/**
* {@inheritDoc}
*/
@Override
protected String getElementName() {
return PRIMARY_KEY_JOIN_COLUMN;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return getAttribute(NAME);
}
/**
* {@inheritDoc}
*/
@Override
public TextRange getNameTextRange() {
return getAttributeTextRange(NAME);
}
/**
* {@inheritDoc}
*/
@Override
public String getReferenceColumnName() {
return getAttribute(REFERENCED_COLUMN_NAME);
}
/**
* {@inheritDoc}
*/
@Override
public TextRange getReferenceColumnNameTextRange() {
return getAttributeTextRange(REFERENCED_COLUMN_NAME);
}
/**
* {@inheritDoc}
*/
@Override
public void removeSelf() {
removeChild(getParent(), getElementName(), index);
}
/**
* {@inheritDoc}
*/
@Override
public void setColumnDefinition(String definition) {
setAttribute(COLUMN_DEFINITION, definition);
}
/**
* {@inheritDoc}
*/
@Override
public void setName(String name) {
setAttribute(NAME, name);
}
/**
* {@inheritDoc}
*/
@Override
public void setReferenceColumnName(String name) {
setAttribute(REFERENCED_COLUMN_NAME, name);
}
}