|
/*
* Copyright 2006, Dustin Metzgar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.CodeDom;
using System.Collections.Generic;
namespace XmiCodeDomLib.Version1_2
{
public class CodeDomHelper
{
private Dictionary<string, XmiDataType> _DataTypes = new Dictionary<string, XmiDataType>();
private Dictionary<string, XmiClass> _Classes = new Dictionary<string, XmiClass>();
private Dictionary<string, List<string>> _Generalizations = new Dictionary<string, List<string>>();
private Dictionary<string, XmiMult> _Mults = new Dictionary<string, XmiMult>();
private Dictionary<string, XmiMultRange> _MultRanges = new Dictionary<string, XmiMultRange>();
public Dictionary<string, XmiDataType> DataTypes
{
get { return _DataTypes; }
}
public Dictionary<string, XmiClass> Classes
{
get { return _Classes; }
}
public Dictionary<string, List<string>> Generalizations
{
get { return _Generalizations; }
}
public Dictionary<string, XmiMult> Mults
{
get { return _Mults; }
}
public Dictionary<string, XmiMultRange> MultRanges
{
get { return _MultRanges; }
}
public CodeDomHelper(Dictionary<string, object> xmiObjects)
{
foreach (string xmiId in xmiObjects.Keys)
{
object obj = xmiObjects[xmiId];
if (obj is XmiDataType)
{
XmiDataType xdt = obj as XmiDataType;
if (xdt.XmiIdRef == null)
_DataTypes.Add(xdt.XmiId, xdt);
}
else if (obj is XmiClass)
{
XmiClass xc = obj as XmiClass;
if (xc.XmiIdRef == null)
_Classes.Add(xc.XmiId, xc);
}
else if (obj is XmiGeneralization)
{
XmiGeneralization xg = obj as XmiGeneralization;
if (xg.Child != null && xg.Parent != null)
{
string childId = xg.Child.XmiIdRef;
string parentId = xg.Parent.XmiIdRef;
List<string> lst = null;
if (_Generalizations.ContainsKey(childId))
lst = _Generalizations[childId];
else
{
lst = new List<string>();
_Generalizations[childId] = lst;
}
lst.Add(parentId);
}
}
else if (obj is XmiMult)
_Mults.Add((obj as XmiMult).XmiId, obj as XmiMult);
else if (obj is XmiMultRange)
_MultRanges.Add((obj as XmiMultRange).XmiId, obj as XmiMultRange);
}
}
public CodeTypeReference ResolveTypeRef(object _Type)
{
CodeTypeReference ctr = null;
string xmiIdRef;
if (_Type is XmiClass)
{
xmiIdRef = (_Type as XmiClass).XmiIdRef;
if (Classes.ContainsKey(xmiIdRef))
{
XmiClass xc = Classes[xmiIdRef];
ctr = new CodeTypeReference(xc.Name);
}
else
{
ctr = new CodeTypeReference(typeof(object));
}
}
else if (_Type is XmiDataType)
{
xmiIdRef = (_Type as XmiDataType).XmiIdRef;
if (DataTypes.ContainsKey(xmiIdRef))
{
XmiDataType xdt = DataTypes[xmiIdRef];
if (!xdt.IsSystemType)
ctr = new CodeTypeReference(xdt.Name);
else
ctr = new CodeTypeReference(xdt.SystemType);
}
else
{
ctr = new CodeTypeReference(typeof(object));
}
}
else
ctr = new CodeTypeReference(typeof(object));
return ctr;
}
public XmiMultRange ResolveMultiplicity(XmiMult xm)
{
if (xm.XmiIdRef != null)
xm = _Mults[xm.XmiIdRef];
if (xm.Range.XmiIdRef != null)
return _MultRanges[xm.Range.XmiIdRef];
else
return xm.Range;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.