1 9 package org.jboss.portal.server.plugins.preferences; 10 11 import java.util.HashSet ; 12 import java.util.Set ; 13 14 import org.apache.log4j.Logger; 15 16 20 public class SimpleMergeStrategy implements MergeStrategy 21 { 22 23 24 private static Logger log = Logger.getLogger(SimpleMergeStrategy.class); 25 26 27 private static final SimpleMergeStrategy singleton = new SimpleMergeStrategy(); 28 29 public static SimpleMergeStrategy getSingleton() 30 { 31 return singleton; 32 } 33 34 public Preference getPreference(PreferenceSet[] sets, String key) throws IllegalArgumentException 35 { 36 if (sets == null) 38 { 39 throw new IllegalArgumentException ("sets must not be null"); 40 } 41 if (key == null) 42 { 43 throw new IllegalArgumentException ("key must not be null"); 44 } 45 46 Preference preference = null; 48 49 for (int i = sets.length - 1;i >= 0;i--) 51 { 52 Preference tmp = sets[i].getPreference(key); 53 if (tmp != null) 54 { 55 if (tmp.isReadOnly()) 56 { 57 preference = tmp; 58 break; 59 } 60 else if (preference == null) 61 { 62 preference = tmp; 63 } 64 } 65 } 66 67 return preference; 68 } 69 70 public boolean isReadOnly(PreferenceSet[] sets, String key) throws IllegalArgumentException 71 { 72 if (sets == null) 74 { 75 throw new IllegalArgumentException ("sets must not be null"); 76 } 77 if (key == null) 78 { 79 throw new IllegalArgumentException ("key must not be null"); 80 } 81 82 for (int i = sets.length - 1;i >= 0;i--) 84 { 85 Preference preference = sets[i].getPreference(key); 86 if (preference != null && preference.isReadOnly()) 87 { 88 return true; 89 } 90 } 91 92 return false; 94 } 95 96 public Set getKeySet(PreferenceSet[] sets) throws IllegalArgumentException 97 { 98 if (sets == null) 100 { 101 throw new IllegalArgumentException ("sets must not be null"); 102 } 103 104 Set keys = new HashSet (); 106 for (int i = 0;i < sets.length;i++) 107 { 108 Set tmp = sets[i].keySet(); 109 keys.addAll(tmp); 110 } 111 return keys; 112 } 113 } 114 | Popular Tags |