1 6 package com.nightlabs.ipanema.person.edit.blockbased; 7 8 import java.util.Collections ; 9 import java.util.HashMap ; 10 import java.util.Iterator ; 11 import java.util.LinkedList ; 12 import java.util.List ; 13 import java.util.Map ; 14 15 import com.nightlabs.ipanema.person.PersonStruct; 16 import com.nightlabs.ipanema.person.PersonStructBlock; 17 import com.nightlabs.ipanema.person.PersonStructCache; 18 import com.nightlabs.ipanema.person.id.PersonStructBlockID; 19 20 26 public class PersonEditorStructBlockRegistry { 27 28 35 private Map editorStructBlocks = new HashMap (); 36 37 45 public void addEditorStructBlocks(String editorScope, String editorName, PersonStructBlockID[] personStructBlockIDs) { 46 if (!editorStructBlocks.containsKey(editorScope)) { 47 editorStructBlocks.put(editorScope,new HashMap ()); 48 } 49 Map editorsStructBlockKeys = (Map )editorStructBlocks.get(editorScope); 50 if (!editorsStructBlockKeys.containsKey(editorName)) 51 editorsStructBlockKeys.put(editorName,new LinkedList ()); 52 List personStructBlockKeyList = (List )editorsStructBlockKeys.get(editorName); 53 for (int i=0; i<personStructBlockIDs.length; i++) { 54 personStructBlockKeyList.add(personStructBlockIDs[i]); 55 } 56 } 57 58 67 public List getEditorStructBlocks(String editorScope, String editorName) { 68 Map editorsStructBlockKeys = (Map )editorStructBlocks.get(editorScope); 69 if (editorsStructBlockKeys != null) { 70 List personStructBlockKeyList = (List )editorsStructBlockKeys.get(editorName); 71 if (personStructBlockKeyList != null) { 72 return personStructBlockKeyList; 73 } 74 else 75 return Collections.EMPTY_LIST; 76 } 77 else 78 return Collections.EMPTY_LIST; 79 } 80 81 public Iterator getEditorStructBlocksIterator(String editorScope, String editorName) { 82 return getEditorStructBlocks(editorScope,editorName).iterator(); 83 } 84 85 93 public boolean hasEditorCoverage(String editorScope, PersonStructBlock structBlock) { 94 Map editorsStructBlockKeys = (Map )editorStructBlocks.get(editorScope); 95 if (editorsStructBlockKeys != null) { 96 for (Iterator it = editorsStructBlockKeys.values().iterator(); it.hasNext(); ) { 97 List personStructBlockKeyList = (List )it.next(); 98 if (personStructBlockKeyList.contains(PersonStructBlockID.create(structBlock.getPersonStructBlockOrganisationID(),structBlock.getPersonStructBlockID()))) 99 return true; 100 } 101 } 102 return false; 103 } 104 105 113 public List computeRemainingBlockKeyList(String editorScope) { 114 List result = new LinkedList (); 115 PersonStruct structure = PersonStructCache.getPersonStructure(); 116 for (Iterator it = structure.getPersonStructBlocks().iterator(); it.hasNext(); ) { 117 PersonStructBlock structBlock = (PersonStructBlock)it.next(); 118 if (!hasEditorCoverage(editorScope,structBlock)) 119 result.add(PersonStructBlockID.create(structBlock.getPersonStructBlockOrganisationID(), structBlock.getPersonStructBlockID())); 120 } 121 return result; 122 } 123 124 public PersonStructBlockID[] computeRemainingBlockKeys(String editorScope) { 125 List keys = computeRemainingBlockKeyList(editorScope); 126 PersonStructBlockID[] result = new PersonStructBlockID[keys.size()]; 127 for (int i=0; i<keys.size(); i++) { 128 result[i] = (PersonStructBlockID)keys.get(i); 129 } 130 return result; 131 } 132 133 private static PersonEditorStructBlockRegistry sharedInstance; 134 public static PersonEditorStructBlockRegistry getSharedInstance() { 135 if (sharedInstance == null) 136 sharedInstance = new PersonEditorStructBlockRegistry(); 137 return sharedInstance; 138 } 139 140 } 141 | Popular Tags |