View Javadoc
1   package org.codehaus.plexus.components.io.resources;
2   
3   /*
4    * Copyright 2007 The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils;
20  import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
21  
22  /**
23   * Default implementation of a resource collection with attributes.
24   */
25  public abstract class AbstractPlexusIoResourceCollectionWithAttributes
26      extends AbstractPlexusIoResourceCollection
27  {
28  
29      private PlexusIoResourceAttributes defaultFileAttributes;
30  
31      private PlexusIoResourceAttributes defaultDirAttributes;
32  
33      private PlexusIoResourceAttributes overrideFileAttributes;
34  
35      private PlexusIoResourceAttributes overrideDirAttributes;
36  
37      protected AbstractPlexusIoResourceCollectionWithAttributes()
38      {
39      }
40  
41      protected PlexusIoResourceAttributes getDefaultFileAttributes()
42      {
43          return defaultFileAttributes;
44      }
45  
46      protected void setDefaultFileAttributes( final PlexusIoResourceAttributes defaultFileAttributes )
47      {
48          this.defaultFileAttributes = defaultFileAttributes;
49      }
50  
51      protected PlexusIoResourceAttributes getDefaultDirAttributes()
52      {
53          return defaultDirAttributes;
54      }
55  
56      protected void setDefaultDirAttributes( final PlexusIoResourceAttributes defaultDirAttributes )
57      {
58          this.defaultDirAttributes = defaultDirAttributes;
59      }
60  
61      protected PlexusIoResourceAttributes getOverrideFileAttributes()
62      {
63          return overrideFileAttributes;
64      }
65  
66      protected void setOverrideFileAttributes( final PlexusIoResourceAttributes overrideFileAttributes )
67      {
68          this.overrideFileAttributes = overrideFileAttributes;
69      }
70  
71      protected PlexusIoResourceAttributes getOverrideDirAttributes()
72      {
73          return overrideDirAttributes;
74      }
75  
76      protected void setOverrideDirAttributes( final PlexusIoResourceAttributes overrideDirAttributes )
77      {
78          this.overrideDirAttributes = overrideDirAttributes;
79      }
80  
81      protected PlexusIoResourceAttributes mergeAttributes( PlexusIoResourceAttributes currentAttrs, boolean isDirectory )
82      {
83          if ( isDirectory )
84          {
85              currentAttrs = PlexusIoResourceAttributeUtils.mergeAttributes( getOverrideDirAttributes(), currentAttrs,
86                                                                             getDefaultDirAttributes() );
87          }
88          else
89          {
90              currentAttrs = PlexusIoResourceAttributeUtils.mergeAttributes( getOverrideFileAttributes(), currentAttrs,
91                                                                             getDefaultFileAttributes() );
92          }
93          return currentAttrs;
94      }
95  }