| /******************************************************************************* |
| * 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.orm.ExternalAttributeOverride; |
| import org.eclipse.persistence.tools.mapping.orm.ExternalEmbeddedIDMapping; |
| |
| /** |
| * The external form for a embedded ID mapping, which is a child of an entity. |
| * |
| * @see MappedSuperClassEntity |
| * |
| * @version 2.6 |
| */ |
| final class EmbeddedIDMapping extends NonTransientMapping |
| implements ExternalEmbeddedIDMapping { |
| |
| /** |
| * Creates a new <code>EmbeddedIDMapping</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 |
| */ |
| EmbeddedIDMapping(MappedSuperClassEntity parent, int index) { |
| super(parent, index); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public ExternalAttributeOverride addAttributeOverride(String name) { |
| AttributeOverride attributeOverride = buildAttributeOverride(-1); |
| attributeOverride.addSelf(); |
| attributeOverride.setName(name); |
| return attributeOverride; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public List<ExternalAttributeOverride> attributeOverrides() { |
| |
| int count = attributeOverridesSize(); |
| List<ExternalAttributeOverride> attributeOverrides = new ArrayList<ExternalAttributeOverride>(count); |
| |
| for (int index = 0; index < count; index++) { |
| attributeOverrides.add(buildAttributeOverride(index)); |
| } |
| |
| return attributeOverrides; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public int attributeOverridesSize() { |
| return getChildrenSize(AttributeOverride.ATTRIBUTE_OVERRIDE); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| protected List<String> buildAttributeNamesOrder() { |
| List<String> names = new ArrayList<String>(); |
| names.add(NAME); |
| names.add(ACCESS); |
| names.add(ATTRIBUTE_TYPE); |
| return names; |
| } |
| |
| private AttributeOverride buildAttributeOverride(int index) { |
| return new AttributeOverride(this, index); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| protected List<String> buildElementNamesOrder() { |
| List<String> names = new ArrayList<String>(); |
| names.add(AttributeOverride.ATTRIBUTE_OVERRIDE); |
| names.add(Property.PROPERTY); |
| names.add(AccessMethods.ACCESS_METHODS); |
| return names; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| protected String getElementName() { |
| return EMBEDDED_ID; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public void removeAttributeOverride(int index) { |
| AttributeOverride attributeOverride = buildAttributeOverride(index); |
| attributeOverride.removeSelf(); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public void setAttributeType(String attributeType) { |
| setAttribute(ATTRIBUTE_TYPE, attributeType); |
| } |
| } |