public int moreSpecific(Twonk other) { if (other.vec.Length != vec.Length) return - 1; bool low = false; bool high = false; for(int i = 0; i < vec.Length; i++) { if (vec[i] > other.vec[i]) { high = true; } else if (vec[i] < other.vec[i]) { low = true; } } /* * this is a 'crossing' - meaning that * we saw the parameter 'slopes' cross * this means ambiguity */ if (high && low) return 0; /* * we saw that all args were 'high', meaning * that the other method is more specific so * we are less */ if (high && !low) return - 1; /* * we saw that all points were lower, therefore * we are more specific */ if (!high && low) return 1; /* * the remainder, neither high or low * means we are the same. This really can't * happen, as it implies the same args, right? */ return 1; }
public int moreSpecific(Twonk other) { if (other.vec.Length != vec.Length) { return(-1); } bool low = false; bool high = false; for (int i = 0; i < vec.Length; i++) { if (vec[i] > other.vec[i]) { high = true; } else if (vec[i] < other.vec[i]) { low = true; } } /* * this is a 'crossing' - meaning that * we saw the parameter 'slopes' cross * this means ambiguity */ if (high && low) { return(0); } /* * we saw that all args were 'high', meaning * that the other method is more specific so * we are less */ if (high && !low) { return(-1); } /* * we saw that all points were lower, therefore * we are more specific */ if (!high && low) { return(1); } /* * the remainder, neither high or low * means we are the same. This really can't * happen, as it implies the same args, right? */ return(1); }
/// <summary> actual factory : creates a Directive that will /// behave correctly wrt getting the framework to /// dig out the correct # of args /// </summary> public Directive.Directive GetVelocimacro(String vmName, String sourceTemplate) { VelocimacroProxy velocimacroProxy = null; lock (this) { /* * don't ask - do */ velocimacroProxy = velocimacroManager.get(vmName, sourceTemplate); /* * if this exists, and autoload is on, we need to check * where this VM came from */ if (velocimacroProxy != null && Autoload) { /* * see if this VM came from a library. Need to pass sourceTemplate * in the event namespaces are set, as it could be masked by local */ String lib = velocimacroManager.GetLibraryName(vmName, sourceTemplate); if (lib != null) { try { /* * get the template from our map */ Twonk twonk = (Twonk)libModMap[lib]; if (twonk != null) { Template template = twonk.template; /* * now, compare the last modified time of the resource * with the last modified time of the template * if the file has changed, then reload. Otherwise, we should * be ok. */ long tt = twonk.modificationTime; long ft = template.ResourceLoader.GetLastModified(template) ; if (ft > tt) { LogVMMessageInfo(string.Format("Velocimacro : autoload reload for VMs from VM library template : {0}", lib)); /* * when there are VMs in a library that invoke each other, * there are calls into getVelocimacro() from the init() * process of the VM directive. To stop the infinite loop * we save the current time reported by the resource loader * and then be honest when the reload is complete */ twonk.modificationTime = ft; template = runtimeServices.GetTemplate(lib) ; /* * and now we be honest */ twonk.template = template; twonk.modificationTime = template.LastModified; /* * note that we don't need to put this twonk back * into the map, as we can just use the same reference * and this block is synchronized */ } } } catch (System.Exception e) { LogVMMessageInfo(string.Format("Velocimacro : error using VM library template {0} : {1}", lib, e)); } /* * and get again */ velocimacroProxy = velocimacroManager.get(vmName, sourceTemplate); } } } return(velocimacroProxy); }
/// <summary> initialize the factory - setup all permissions /// load all global libraries. /// </summary> public void InitVelocimacro() { /* * maybe I'm just paranoid... */ lock (this) { /* * allow replacements while we add the libraries, if exist */ ReplacementPermission = true; Blather = true; LogVMMessageInfo("Velocimacro : initialization starting."); /* * add all library macros to the global namespace */ velocimacroManager.NamespaceUsage = false; /* * now, if there is a global or local libraries specified, use them. * All we have to do is get the template. The template will be parsed; * VM's are added during the parse phase */ Object libraryFiles = runtimeServices.GetProperty(RuntimeConstants.VM_LIBRARY); if (libraryFiles != null) { if (libraryFiles is ArrayList) { macroLibVec = (ArrayList)libraryFiles; } else if (libraryFiles is String) { macroLibVec = new ArrayList(); macroLibVec.Add(libraryFiles); } for (int i = 0; i < macroLibVec.Count; i++) { String lib = (String)macroLibVec[i]; /* * only if it's a non-empty string do we bother */ if (lib != null && !lib.Equals(string.Empty)) { /* * let the VMManager know that the following is coming * from libraries - need to know for auto-load */ velocimacroManager.RegisterFromLib = true; LogVMMessageInfo(string.Format("Velocimacro : adding VMs from VM library template : {0}", lib)); try { Template template = runtimeServices.GetTemplate(lib); /* * save the template. This depends on the assumption * that the Template object won't change - currently * this is how the Resource manager works */ Twonk twonk = new Twonk(this); twonk.template = template; twonk.modificationTime = template.LastModified; libModMap[lib] = twonk; } catch (System.Exception e) { LogVMMessageInfo(string.Format("Velocimacro : error using VM library template {0} : {1}", lib, e)); } LogVMMessageInfo("Velocimacro : VM library template macro registration complete."); velocimacroManager.RegisterFromLib = false; } } } /* * now, the permissions */ /* * allowinline : anything after this will be an inline macro, I think * there is the question if a #include is an inline, and I think so * * default = true */ AddMacroPermission = true; if (!runtimeServices.GetBoolean(RuntimeConstants.VM_PERM_ALLOW_INLINE, true)) { AddMacroPermission = false; LogVMMessageInfo("Velocimacro : allowInline = false : VMs can not be defined inline in templates"); } else { LogVMMessageInfo("Velocimacro : allowInline = true : VMs can be defined inline in templates"); } /* * allowInlineToReplaceGlobal : allows an inline VM , if allowed at all, * to replace an existing global VM * * default = false */ ReplacementPermission = false; if (runtimeServices.GetBoolean(RuntimeConstants.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, false)) { ReplacementPermission = true; LogVMMessageInfo( "Velocimacro : allowInlineToOverride = true : VMs defined inline may replace previous VM definitions"); } else { LogVMMessageInfo( "Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions"); } /* * now turn on namespace handling as far as permissions allow in the * manager, and also set it here for gating purposes */ velocimacroManager.NamespaceUsage = true; /* * template-local inline VM mode : default is off */ TemplateLocalInline = runtimeServices.GetBoolean(RuntimeConstants.VM_PERM_INLINE_LOCAL, false); if (TemplateLocalInline) { LogVMMessageInfo( "Velocimacro : allowInlineLocal = true : VMs defined inline will be local to their defining template only."); } else { LogVMMessageInfo("Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed."); } velocimacroManager.TemplateLocalInlineVM = TemplateLocalInline; /* * general message switch. default is on */ Blather = runtimeServices.GetBoolean(RuntimeConstants.VM_MESSAGES_ON, true); if (Blather) { LogVMMessageInfo("Velocimacro : messages on : VM system will output logging messages"); } else { LogVMMessageInfo("Velocimacro : messages off : VM system will be quiet"); } /* * autoload VM libraries */ Autoload = runtimeServices.GetBoolean(RuntimeConstants.VM_LIBRARY_AUTORELOAD, false); if (Autoload) { LogVMMessageInfo("Velocimacro : autoload on : VM system will automatically reload global library macros"); } else { LogVMMessageInfo("Velocimacro : autoload off : VM system will not automatically reload global library macros"); } runtimeServices.Info("Velocimacro : initialization complete."); } return; }
/// <since> 1.6 /// </since> public virtual Directive.Directive GetVelocimacro(string vmName, string sourceTemplate, string renderingTemplate) { VelocimacroProxy vp = null; vp = vmManager.Get(vmName, sourceTemplate, renderingTemplate); /* * if this exists, and autoload is on, we need to check where this VM came from */ if (vp != null && autoReloadLibrary) { lock (this) { /* * see if this VM came from a library. Need to pass sourceTemplate in the event * namespaces are set, as it could be masked by local */ string lib = vmManager.GetLibraryName(vmName, sourceTemplate); if (lib != null) { try { /* * Get the template from our map */ if (libModMap.ContainsKey(lib)) { Twonk tw = libModMap[lib]; Template template = tw.template; /* * now, Compare the last modified time of the resource with the last * modified time of the template if the file has changed, then reload. * Otherwise, we should be ok. */ long tt = tw.modificationTime; long ft = template.ResourceLoader.GetLastModified(template); if (ft > tt) { log.Debug("auto-reloading VMs from VM library : " + lib); /* * when there are VMs in a library that invoke each other, there are * calls into getVelocimacro() from the Init() process of the VM * directive. To stop the infinite loop we save the current time * reported by the resource loader and then be honest when the * reload is complete */ tw.modificationTime = ft; template = rsvc.GetTemplate(lib); /* * and now we be honest */ tw.template = template; tw.modificationTime = template.LastModified; /* * note that we don't need to Put this twonk * back into the map, as we can just use the * same reference and this block is synchronized */ } } } catch (System.Exception e) { string msg = "Velocimacro : Error using VM library : " + lib; //Log.Error(true, msg, e); throw new VelocityException(msg, e); } vp = vmManager.Get(vmName, sourceTemplate, renderingTemplate); } } } return(vp); }
/// <summary> Initialize the factory - setup all permissions /// load all global libraries. /// </summary> public void InitVelocimacro() { /* * maybe I'm just paranoid... */ lock (this) { log.Trace("initialization starting."); /* * allow replacements while we Add the libraries, if exist */ SetReplacementPermission(true); /* * Add all library macros to the global namespace */ vmManager.NamespaceUsage = false; /* * now, if there is a global or local libraries specified, use them. * All we have to do is Get the template. The template will be parsed; * VM's are added during the parse phase */ object libfiles = rsvc.GetProperty(RuntimeConstants.VM_LIBRARY); if (libfiles == null) { log.Debug("\"" + RuntimeConstants.VM_LIBRARY + "\" is not set. Trying default library: " + NVelocity.Runtime.RuntimeConstants.VM_LIBRARY_DEFAULT); // try the default library. if (rsvc.GetLoaderNameForResource(RuntimeConstants.VM_LIBRARY_DEFAULT) != null) { libfiles = RuntimeConstants.VM_LIBRARY_DEFAULT; } else { log.Debug("Default library not found."); } } if (libfiles != null) { macroLibVec = new ArrayList(); if (libfiles is ArrayList) { var lbs = (ArrayList)libfiles; foreach (var lb in lbs) { macroLibVec.Add(lb); } } else if (libfiles is string) { macroLibVec.Add(libfiles); } for (int i = 0, is_Renamed = macroLibVec.Count; i < is_Renamed; i++) { string lib = (string)macroLibVec[i]; /* * only if it's a non-empty string do we bother */ if (!String.IsNullOrEmpty(lib)) { /* * let the VMManager know that the following is coming * from libraries - need to know for auto-load */ vmManager.RegisterFromLib = true; log.Debug("adding VMs from VM library : " + lib); try { Template template = rsvc.GetTemplate(lib); /* * save the template. This depends on the assumption * that the Template object won't change - currently * this is how the Resource manager works */ Twonk twonk = new Twonk(); twonk.template = template; twonk.modificationTime = template.LastModified; libModMap[lib] = twonk; } catch (System.Exception e) { string msg = "Velocimacro : Error using VM library : " + lib; log.Error(true, msg, e); } log.Trace("VM library registration complete."); vmManager.RegisterFromLib = false; } } } /* * now, the permissions */ /* * allowinline : anything after this will be an inline macro, I think * there is the question if a #include is an inline, and I think so * * default = true */ SetAddMacroPermission(true); if (!rsvc.GetBoolean(RuntimeConstants.VM_PERM_ALLOW_INLINE, true)) { SetAddMacroPermission(false); log.Debug("allowInline = false : VMs can NOT be defined inline in templates"); } else { log.Debug("allowInline = true : VMs can be defined inline in templates"); } /* * allowInlineToReplaceGlobal : allows an inline VM , if allowed at all, * to replace an existing global VM * * default = false */ SetReplacementPermission(false); if (rsvc.GetBoolean(RuntimeConstants.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, false)) { SetReplacementPermission(true); log.Debug("allowInlineToOverride = true : VMs " + "defined inline may replace previous VM definitions"); } else { log.Debug("allowInlineToOverride = false : VMs " + "defined inline may NOT replace previous VM definitions"); } /* * now turn on namespace handling as far as permissions allow in the * manager, and also set it here for gating purposes */ vmManager.NamespaceUsage = true; /* * template-local inline VM mode : default is off */ TemplateLocalInline = rsvc.GetBoolean(Runtime.RuntimeConstants.VM_PERM_INLINE_LOCAL, false); if (TemplateLocalInline) { log.Debug("allowInlineLocal = true : VMs " + "defined inline will be local to their defining template only."); } else { log.Debug("allowInlineLocal = false : VMs " + "defined inline will be global in scope if allowed."); } vmManager.TemplateLocalInlineVM = TemplateLocalInline; /* * autoload VM libraries */ Autoload = rsvc.GetBoolean(RuntimeConstants.VM_LIBRARY_AUTORELOAD, false); if (Autoload) { log.Debug("autoload on : VM system " + "will automatically reload global library macros"); } else { log.Debug("autoload off : VM system " + "will not automatically reload global library macros"); } log.Trace("Velocimacro : initialization complete."); } }
/// <summary> initialize the factory - setup all permissions /// load all global libraries. /// </summary> public virtual void initVelocimacro() { /* * maybe I'm just paranoid... */ lock(this) { /* * allow replacements while we add the libraries, if exist */ ReplacementPermission = true; Blather = true; logVMMessageInfo("Velocimacro : initialization starting."); /* * add all library macros to the global namespace */ vmManager.NamespaceUsage = false; /* * now, if there is a global or local libraries specified, use them. * All we have to do is get the template. The template will be parsed; * VM's are added during the parse phase */ System.Object libfiles = rsvc.getProperty(NVelocity.Runtime.RuntimeConstants_Fields.VM_LIBRARY); if (libfiles != null) { if (libfiles is System.Collections.ArrayList) { macroLibVec = (System.Collections.ArrayList) libfiles; } else if (libfiles is System.String) { macroLibVec = new System.Collections.ArrayList(); macroLibVec.Add(libfiles); } for (int i = 0; i < macroLibVec.Count; i++) { System.String lib = (System.String) macroLibVec[i]; /* * only if it's a non-empty string do we bother */ if (lib != null && !lib.Equals("")) { /* * let the VMManager know that the following is coming * from libraries - need to know for auto-load */ vmManager.RegisterFromLib = true; logVMMessageInfo("Velocimacro : adding VMs from " + "VM library template : " + lib); try { Template template = rsvc.getTemplate(lib); /* * save the template. This depends on the assumption * that the Template object won't change - currently * this is how the Resource manager works */ Twonk twonk = new Twonk(this); twonk.template = template; twonk.modificationTime = template.LastModified; libModMap[lib] = twonk; } catch (System.Exception e) { logVMMessageInfo("Velocimacro : error using VM " + "library template " + lib + " : " + e); } logVMMessageInfo("Velocimacro : VM library template " + "macro registration complete."); vmManager.RegisterFromLib = false; } } } /* * now, the permissions */ /* * allowinline : anything after this will be an inline macro, I think * there is the question if a #include is an inline, and I think so * * default = true */ AddMacroPermission = true; if (!rsvc.getBoolean(NVelocity.Runtime.RuntimeConstants_Fields.VM_PERM_ALLOW_INLINE, true)) { AddMacroPermission = false; logVMMessageInfo("Velocimacro : allowInline = false : VMs can not " + "be defined inline in templates"); } else { logVMMessageInfo("Velocimacro : allowInline = true : VMs can be " + "defined inline in templates"); } /* * allowInlineToReplaceGlobal : allows an inline VM , if allowed at all, * to replace an existing global VM * * default = false */ ReplacementPermission = false; if (rsvc.getBoolean(NVelocity.Runtime.RuntimeConstants_Fields.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, false)) { ReplacementPermission = true; logVMMessageInfo("Velocimacro : allowInlineToOverride = true : VMs " + "defined inline may replace previous VM definitions"); } else { logVMMessageInfo("Velocimacro : allowInlineToOverride = false : VMs " + "defined inline may NOT replace previous VM definitions"); } /* * now turn on namespace handling as far as permissions allow in the * manager, and also set it here for gating purposes */ vmManager.NamespaceUsage = true; /* * template-local inline VM mode : default is off */ TemplateLocalInline = rsvc.getBoolean(NVelocity.Runtime.RuntimeConstants_Fields.VM_PERM_INLINE_LOCAL, false); if (TemplateLocalInline) { logVMMessageInfo("Velocimacro : allowInlineLocal = true : VMs " + "defined inline will be local to their defining template only."); } else { logVMMessageInfo("Velocimacro : allowInlineLocal = false : VMs " + "defined inline will be global in scope if allowed."); } vmManager.TemplateLocalInlineVM = TemplateLocalInline; /* * general message switch. default is on */ Blather = rsvc.getBoolean(NVelocity.Runtime.RuntimeConstants_Fields.VM_MESSAGES_ON, true); if (Blather) { logVMMessageInfo("Velocimacro : messages on : VM system " + "will output logging messages"); } else { logVMMessageInfo("Velocimacro : messages off : VM system will be quiet"); } /* * autoload VM libraries */ Autoload = rsvc.getBoolean(NVelocity.Runtime.RuntimeConstants_Fields.VM_LIBRARY_AUTORELOAD, false); if (Autoload) { logVMMessageInfo("Velocimacro : autoload on : VM system " + "will automatically reload global library macros"); } else { logVMMessageInfo("Velocimacro : autoload off : VM system " + "will not automatically reload global library macros"); } rsvc.info("Velocimacro : initialization complete."); } return ; }