/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
package org.apache.openjpa.sdo.mapping;

import org.apache.openjpa.jdbc.meta.FieldMapping;
import org.apache.openjpa.sdo.SDOInstanceMapping;
import org.apache.openjpa.sdo.SDOMappingRepository;

import serp.bytecode.BCField;

import commonj.sdo.DataObject;
import commonj.sdo.Property;

/**
 * Defines protocol of mapping between DataObject instance and Persistence
 * Capable instance per Property basis.
 * 
 * @author Pinaki Poddar
 * @since 0.2.0
 */
public interface PropertyMapping  {
	public void resolve(FieldMapping fm);
	/**
	 * Get the Property being mapped by this receiver.
	 */
	public Property getProperty();
	
	/**
	 * Gets a logical name of this receiver. This name is only used for
	 * descriptiove purpose.
	 */
	public String getName();
	
	/**
	 * Gets the name of target Java field. 
	 * 
	 */
	public String getFieldName();
	
	/**
	 * Gets the name of the type of target Java Field.
	 */
	public String getFieldTypeName();
	
	public Class getFieldType(SDOMappingRepository repos);
	
	/**
	 * Gets the persistent annotations for the target Java field.
	 */
	public String[] getAnnotationStrings();
	
	public void annotate(BCField field);
	
	/**
	 * Populate the given <code>target</code> DataObject from the field value
	 * of the given <code>source</code> PersistenceCapable instance.
	 * 
	 * @param target the DataObject whose value of the property to be set.
	 * @param source the PersistenceCapable instance whose field value
	 * is to be extracted.
	 * @param ctx The context this receiver is activated.
	 * 
	 * @return the DataObject which has been modified. For primitive field
	 * it is the given <code>target</code> DataObject itself. But for
	 * relation mapping, it can be another DataObject.
	 * 
	 * @throws Exception if the value can be set for some reason.
	 */
	public DataObject populateDataObject(DataObject target, Object source, 
			SDOInstanceMapping ctx) throws Exception;
	
	
	/**
	 * Populate the given <code>target</code> PersistenceCapable instance from 
	 * the property value of the given <code>source</code> DataObject .
	 * 
	 * @param target the PersistenceCapable instance whose field value 
	 * to be set.
	 * @param source the DataObject whose property value
	 * is to be extracted.
	 * @param ctx The context this receiver is activated.
	 * 
	 * @return the PersistenceCapable instance which has been modified. 
	 * For primitive field, it is the given <code>target</code> 
	 * PersistenceCapable instance itself. But for
	 * relation mapping, it can be another PersistenceCapable instance.
	 * 
	 * @throws Exception if the value can be set for some reason.
	 */
	public Object populatePC(Object target, DataObject source, 
			SDOInstanceMapping ctx) throws Exception;
	
	
}
