1 18 package org.objectweb.jorm.lib; 19 20 import org.objectweb.jorm.api.PMapCluster; 21 import org.objectweb.jorm.api.PException; 22 23 import java.util.Set ; 24 import java.util.Collection ; 25 import java.util.HashSet ; 26 27 33 public abstract class AbstractPMapcluster implements PMapCluster { 34 35 38 protected Set jcNames; 39 40 45 protected Set unresolvedDependencies; 46 47 52 protected boolean structuresActive; 53 54 public AbstractPMapcluster() { 55 jcNames = new HashSet (1); 56 unresolvedDependencies = new HashSet (1); 57 structuresActive = false; 58 } 59 60 65 public Collection getClusterClasses() { 66 if (unresolvedDependencies.isEmpty()) { 67 return jcNames; 68 } else { 69 Set res = new HashSet (jcNames); 70 res.addAll(unresolvedDependencies); 71 return res; 72 } 73 } 74 75 public boolean isDefined() { 76 return unresolvedDependencies.isEmpty(); 77 } 78 79 public Set getUnResolvedDependencies() { 80 return unresolvedDependencies; 81 } 82 83 public void addDependency(String jcname) { 84 if (!jcNames.contains(jcname) && !unresolvedDependencies.contains(jcname)) { 85 unresolvedDependencies.add(jcname); 86 } 87 } 88 89 public void classDefined(String jcname) { 90 if (!jcNames.contains(jcname)) { 91 jcNames.add(jcname); 92 unresolvedDependencies.remove(jcname); 93 } 94 } 95 96 101 public boolean containClass(String jcname) { 102 return jcNames.contains(jcname); 103 } 104 105 111 public void start() throws PException { 112 if (!structuresActive) { 113 throw new PException("Cannot start map cluster: not yet inactive"); 114 } 115 if (!isDefined()) { 116 throw new PException("Cannot start map cluster: the following " + 117 "dependencies have not been resolved: " 118 + unresolvedDependencies); 119 } 120 structuresActive = true; 121 } 122 123 127 public void stop() throws PException { 128 if (structuresActive) { 129 throw new PException("Cannot stop map cluster: not yet active"); 130 } 131 structuresActive = false; 132 } 133 134 143 public void updateMappingStructures() 144 throws PException, UnsupportedOperationException { 145 if (structuresActive) { 146 throw new PException("Cannot change mapping structures while they are under use"); 147 } 148 throw new UnsupportedOperationException (); 149 } 150 } 151 | Popular Tags |