KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployers > plugins > structure > BasicStructuredDeployers


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.deployers.plugins.structure;
23
24 import java.util.HashSet JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.SortedSet JavaDoc;
27 import java.util.TreeSet JavaDoc;
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 /**
36  * A basic StructuredDeployers implementation.
37  *
38  * @author Scott.Stark@jboss.org
39  * @version $Revision:$
40  */

41 public class BasicStructuredDeployers
42    implements StructuredDeployers
43 {
44    
45    private SortedSet JavaDoc<StructureDeployer> structureDeployers;
46
47    public BasicStructuredDeployers()
48    {
49       this(new TreeSet JavaDoc<StructureDeployer>(StructureDeployer.COMPARATOR));
50    }
51    public BasicStructuredDeployers(SortedSet JavaDoc<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 JavaDoc("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    /**
86     * Get the
87     */

88    public SortedSet JavaDoc<StructureDeployer> getDeployers()
89    {
90       return structureDeployers;
91    }
92    public void setDeployers(Set JavaDoc<StructureDeployer> deployers)
93    {
94       // Remove all the old deployers that are not in the new set
95
HashSet JavaDoc<StructureDeployer> oldDeployers = new HashSet JavaDoc<StructureDeployer>(structureDeployers);
96       oldDeployers.removeAll(deployers);
97       for (StructureDeployer deployer : oldDeployers)
98          removeDeployer(deployer);
99       
100       // Add all the new deployers that were not already present
101
HashSet JavaDoc<StructureDeployer> newDeployers = new HashSet JavaDoc<StructureDeployer>(deployers);
102       newDeployers.removeAll(structureDeployers);
103       for (StructureDeployer deployer : newDeployers)
104          addDeployer(deployer);
105    }
106
107    /**
108     * Add a structure deployer
109     *
110     * @param deployer the deployer
111     */

112    public synchronized void addDeployer(StructureDeployer deployer)
113    {
114       if (deployer == null)
115          throw new IllegalArgumentException JavaDoc("Null deployer");
116       structureDeployers.add(deployer);
117    }
118
119    /**
120     * Remove a structure deployer
121     *
122     * @param deployer the deployer
123     */

124    public synchronized void removeDeployer(StructureDeployer deployer)
125    {
126       if (deployer == null)
127          throw new IllegalArgumentException JavaDoc("Null deployer");
128       structureDeployers.remove(deployer);
129    }
130
131 }
132
Popular Tags