1 package fr.in2p3.jsaga.adaptor.data;
2
3 import fr.in2p3.jsaga.adaptor.data.permission.PermissionBytes;
4 import fr.in2p3.jsaga.adaptor.data.read.FileAttributes;
5 import org.ogf.saga.error.NoSuccessException;
6 import org.ogf.srm22.*;
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public class SRM22FileAttributes extends FileAttributes {
21 private TMetaDataPathDetail m_entry;
22
23 public SRM22FileAttributes(TMetaDataPathDetail entry) throws NoSuccessException {
24 m_entry = entry;
25 }
26
27 public String getName() {
28 String path = m_entry.getPath();
29 int pos = path.lastIndexOf("/");
30 if (pos > 0) {
31 return path.substring(pos+1);
32 } else {
33 throw new RuntimeException("unexpected exception");
34 }
35 }
36
37 public int getType() {
38 TFileType type = m_entry.getType();
39 if (TFileType.FILE.equals(type)) {
40 return TYPE_FILE;
41 } else if (TFileType.DIRECTORY.equals(type)) {
42 return TYPE_DIRECTORY;
43 } else if (TFileType.LINK.equals(type)) {
44 return TYPE_LINK;
45 } else {
46 return TYPE_UNKNOWN;
47 }
48 }
49
50 public long getSize() {
51 if (m_entry.getSize() != null) {
52 return m_entry.getSize().longValue();
53 } else {
54 return SIZE_UNKNOWN;
55 }
56 }
57
58 public PermissionBytes getUserPermission() {
59 if (m_entry.getOwnerPermission() != null) {
60 return getPermission(m_entry.getOwnerPermission().getMode());
61 } else {
62 return PERMISSION_UNKNOWN;
63 }
64 }
65
66 public PermissionBytes getGroupPermission() {
67 if (m_entry.getGroupPermission() != null) {
68 return getPermission(m_entry.getGroupPermission().getMode());
69 } else {
70 return PERMISSION_UNKNOWN;
71 }
72 }
73
74 public PermissionBytes getAnyPermission() {
75 if (m_entry.getOtherPermission() != null) {
76 return getPermission(m_entry.getOtherPermission());
77 } else {
78 return PERMISSION_UNKNOWN;
79 }
80 }
81
82 private static PermissionBytes getPermission(TPermissionMode perm) {
83 if (TPermissionMode.NONE.equals(perm)) {
84 return PermissionBytes.NONE;
85 } else if (TPermissionMode.X.equals(perm)) {
86 return PermissionBytes.EXEC;
87 } else if (TPermissionMode.W.equals(perm)) {
88 return PermissionBytes.WRITE;
89 } else if (TPermissionMode.R.equals(perm)) {
90 return PermissionBytes.READ;
91 } else if (TPermissionMode.WX.equals(perm)) {
92 return PermissionBytes.WRITE.or(PermissionBytes.EXEC);
93 } else if (TPermissionMode.RX.equals(perm)) {
94 return PermissionBytes.READ.or(PermissionBytes.EXEC);
95 } else if (TPermissionMode.RW.equals(perm)) {
96 return PermissionBytes.READ.or(PermissionBytes.WRITE);
97 } else if (TPermissionMode.RWX.equals(perm)) {
98 return PermissionBytes.READ.or(PermissionBytes.WRITE).or(PermissionBytes.EXEC);
99 } else {
100 return PERMISSION_UNKNOWN;
101 }
102 }
103
104 public String getOwner() {
105 if (m_entry.getOwnerPermission() != null) {
106 return m_entry.getOwnerPermission().getUserID();
107 } else {
108 return ID_UNKNOWN;
109 }
110 }
111
112 public String getGroup() {
113 if (m_entry.getGroupPermission() != null) {
114 return m_entry.getGroupPermission().getGroupID();
115 } else {
116 return ID_UNKNOWN;
117 }
118 }
119
120 public long getLastModified() {
121 if (m_entry.getLastModificationTime() != null) {
122 return m_entry.getLastModificationTime().getTimeInMillis();
123 } else {
124 return DATE_UNKNOWN;
125 }
126 }
127 }