001 /** 002 * DirectAttributeCopyMethod.java 003 * jCOLIBRI2 framework. 004 * @author Juan A. Recio-García. 005 * GAIA - Group for Artificial Intelligence Applications 006 * http://gaia.fdi.ucm.es 007 * 05/01/2007 008 */ 009 package jcolibri.method.reuse; 010 011 import java.util.Collection; 012 013 import jcolibri.cbrcore.*; 014 import jcolibri.exception.AttributeAccessException; 015 016 /** 017 * Copies the value of an attribute in the query to an attribute of a case 018 * @author Juan A. Recio-Garcia 019 * @version 2.0 020 * 021 */ 022 public class DirectAttributeCopyMethod { 023 024 /** 025 * Copies the value of the querySource attribute into the caseDestination attribute of the cases. 026 */ 027 public static void copyAttribute(Attribute querySource, Attribute caseDestination, CBRQuery query, Collection<CBRCase> cases) 028 { 029 Object queryValue = jcolibri.util.AttributeUtils.findValue(querySource, query); 030 try { 031 032 for(CBRCase c: cases) 033 { 034 CaseComponent cc = jcolibri.util.AttributeUtils.findBelongingComponent(caseDestination, c); 035 caseDestination.setValue(cc, queryValue); 036 } 037 } catch (AttributeAccessException e) { 038 org.apache.commons.logging.LogFactory.getLog(DirectAttributeCopyMethod.class).error(e); 039 } 040 } 041 042 }