| /******************************************************************************* |
| * Copyright (c) 2008, 2012 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.jpa.eclipselink.core.internal.context.java; |
| |
| import java.util.List; |
| import org.eclipse.jdt.core.dom.CompilationUnit; |
| import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; |
| import org.eclipse.jpt.common.utility.internal.NotNullFilter; |
| import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; |
| import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; |
| import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; |
| import org.eclipse.jpt.jpa.core.context.AttributeMapping; |
| import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode; |
| import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; |
| import org.eclipse.jpt.jpa.core.internal.context.JptValidator; |
| import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaEmbeddable; |
| import org.eclipse.jpt.jpa.core.resource.java.EmbeddableAnnotation; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkChangeTracking; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkConverter; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkCustomizer; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.java.JavaEclipseLinkConverterContainer; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.java.JavaEclipseLinkEmbeddable; |
| import org.eclipse.jpt.jpa.eclipselink.core.internal.context.EclipseLinkTypeMappingValidator; |
| import org.eclipse.wst.validation.internal.provisional.core.IMessage; |
| import org.eclipse.wst.validation.internal.provisional.core.IReporter; |
| |
| /** |
| * EclipseLink |
| * Java embeddable type mapping |
| */ |
| public class JavaEclipseLinkEmbeddableImpl |
| extends AbstractJavaEmbeddable |
| implements JavaEclipseLinkEmbeddable, JavaEclipseLinkConverterContainer.ParentAdapter |
| { |
| protected final JavaEclipseLinkConverterContainer converterContainer; |
| |
| protected final JavaEclipseLinkChangeTracking changeTracking; |
| |
| protected final JavaEclipseLinkCustomizer customizer; |
| |
| |
| public JavaEclipseLinkEmbeddableImpl(JavaPersistentType parent, EmbeddableAnnotation mappingAnnotation) { |
| super(parent, mappingAnnotation); |
| this.converterContainer = this.buildConverterContainer(); |
| this.changeTracking = this.buildChangeTracking(); |
| this.customizer = this.buildCustomizer(); |
| } |
| |
| |
| // ********** synchronize/update ********** |
| |
| @Override |
| public void synchronizeWithResourceModel() { |
| super.synchronizeWithResourceModel(); |
| this.converterContainer.synchronizeWithResourceModel(); |
| this.changeTracking.synchronizeWithResourceModel(); |
| this.customizer.synchronizeWithResourceModel(); |
| } |
| |
| @Override |
| public void update() { |
| super.update(); |
| this.converterContainer.update(); |
| this.changeTracking.update(); |
| this.customizer.update(); |
| } |
| |
| |
| // ********** converter container ********** |
| |
| public JavaEclipseLinkConverterContainer getConverterContainer() { |
| return this.converterContainer; |
| } |
| |
| protected JavaEclipseLinkConverterContainer buildConverterContainer() { |
| return new JavaEclipseLinkConverterContainerImpl(this); |
| } |
| |
| @SuppressWarnings("unchecked") |
| public Iterable<EclipseLinkConverter> getConverters() { |
| return new CompositeIterable<EclipseLinkConverter>( |
| this.converterContainer.getConverters(), |
| this.getAttributeMappingConverters() |
| ); |
| } |
| |
| protected Iterable<EclipseLinkConverter> getAttributeMappingConverters() { |
| return new FilteringIterable<EclipseLinkConverter>(this.getAttributeMappingConverters_(), NotNullFilter.<EclipseLinkConverter>instance()); |
| } |
| |
| protected Iterable<EclipseLinkConverter> getAttributeMappingConverters_() { |
| return new CompositeIterable<EclipseLinkConverter>(this.getAttributeMappingConverterLists()); |
| } |
| |
| protected Iterable<Iterable<EclipseLinkConverter>> getAttributeMappingConverterLists() { |
| return new TransformationIterable<AttributeMapping, Iterable<EclipseLinkConverter>>( |
| this.getAttributeMappings(), |
| ATTRIBUTE_MAPPING_CONVERTER_TRANSFORMER |
| ); |
| } |
| |
| |
| // ********** change tracking ********** |
| |
| public EclipseLinkChangeTracking getChangeTracking() { |
| return this.changeTracking; |
| } |
| |
| protected JavaEclipseLinkChangeTracking buildChangeTracking() { |
| return new JavaEclipseLinkChangeTracking(this); |
| } |
| |
| |
| // ********** customizer ********** |
| |
| public EclipseLinkCustomizer getCustomizer() { |
| return this.customizer; |
| } |
| |
| protected JavaEclipseLinkCustomizer buildCustomizer() { |
| return new JavaEclipseLinkCustomizer(this); |
| } |
| |
| |
| // ********** misc ********** |
| |
| public boolean usesPrimaryKeyColumns() { |
| return false; |
| } |
| |
| public boolean usesPrimaryKeyTenantDiscriminatorColumns() { |
| return false; |
| } |
| |
| // ********** converter container parent adapter ********** |
| |
| public JavaJpaContextNode getConverterContainerParent() { |
| return this; // no adapter |
| } |
| |
| public JavaResourceAnnotatedElement getJavaResourceAnnotatedElement() { |
| return this.getJavaResourceType(); |
| } |
| |
| public boolean parentSupportsConverters() { |
| return true; |
| } |
| |
| // ********** validation ********** |
| |
| @Override |
| public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| super.validate(messages, reporter, astRoot); |
| this.converterContainer.validate(messages, reporter, astRoot); |
| this.changeTracking.validate(messages, reporter, astRoot); |
| this.customizer.validate(messages, reporter, astRoot); |
| } |
| |
| @Override |
| protected JptValidator buildTypeMappingValidator(CompilationUnit astRoot) { |
| return new EclipseLinkTypeMappingValidator(this, this.getJavaResourceType(), this.buildTextRangeResolver(astRoot)); |
| } |
| } |