KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployers > plugins > structure > vfs > AbstractCandidateStructureVisitor


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
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.vfs;
23
24 import java.io.IOException JavaDoc;
25
26 import org.jboss.deployers.spi.structure.vfs.ContextInfo;
27 import org.jboss.deployers.spi.structure.vfs.StructureMetaData;
28 import org.jboss.deployers.spi.structure.vfs.StructuredDeployers;
29 import org.jboss.logging.Logger;
30 import org.jboss.virtual.VirtualFile;
31 import org.jboss.virtual.VirtualFileFilter;
32 import org.jboss.virtual.VisitorAttributes;
33 import org.jboss.virtual.plugins.vfs.helpers.AbstractVirtualFileVisitor;
34
35 /**
36  * Visits the structure and creates candidates
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 1.1 $
40  */

41 public class AbstractCandidateStructureVisitor extends AbstractVirtualFileVisitor
42 {
43    /** The log */
44    private static final Logger log = Logger.getLogger(AbstractCandidateStructureVisitor.class);
45
46    /** The parent deployment file */
47    private final VirtualFile parent;
48
49    /** The meta data location */
50    private final StructureMetaData metaData;
51    private final StructuredDeployers deployers;
52
53    /** Ignore directories */
54    private boolean ignoreDirectories;
55
56    /** A filter */
57    private VirtualFileFilter filter;
58    
59    /**
60     * Create a new CandidateStructureVisitor.
61     *
62     * @param parent the parent
63     * @throws IllegalArgumentException for a null parent
64     */

65    public AbstractCandidateStructureVisitor(VirtualFile parent, StructureMetaData metaData, StructuredDeployers deployers)
66    {
67       this(parent, metaData, deployers, null);
68    }
69    
70    /**
71     * Create a new CandidateStructureVisitor.
72     *
73     * @param parent the parent
74     * @param attributes the attributes
75     * @throws IllegalArgumentException for a null parent
76     */

77    public AbstractCandidateStructureVisitor(VirtualFile parent, StructureMetaData metaData, StructuredDeployers deployers, VisitorAttributes attributes)
78    {
79       super(attributes);
80       if (parent == null)
81          throw new IllegalArgumentException JavaDoc("Null parent");
82       this.parent = parent;
83       this.metaData = metaData;
84       this.deployers = deployers;
85    }
86
87    /**
88     * Get the parent deployment context
89     *
90     * @return the parent.
91     */

92    public VirtualFile getParent()
93    {
94       return parent;
95    }
96
97    /**
98     * Get the ignoreDirectories.
99     *
100     * @return the ignoreDirectories.
101     */

102    public boolean isIgnoreDirectories()
103    {
104       return ignoreDirectories;
105    }
106
107    /**
108     * Get the filter.
109     *
110     * @return the filter.
111     */

112    public VirtualFileFilter getFilter()
113    {
114       return filter;
115    }
116
117    /**
118     * Set the filter.
119     *
120     * @param filter the filter.
121     */

122    public void setFilter(VirtualFileFilter filter)
123    {
124       this.filter = filter;
125    }
126
127    /**
128     * Set the ignoreDirectories.
129     *
130     * @param ignoreDirectories the ignoreDirectories.
131     */

132    public void setIgnoreDirectories(boolean ignoreDirectories)
133    {
134       this.ignoreDirectories = ignoreDirectories;
135    }
136
137    public void visit(VirtualFile file)
138    {
139       ContextInfo context = metaData.getContext(file.getPathName());
140       if (context == null)
141       {
142          // Ignore directories when asked
143
try
144          {
145             if (ignoreDirectories && file.isLeaf() == false)
146                return;
147          }
148          catch (IOException JavaDoc e)
149          {
150             log.debug("Ignoring " + file + " reason=" + e);
151             return;
152          }
153          
154          // Apply any filter
155
if (filter != null && filter.accepts(file) == false)
156             return;
157
158          try
159          {
160             // Ask the deployers to process this file
161
deployers.determineStructure(file, metaData);
162          }
163          catch (Exception JavaDoc e)
164          {
165             log.debug("Ignoring " + file + " reason=" + e);
166             return;
167          }
168       }
169    }
170 }
171
Popular Tags