View Javadoc
1 /* 2 * PROJECT : DAR Runtime and Tools 3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org 4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE 5 * Version 2.1, February 1999 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 package org.enableit.db.darrt; 22 23 import java.util.ArrayList; 24 import java.util.Iterator; 25 import java.util.List; 26 27 import org.apache.log4j.Logger; 28 import org.enableit.db.beans.Provider; 29 import org.enableit.db.beans.RowSet; 30 31 32 /*** 33 * @author Tim Stephenson 34 */ 35 public class ConflictResolutionChain extends Object { 36 /*** 37 * The Log4J <code>Logger</code> doing the logging. 38 */ 39 private static Logger logger = Logger.getLogger(ConflictResolutionChain.class); 40 41 /*** 42 * CVS info ABOUT this class and its current version 43 */ 44 public static final String about = "$Revision $"; 45 46 /* 47 * Properties 48 */ 49 protected List resolvers; 50 51 /* 52 * Constructors 53 */ 54 55 /*** 56 * Default Constructor, returns an empty chain. 57 */ 58 public ConflictResolutionChain() { 59 resolvers = new ArrayList(); 60 } 61 62 /*** 63 * Constructor, returns a chain constructed from info within row set. 64 */ 65 public ConflictResolutionChain(RowSet rowSet) { 66 this(); 67 68 ClassLoader cl = getClassLoader(); 69 70 for (int i = 0; i < rowSet.getConflictResolverCount(); i++) { 71 try { 72 resolvers.add(cl.loadClass(rowSet.getConflictResolver(i)) 73 .newInstance()); 74 } catch (Exception e) { 75 logger.error("Problem loading conflict resolver: " 76 + rowSet.getConflictResolver(i)); 77 } 78 } 79 } 80 81 /* 82 * Methods 83 */ 84 85 /*** 86 * @return ClassLoader to use in loading Conflit Resolvers. 87 */ 88 protected ClassLoader getClassLoader() { 89 return ConflictResolutionChain.class.getClassLoader(); 90 } 91 92 /*** 93 * Attempt to resolve the conflicts thru the use of the resolvers in the chain. 94 */ 95 public RowSet resolve(Provider target, RowSet unresolvedSet) { 96 for (Iterator i = resolvers.iterator(); i.hasNext();) { 97 ConflictResolver cr = (ConflictResolver) i.next(); 98 99 unresolvedSet = cr.resolve(target, unresolvedSet); 100 } 101 102 return unresolvedSet; 103 } 104 }

This page was automatically generated by Maven