kmoore | c9c9e2b | 2011-02-06 02:07:28 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
kmoore | c7a0867 | 2011-08-01 15:10:18 +0000 | [diff] [blame] | 2 | * Copyright (c) 2006, 2011 Oracle. All rights reserved. |
kmoore | c9c9e2b | 2011-02-06 02:07:28 +0000 | [diff] [blame] | 3 | * This program and the accompanying materials are made available under the |
| 4 | * terms of the Eclipse Public License v1.0, which accompanies this distribution |
| 5 | * and is available at http://www.eclipse.org/legal/epl-v10.html. |
| 6 | * |
| 7 | * Contributors: |
| 8 | * Oracle - initial API and implementation |
| 9 | ******************************************************************************/ |
| 10 | package org.eclipse.jpt.jpa.core.internal.context.java; |
| 11 | |
| 12 | import java.util.List; |
kmoore | c9c9e2b | 2011-02-06 02:07:28 +0000 | [diff] [blame] | 13 | import org.eclipse.jdt.core.dom.CompilationUnit; |
kmoore | c7a0867 | 2011-08-01 15:10:18 +0000 | [diff] [blame] | 14 | import org.eclipse.jpt.common.core.resource.java.Annotation; |
kmoore | c9c9e2b | 2011-02-06 02:07:28 +0000 | [diff] [blame] | 15 | import org.eclipse.jpt.common.core.utility.TextRange; |
bvosburgh | 7b9ff96 | 2011-09-01 18:35:57 +0000 | [diff] [blame] | 16 | import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; |
kmoore | c9c9e2b | 2011-02-06 02:07:28 +0000 | [diff] [blame] | 17 | import org.eclipse.jpt.jpa.core.MappingKeys; |
bvosburgh | 7b9ff96 | 2011-09-01 18:35:57 +0000 | [diff] [blame] | 18 | import org.eclipse.jpt.jpa.core.context.Query; |
kmoore | c9c9e2b | 2011-02-06 02:07:28 +0000 | [diff] [blame] | 19 | import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; |
| 20 | import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; |
| 21 | import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; |
kmoore | c9c9e2b | 2011-02-06 02:07:28 +0000 | [diff] [blame] | 22 | import org.eclipse.wst.validation.internal.provisional.core.IMessage; |
| 23 | import org.eclipse.wst.validation.internal.provisional.core.IReporter; |
| 24 | |
| 25 | /** |
| 26 | * Java null type mapping |
| 27 | */ |
| 28 | public class JavaNullTypeMapping |
| 29 | extends AbstractJavaTypeMapping<Annotation> |
| 30 | { |
| 31 | public JavaNullTypeMapping(JavaPersistentType parent) { |
| 32 | super(parent, null); |
| 33 | } |
| 34 | |
| 35 | public String getKey() { |
| 36 | return MappingKeys.NULL_TYPE_MAPPING_KEY; |
| 37 | } |
| 38 | |
| 39 | public JavaPersistentType getIdClass() { |
| 40 | return null; |
| 41 | } |
| 42 | |
| 43 | public boolean isMapped() { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | public boolean tableNameIsInvalid(String tableName) { |
| 48 | return false; |
| 49 | } |
| 50 | |
bvosburgh | 7b9ff96 | 2011-09-01 18:35:57 +0000 | [diff] [blame] | 51 | public Iterable<Query> getQueries() { |
| 52 | return EmptyIterable.instance(); |
| 53 | } |
| 54 | |
kmoore | c9c9e2b | 2011-02-06 02:07:28 +0000 | [diff] [blame] | 55 | |
| 56 | // ********** validation ********** |
| 57 | |
| 58 | /** |
| 59 | * We added this message here because the most likely solution is to add |
| 60 | * an annotation to the .java file. |
| 61 | * This message used to be found on the <class> tag in persistence.xml. |
| 62 | * The other possible way to fix the error is to remove it from persistence.xml. |
| 63 | * This can be accomplished with the Synchronize Classes action. |
| 64 | * We could also add a quick fix for this error. |
| 65 | */ |
| 66 | @Override |
| 67 | public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 68 | super.validate(messages, reporter, astRoot); |
| 69 | messages.add( |
| 70 | DefaultJpaValidationMessages.buildMessage( |
| 71 | IMessage.HIGH_SEVERITY, |
| 72 | JpaValidationMessages.PERSISTENCE_UNIT_INVALID_CLASS, |
| 73 | new String[] {this.getPersistentType().getName()}, |
| 74 | this, |
| 75 | this.getValidationTextRange(astRoot) |
| 76 | ) |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public boolean validatesAgainstDatabase() { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public TextRange getValidationTextRange(CompilationUnit astRoot) { |
| 87 | return this.getPersistentType().getValidationTextRange(astRoot); |
| 88 | } |
| 89 | } |