KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > xmlimporter > BasicMerger


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10
11 package org.mmbase.applications.xmlimporter;
12
13 import java.util.*;
14
15 /**
16  * This is a basic implementation of ObjectMerger.
17  * It applies these rules:
18  * <ul>
19  * <li>Leave the fields of the merging objects unaffected.
20  * <li>Move the relations of both to the merged object.
21  * <li>Relations are considered duplicates when of same type and
22  * with same source and destination.
23  * <li>Add objects to the persistent cloud that are not present already.
24  * </ul>
25  *
26  * @author Rob van Maris: Finalist IT Group
27  * @since MMBase-1.5
28  * @version $Id: BasicMerger.java,v 1.5 2005/01/30 16:46:38 nico Exp $
29  */

30 public class BasicMerger implements ObjectMerger {
31
32     /** Initialize this instance. This implementation simply stores
33      * the initialization parameters.
34      * @param params The initialization parameters, provided as
35      * name/value pairs (both String).
36      */

37     public void init(HashMap params) {
38     }
39
40     /** Merge a field. This implementation leaves all fields unaffected.
41      * @param name The name of the field.
42      * (Note: "number" and "owner" are not considered fields in this context,
43      * so this method will not be called with these values for name.)
44      * @param tmpObj1 The first object to be merged. This will hold
45      * the resulting merged object afterwards.
46      * @param tmpObj2 The second object. this object must be deleted
47      * afterwards.
48      */

49     public void mergeField(TmpObject tmpObj1, TmpObject tmpObj2, String JavaDoc name) {}
50
51     /** Merge relations. This implementation moves all relations of the second
52      * object to the merged object.
53      * @param tmpObj1 The first object to be merged. This will hold
54      * the resulting merged object afterwards.
55      * @param tmpObj2 The second object. this object must be deleted
56      * afterwards.
57      * @param relations1 List of all relations of the first object.
58      * @param relations2 List of all relations of the second object.
59      */

60     public void mergeRelations(TmpObject tmpObj1, TmpObject tmpObj2,
61             List relations1, List relations2) {
62
63         Iterator i = relations2.iterator();
64         while (i.hasNext()) {
65             TmpObject relation = (TmpObject) i.next();
66             if (tmpObj2.isSourceOf(relation)) {
67                relation.setSource(tmpObj1);
68             }
69             if (tmpObj2.isDestinationOf(relation)) {
70                relation.setDestination(tmpObj1);
71             }
72         }
73     }
74
75     /** Tests if two relations should be considered duplicates,
76      * indicating that one of them can be disposed of.
77      * This test will only be called for pairs of relations that
78      * have already been verified to be of the same type, and have the
79      * same source, destination.
80      * This implementation always considers these pairs duplicates,
81      * it provides no additional tests.
82      * @param relation1 The first relation.
83      * @param relation2 The second relation.
84      * @return true if these relations should be considered duplicates.
85      */

86     public boolean areDuplicates(TmpObject relation1, TmpObject relation2) {
87         return true;
88     }
89
90     /** Tests if this object should be added to the persistent cloud
91      * when not present already.
92      * When this returns false, the object will be deleted from the
93      * transaction if no object is found to merge it with.
94      * This implementation allows all objects to be added when not present
95      * already.
96      * @param tmpObj The object.
97      * @return true If this object should be added, when not present already.
98      */

99     public boolean isAllowedToAdd(TmpObject tmpObj) {
100         return true;
101     }
102
103 }
104
Popular Tags