Map is a hashm_map of key value pairs.
Inheritance: FanObj, Literal
Ejemplo n.º 1
0
 static Map read(Map defProps, Key key, List files)
 {
     if (files.isEmpty()) return defProps;
       Map acc = defProps.dup();
       for (int i=files.sz()-1; i>=0; --i)
       {
     InStream input = ((File)files.get(i)).@in();
     try { acc.setAll(input.readProps()); }
     finally { input.close(); }
       }
       return (Map)acc.toImmutable();
 }
Ejemplo n.º 2
0
Archivo: Zip.cs Proyecto: nomit007/f4
 public static Map contents(ZipFile zipFile)
 {
     Map c = new Map(Sys.UriType, Sys.FileType);
       IEnumerator e = zipFile.GetEnumerator();
       while (e.MoveNext())
       {
     ZipEntry entry = (ZipEntry)e.Current;
     ZipEntryFile f = new ZipEntryFile(zipFile, entry);
     c.set(f.m_uri, f);
       }
       return c;
 }
Ejemplo n.º 3
0
 //////////////////////////////////////////////////////////////////////////
 // Construction
 //////////////////////////////////////////////////////////////////////////
 public BootEnv()
 {
     this.m_args    = initArgs();
       this.m_vars    = initVars();
       this.m_host    = initHost();
       this.m_user    = initUser();
       this.m_in      = new SysInStream(Console.OpenStandardInput());
       this.m_out     = new SysOutStream(Console.OpenStandardOutput());
       this.m_err     = new SysOutStream(Console.OpenStandardError());
       this.m_homeDir = new LocalFile(new DirectoryInfo(Sys.m_homeDir), true).normalize();
       this.m_tempDir = m_homeDir.plus(Uri.fromStr("temp/"), false);
 }
Ejemplo n.º 4
0
        private static void addProps(Hashtable index, Map props)
        {
            IDictionaryEnumerator en = props.pairsIterator();
              while (en.MoveNext())
              {
            string key = (string)en.Key;
            List val   = (List)en.Value;
            List master = (List)index[key];
            if (master == null)
              index[key] = val;
            else
              master.addAll(val);

              }
        }
Ejemplo n.º 5
0
        //////////////////////////////////////////////////////////////////////////
        // Public
        //////////////////////////////////////////////////////////////////////////
        public Type compile(File file, Map options)
        {
            // normalize the file path as our cache key
              file = file.normalize();

              // unless force=true, check the cache
              if (!getOption(options, m_strForce, false))
              {
            CachedScript c = getCache(file);

            // if cached, try to lookup type (it might have been GCed)
            if (c != null)
            {
              Type t1 = Type.find(c.typeName, false);
              if (t1 != null) return t1;
            }
              }

              // generate a unique pod name
              string podName = generatePodName(file);

              // compile the script
              Pod pod = compile(podName, file, options);

              // get the primary type
              List types = pod.types();
              Type t = null;
              for (int i=0; i<types.sz(); ++i)
              {
            t = (Type)types.get(i);
            if (t.isPublic()) break;
              }
              if (t == null)
            throw Err.make("Script file defines no public classes: " +  file).val;

              // put it into the cache
              putCache(file, t);

              return t;
        }
Ejemplo n.º 6
0
Archivo: Map.cs Proyecto: nomit007/f4
        private void modify()
        {
            // if readonly then throw readonly exception
              if (m_isReadonly)
            throw ReadonlyErr.make("Map is readonly").val;

              // if we have a cached m_readonlyMap, then detach
              // it so it remains m_immutable
              if (m_readonlyMap != null)
              {
            m_readonlyMap.m_map = cloneMap(m_map);
            m_readonlyMap = null;
              }
        }
Ejemplo n.º 7
0
Archivo: Map.cs Proyecto: nomit007/f4
 public Map setAll(Map m)
 {
     modify();
       IDictionaryEnumerator en = m.m_map.GetEnumerator();
       while (en.MoveNext())
       {
     object key = en.Key;
     object val = en.Value;
     m_map[key] = val;
       }
       return this;
 }
Ejemplo n.º 8
0
Archivo: Map.cs Proyecto: nomit007/f4
 public Map ro()
 {
     if (m_isReadonly) return this;
       if (m_readonlyMap == null)
       {
     Map ro = new Map(m_type);
     ro.m_map = m_map;
     ro.m_isReadonly  = true;
     ro.m_caseInsensitive = m_caseInsensitive;
     ro.m_def = m_def;
     m_readonlyMap = ro;
       }
       return m_readonlyMap;
 }
Ejemplo n.º 9
0
Archivo: Map.cs Proyecto: nomit007/f4
 public Map findAll(Func f)
 {
     Map acc = new Map(m_type);
       if (this.ordered()) acc.ordered(true);
       if (this.caseInsensitive()) acc.caseInsensitive(true);
       IDictionaryEnumerator en = m_map.GetEnumerator();
       while (en.MoveNext())
       {
     object key = en.Key;
     object val = en.Value;
     if (f.call(val, key) == Boolean.True)
       acc.set(key, val);
       }
       return acc;
 }
