KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > virtual > VisitorAttributes


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.virtual;
23
24 /**
25  * Attributes used when visiting a virtual file system
26  *
27  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
28  * @author Scott.Stark@jboss.org
29  * @version $Revision: 1.1 $
30  */

31 public class VisitorAttributes
32 {
33    /** A VirtualFileFilter than accepts any file */
34    public static final AcceptAnyFilter RECURSE_ALL = new AcceptAnyFilter();
35
36    /** The default attributes - visit nothing both leaves, non-leaves, no recursion */
37    public static final VisitorAttributes DEFAULT = new ImmutableVisitorAttributes();
38
39    /** Visit leaves only and do not recurse non-leaf files */
40    public static final VisitorAttributes LEAVES_ONLY = new ImmutableVisitorAttributes(true, null);
41
42    /** Recurse and visit all non-leaf files */
43    public static final VisitorAttributes RECURSE = new ImmutableVisitorAttributes(false, RECURSE_ALL);
44
45    /** Recurse all non-leaf files but only visit leaves */
46    public static final VisitorAttributes RECURSE_LEAVES_ONLY = new ImmutableVisitorAttributes(true, RECURSE_ALL);
47    
48    /** Whether to include the root */
49    private boolean includeRoot;
50
51    /** Whether to only visit leaves */
52    private boolean leavesOnly;
53
54    /** Whether to ignore individual file errors */
55    private boolean ignoreErrors;
56
57    /** Whether to include hidden files */
58    private boolean includeHidden;
59
60    /** A filter used to control whether a non-leaf is recursive visited */
61    private VirtualFileFilter recurseFilter;
62
63    /**
64     * Whether to visit leaves only<p>
65     *
66     * Default: false
67     *
68     * @return the visit leaves only.
69     */

70    public boolean isLeavesOnly()
71    {
72       return leavesOnly;
73    }
74
75    /**
76     * Set the leaves only.
77     *
78     * @param leavesOnly the leaves only
79     * @throws IllegalStateException if you attempt to modify one of the preconfigured static values of this class
80     */

81    public void setLeavesOnly(boolean leavesOnly)
82    {
83       this.leavesOnly = leavesOnly;
84    }
85
86    /**
87     * Whether to recurse into the non-leaf file<p>. If there is a recurse
88     * filter then the result will by its accepts(file) value.
89     *
90     * Default: false
91     *
92     * @return the recurse flag.
93     */

94    public boolean isRecurse(VirtualFile file)
95    {
96       boolean recurse = false;
97       if( recurseFilter != null )
98          recurse = recurseFilter.accepts(file);
99       return recurse;
100    }
101
102    /**
103     * Get the recurse filter.
104     * @return the current recurse filter.
105     */

106    public VirtualFileFilter getRecurseFilter()
107    {
108       return recurseFilter;
109    }
110
111    /**
112     * Set the recurse filter.
113     *
114     * @param filter - the recurse filter.
115     * @throws IllegalStateException if you attempt to modify one of the preconfigured static values of this class
116     */

117    public void setRecurseFilter(VirtualFileFilter filter)
118    {
119       this.recurseFilter = filter;
120    }
121
122    /**
123     * Whether to include the root of the visit<p>
124     *
125     * Default: false
126     *
127     * @return the includeRoot.
128     */

129    public boolean isIncludeRoot()
130    {
131       return includeRoot;
132    }
133
134    /**
135     * Set the includeRoot.
136     *
137     * @param includeRoot the includeRoot.
138     * @throws IllegalStateException if you attempt to modify one of the preconfigured static values of this class
139     */

140    public void setIncludeRoot(boolean includeRoot)
141    {
142       this.includeRoot = includeRoot;
143    }
144
145    /**
146     * Whether to ignore individual errors<p>
147     *
148     * Default: false
149     *
150     * @return the ignoreErrors.
151     */

152    public boolean isIgnoreErrors()
153    {
154       return ignoreErrors;
155    }
156
157    /**
158     * Set the ignoreErrors.
159     *
160     * @param ignoreErrors the ignoreErrors.
161     * @throws IllegalStateException if you attempt to modify one of the preconfigured static values of this class
162     */

163    public void setIgnoreErrors(boolean ignoreErrors)
164    {
165       this.ignoreErrors = ignoreErrors;
166    }
167
168    /**
169     * Whether to include hidden files<p>
170     *
171     * Default: false
172     *
173     * @return the includeHidden.
174     */

175    public boolean isIncludeHidden()
176    {
177       return includeHidden;
178    }
179
180    /**
181     * Set the includeHidden.
182     *
183     * @param includeHidden the includeHidden.
184     * @throws IllegalStateException if you attempt to modify one of the preconfigured static values of this class
185     */

186    public void setIncludeHidden(boolean includeHidden)
187    {
188       this.includeHidden = includeHidden;
189    }
190
191    private static class AcceptAnyFilter implements VirtualFileFilter
192    {
193       public boolean accepts(VirtualFile file)
194       {
195          return true;
196       }
197    }
198    /**
199     * Immutable version of the attribues
200     */

201    private static class ImmutableVisitorAttributes extends VisitorAttributes
202    {
203       /**
204        * Create a new ImmutableVirtualFileVisitorAttributes with default values
205        */

206       public ImmutableVisitorAttributes()
207       {
208       }
209       
210       /**
211        * Create a new ImmutableVirtualFileVisitorAttributes.
212        *
213        * @param leavesOnly whether to visit leaves only
214        * @param recurseFilter - filter which controls whether to recurse
215        */

216       public ImmutableVisitorAttributes(boolean leavesOnly, VirtualFileFilter recurseFilter)
217       {
218          super.setLeavesOnly(leavesOnly);
219          super.setRecurseFilter(recurseFilter);
220       }
221       
222       @Override JavaDoc
223       public void setLeavesOnly(boolean leavesOnly)
224       {
225          throw new IllegalStateException JavaDoc("The preconfigured attributes are immutable");
226       }
227
228       @Override JavaDoc
229       public void setIncludeRoot(boolean includeRoot)
230       {
231          throw new IllegalStateException JavaDoc("The preconfigured attributes are immutable");
232       }
233
234       @Override JavaDoc
235       public void setRecurseFilter(VirtualFileFilter filter)
236       {
237          throw new IllegalStateException JavaDoc("The preconfigured attributes are immutable");
238       }
239
240       @Override JavaDoc
241       public void setIgnoreErrors(boolean ignoreErrors)
242       {
243          throw new IllegalStateException JavaDoc("The preconfigured attributes are immutable");
244       }
245
246       @Override JavaDoc
247       public void setIncludeHidden(boolean includeHidden)
248       {
249          throw new IllegalStateException JavaDoc("The preconfigured attributes are immutable");
250       }
251    }
252 }
253
Popular Tags