1 //
2 // Copyright (c) 2006, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 15 Sep 05 Brian Frank Creation
7 // 29 Aug 06 Brian Frank Ported from Java to Fan
8 //
9
10 **
11 ** FPodNamespace implements Namespace by reading the fcode
12 ** from pods directly. Its not as efficient as using reflection,
13 ** but lets us compile against a different pod set.
14 **
15 class FPodNamespace : Namespace
16 {
17
18 //////////////////////////////////////////////////////////////////////////
19 // Construction
20 //////////////////////////////////////////////////////////////////////////
21
22 **
23 ** Make a FPod namespace which looks in the
24 ** specified directory to resolve pod files.
25 **
26 new make(File dir)
27 {
28 this.dir = dir
29 init
30 }
31
32 //////////////////////////////////////////////////////////////////////////
33 // Namespace
34 //////////////////////////////////////////////////////////////////////////
35
36 **
37 ** Map to an FPod
38 **
39 override FPod resolvePod(Str podName, Bool checked)
40 {
41 if (pods == null) pods = Str:FPod[:]
42
43 // check cache
44 fpod := pods[podName]
45 if (fpod != null) return fpod
46
47 // try to find it
48 file := dir + (podName + ".pod").toUri
49 if (!file.exists)
50 {
51 if (checked) throw UnknownPodErr.make(podName)
52 return null
53 }
54
55 // load it and stash in the cache
56 fpod = FPod.make(this, podName, Zip.open(file))
57 fpod.read
58 pods[podName] = fpod
59 return fpod
60 }
61
62 //////////////////////////////////////////////////////////////////////////
63 // Fields
64 //////////////////////////////////////////////////////////////////////////
65
66 readonly File dir // where we look for pod files
67 private Str:FPod pods // keyed by pod name
68
69 }
2 // Copyright (c) 2006, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 15 Sep 05 Brian Frank Creation
7 // 29 Aug 06 Brian Frank Ported from Java to Fan
8 //
9
10 **
11 ** FPodNamespace implements Namespace by reading the fcode
12 ** from pods directly. Its not as efficient as using reflection,
13 ** but lets us compile against a different pod set.
14 **
15 class FPodNamespace : Namespace
16 {
17
18 //////////////////////////////////////////////////////////////////////////
19 // Construction
20 //////////////////////////////////////////////////////////////////////////
21
22 **
23 ** Make a FPod namespace which looks in the
24 ** specified directory to resolve pod files.
25 **
26 new make(File dir)
27 {
28 this.dir = dir
29 init
30 }
31
32 //////////////////////////////////////////////////////////////////////////
33 // Namespace
34 //////////////////////////////////////////////////////////////////////////
35
36 **
37 ** Map to an FPod
38 **
39 override FPod resolvePod(Str podName, Bool checked)
40 {
41 if (pods == null) pods = Str:FPod[:]
42
43 // check cache
44 fpod := pods[podName]
45 if (fpod != null) return fpod
46
47 // try to find it
48 file := dir + (podName + ".pod").toUri
49 if (!file.exists)
50 {
51 if (checked) throw UnknownPodErr.make(podName)
52 return null
53 }
54
55 // load it and stash in the cache
56 fpod = FPod.make(this, podName, Zip.open(file))
57 fpod.read
58 pods[podName] = fpod
59 return fpod
60 }
61
62 //////////////////////////////////////////////////////////////////////////
63 // Fields
64 //////////////////////////////////////////////////////////////////////////
65
66 readonly File dir // where we look for pod files
67 private Str:FPod pods // keyed by pod name
68
69 }