Ejemplo n.º 10
0
Archivo: Map.cs Proyecto: nomit007/f4
 public Map addAll(Map m)
 {
     modify();
       IDictionaryEnumerator en = m.m_map.GetEnumerator();
       while (en.MoveNext())
       {
     object key = en.Key;
     object val = en.Value;
     add(key, val);
       }
       return this;
 }
Ejemplo n.º 11
0
Archivo: Uri.cs Proyecto: xored/f4
        public static string encodeQuery(Map map)
        {
            StringBuilder buf = new StringBuilder(256);

              IEnumerator en = map.keysEnumerator();
              while (en.MoveNext())
              {
            string key = (string)en.Current;
            string val = (string)map.get(key);
            if (buf.Length > 0) buf.Append('&');
            encodeQueryStr(buf, key);
            if (val != null)
            {
              buf.Append('=');
              encodeQueryStr(buf, val);
            }
              }
              return buf.ToString();
        }
Ejemplo n.º 12
0
Archivo: Uri.cs Proyecto: xored/f4
 private void normalizeQuery()
 {
     if (query == null)
       query = emptyQuery();
 }
Ejemplo n.º 13
0
Archivo: Uri.cs Proyecto: xored/f4
 internal void setQuery(Uri x)
 {
     queryStr = x.m_queryStr; query = x.m_query;
 }
Ejemplo n.º 14
0
Archivo: Uri.cs Proyecto: xored/f4
 //////////////////////////////////////////////////////////////////////////
 // Java Constructors
 //////////////////////////////////////////////////////////////////////////
 private Uri(Sections x)
 {
     m_scheme   = x.scheme;
       m_userInfo = x.userInfo;
       m_host     = x.host;
       m_port     = x.port;
       m_pathStr  = x.pathStr;
       m_path     = x.path.ro();
       m_queryStr = x.queryStr;
       m_query    = x.query.ro();
       m_frag     = x.frag;
       m_str      = x.str != null ? x.str : new Encoder(this, false).encode();
 }
Ejemplo n.º 15
0
Archivo: Uri.cs Proyecto: xored/f4
            private Map parseQuery(string q)
            {
                if (q == null) return null;
                Map map = new Map(Sys.StrType, Sys.StrType);

                try
                {
                  int start = 0, eq = 0, len = q.Length, prev = 0;
                  bool escaped = false;
                  for (int i=0; i<len; ++i)
                  {
                int ch = q[i];
                if (prev != '\\')
                {
                  if (ch == '=') eq = i;
                  if (ch != '&' && ch != ';') { prev = ch; continue; }
                }
                else
                {
                  escaped = true;
                  prev = (ch != '\\') ? ch : 0;
                  continue;
                }

                if (start < i)
                {
                  addQueryParam(map, q, start, eq, i, escaped);
                  escaped = false;
                }

                start = eq = i+1;
                  }

                  if (start < len)
                addQueryParam(map, q, start, eq, len, escaped);
                }
                catch (Exception e)
                {
                  // don't let internal error bring down whole uri
                  Err.dumpStack(e);
                }

                return map;
            }
Ejemplo n.º 16
0
Archivo: Uri.cs Proyecto: xored/f4
            private void addQueryParam(Map map, string q, int start, int eq, int end, bool escaped)
            {
                string key, val;
                if (start == eq && q[start] != '=')
                {
                  key = toQueryStr(q, start, end, escaped);
                  val = "true";
                }
                else
                {
                  key = toQueryStr(q, start, eq, escaped);
                  val = toQueryStr(q, eq+1, end, escaped);
                }

                string dup = (string)map.get(key);
                if (dup != null) val = dup + "," + val;
                map.set(key, val);
            }
Ejemplo n.º 17
0
 //////////////////////////////////////////////////////////////////////////
 // Diagnostics
 //////////////////////////////////////////////////////////////////////////
 public override Map diagnostics()
 {
     // TODO: return empty map for now
       Map d = new Map(Sys.StrType, Sys.ObjType);
       return d;
 }
Ejemplo n.º 18
0
Archivo: Uri.cs Proyecto: xored/f4
        public Uri plusQuery(Map q)
        {
            if (q == null || q.isEmpty()) return this;

              Map merge = m_query.dup().setAll(q);

              StringBuilder s = new StringBuilder(256);
              IDictionaryEnumerator en = merge.pairsIterator();
              while (en.MoveNext())
              {
            if (s.Length > 0) s.Append('&');
            string key = (string)en.Key;
            string val = (string)en.Value;
            appendQueryStr(s, key);
            s.Append('=');
            appendQueryStr(s, val);
              }

              Sections t = new Sections();
              t.scheme   = m_scheme;
              t.userInfo = m_userInfo;
              t.host     = m_host;
              t.port     = m_port;
              t.frag     = m_frag;
              t.pathStr  = m_pathStr;
              t.path     = m_path;
              t.query    = merge.ro();
              t.queryStr = s.ToString();
              return new Uri(t);
        }
