/// <summary> /// Processes interface node. /// </summary> /// <param name="node">The node.</param> private void Process_Interface(dynamic node) { Interface @interface = new Interface(); // Map source location and node to object @interface.AddMetaInfo(new SourceLocationInfo(node, context)); context.AddObject(node, @interface); // Namespace (from parent) try { NameContext.Current.CheckName(node.Name, typeof(Interface)); @interface.Namespace = (Namespace)NameContext.Current.Scope; } catch (NameCollisionException exception) { Error_NameExists(@interface, exception); } // Name (obligatory) @interface.Name = node.Name; // Version (obligatory) string s = node.Version; string[] versions = s.Split('.'); @interface.Version = new VersionInfo(); @interface.Version.Major = System.Convert.ToInt32(versions[0]); @interface.Version.Minor = System.Convert.ToInt32(versions[1]); // Operations are not processed yet // SuperInterfaces are not processed yet }
/// <summary> /// Processes operation signature node. /// </summary> /// <remarks> /// Find operation in scope that matches the signature. /// </remarks> /// <param name="node">The node.</param> /// <param name="scope">The scope to search for operations.</param> /// <returns>The operation.</returns> /// <exception cref="NameNotFoundException" private Operation Process_OperationSignature(dynamic node, Interface scope) { Operation operation = null; bool error = false; // Name string name = node.Name; // Parameters List<Type> parameterTypes = new List<Type>(); if (node.Parameters != null) { foreach (dynamic parameter in node.Parameters) { try { parameterTypes.Add(this.Process_TypeReference(parameter.Type)); } catch (NameNotFoundException exception) { Error_NameNotFound(new SourceLocationInfo(parameter, context), exception); error = true; } catch (NameCollisionException exception) { Error_NameCollision(new SourceLocationInfo(parameter, context), exception); error = true; } } if (error) { throw new OperationValidationException(); } } try { operation = (Operation)NameContext.ResolveOperation(scope, name, parameterTypes, false); } catch (NameNotFoundException) { Error_OperationSignatureMismatch(new SourceLocationInfo(node, context)); throw new OperationValidationException(); } // Return type try { Type returnType = this.Process_ReturnTypeReference(node.ReturnType); if (returnType != operation.ReturnType) { Error_OperationReturnMismatch(new SourceLocationInfo(node.ReturnType, context)); error = true; } } catch (NameNotFoundException exception) { Error_NameNotFound(new SourceLocationInfo(node.Operation.ReturnType, context), exception); error = true; } catch (NameCollisionException exception) { Error_NameCollision(new SourceLocationInfo(node.Operation.ReturnType, context), exception); error = true; } // Exceptions List<ExceptionType> exceptionTypes = new List<ExceptionType>(); if (node.Exceptions != null) { foreach (dynamic exception in node.Exceptions) { try { ExceptionType exceptionType = this.Process_NamespacedTypeReference(exception, typeof(ExceptionType)); if (exceptionTypes.Contains(exceptionType)) { Error_NameRedundant(new SourceLocationInfo(exception, context), typeof(ExceptionType), exceptionType.FullName); } else { exceptionTypes.Add(exceptionType); } } catch (NameNotFoundException ex) { Error_NameNotFound(new SourceLocationInfo(exception, context), ex); error = true; } catch (NameCollisionException ex) { Error_NameCollision(new SourceLocationInfo(exception, context), ex); error = true; } } if (error) { throw new OperationValidationException(); } } if (operation.Exceptions.Any(ex => !exceptionTypes.Contains(ex)) || exceptionTypes.Any(ex => !operation.Exceptions.Contains(ex))) { Error_OperationExceptionMismatch(new SourceLocationInfo((node.Exceptions != null) ? node.Exceptions : node, context)); error = true; } if (error) { throw new OperationValidationException(); } return operation; }
// 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); } }
// 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); } }