KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, 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;
23
24 import org.jboss.virtual.VirtualFile;
25 import org.jboss.virtual.VirtualFileFilterWithAttributes;
26 import org.jboss.virtual.VisitorAttributes;
27
28 /**
29  * Matches meta data
30  *
31  * @author adrian@jboss.org
32  * @version $Revision: 44223 $
33  */

34 public class MetaDataMatchFilter implements VirtualFileFilterWithAttributes
35 {
36    /** The name */
37    private String JavaDoc name;
38
39    /** The suffix */
40    private String JavaDoc suffix;
41    
42    /** The attributes */
43    private VisitorAttributes attributes;
44    
45    /**
46     * Create a new MetaDataMatchFilter.
47     * using {@link VisitorAttributes#LEAVES_ONLY}
48     *
49     * @param name the name to exactly match
50     * @param suffix the suffix to partially match
51     * @throws IllegalArgumentException if both the name and suffix are null
52     */

53    public MetaDataMatchFilter(String JavaDoc name, String JavaDoc suffix)
54    {
55       this(name, suffix, null);
56    }
57    
58    /**
59     * Create a new MetaDataMatchFilter.
60     *
61     * @param name the name to exactly match
62     * @param suffix the suffix to partially match
63     * @param attributes the attributes, pass null to use {@link VisitorAttributes#LEAVES_ONLY}
64     * @throws IllegalArgumentException if both the name and suffix are null
65     */

66    public MetaDataMatchFilter(String JavaDoc name, String JavaDoc suffix, VisitorAttributes attributes)
67    {
68       if (name == null && suffix == null)
69          throw new IllegalArgumentException JavaDoc("Null name and suffix");
70       this.name = name;
71       this.suffix = suffix;
72       if (attributes == null)
73          attributes = VisitorAttributes.LEAVES_ONLY;
74       this.attributes = attributes;
75    }
76    
77    public VisitorAttributes getAttributes()
78    {
79       return attributes;
80    }
81
82    public boolean accepts(VirtualFile file)
83    {
84       String JavaDoc fileName = file.getName();
85       if (name != null && fileName.equals(name))
86          return true;
87       if (suffix != null)
88          return fileName.endsWith(suffix);
89       return false;
90    }
91 }
92
Popular Tags