/// <summary> /// Declare a new enum type in the current scope based on an actual enum. /// </summary> /// <remarks> /// Used to declare predefined enum types representing existing enums in metamodel. /// </remarks> /// <param name="type">The enum type.</param> private void Process_ModelEnum(System.Type type) { if (NameContext.Current.Scope.Model.Instances.OfType<Type>().Count(t => t.UnderlyingType == type) == 0) { EnumType enumType = new EnumType(); // Namespace enumType.Namespace = (Namespace)NameContext.Current.Scope; // Name enumType.Name = AttributeHelpers.GetTypeName(type); // Underlying type enumType.UnderlyingType = type; // Hidden enumType.AddMetaInfo(new HiddenInfo()); // Enter scope using (new NameContextScope(enumType)) { // Values foreach (FieldInfo field in type.GetFields(BindingFlags.Static | BindingFlags.Public)) { EnumValue enumValue = new EnumValue(); enumValue.Name = AttributeHelpers.GetMemberName(field); enumValue.Enum = enumType; // Hidden enumValue.AddMetaInfo(new HiddenInfo()); } } } }
// Deklarálja az objektumokat private void Declare() { // service var services = from c in store where c.objectType == StoreItemType.service select c; Wr("Declare services:"); foreach (StoreItem service in services) { Endpoint ep = new Endpoint() { Name = (string)service.definition.Attribute("name") }; service.objRef = ep; Wr(" " + ep.Name); } // binding var bindings = from c in store where c.objectType == StoreItemType.binding select c; Wr("Declare bindings:"); foreach (StoreItem binding in bindings) { Binding bg = new Binding() { Name = (string)binding.definition.Attribute("name") }; binding.objRef = bg; Wr(" " + bg.Name); } // porttype var portTypes = from c in store where c.objectType == StoreItemType.portType select c; Wr("Declare porttypes:"); foreach (StoreItem porttype in portTypes) { Interface ifa = new Interface() { Name = (string)porttype.definition.Attribute("name") }; porttype.objRef = ifa; Wr(" " + ifa.Name); } // simpleTypes var simpleTypes = from c in store where c.objectType == StoreItemType.enumType select c; Wr("Declare SimpleTypes:"); foreach (StoreItem simpleType in simpleTypes) { EnumType et = new EnumType() { Name = (string)simpleType.definition.Attribute("name") }; simpleType.objRef = et; Wr(" " + et.Name); } // arrayType létrehozása // TODO: !!! mi van, ha több element van ??? var arrayTypes = from c in store where c.objectType == StoreItemType.complexType && c.definition.Element(xsdNS + "sequence") != null && c.definition.Element(xsdNS + "sequence").Element(xsdNS + "element") != null && c.definition.Element(xsdNS + "sequence").Element(xsdNS + "element").Attribute("maxOccurs") != null && (string)c.definition.Element(xsdNS + "sequence").Element(xsdNS + "element").Attribute("maxOccurs") != "1" select c; Wr("Declare ArrayTypes:"); foreach (StoreItem arrayType in arrayTypes) { ArrayType at = new ArrayType() { Name = (string)arrayType.definition.Attribute("name") }; arrayType.objRef = at; arrayType.objectType = StoreItemType.arrayType; Wr(" " + at.Name); } // ExceptionType // kiválasztjuk a portType-okat Wr("Declare ExceptionTypes:"); foreach (StoreItem portType in portTypes) { XElement node = portType.definition; XElement def = node; // kiszűrjük a fault-tagek message attribútumát var faultsFromPorttype = from c in node.Descendants(wsdlNS + "fault") select c.Attribute("message"); foreach (string faultMsgName in faultsFromPorttype) { StoreItem message = SearchObject(StoreItemType.message, faultMsgName, def); string referencedTypeName = null; referencedTypeName = (string)message.definition.Element(wsdlNS + "part").Attribute("type"); def = message.definition; if (referencedTypeName == null) { referencedTypeName = (string)message.definition.Element(wsdlNS + "part").Attribute("element"); StoreItem element = TrySearchObject(StoreItemType.unNamedElementType, referencedTypeName, def); if (element != null) { referencedTypeName = (string)element.definition.Attribute("type"); def = element.definition; } } StoreItem exceptionType = TrySearchObject(StoreItemType.complexType, referencedTypeName, def); if (exceptionType != null) { ExceptionType et = new ExceptionType() { Name = exceptionType.name }; exceptionType.objRef = et; exceptionType.objectType = StoreItemType.exceptionType; Wr(" " + et.Name); } else { Wr("Unable to make ExceptionType from " + referencedTypeName); throw new XmlException(); } } } // structType létrehozása (minden olyan complexType, ami nem arrayType, vagy ExceptionType) var structTypes = from c in store where c.objectType == StoreItemType.complexType select c; Wr("Declare StructTypes:"); foreach (StoreItem structType in structTypes) { StructType at = new StructType() { Name = (string)structType.definition.Attribute("name") }; structType.objRef = at; structType.objectType = StoreItemType.structType; Wr(" " + at.Name); } }
/// <summary> /// Processes enum node. /// </summary> /// <param name="node">The node.</param> private void Process_EnumType(dynamic node) { EnumType enumType = new EnumType(); // Map source location and node to object enumType.AddMetaInfo(new SourceLocationInfo(node, context)); context.AddObject(node, enumType); // Namespace (from parent) try { NameContext.Current.CheckName(node.Name, typeof(EnumType), typeof(StructType), typeof(ExceptionType), typeof(ClaimsetType)); enumType.Namespace = (Namespace)NameContext.Current.Scope; } catch (NameCollisionException exception) { Error_NameExists(enumType, exception); } // Name (obligatory) enumType.Name = node.Name; // Values are not processed yet }
// Deklarálja az objektumokat private void Declare() { // service var services = from c in readedElements where c.objectType == ObjectTypes.service select c; Wr("Declare services:"); foreach (Collective service in services) { Endpoint ep = new Endpoint() { Name = (string)service.definition.Attribute("name") }; service.objRef = ep; Wr(" " + ep.Name); } // binding var bindings = from c in readedElements where c.objectType == ObjectTypes.binding select c; Wr("Declare bindings:"); foreach (Collective binding in bindings) { Binding bg = new Binding() { Name = (string)binding.definition.Attribute("name") }; binding.objRef = bg; Wr(" " + bg.Name); } // porttype var portTypes = from c in readedElements where c.objectType == ObjectTypes.porttype select c; Wr("Declare porttypes:"); foreach (Collective porttype in portTypes) { Interface ifa = new Interface() { Name = (string)porttype.definition.Attribute("name") }; porttype.objRef = ifa; Wr(" " + ifa.Name); } // simpleTypes var simpleTypes = from c in readedElements where c.objectType == ObjectTypes.enumType select c; Wr("Declare SimpleTypes:"); foreach (Collective simpleType in simpleTypes) { EnumType et = new EnumType() { Name = (string)simpleType.definition.Attribute("name") }; simpleType.objRef = et; Wr(" " + et.Name); } // arrayType létrehozása // TODO: !!! mi van, ha több element van ??? var arrayTypes = from c in readedElements where c.objectType == ObjectTypes.complexType && c.definition.Element(xmlNS + "sequence") != null && c.definition.Element(xmlNS + "sequence").Element(xmlNS + "element") != null && c.definition.Element(xmlNS + "sequence").Element(xmlNS + "element").Attribute("maxOccurs") != null && (string)c.definition.Element(xmlNS + "sequence").Element(xmlNS + "element").Attribute("maxOccurs") != "1" select c; Wr("Declare ArrayTypes:"); foreach (Collective arrayType in arrayTypes) { ArrayType at = new ArrayType() { Name = (string)arrayType.definition.Attribute("name") }; arrayType.objRef = at; arrayType.objectType = ObjectTypes.arrayType; Wr(" " + at.Name); } // ExceptionType // kiválasztjuk a portType-okat Wr("Declare ExceptionTypes:"); foreach (Collective portType in portTypes) { XElement node = portType.definition; // kiszűrjük a fault-tagek message attribútumát var faultsFromPorttype = from c in node.Descendants(wsdlNS + "fault") select c.Attribute("message"); foreach (string faultMsgName in faultsFromPorttype) { Collective message = SearchObject(ObjectTypes.message, faultMsgName, node); var exceptionTypeNames = from c in message.definition.Descendants(wsdlNS + "part") select c.Attribute("element"); /// ?!?!?! foreach (string excTypeName in exceptionTypeNames) { Collective exceptionType = SearchObject(ObjectTypes.complexType, excTypeName, node); ExceptionType et = new ExceptionType() { Name = exceptionType.name }; exceptionType.objRef = et; exceptionType.objectType = ObjectTypes.exceptionType; Wr(" " + et.Name); } } } // structType létrehozása (minden olyan complexType, ami nem arrayType, vagy ExceptionType) var structTypes = from c in readedElements where c.objectType == ObjectTypes.complexType select c; Wr("Declare StructTypes:"); foreach (Collective structType in structTypes) { StructType at = new StructType() { Name = (string)structType.definition.Attribute("name") }; structType.objRef = at; structType.objectType = ObjectTypes.structType; Wr(" " + at.Name); } }