Ejemplo n.º 19
0
Archivo: Map.cs Proyecto: nomit007/f4
 public Map dup()
 {
     Map dup = new Map(m_type);
       dup.m_map = cloneMap(this.m_map);
       return dup;
 }
Ejemplo n.º 20
0
Archivo: Uri.cs Proyecto: xored/f4
 static Map emptyQuery()
 {
     Map q = m_emptyQuery;
       if (q == null) q = m_emptyQuery = (Map)new Map(Sys.StrType, Sys.StrType).toImmutable();
       return q;
 }
Ejemplo n.º 21
0
Archivo: Map.cs Proyecto: nomit007/f4
 public Map map(Func f)
 {
     Type r = f.returns();
       if (r == Sys.VoidType) r = Sys.ObjType.toNullable();
       Map acc = new Map(m_type.m_k, r);
       if (this.ordered()) acc.ordered(true);
       if (this.caseInsensitive()) acc.caseInsensitive(true);
       IDictionaryEnumerator en = m_map.GetEnumerator();
       while (en.MoveNext())
       {
     object key = en.Key;
     object val = en.Value;
     acc.set(key, f.call(val, key));
       }
       return acc;
 }
Ejemplo n.º 22
0
 public override Map @params()
 {
     if (m_params == null) m_params = makeParams();
       return m_params;
 }
Ejemplo n.º 23
0
Archivo: Map.cs Proyecto: nomit007/f4
        public Map rw()
        {
            if (!m_isReadonly) return this;

              Map rw = new Map(m_type);
              rw.m_map = cloneMap(m_map);
              rw.m_isReadonly = false;
              rw.m_readonlyMap = this;
              rw.m_caseInsensitive = m_caseInsensitive;
              rw.m_def = m_def;
              return rw;
        }
Ejemplo n.º 24
0
Archivo: Buf.cs Proyecto: nomit007/f4
 public object readObj(Map opt)
 {
     return m_in.readObj(opt);
 }
Ejemplo n.º 25
0
Archivo: Map.cs Proyecto: nomit007/f4
        public override object toImmutable()
        {
            if (m_immutable) return this;

              // make safe copy
              IDictionary temp;
              if (caseInsensitive()) temp = new Hashtable(new CIEqualityComparer());
              else if (ordered()) temp = new OrderedDictionary();
              else temp = new Hashtable();

              IDictionaryEnumerator en = m_map.GetEnumerator();
              while (en.MoveNext())
              {
            object key = en.Key;
            object val = en.Value;

            if (val != null)
            {
              if (val is List)
            val = ((List)val).toImmutable();
              else if (val is Map)
            val = ((Map)val).toImmutable();
              else if (!isImmutable(val))
            throw NotImmutableErr.make("Item [" + key + "] not immutable " + @typeof(val)).val;
            }

            temp[key] = val;
              }

              // return new m_immutable m_map
              Map ro = new Map(m_type, temp);
              ro.m_isReadonly = true;
              ro.m_immutable = true;
              ro.m_caseInsensitive = m_caseInsensitive;
              ro.m_def = m_def;
              return ro;
        }
Ejemplo n.º 26
0
Archivo: Buf.cs Proyecto: nomit007/f4
 public Buf writeObj(object obj, Map opt)
 {
     m_out.writeObj(obj, opt); return this;
 }
Ejemplo n.º 27
0
 //////////////////////////////////////////////////////////////////////////
 // Option Utils
 //////////////////////////////////////////////////////////////////////////
 bool getOption(Map options, string key, bool def)
 {
     if (options == null) return def;
       Boolean x = (Boolean)options.get(key);
       if (x == null) return def;
       return x.booleanValue();
 }
Ejemplo n.º 28
0
Archivo: Buf.cs Proyecto: nomit007/f4
 public Buf writeProps(Map props)
 {
     m_out.writeProps(props); return this;
 }
Ejemplo n.º 29
0
 private Pod compile(string podName, File f, Map options)
 {
     // use Fantom reflection to run compiler::Main.compileScript(File)
       Method m = Slot.findMethod("compiler::Main.compileScript", true);
       return (Pod)m.call(podName, f, options);
 }
Ejemplo n.º 30
0
        private static Map initVars()
        {
            Map vars = new Map(Sys.StrType, Sys.StrType);
              try
              {
            vars.caseInsensitive(true);

            // predefined
            vars.set("os.name", Environment.OSVersion.Platform.ToString());
            vars.set("os.version", Environment.OSVersion.Version.ToString());

            // environment variables
            IDictionary getenv = Environment.GetEnvironmentVariables();
            foreach (DictionaryEntry de in getenv)
            {
              string key = (string)de.Key;
              string val = (string)de.Value;
              vars.set(key, val);
            }
              }
              catch (Exception e)
              {
            Err.dumpStack(e);
              }
              return (Map)vars.toImmutable();
        }