예제 #1
0
        // Don't just retrieve the template instance; also Apply() it to our project,
        // instantiating whatever providers or whatever the template defines.

        public StructureTemplate UseNamespaceTemplate(string ns, string declloc,
                                                      IWarningLogger log)
        {
            if (proj == null)
            {
                throw new InvalidOperationException("Must call SetProject before UseNamespaceMaster!");
            }

            StructureTemplate tmpl = GetNamespaceTemplate(ns, log);

            if (tmpl == null)
            {
                return(null);
            }

            if (sused[ns])
            {
                return(tmpl);
            }

            if (tmpl.Apply(proj, declloc, log))
            {
                return(null);
            }

            sused[ns] = true;
            return(tmpl);
        }
예제 #2
0
        public StructureTemplate GetNamespaceTemplate(string ns, IWarningLogger log)
        {
            if (sinfo.ContainsKey(ns))
            {
                return(sinfo[ns]);
            }

            string cfg = MBuildPrefix + ns + "." + DefaultStructureClass;
            Type   t   = null;

            if (LookupType(cfg, out t, log))
            {
                log.Error(9999, "Error looking up namespacep parameter class " + cfg,
                          null);
                return(null);
            }

            if (t == null)
            {
                log.Error(9999, "No bundle defines the namespace parameter class" +
                          cfg, null);
                return(null);
            }

            StructureTemplate stmpl = (StructureTemplate)Activator.CreateInstance(t);

            MethodInfo mi  = t.GetMethod("ApplyDefaults");
            object     ret = mi.Invoke(stmpl, new object[] { this, log });

            if ((bool)ret)
            {
                return(null);
            }

            sinfo[ns] = stmpl;
            sused[ns] = false;

            return(stmpl);
        }
예제 #3
0
        // Context -- used for the lookup of names of this provider's
        // targets. This needs to be here for providers created by
        // structure templates, which need context to instantiate any
        // structure-bound items they may reference

        public abstract void AddContextStructure(StructureTemplate st);
예제 #4
0
	// Context -- used for the lookup of names of this provider's
	// targets. This needs to be here for providers created by 
	// structure templates, which need context to instantiate any
	// structure-bound items they may reference

	public abstract void AddContextStructure (StructureTemplate st);
예제 #5
0
	public void UseStructure (StructureTemplate st)
	{
	    Type stype = st.GetType ();

	    known_structs[stype] = st;

	    UseRawNamespace (stype.Namespace);
	}
예제 #6
0
	public RegexMatcher (StructureTemplate stmpl)
	{
	    this.stmpl = stmpl;
	}
예제 #7
0
	public RegexMatcher ()
	{
	    stmpl = null;
	}
예제 #8
0
	public override void AddContextStructure (StructureTemplate st)
	{
	    namecontext.UseStructure (st);
	}
예제 #9
0
        // Rule template helpers

        public bool GetTemplateForRule(string ns, Type rtype, out TargetTemplate ttmpl, IWarningLogger log)
        {
            ttmpl = null;

            StructureTemplate stmpl = GetNamespaceTemplate(ns, log);

            if (stmpl == null || !sused[ns])
            {
                log.Error(9999, "Trying to use structure template of namespace " +
                          ns + ", but either it wasn't defined or it hasn't been " +
                          "initialized yet.", null);
                return(true);
            }

            // See if we can find a type that has a StructureBinding to tmpl
            // and a RuleBinding to rtype.

            string pns = MBuildPrefix + ns;
            Type   ttype = null, stype = stmpl.GetType();

            foreach (Assembly assy in BundleAssemblies)
            {
                foreach (Type t in assy.GetExportedTypes())
                {
                    if (t.Namespace != pns)
                    {
                        continue;
                    }

                    if (!t.IsSubclassOf(typeof(TargetTemplate)))
                    {
                        continue;
                    }

                    object[] attrs = t.GetCustomAttributes(typeof(StructureBindingAttribute), false);

                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    StructureBindingAttribute sba = (StructureBindingAttribute)attrs[0];

                    if (sba.StructureType == null)
                    {
                        continue;
                    }

                    if (!sba.StructureType.Equals(stype))
                    {
                        continue;
                    }

                    attrs = t.GetCustomAttributes(typeof(RuleBindingAttribute), false);

                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    if (!((RuleBindingAttribute)attrs[0]).RuleType.Equals(rtype))
                    {
                        continue;
                    }

                    if (ttype != null)
                    {
                        log.Warning(9999, "Two hits for rule template: " + ttype.ToString() +
                                    " and " + t.ToString(), rtype.ToString());
                    }

                    ttype = t;
                }
            }

            if (ttype != null)
            {
                ttmpl = (TargetTemplate)Activator.CreateInstance(ttype, stmpl);
            }

            return(false);
        }