001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.devtools.jpa.eclipselink.conv.parser.helper.resolver; 017 018import japa.parser.ast.ImportDeclaration; 019import japa.parser.ast.expr.AnnotationExpr; 020import japa.parser.ast.expr.Expression; 021import japa.parser.ast.expr.NameExpr; 022import japa.parser.ast.expr.QualifiedNameExpr; 023import org.apache.commons.logging.Log; 024import org.apache.commons.logging.LogFactory; 025import org.apache.ojb.broker.metadata.DescriptorRepository; 026import org.kuali.rice.devtools.jpa.eclipselink.conv.parser.helper.NodeData; 027 028import java.util.Collection; 029import java.util.List; 030 031/** 032 * this only does mappings for OneToOne at the field level for non-compound fks. 033 */ 034public class PrimaryKeyJoinColumnResolver extends AbstractPrimaryKeyJoinColumnResolver { 035 private static final Log LOG = LogFactory.getLog(PrimaryKeyJoinColumnResolver.class); 036 037 public static final String PACKAGE = "javax.persistence"; 038 public static final String SIMPLE_NAME = "PrimaryKeyJoinColumn"; 039 040 public PrimaryKeyJoinColumnResolver(Collection<DescriptorRepository> descriptorRepositories) { 041 super(descriptorRepositories); 042 } 043 @Override 044 public String getFullyQualifiedName() { 045 return PACKAGE + "." + SIMPLE_NAME; 046 } 047 048 @Override 049 protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { 050 final List<Expression> joinColumns = getJoinColumns(enclosingClass, fieldName, mappedClass); 051 if (joinColumns != null && joinColumns.size() == 1) { 052 return new NodeData((AnnotationExpr) joinColumns.get(0), 053 new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); 054 } 055 056 return null; 057 } 058}