View Javadoc
1   package org.codehaus.plexus.components.io.attributes;
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 javax.annotation.Nullable;
20  
21  /*
22   * A very simple pojo based PlexusIoResourceAttributes without any kind of backing
23   */
24  public class SimpleResourceAttributes
25      implements PlexusIoResourceAttributes
26  {
27  
28      private Integer gid;
29  
30      private Integer uid;
31  
32      private String userName;
33  
34      private String groupName;
35  
36      private int mode = PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE;
37  
38      private boolean isSymbolicLink;
39  
40      public SimpleResourceAttributes( Integer uid, String userName, Integer gid, String groupName, int mode )
41      {
42          this.uid = uid;
43          this.userName = userName;
44          this.gid = gid;
45          this.groupName = groupName;
46          this.mode = mode;
47      }
48  
49      public static PlexusIoResourceAttributes lastResortDummyAttributesForBrokenOS()
50      {
51          return new SimpleResourceAttributes();
52      }
53  
54      SimpleResourceAttributes()
55      {
56      }
57  
58      public int getOctalMode()
59      {
60          return mode;
61      }
62  
63      @Nullable public Integer getGroupId()
64      {
65          return gid;
66      }
67  
68      @Nullable public String getGroupName()
69      {
70          return groupName;
71      }
72  
73  
74      public Integer getUserId()
75      {
76          return uid;
77      }
78  
79      public String getUserName()
80      {
81          return userName;
82      }
83  
84      public boolean isGroupExecutable()
85      {
86          return PlexusIoResourceAttributeUtils.isGroupExecutableInOctal( mode );
87      }
88  
89      public boolean isGroupReadable()
90      {
91          return PlexusIoResourceAttributeUtils.isGroupReadableInOctal( mode );
92      }
93  
94      public boolean isGroupWritable()
95      {
96          return PlexusIoResourceAttributeUtils.isGroupWritableInOctal( mode );
97      }
98  
99      public boolean isOwnerExecutable()
100     {
101         return PlexusIoResourceAttributeUtils.isOwnerExecutableInOctal( mode );
102     }
103 
104     public boolean isOwnerReadable()
105     {
106         return PlexusIoResourceAttributeUtils.isOwnerReadableInOctal( mode );
107     }
108 
109     public boolean isOwnerWritable()
110     {
111         return PlexusIoResourceAttributeUtils.isOwnerWritableInOctal( mode );
112     }
113 
114     public boolean isWorldExecutable()
115     {
116         return PlexusIoResourceAttributeUtils.isWorldExecutableInOctal( mode );
117     }
118 
119     public boolean isWorldReadable()
120     {
121         return PlexusIoResourceAttributeUtils.isWorldReadableInOctal( mode );
122     }
123 
124     public boolean isWorldWritable()
125     {
126         return PlexusIoResourceAttributeUtils.isWorldWritableInOctal( mode );
127     }
128 
129     public String getOctalModeString()
130     {
131         return Integer.toString( mode, 8 );
132     }
133 
134     public PlexusIoResourceAttributes setOctalMode( int mode )
135     {
136         this.mode = mode;
137         return this;
138     }
139 
140     public PlexusIoResourceAttributes setGroupId( Integer gid )
141     {
142         this.gid = gid;
143         return this;
144     }
145 
146     public PlexusIoResourceAttributes setGroupName( String name )
147     {
148         this.groupName = name;
149         return this;
150     }
151 
152     public PlexusIoResourceAttributes setUserId( Integer uid )
153     {
154         this.uid = uid;
155         return this;
156     }
157 
158     public PlexusIoResourceAttributes setUserName( String name )
159     {
160         this.userName = name;
161         return this;
162     }
163 
164     public PlexusIoResourceAttributes setOctalModeString( String mode )
165     {
166         setOctalMode( Integer.parseInt( mode, 8 ) );
167         return this;
168     }
169 
170     public String toString()
171     {
172         return String.format(
173             "%nResource Attributes:%n------------------------------%nuser: %s%ngroup: %s%nuid: %d%ngid: %d%nmode: %06o",
174             userName == null ? "" : userName,
175             groupName == null ? "" : groupName,
176             uid != null ? uid : 0,
177             gid != null ? gid : 0,
178             mode );
179     }
180 
181 
182     public void setSymbolicLink( boolean isSymbolicLink )
183     {
184         this.isSymbolicLink = isSymbolicLink;
185     }
186 
187     public boolean isSymbolicLink()
188     {
189         return isSymbolicLink;
190     }
191 }