1 18 package org.objectweb.kilim.repository; 19 import java.util.HashMap ; 20 import java.util.Iterator ; 21 import java.util.LinkedList ; 22 23 import org.objectweb.kilim.description.Instance; 24 import org.objectweb.kilim.description.KILIM; 25 import org.objectweb.kilim.description.TemplateDescription; 26 27 36 public class ResourceMapping { 37 private Repository repository; 38 private LinkedList unParsedTemplates; 39 private HashMap knownTemplates; 40 private LinkedList unknownSuperTemplateOfInstances; 41 42 47 public ResourceMapping(Repository aRepository) { 48 repository = aRepository; 49 } 50 51 55 public void addUnparsedTemplate(String name) { 56 if (name == null) { 57 return; 58 } 59 60 if (unParsedTemplates == null) { 61 unParsedTemplates = new LinkedList (); 62 } 63 if (unParsedTemplates.contains(name)) { 64 return; 65 } 66 unParsedTemplates.add(name); 67 } 68 69 73 public void removeUnparsedTemplate(String name) { 74 if (name == null) { 75 return; 76 } 77 if (unParsedTemplates == null) { 78 return; 79 } 80 unParsedTemplates.remove(name); 81 } 82 83 88 public void addKnownTemplate(String name, TemplateDescription aTemplate) { 89 if (name == null || aTemplate == null) { 90 return; 91 } 92 if (knownTemplates == null) { 93 knownTemplates = new HashMap (); 94 } 95 if (knownTemplates.containsKey(name)) { 96 return; 97 } 98 knownTemplates.put(name, aTemplate); 99 } 100 101 105 public void removeKnownTemplate(String name) { 106 if (name == null) { 107 return; 108 } 109 if (knownTemplates == null) { 110 return; 111 } 112 knownTemplates.remove(name); 113 } 114 115 120 public TemplateDescription getKnownTemplate(String name) { 121 if (name == null || knownTemplates == null) { 122 return null; 123 } 124 return (TemplateDescription) knownTemplates.get(name); 125 } 126 127 131 public String getNextUnparsedTemplate() { 132 if (unParsedTemplates == null) { 133 return null; 134 } 135 if (unParsedTemplates.size() > 0) { 136 String result = (String ) unParsedTemplates.getFirst(); 137 unParsedTemplates.removeFirst(); 138 return result; 139 } 140 return null; 141 } 142 143 147 public void addUnknownSuperTemplateOfInstance(Instance aInstance) { 148 if (unknownSuperTemplateOfInstances == null) { 149 unknownSuperTemplateOfInstances = new LinkedList (); 151 } 152 unknownSuperTemplateOfInstances.addLast(aInstance); 154 } 155 156 160 public Iterator getUnknownSuperTemplateOfInstances() { 161 if (unknownSuperTemplateOfInstances == null) { 162 return KILIM.EMPTY_ITERATOR; 163 } 164 165 return unknownSuperTemplateOfInstances.iterator(); 166 } 167 } | Popular Tags |