Files
mono/mcs/class/System.Web/System.Web.Compilation/AspComponentFoundry.cs
T
Gonzalo Paniagua Javier e80814a23c 2003-04-30 Gonzalo Paniagua Javier <[email protected]>
* AspComponentFoundry.cs: simplified it a lot by using Type and Assembly
	instead of their names.

	* AspElements.cs: removed. No longer needed.

	* AspGenerator.cs: this file is now in charge of interfacing between
	the parser and the compiler. It manages the creation of the
	ControlBuilder tree and the compilation of the CodeDOM tree.

	* AspParser.cs: tag handling is simpler now.  Instead of a whole bunch
	of different Types, tags are just and id and a set of attributes.
	Implement ILocation interface.

	* AspTokenizer.cs: added a few methods to help the parser implementing
	ILocation.

	* BaseCompiler.cs: handles the portions of the CodeDOM tree that are
	common to appliaction, page and user control, including the actual
	compilation and error handling.

	* CSCompiler.cs: compiles C# files using CodeDOM interfaces.

	* CachingCompiler.cs: simplified to use the new interfaces.

	* CompilationException.cs: it's now using CompilationResult to report
	errors.

	* CompilationResult.cs: Removed file.

	* Directive.cs: to check for the validity of a directive.

	* GlobalAsaxCompiler.cs: simplified a lot, as most of the work is done
	in BaseCompiler.

	* ILocation.cs: interface used to now the exact place where a parse
	error happens.

	* PageCompiler.cs: generates a couple of methods that are only used in
	pages.

	* ParseException.cs: use the ILocation interface.

	* TagAttributes.cs: handles the attributes of the tags parsed.

	* TagType.cs: an enum for the different kinds of tags.

	* TemplateControlCompiler.cs: this is the one that does most of the
	conversion from teh ControlBuilder tree into a CodeDOM tree.

	* UserControlCompiler.cs: simplified as most of the work is done in
	its base classes.

	* WebServiceCompiler.cs: dummy.

svn path=/trunk/mcs/; revision=14140
2003-04-30 04:56:01 +00:00

175 lines
4.3 KiB
C#

//
// System.Web.Compilation.AspComponentFoundry
//
// Authors:
// Gonzalo Paniagua Javier ([email protected])
//
// (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
//
using System;
using System.Collections;
using System.IO;
using System.Reflection;
namespace System.Web.Compilation
{
internal class AspComponentFoundry
{
private Hashtable foundries;
public AspComponentFoundry ()
{
foundries = new Hashtable (CaseInsensitiveHashCodeProvider.Default,
CaseInsensitiveComparer.Default);
Assembly sw = typeof (AspComponentFoundry).Assembly;
RegisterFoundry ("asp", sw, "System.Web.UI.WebControls");
RegisterFoundry ("", "object", typeof (System.Web.UI.ObjectTag));
}
public Type GetComponentType (string foundryName, string tag)
{
Foundry foundry = foundries [foundryName] as Foundry;
if (foundry == null)
return null;
return foundry.GetType (tag);
}
public void RegisterFoundry (string foundryName,
Assembly assembly,
string nameSpace)
{
AssemblyFoundry foundry = new AssemblyFoundry (assembly, nameSpace);
InternalRegister (foundryName, foundry);
}
public void RegisterFoundry (string foundryName,
string tagName,
Type type)
{
TagNameFoundry foundry = new TagNameFoundry (tagName, type);
InternalRegister (foundryName, foundry);
}
void InternalRegister (string foundryName, Foundry foundry)
{
object f = foundries [foundryName];
if (f is CompoundFoundry) {
((CompoundFoundry) f).Add (foundry);
} else if (f == null || (f is AssemblyFoundry && foundry is AssemblyFoundry)) {
// If more than 1 namespace/assembly specified, the last one is used.
foundries [foundryName] = foundry;
} else if (f != null) {
CompoundFoundry compound = new CompoundFoundry (foundryName);
compound.Add ((Foundry) f);
compound.Add (foundry);
foundries [foundryName] = compound;
}
}
public bool LookupFoundry (string foundryName)
{
return foundries.Contains (foundryName);
}
abstract class Foundry
{
public abstract Type GetType (string componentName);
}
class TagNameFoundry : Foundry
{
string tagName;
Type type;
public TagNameFoundry (string tagName, Type type)
{
this.tagName = tagName;
this.type = type;
}
public override Type GetType (string componentName)
{
if (0 != String.Compare (componentName, tagName, true))
return null;
return type;
}
public string TagName {
get { return tagName; }
}
}
class AssemblyFoundry : Foundry
{
string nameSpace;
Assembly assembly;
public AssemblyFoundry (Assembly assembly, string nameSpace)
{
this.assembly = assembly;
this.nameSpace = nameSpace;
}
public override Type GetType (string componentName)
{
return assembly.GetType (nameSpace + "." + componentName, true, true);
}
}
class CompoundFoundry : Foundry
{
AssemblyFoundry assemblyFoundry;
Hashtable tagnames;
string tagPrefix;
public CompoundFoundry (string tagPrefix)
{
this.tagPrefix = tagPrefix;
tagnames = new Hashtable (CaseInsensitiveHashCodeProvider.Default,
CaseInsensitiveComparer.Default);
}
public void Add (Foundry foundry)
{
if (foundry is AssemblyFoundry) {
assemblyFoundry = (AssemblyFoundry) foundry;
return;
}
TagNameFoundry tn = (TagNameFoundry) foundry;
string tagName = tn.TagName;
if (tagnames.Contains (tagName)) {
string msg = String.Format ("{0}:{1} already registered.", tagPrefix, tagName);
throw new ApplicationException (msg);
}
tagnames.Add (tagName, foundry);
}
public override Type GetType (string componentName)
{
Type type = null;
if (assemblyFoundry != null) {
try {
type = assemblyFoundry.GetType (componentName);
return type;
} catch { }
}
Foundry foundry = tagnames [componentName] as Foundry;
if (foundry == null) {
string msg = String.Format ("Type {0} not registered for prefix {1}",
componentName, tagPrefix);
throw new ApplicationException (msg);
}
return foundry.GetType (componentName);
}
}
}
}