
1 // 2 // Copyright (c) 2007, Brian Frank and Andy Frank 3 // Licensed under the Academic Free License version 3.0 4 // 5 // History: 6 // 24 Nov 07 Brian Frank Creation 7 // 8 9 ** 10 ** Resource models an object in the Uri namespace. Resources 11 ** can be both containers for other resources and a container 12 ** for a Fan object. 13 ** 14 abstract class Resource 15 { 16 17 ////////////////////////////////////////////////////////////////////////// 18 // Constructor 19 ////////////////////////////////////////////////////////////////////////// 20 21 ** 22 ** Constructor for the specified Uri. 23 ** Throw ArgErr if uri is null. 24 ** 25 protected new make(Uri uri) 26 27 ////////////////////////////////////////////////////////////////////////// 28 // Naming 29 ////////////////////////////////////////////////////////////////////////// 30 31 ** 32 ** Return if this resource exists in the namespace. 33 ** 34 Bool exists() 35 36 ** 37 ** Return the Uri of this resource which identifies 38 ** its within the local VM namespace. 39 ** 40 Uri uri() 41 42 ** 43 ** Convenience for [uri.isDir]`Uri.isDir` 44 ** 45 Bool isDir() 46 47 ** 48 ** Convenience for [uri.path]`Uri.path`. 49 ** 50 Str[] path() 51 52 ** 53 ** Convenience for [uri.pathStr]`Uri.pathStr`. 54 ** 55 Str pathStr() 56 57 ** 58 ** Convenience for [uri.name]`Uri.name`. 59 ** 60 Str name() 61 62 ** 63 ** Convenience for [uri.basename]`Uri.basename`. 64 ** 65 Str basename() 66 67 ** 68 ** Convenience for [uri.ext]`Uri.ext`. 69 ** 70 Str ext() 71 72 ////////////////////////////////////////////////////////////////////////// 73 // Contents 74 ////////////////////////////////////////////////////////////////////////// 75 76 ** 77 ** Get or set this resource's contents as a Fan object. 78 ** This object is always a thread-safe copy of the object. 79 ** Use the `save` method to save this object as the 80 ** actual resource. 81 ** 82 virtual Obj obj 83 84 ////////////////////////////////////////////////////////////////////////// 85 // Children 86 ////////////////////////////////////////////////////////////////////////// 87 88 ** 89 ** List the children resources contained by this resource. 90 ** If this resource doesn't contain children, then return 91 ** an empty list. Note this can potentially be an expensive 92 ** operation. The default implementation returns an empty 93 ** list. 94 ** 95 virtual Resource[] list() 96 97 ** 98 ** Refresh this resource to reflect the current state of 99 ** the contents. This method will typically overwrite the 100 ** value of the `obj` field. The default implementation 101 ** throws UnsupportedErr. 102 ** 103 virtual Void refresh() 104 105 ** 106 ** Create this resource under the namespace. If there is a 107 ** uri conflict, type conflict, or the resource is already 108 ** mounted then throw an Err. Return this. The default 109 ** implementation throws UnsupportedErr. 110 ** 111 virtual Resource create() 112 113 ** 114 ** Create a child resource under this parent resource 115 ** which wraps the specified object. Return the newly 116 ** created resource. 117 ** 118 virtual Resource add(Obj obj) 119 120 ** 121 ** Save the thread-safe copy of `obj` back to the namespace. 122 ** If between the last read and the update, another thread 123 ** or application has modified the object then throw an Err. 124 ** The default implementation throws UnsupportedErr. 125 ** 126 ** TODO: throw VersionErr, might be a type likely to be caught 127 ** 128 virtual Void save() 129 130 ** 131 ** Delete this resource from the namespace. If this resource 132 ** contains a child tree of resources, then recursively delete 133 ** the entire tree. The default implementation throws 134 ** UnsupportedErr. 135 ** 136 virtual Void delete() 137 138 ** 139 ** Resolve the Uri to its target as a thread safe working 140 ** instance of the resource. Return null if it can't be 141 ** resolved. The depth indicates the current path depth to 142 ** be resolved. The default implementation returns null. 143 ** 144 virtual Resource resolve(Uri uri, Int startDepth) 145 146 } 147 148 ************************************************************************** 149 ** RootResource 150 ************************************************************************** 151 152 internal class RootResource : Resource 153 { 154 internal new make(Uri uri) 155 } 156 157 ************************************************************************** 158 ** SysResource 159 ************************************************************************** 160 161 internal class SysResource : Resource 162 { 163 }