Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-06 07:57:07 +0400
committerIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-06 07:57:07 +0400
commitfd442105c900fa98bb7d6210638ef18056f2a443 (patch)
tree5883bffbcfa209c80a67ae0a5dd6034de7a783bb /mcs/class/PresentationFramework
parent931a797249597010f8a95c56efdb904e79bbee41 (diff)
parente177eb71722040814a9b7b2cd26d0a220d7b593b (diff)
2005-07-06 Iain McCoy <iain@mccoy.id.au>
* Mono.Windows.Serialization/Mapping.cs: removed in favour of System.Windows.Serialization/Mapper.cs * System.Windows.Serialization/Mapper.cs: Added because it is the microsoft-documented mapping API * Mono.Windows.Serialization/XamlParser.cs: transition to the new mapper system, also some general converging on the name DependencyProperty throughout instead of ContextProperty or AttachedProperty. svn path=/trunk/mcs/; revision=46984
Diffstat (limited to 'mcs/class/PresentationFramework')
-rw-r--r--mcs/class/PresentationFramework/ChangeLog11
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs14
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs38
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs6
-rw-r--r--mcs/class/PresentationFramework/PresentationFramework.dll.sources3
-rw-r--r--mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs (renamed from mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs)84
-rw-r--r--mcs/class/PresentationFramework/System.Windows.Serialization/NamespaceMapEntry.cs55
7 files changed, 150 insertions, 61 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog
index c2499135815..1d8af02c8f7 100644
--- a/mcs/class/PresentationFramework/ChangeLog
+++ b/mcs/class/PresentationFramework/ChangeLog
@@ -1,3 +1,14 @@
+2005-07-06 Iain McCoy <iain@mccoy.id.au>
+
+ * Mono.Windows.Serialization/Mapping.cs: removed in favour of
+ System.Windows.Serialization/Mapper.cs
+ * System.Windows.Serialization/Mapper.cs: Added because it is the
+ microsoft-documented mapping API
+ * Mono.Windows.Serialization/XamlParser.cs: transition to the new
+ mapper system, also some general converging on the name
+ DependencyProperty throughout instead of ContextProperty or
+ AttachedProperty.
+
2005-07-05 Iain McCoy <iain@mccoy.id.au>
* Mono.Windows.Serialization/XamlParser.cs,
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
index 717aad9795a..578a30677ee 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
@@ -127,9 +127,11 @@ namespace Mono.Windows.Serialization {
}
// top of stack is a reference to an object
- // pushes the name of the instance to attach to, the name of
- // the property, and a reference to an object
- public void CreateAttachedProperty(Type attachedTo, string propertyName, Type propertyType)
+ // pushes a reference to the expression that
+ // will set the property and a reference to
+ // the name of the temp variable to hold the
+ // property
+ public void CreateDependencyProperty(Type attachedTo, string propertyName, Type propertyType)
{
string varName = "temp";
varName += tempIndex;
@@ -149,7 +151,7 @@ namespace Mono.Windows.Serialization {
}
// pops 2 items: the name of the property, and the object to attach to
- public void EndAttachedProperty()
+ public void EndDependencyProperty()
{
objects.RemoveAt(objects.Count - 1);
CodeExpression call = (CodeExpression)(objects[objects.Count - 1]);
@@ -198,10 +200,10 @@ namespace Mono.Windows.Serialization {
// top of stack is reference to a property
public void CreatePropertyText(string text, Type propertyType, Type converterType)
{
- CreateAttachedPropertyText(text, propertyType, converterType);
+ CreateDependencyPropertyText(text, propertyType, converterType);
}
// top of stack is reference to an attached property
- public void CreateAttachedPropertyText(string text, Type propertyType, Type converterType)
+ public void CreateDependencyPropertyText(string text, Type propertyType, Type converterType)
{
CodeExpression expr = new CodePrimitiveExpression(text);
if (converterType != null) {
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
index fa49d898dd0..749f9feefb7 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
@@ -33,17 +33,18 @@ using System.IO;
using System.Xml;
using System.Reflection;
using System.Windows;
+using System.Windows.Serialization;
namespace Mono.Windows.Serialization {
public class XamlParser {
public const string XAML_NAMESPACE = "http://schemas.microsoft.com/winfx/xaml/2005";
- private Mapper mapper = new Mapper();
+ private Mapper mapper = new Mapper(new string[] { });
private XmlReader reader;
private XamlWriter writer;
private enum CurrentType { Object,
Property,
- AttachedProperty,
+ DependencyProperty,
Code }
private class ParserState {
@@ -101,8 +102,7 @@ namespace Mono.Windows.Serialization {
{
if (reader.Name != "Mapping")
Console.WriteLine("Unknown processing instruction");
- Mapping mapping = new Mapping(reader.Value);
- mapper.AddMapping(mapping);
+ mapper.AddMappingProcessingInstruction(reader.Value);
}
void parseElement()
@@ -133,7 +133,7 @@ namespace Mono.Windows.Serialization {
if (isNameOfAncestorClass(beforeDot, (Type)currentState.obj))
parseNormalPropertyElement(afterDot);
else
- parseAttachedPropertyElement(beforeDot, afterDot);
+ parseDependencyPropertyElement(beforeDot, afterDot);
}
// check if the given name is the name of an ancestor of
@@ -162,9 +162,9 @@ namespace Mono.Windows.Serialization {
{
if (currentState.type == CurrentType.Object) {
writer.CreateElementText(reader.Value);
- } else if (currentState.type == CurrentType.AttachedProperty) {
+ } else if (currentState.type == CurrentType.DependencyProperty) {
DependencyProperty dp = (DependencyProperty)currentState.obj;
- writer.CreateAttachedPropertyText(reader.Value, dp.PropertyType,
+ writer.CreateDependencyPropertyText(reader.Value, dp.PropertyType,
getTypeConverter(dp.PropertyType));
} else {
PropertyInfo prop = (PropertyInfo)currentState.obj;
@@ -224,7 +224,7 @@ namespace Mono.Windows.Serialization {
}
- void parseAttachedPropertyElement(string attachedTo, string propertyName)
+ void parseDependencyPropertyElement(string attachedTo, string propertyName)
{
Type currentType = (Type)currentState.obj;
ensureDependencyObject(currentType);
@@ -234,9 +234,9 @@ namespace Mono.Windows.Serialization {
oldStates.Add(currentState);
currentState = new ParserState();
currentState.obj = dp;
- currentState.type = CurrentType.AttachedProperty;
+ currentState.type = CurrentType.DependencyProperty;
- writer.CreateAttachedProperty(typeAttachedTo, propertyName, dp.PropertyType);
+ writer.CreateDependencyProperty(typeAttachedTo, propertyName, dp.PropertyType);
}
void parseObjectElement()
@@ -245,7 +245,7 @@ namespace Mono.Windows.Serialization {
string objectName = null;
bool isEmpty = reader.IsEmptyElement;
- parent = mapper.Resolve(reader.NamespaceURI, reader.Name);
+ parent = mapper.GetType(reader.NamespaceURI, reader.Name);
objectName = reader.GetAttribute("Class", XAML_NAMESPACE);
if (parent.GetInterface("System.Windows.Serialization.IAddChild") == null)
{} //TODO: throw exception
@@ -264,7 +264,7 @@ namespace Mono.Windows.Serialization {
if (reader.LocalName.IndexOf(".") < 0)
parseLocalPropertyAttribute();
else
- parseContextPropertyAttribute();
+ parseDependencyPropertyAttribute();
} while (reader.MoveToNextAttribute());
}
@@ -334,7 +334,7 @@ namespace Mono.Windows.Serialization {
void ensureDependencyObject(Type currentType)
{
if (!currentType.IsSubclassOf(typeof(System.Windows.DependencyObject)))
- throw new Exception("Attached properties can only be set on "+
+ throw new Exception("Dependency properties can only be set on "+
"DependencyObjects (not " + currentType.Name + ")");
}
Type findTypeToAttachTo(string attachedTo, string propertyName)
@@ -360,7 +360,7 @@ namespace Mono.Windows.Serialization {
return (DependencyProperty)propField.GetValue(null);
}
- void parseContextPropertyAttribute()
+ void parseDependencyPropertyAttribute()
{
int index = reader.LocalName.LastIndexOf('.');
string attachedTo = reader.LocalName.Substring(0, index);
@@ -371,10 +371,10 @@ namespace Mono.Windows.Serialization {
Type typeAttachedTo = findTypeToAttachTo(attachedTo, propertyName);
DependencyProperty dp = getDependencyProperty(typeAttachedTo, propertyName);
- writer.CreateAttachedProperty(typeAttachedTo, propertyName, dp.PropertyType);
- writer.CreateAttachedPropertyText(reader.Value, dp.PropertyType,
+ writer.CreateDependencyProperty(typeAttachedTo, propertyName, dp.PropertyType);
+ writer.CreateDependencyPropertyText(reader.Value, dp.PropertyType,
getTypeConverter(dp.PropertyType));
- writer.EndAttachedProperty();
+ writer.EndDependencyProperty();
}
void parseEndElement()
@@ -385,8 +385,8 @@ namespace Mono.Windows.Serialization {
writer.EndObject();
else if (currentState.type == CurrentType.Property)
writer.EndProperty();
- else if (currentState.type == CurrentType.AttachedProperty)
- writer.EndAttachedProperty();
+ else if (currentState.type == CurrentType.DependencyProperty)
+ writer.EndDependencyProperty();
pop();
}
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
index 9efbc9b5011..0c93c74c955 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
@@ -47,9 +47,9 @@ namespace Mono.Windows.Serialization {
void CreateEventDelegate(string functionName, Type eventDelegateType);
void EndEvent();
- void CreateAttachedProperty(Type attachedTo, string propertyName, Type propertyType);
- void CreateAttachedPropertyText(string text, Type propertyType, Type converterType);
- void EndAttachedProperty();
+ void CreateDependencyProperty(Type attachedTo, string propertyName, Type propertyType);
+ void CreateDependencyPropertyText(string text, Type propertyType, Type converterType);
+ void EndDependencyProperty();
void CreateCode(string code);
diff --git a/mcs/class/PresentationFramework/PresentationFramework.dll.sources b/mcs/class/PresentationFramework/PresentationFramework.dll.sources
index 3c5f13ec377..441e473e613 100644
--- a/mcs/class/PresentationFramework/PresentationFramework.dll.sources
+++ b/mcs/class/PresentationFramework/PresentationFramework.dll.sources
@@ -1,7 +1,8 @@
System.Windows.Serialization/IAddChild.cs
+System.Windows.Serialization/Mapper.cs
+System.Windows.Serialization/NamespaceMapEntry.cs
Mono.Windows.Serialization/CodeWriter.cs
Mono.Windows.Serialization/Exceptions.cs
-Mono.Windows.Serialization/Mapping.cs
Mono.Windows.Serialization/XamlParser.cs
Mono.Windows.Serialization/XamlWriter.cs
Assembly/AssemblyInfo.cs
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs b/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs
index 256fafd13b0..3594d898878 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs
+++ b/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs
@@ -1,5 +1,5 @@
//
-// Mapping.cs
+// Mapper.cs
//
// Author:
// Iain McCoy (iain@mccoy.id.au)
@@ -30,34 +30,38 @@ using System;
using System.Reflection;
using System.Collections;
-namespace Mono.Windows.Serialization {
+namespace System.Windows.Serialization {
class Mapper {
- private Hashtable mappings = new Hashtable();
- public void AddMapping(Mapping mapping)
- {
- if (mappings.ContainsKey(mapping.XmlNamespace))
- {}// TODO: throw exception
+ private ArrayList map = new ArrayList();
+ private ArrayList assemblyNames = new ArrayList();
+ private Hashtable assemblyPath = new Hashtable();
- mappings[mapping.XmlNamespace] = mapping;
+ public Mapper(string[] assemblyNames)
+ {
+ foreach (string name in assemblyNames) {
+ this.assemblyNames.Add(name);
+ }
}
-
- public Type Resolve(string clrNamespace, string classname)
+ public Mapper(string[] assemblyNames, NamespaceMapEntry[] map) : this(assemblyNames)
+ {
+ foreach (NamespaceMapEntry entry in map) {
+ this.map.Add(entry);
+ }
+ }
+
+ public void AddMappingProcessingInstruction(string xmlNamespace, string clrNamespace, string assemblyName)
{
- return ((Mapping)mappings[clrNamespace]).Resolve(classname);
+ NamespaceMapEntry entry = new NamespaceMapEntry(xmlNamespace, assemblyName, clrNamespace);
+ map.Add(entry);
}
- }
-
- class Mapping {
- string xmlNamespace;
- string clrNamespace;
- string assemblyName;
// this function takes the processing instructions value, which
// should be something like:
// Assembly="Foo.dll" ClrNamespace="Foo" XmlNamespace="foo"
- public Mapping(string instruction)
+ public void AddMappingProcessingInstruction(string instruction)
{
+ string xmlNamespace = null, clrNamespace = null, assemblyName = null;
string name = "", value = "";
int i = 0;
instruction = instruction.Trim();
@@ -103,28 +107,44 @@ namespace Mono.Windows.Serialization {
assemblyName == null ||
xmlNamespace == null)
throw new Exception("underspecified");
+ AddMappingProcessingInstruction(xmlNamespace, clrNamespace, assemblyName);
}
- public Mapping(string clrNamespace, string assembly, string xmlNamespace)
+ public string[] GetAssemblyNames()
{
- this.clrNamespace = clrNamespace;
- this.assemblyName = assembly;
- this.xmlNamespace = xmlNamespace;
+ return (string[])assemblyNames.ToArray(typeof(string));
}
-
- public string XmlNamespace {
- get { return xmlNamespace; }
+ public NamespaceMapEntry[] GetNamespaceMap()
+ {
+ return (NamespaceMapEntry[])map.ToArray(typeof(NamespaceMapEntry));
}
- public Type Resolve(string className)
+ public Type GetType(string xmlNamespace, string localName)
{
- Assembly assembly = Assembly.Load(assemblyName);
- Type type = assembly.GetType(clrNamespace + "." + className);
- if (type == null) {
- throw new MappingException(className, XmlNamespace);
- } else {
- return type;
+ foreach (NamespaceMapEntry entry in map)
+ {
+ Assembly assembly = getAssembly(entry.AssemblyName);
+ Type type = assembly.GetType(entry.ClrNamespace + "." + localName);
+ if (type != null)
+ return type;
}
+ return null;
+ }
+
+ Assembly getAssembly(string name)
+ {
+ if (assemblyPath[name] != null)
+ name = (string)assemblyPath[name];
+ return Assembly.Load(name);
+ }
+
+ public void SetAssemblyPath(string assemblyName, string assemblyPath)
+ {
+ this.assemblyPath[assemblyName] = assemblyPath;
+ }
+
+ public static Mapper DefaultMapper {
+ get { throw new NotImplementedException(); }
}
}
}
diff --git a/mcs/class/PresentationFramework/System.Windows.Serialization/NamespaceMapEntry.cs b/mcs/class/PresentationFramework/System.Windows.Serialization/NamespaceMapEntry.cs
new file mode 100644
index 00000000000..8e441fe8202
--- /dev/null
+++ b/mcs/class/PresentationFramework/System.Windows.Serialization/NamespaceMapEntry.cs
@@ -0,0 +1,55 @@
+//
+// NamespaceMapEntry.cs
+//
+// Author:
+// Iain McCoy (iain@mccoy.id.au)
+//
+// (C) 2005 Iain McCoy
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace System.Windows.Serialization {
+ public class NamespaceMapEntry {
+ private string xmlNamespace, clrNamespace, assemblyName;
+ public NamespaceMapEntry() {
+ }
+
+ public NamespaceMapEntry(string xmlNamespace, string assemblyName, string clrNamespace)
+ {
+ this.xmlNamespace = xmlNamespace;
+ this.clrNamespace = clrNamespace;
+ this.assemblyName = assemblyName;
+ }
+
+ public string XmlNamespace {
+ get { return xmlNamespace; }
+ set { xmlNamespace = value; }
+ }
+ public string ClrNamespace {
+ get { return clrNamespace; }
+ set { clrNamespace = value; }
+ }
+ public string AssemblyName {
+ get { return assemblyName; }
+ set { assemblyName = value; }
+ }
+ }
+}