| /******************************************************************************* |
| * Copyright (c) 2012, 2013 Oracle. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0, which accompanies this distribution |
| * and is available at https://www.eclipse.org/legal/epl-2.0/. |
| * |
| * Contributors: |
| * Oracle - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.jpt.jpa.eclipselink.core.internal.context.orm; |
| |
| import java.util.List; |
| import org.eclipse.jdt.core.IType; |
| import org.eclipse.jpt.common.core.internal.utility.JavaProjectTools; |
| import org.eclipse.jpt.common.core.utility.TextRange; |
| import org.eclipse.jpt.common.utility.internal.StringTools; |
| import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; |
| import org.eclipse.jpt.jpa.core.context.orm.OrmSpecifiedPersistentAttribute; |
| import org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.AbstractOrmEmbeddedMapping; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkAccessType; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkPersistenceUnit; |
| import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.XmlEmbedded; |
| import org.eclipse.jpt.jpa.eclipselink.core.validation.JptJpaEclipseLinkCoreValidationMessages; |
| import org.eclipse.wst.validation.internal.provisional.core.IMessage; |
| |
| /** |
| * <code>orm.xml</code> embedded mapping |
| */ |
| public class EclipseLinkOrmEmbeddedMapping |
| extends AbstractOrmEmbeddedMapping<XmlEmbedded> |
| { |
| public EclipseLinkOrmEmbeddedMapping(OrmSpecifiedPersistentAttribute parent, XmlEmbedded xmlMapping) { |
| super(parent, xmlMapping); |
| } |
| |
| |
| // ********** attribute type ********** |
| |
| @Override |
| protected String buildSpecifiedAttributeType() { |
| return this.xmlAttributeMapping.getAttributeType(); |
| } |
| |
| @Override |
| protected void setSpecifiedAttributeTypeInXml(String attributeType) { |
| this.xmlAttributeMapping.setAttributeType(attributeType); |
| } |
| |
| // ********** validation ********** |
| |
| @Override |
| protected boolean validateTargetEmbeddable(List<IMessage> messages) { |
| if (this.isVirtualAccess()) { |
| if (StringTools.isBlank(this.getAttributeType())) { |
| messages.add( |
| this.buildValidationMessage( |
| this.getAttributeTypeTextRange(), |
| JptJpaEclipseLinkCoreValidationMessages.VIRTUAL_ATTRIBUTE_NO_ATTRIBUTE_TYPE_SPECIFIED, |
| this.getName() |
| ) |
| ); |
| return false; |
| } |
| if (this.getResolvedAttributeType() == null) { |
| IType jdtType = JavaProjectTools.findType(this.getJavaProject(), this.getFullyQualifiedAttributeType()); |
| if (jdtType == null) { |
| messages.add( |
| this.buildValidationMessage( |
| this.getAttributeTypeTextRange(), |
| JptJpaEclipseLinkCoreValidationMessages.VIRTUAL_ATTRIBUTE_ATTRIBUTE_TYPE_DOES_NOT_EXIST, |
| this.getFullyQualifiedAttributeType() |
| ) |
| ); |
| return false; |
| } |
| } |
| } |
| return super.validateTargetEmbeddable(messages); |
| } |
| |
| protected boolean isVirtualAccess() { |
| return this.getPersistentAttribute().getAccess() == EclipseLinkAccessType.VIRTUAL; |
| } |
| |
| @Override |
| protected TextRange getAttributeTypeTextRange() { |
| return this.getValidationTextRange(this.xmlAttributeMapping.getAttributeTypeTextRange()); |
| } |
| |
| // ********** completion proposals ********** |
| |
| @Override |
| public Iterable<String> getCompletionProposals(int pos) { |
| Iterable<String> result = super.getCompletionProposals(pos); |
| if (result != null) { |
| return result; |
| } |
| if (this.attributeTypeTouches(pos)) { |
| return this.getCandidateAttributeTypeNames(); |
| } |
| return null; |
| } |
| |
| protected boolean attributeTypeTouches(int pos) { |
| return this.xmlAttributeMapping.attributeTypeTouches(pos); |
| } |
| |
| @SuppressWarnings("unchecked") |
| protected Iterable<String> getCandidateAttributeTypeNames() { |
| return IterableTools.concatenate( |
| JavaProjectTools.getJavaClassNames(getJavaProject()), |
| IterableTools.sort(((EclipseLinkPersistenceUnit) this.getPersistenceUnit()).getEclipseLinkDynamicPersistentTypeNames()) |
| ); |
| } |
| } |