blob: 9cbe5e414497c7214a8e5906b60e3843872db2f2 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007, 2011 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.core.internal.resource.java.source;
import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.ElementAnnotationAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationAdapter;
import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter;
import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
import org.eclipse.jpt.jpa.core.resource.java.JPA;
import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation;
/**
* <code>javax.persistence.JoinColumn</code>
*/
public final class SourceJoinColumnAnnotation
extends SourceBaseJoinColumnAnnotation
implements JoinColumnAnnotation
{
private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
private static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(JPA.JOIN_COLUMNS);
public static SourceJoinColumnAnnotation buildSourceJoinColumnAnnotation(
JavaResourceNode parent,
AnnotatedElement element) {
return new SourceJoinColumnAnnotation(parent, element, DECLARATION_ANNOTATION_ADAPTER);
}
public static SourceJoinColumnAnnotation buildSourceJoinColumnAnnotation(
JavaResourceAnnotatedElement parent,
AnnotatedElement annotatedElement,
int index) {
IndexedDeclarationAnnotationAdapter idaa = buildJoinColumnDeclarationAnnotationAdapter(index);
IndexedAnnotationAdapter iaa = buildJoinColumnAnnotationAdapter(annotatedElement, idaa);
return new SourceJoinColumnAnnotation(
parent,
annotatedElement,
idaa,
iaa);
}
public static SourceJoinColumnAnnotation buildNestedSourceJoinColumnAnnotation(
JavaResourceNode parent,
AnnotatedElement element,
IndexedDeclarationAnnotationAdapter idaa) {
return new SourceJoinColumnAnnotation(parent, element, idaa);
}
private SourceJoinColumnAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa) {
this(parent, element, daa, new ElementAnnotationAdapter(element, daa));
}
private SourceJoinColumnAnnotation(JavaResourceNode parent, AnnotatedElement element, IndexedDeclarationAnnotationAdapter idaa) {
this(parent, element, idaa, new ElementIndexedAnnotationAdapter(element, idaa));
}
private SourceJoinColumnAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
super(parent, element, daa, annotationAdapter);
}
public String getAnnotationName() {
return ANNOTATION_NAME;
}
// ********** SourceNamedColumnAnnotation implementation **********
@Override
protected String getNameElementName() {
return JPA.JOIN_COLUMN__NAME;
}
@Override
protected String getColumnDefinitionElementName() {
return JPA.JOIN_COLUMN__COLUMN_DEFINITION;
}
// ********** SourceBaseColumnAnnotation implementation **********
@Override
protected String getTableElementName() {
return JPA.JOIN_COLUMN__TABLE;
}
@Override
protected String getUniqueElementName() {
return JPA.JOIN_COLUMN__UNIQUE;
}
@Override
protected String getNullableElementName() {
return JPA.JOIN_COLUMN__NULLABLE;
}
@Override
protected String getInsertableElementName() {
return JPA.JOIN_COLUMN__INSERTABLE;
}
@Override
protected String getUpdatableElementName() {
return JPA.JOIN_COLUMN__UPDATABLE;
}
// ********** SourceBaseJoinColumnAnnotation implementation **********
@Override
protected String getReferencedColumnNameElementName() {
return JPA.JOIN_COLUMN__REFERENCED_COLUMN_NAME;
}
// ********** static methods **********
private static IndexedAnnotationAdapter buildJoinColumnAnnotationAdapter(AnnotatedElement annotatedElement, IndexedDeclarationAnnotationAdapter idaa) {
return new ElementIndexedAnnotationAdapter(annotatedElement, idaa);
}
private static IndexedDeclarationAnnotationAdapter buildJoinColumnDeclarationAnnotationAdapter(int index) {
IndexedDeclarationAnnotationAdapter idaa =
new CombinationIndexedDeclarationAnnotationAdapter(
DECLARATION_ANNOTATION_ADAPTER,
CONTAINER_DECLARATION_ANNOTATION_ADAPTER,
index,
ANNOTATION_NAME);
return idaa;
}
}