1 22 package org.jboss.deployers.plugins.structure; 23 24 import java.util.HashSet ; 25 import java.util.Set ; 26 import java.util.SortedSet ; 27 import java.util.TreeSet ; 28 29 import org.jboss.deployers.spi.DeploymentException; 30 import org.jboss.deployers.spi.structure.vfs.StructureDeployer; 31 import org.jboss.deployers.spi.structure.vfs.StructureMetaData; 32 import org.jboss.deployers.spi.structure.vfs.StructuredDeployers; 33 import org.jboss.virtual.VirtualFile; 34 35 41 public class BasicStructuredDeployers 42 implements StructuredDeployers 43 { 44 45 private SortedSet <StructureDeployer> structureDeployers; 46 47 public BasicStructuredDeployers() 48 { 49 this(new TreeSet <StructureDeployer>(StructureDeployer.COMPARATOR)); 50 } 51 public BasicStructuredDeployers(SortedSet <StructureDeployer> structureDeployers) 52 { 53 this.structureDeployers = structureDeployers; 54 } 55 56 public boolean isEmpty() 57 { 58 return structureDeployers == null ? true : structureDeployers.isEmpty(); 59 } 60 61 public boolean determineStructure(VirtualFile file, StructureMetaData metaData) 62 throws DeploymentException 63 { 64 StructureDeployer[] theDeployers; 65 synchronized (this) 66 { 67 if (structureDeployers.isEmpty()) 68 throw new IllegalStateException ("No structure deployers"); 69 70 theDeployers = structureDeployers.toArray(new StructureDeployer[structureDeployers.size()]); 71 } 72 73 boolean result = false; 74 for (StructureDeployer deployer : theDeployers) 75 { 76 if (deployer.determineStructure(file, metaData, this)) 77 { 78 result = true; 79 break; 80 } 81 } 82 return result; 83 } 84 85 88 public SortedSet <StructureDeployer> getDeployers() 89 { 90 return structureDeployers; 91 } 92 public void setDeployers(Set <StructureDeployer> deployers) 93 { 94 HashSet <StructureDeployer> oldDeployers = new HashSet <StructureDeployer>(structureDeployers); 96 oldDeployers.removeAll(deployers); 97 for (StructureDeployer deployer : oldDeployers) 98 removeDeployer(deployer); 99 100 HashSet <StructureDeployer> newDeployers = new HashSet <StructureDeployer>(deployers); 102 newDeployers.removeAll(structureDeployers); 103 for (StructureDeployer deployer : newDeployers) 104 addDeployer(deployer); 105 } 106 107 112 public synchronized void addDeployer(StructureDeployer deployer) 113 { 114 if (deployer == null) 115 throw new IllegalArgumentException ("Null deployer"); 116 structureDeployers.add(deployer); 117 } 118 119 124 public synchronized void removeDeployer(StructureDeployer deployer) 125 { 126 if (deployer == null) 127 throw new IllegalArgumentException ("Null deployer"); 128 structureDeployers.remove(deployer); 129 } 130 131 } 132 | Popular Tags |