| /******************************************************************************* |
| * Copyright (c) 2008, 2009 Oracle. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v1.0, which accompanies this distribution |
| * and is available at http://www.eclipse.org/legal/epl-v10.html. |
| * |
| * Contributors: |
| * Oracle - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.jpt.core.internal.context.orm; |
| |
| import java.util.ListIterator; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.util.EObjectContainmentEList; |
| import org.eclipse.jpt.core.context.java.JavaAttributeOverride; |
| import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; |
| import org.eclipse.jpt.core.context.orm.OrmTypeMapping; |
| import org.eclipse.jpt.core.resource.orm.OrmPackage; |
| import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; |
| import org.eclipse.jpt.core.resource.orm.XmlColumn; |
| import org.eclipse.jpt.core.resource.orm.XmlEmbedded; |
| import org.eclipse.jpt.core.utility.TextRange; |
| import org.eclipse.jpt.utility.internal.CollectionTools; |
| |
| /** |
| * VirtualEmbedded is an implementation of Embedded used when there is |
| * no tag in the orm.xml and an underlying javaEmbeddedMapping exists. |
| */ |
| public class VirtualXmlEmbedded extends XmlEmbedded |
| { |
| protected OrmTypeMapping ormTypeMapping; |
| |
| protected final JavaEmbeddedMapping javaAttributeMapping; |
| |
| protected final VirtualXmlAttributeMapping virtualXmlAttributeMapping; |
| |
| public VirtualXmlEmbedded(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping) { |
| super(); |
| this.ormTypeMapping = ormTypeMapping; |
| this.javaAttributeMapping = javaEmbeddedMapping; |
| this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaEmbeddedMapping); |
| } |
| |
| protected boolean isOrmMetadataComplete() { |
| return this.ormTypeMapping.isMetadataComplete(); |
| } |
| |
| @Override |
| public String getMappingKey() { |
| return this.virtualXmlAttributeMapping.getMappingKey(); |
| } |
| |
| @Override |
| public String getName() { |
| return this.virtualXmlAttributeMapping.getName(); |
| } |
| |
| @Override |
| public void setName(String newName) { |
| this.virtualXmlAttributeMapping.setName(newName); |
| } |
| |
| @Override |
| public TextRange getNameTextRange() { |
| return this.virtualXmlAttributeMapping.getNameTextRange(); |
| } |
| |
| @Override |
| public EList<XmlAttributeOverride> getAttributeOverrides() { |
| EList<XmlAttributeOverride> attributeOverrides = new EObjectContainmentEList<XmlAttributeOverride>(XmlAttributeOverride.class, this, OrmPackage.XML_EMBEDDED__ATTRIBUTE_OVERRIDES); |
| ListIterator<JavaAttributeOverride> javaAttributeOverrides; |
| if (!this.isOrmMetadataComplete()) { |
| javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().attributeOverrides(); |
| } |
| else { |
| javaAttributeOverrides = this.javaAttributeMapping.getAttributeOverrideContainer().virtualAttributeOverrides(); |
| } |
| for (JavaAttributeOverride javaAttributeOverride : CollectionTools.iterable(javaAttributeOverrides)) { |
| XmlColumn xmlColumn = new VirtualXmlColumn(this.ormTypeMapping, javaAttributeOverride.getColumn()); |
| XmlAttributeOverride xmlAttributeOverride = new VirtualXmlAttributeOverride(javaAttributeOverride.getName(), xmlColumn); |
| attributeOverrides.add(xmlAttributeOverride); |
| } |
| return attributeOverrides; |
| } |
| } |