/// <summary> /// Parses the SIF Version from the version attribute or namespace. If not able /// to parse the version, the default version is returned. /// </summary> /// <param name="reader"></param> /// <param name="dtd"></param> /// <param name="zone"></param> /// <param name="flags"></param> /// <param name="defaultVersion"></param> /// <returns></returns> private SifVersion ParseVersion( XmlReader reader, IDtd dtd, IZone zone, SifParserFlags flags, SifVersion defaultVersion) { SifVersion version; String verAttr = reader.GetAttribute("Version"); // Order of precedence: // 1) Version attribute of message // 2) The version passed in (if not null) // 3) The namespace version (if able to parse) // 4) The ADK SIF Version if (verAttr != null) { version = SifVersion.Parse(verAttr); } else if (defaultVersion != null) { version = defaultVersion; } else { String namespc = reader.NamespaceURI; version = SifVersion.ParseXmlns(namespc); if (version == null) { version = Adk.SifVersion; } } // Do validation on the version if (!Adk.IsSIFVersionSupported(version)) { throw new SifException( SifErrorCategoryCode.Generic, SifErrorCodes.GENERIC_VERSION_NOT_SUPPORTED_3, string.Format("SIF {0} not supported", version.ToString()), reader.NamespaceURI, zone); } else if (zone != null && zone.Properties.StrictVersioning) { if (version.CompareTo(Adk.SifVersion) != 0) { throw new SifException( SifErrorCategoryCode.Generic, SifErrorCodes.GENERIC_VERSION_NOT_SUPPORTED_3, "SIF " + version.ToString() + " message support disabled by this agent", string.Format("This agent is running in strict SIF {0} mode", Adk.SifVersion.ToString()), zone); } } return(version); }
private void SetFieldValueFromAttribute( SifElement element, XmlReader reader, IDtd dtd, SifVersion version, SifFormatter formatter, IZone zone) { IElementDef elementDef = element.ElementDef; IElementDef field = dtd.LookupElementDef(element.ElementDef, reader.LocalName); if (field == null && reader.Prefix != null) { if (reader.LocalName == SifWriter.NIL && reader.NamespaceURI == XmlSchema.InstanceNamespace) { TypeConverter converter = elementDef.TypeConverter; if (converter != null) { SifSimpleType sst = converter.GetSifSimpleType(null); element.SetField(elementDef, sst); } return; } else if (reader.Name.StartsWith("xmlns")) { return; } else { field = dtd.LookupElementDef(elementDef, reader.Prefix + ":" + reader.LocalName); } } if (field != null) { string strVal = reader.Value.Trim(); SifSimpleType val = ParseValue(field, strVal, version, formatter, zone); element.SetField(field, val); } else if (element.ElementDef.EarliestVersion >= SifVersion.SIF20 && version < SifVersion.SIF20) { Adk.Log.Warn("Field " + element.ElementDef.ClassName + "." + (reader.Prefix == null ? reader.LocalName : reader.Prefix + ":" + reader.LocalName) + " does not exist in the sif 2.0 specification onwards. It may or may not be valid in sif 1.5r1. It will be ignored."); } else { // TODO: Log and gracefully ignore, depending on whether the ADK is set to strict or loose parsing throw new SifException (SifErrorCategoryCode.Xml, SifErrorCodes.XML_GENERIC_VALIDATION_3, "Unknown element or attribute", reader.LocalName + " is not a recognized attribute of the " + elementDef.Name + " element (SIF " + element.EffectiveSIFVersion.ToString() + ")", zone); } }
private IElementDef LookupElementDef(SifElement parent, XmlReader reader, IDtd dtd, SifVersion version, IZone zone) { // Lookup the ElementDef metadata in the SifDtd object for the // version of SIF we are parsing. First try looking up a ElementDef // for a field or complex object that is a child of another element, // such as StudentPersonal_Name, SIF_Ack_SIF_Header, etc. If none // found then look for a root-level element such as StudentPersonal, // SIF_Ack, etc. If still nothing is found we don't know how to // parse this element -- it is neither a top-level object element // nor a child field element for this version of SIF. String elementName = reader.LocalName; IElementDef def = null; if (parent != null) { def = dtd.LookupElementDef(parent.ElementDef, elementName); } if (def == null) { def = dtd.LookupElementDef(elementName); } // Beginning with SIF 1.5 *any* object can have a SIF_ExtendedElements // child, so we need to check for that case since the Adk metadata // does not add SIF_ExtendedElements to all object types if (def == null && elementName.Equals("SIF_ExtendedElements")) { def = GlobalDTD.SIF_EXTENDEDELEMENTS; } // Beginning with SIF 2.0 *any* object can have a SIF_ExtendedElements // child, so we need to check for that case since the Adk metadata // does not add SIF_ExtendedElements to all object types if (def == null && elementName.Equals("SIF_Metadata")) { // TODO: Add support for SIF_Metadata back in to the .NET ADK def = null; // DatamodelDTD.SIF_METADATA; } // Note: def returned can be null. return(def); }
private SifElement ReadSifElementFromElementNode( IElementDef def, XmlReader reader, IDtd dtd, SifElement parent, SifFormatter formatter, SifVersion version, IZone zone) { SifElement element; try { element = SifElement.Create(parent, def); } catch (TypeLoadException tle) { throw new AdkParsingException ("Could not create an instance of " + def.FQClassName + " to wrap a " + reader.LocalName + " element because that class doesn't exist", zone, tle); } catch (Exception ex) { throw new AdkParsingException ("Could not create an instance of " + def.FQClassName, zone, ex); } element.ElementDef = def; element.SifVersion = version; if (parent != null) { element = formatter.AddChild(parent, element, version); } // Set the attributes to fields of the SifElement while (reader.MoveToNextAttribute()) { SetFieldValueFromAttribute(element, reader, dtd, version, formatter, zone); } return(element); }
/// <summary> /// Reads a SIF_Message element, which sets the version and namespace scope for the rest of the /// xml parsing /// </summary> /// <param name="reader"></param> /// <param name="dtd"></param> /// <param name="zone"></param> /// <param name="flags"></param> /// <param name="defaultVersion"></param> /// <returns></returns> /// <exception cref="OpenADK.Library.AdkParsingException">AdkParsingException is thrown if unable to /// parse the message</exception> /// <exception cref="System.IO.IOException"> IOException is thrown if an error is reported while reading /// the message content</exception> private SifElement ReadSIFMessageElement( XmlReader reader, IDtd dtd, IZone zone, SifParserFlags flags, SifVersion defaultVersion) { SifVersion version = ParseVersion(reader, dtd, zone, flags, defaultVersion); SIF_Message message = new SIF_Message(); // Set the namespace from our working version message.SetXmlns(version.Xmlns); if (version.CompareTo(SifVersion.SIF11) >= 0) { // If we are at SifVersion 1.1 or greater, set the version attribute message.SetVersionAttribute(version.ToString()); } // Advance to the next element if (reader.Read()) { while (reader.NodeType != XmlNodeType.Element) { if (!reader.Read()) { break; } } if (reader.NodeType == XmlNodeType.Element) { SifElement element = ParseElementStream(reader, version, dtd, zone, flags); message.AddChild(element); } } return(message); }
private SifElement ParseElementStream(XmlReader reader, SifVersion version, IDtd dtd, IZone zone, SifParserFlags flags) { bool legacyParse = version.CompareTo(SifVersion.SIF20) < 0; // The current SIFElement being parsed SifElement currentElement = null; // The actual tag name of the current element SifFormatter formatter = Adk.Dtd.GetFormatter(version); reader.MoveToContent(); bool doneParsing = false; while (!(reader.EOF || doneParsing)) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.LocalName == "SIF_Message") { // Special case for embedded SIF_Message envelopes if ((flags & SifParserFlags.ExpectInnerEnvelope) != 0) { SifElement msgElement = ReadSIFMessageElement(reader, dtd, zone, SifParserFlags.None, version); currentElement.AddChild(msgElement); currentElement = msgElement; } else { throw new AdkParsingException ("Unexpected SIF_Message encountered in parsing", zone); } } else { String xmlName = reader.LocalName; if (xmlName == "Teacher") { Console.WriteLine("Ready to break"); } IElementDef foundDef = LookupElementDef(currentElement, reader, dtd, version, zone); if (foundDef == null) { if (legacyParse) { ParseLegacyXML(reader, version, zone, currentElement, formatter, xmlName); continue; } else if (currentElement != null && currentElement.ElementDef.Name.Equals("XMLData")) { // Parse this into a DOM and set on the XMLData // element XmlReader nestedReader = reader.ReadSubtree(); XmlDocument doc = new XmlDocument(); doc.Load(nestedReader); ((XMLData)currentElement).Xml = doc; continue; } else { String _tag = currentElement != null ? currentElement.ElementDef.Name + "/" + xmlName : xmlName; throw new SifException(SifErrorCategoryCode.Xml, SifErrorCodes.XML_GENERIC_VALIDATION_3, "Unknown element or attribute", _tag + " is not a recognized element of SIF " + version.ToString(), zone); } } if (legacyParse) { IElementVersionInfo evi = foundDef.GetVersionInfo(version); if (evi != null) { IRenderSurrogate rs = evi.GetSurrogate(); if (rs != null) { using (XmlReader subtreeReader = reader.ReadSubtree()) { bool shouldContinue = true; subtreeReader.Read(); try { shouldContinue = rs.ReadRaw(subtreeReader, version, currentElement, formatter); } catch (AdkTypeParseException atpe) { HandleTypeParseException("Unable to parse value: " + atpe.Message, atpe, zone); } subtreeReader.Close(); // advance to the next tag reader.Read(); if (shouldContinue) { continue; } else { throw new SifException(SifErrorCategoryCode.Xml, SifErrorCodes.XML_GENERIC_VALIDATION_3, "Unknown element or attribute", reader.LocalName + " was not able to be parsed by " + rs, zone); } } } } } if (foundDef.Field) { SetFieldValueFromElement (foundDef, currentElement, reader, version, formatter, zone); // Advance to the next tag do { reader.Read(); } while ( !(reader.EOF || reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement)); continue; } else if (reader.IsEmptyElement) { // The .Net XmlReader does not return an EndElement event for // tags with empty content. Therefore, this region of the code is // slightly different from Java ReadSifElementFromElementNode(foundDef, reader, dtd, currentElement, formatter, version, zone); } else { currentElement = ReadSifElementFromElementNode(foundDef, reader, dtd, currentElement, formatter, version, zone); } } break; case XmlNodeType.Text: if (currentElement.ElementDef.HasSimpleContent) { SetFieldValueFromElement(currentElement.ElementDef, currentElement, reader, version, formatter, zone); // The XML Reader cursor is automatically advanced by this method, so we // need to continue on without calling read() continue; } break; case XmlNodeType.EndElement: if (currentElement.Parent != null) { currentElement = (SifElement)currentElement.Parent; while (legacyParse && currentElement.ElementDef.IsCollapsed(version)) { currentElement = (SifElement)currentElement.Parent; } } if (reader.LocalName == "SIF_Message") { // We need to return here. If we let the reader keep reading, and we are reading an embedded // SIF_Message, it will keep parsing the end tags and not let the stack of SifElement objects // propertly unwind. We're done anyway. doneParsing = true; } break; } // Advance the cursor reader.Read(); } if (currentElement == null) { return(null); } else { // Now, unwind and pop off the top element parsed Element top = currentElement; Element current; while ((current = top.Parent) != null) { top = current; } return((SifElement)top); } }
/// <summary> /// Reads a SIF_Message element, which sets the version and namespace scope for the rest of the /// xml parsing /// </summary> /// <param name="reader"></param> /// <param name="dtd"></param> /// <param name="zone"></param> /// <param name="flags"></param> /// <param name="defaultVersion"></param> /// <returns></returns> /// <exception cref="OpenADK.Library.AdkParsingException">AdkParsingException is thrown if unable to /// parse the message</exception> /// <exception cref="System.IO.IOException"> IOException is thrown if an error is reported while reading /// the message content</exception> private SifElement ReadSIFMessageElement( XmlReader reader, IDtd dtd, IZone zone, SifParserFlags flags, SifVersion defaultVersion ) { SifVersion version = ParseVersion( reader, dtd, zone, flags, defaultVersion ); SIF_Message message = new SIF_Message(); // Set the namespace from our working version message.SetXmlns( version.Xmlns ); if ( version.CompareTo( SifVersion.SIF11 ) >= 0 ) { // If we are at SifVersion 1.1 or greater, set the version attribute message.SetVersionAttribute( version.ToString() ); } // Advance to the next element if ( reader.Read() ) { while ( reader.NodeType != XmlNodeType.Element ) { if ( !reader.Read() ) { break; } } if ( reader.NodeType == XmlNodeType.Element ) { SifElement element = ParseElementStream( reader, version, dtd, zone, flags ); message.AddChild( element ); } } return message; }
private void SetFieldValueFromAttribute( SifElement element, XmlReader reader, IDtd dtd, SifVersion version, SifFormatter formatter, IZone zone ) { IElementDef elementDef = element.ElementDef; IElementDef field = dtd.LookupElementDef( element.ElementDef, reader.LocalName ); if ( field == null && reader.Prefix != null ) { if(reader.LocalName == SifWriter.NIL && reader.NamespaceURI == XmlSchema.InstanceNamespace ) { TypeConverter converter = elementDef.TypeConverter; if ( converter != null ) { SifSimpleType sst = converter.GetSifSimpleType( null ); element.SetField(elementDef, sst); } return; } else if( reader.Name.StartsWith( "xmlns" ) ) { return; } else { field = dtd.LookupElementDef(elementDef, reader.Prefix + ":" + reader.LocalName); } } if( field != null ) { string strVal = reader.Value.Trim(); SifSimpleType val = ParseValue( field, strVal, version, formatter, zone ); element.SetField( field, val ); } else if (element.ElementDef.EarliestVersion >= SifVersion.SIF20 && version < SifVersion.SIF20) { Adk.Log.Warn("Field " + element.ElementDef.ClassName + "." + (reader.Prefix == null ? reader.LocalName : reader.Prefix + ":" + reader.LocalName ) + " does not exist in the sif 2.0 specification onwards. It may or may not be valid in sif 1.5r1. It will be ignored." ); } else { // TODO: Log and gracefully ignore, depending on whether the ADK is set to strict or loose parsing throw new SifException (SifErrorCategoryCode.Xml, SifErrorCodes.XML_GENERIC_VALIDATION_3, "Unknown element or attribute", reader.LocalName + " is not a recognized attribute of the " + elementDef.Name + " element (SIF " + element.EffectiveSIFVersion.ToString() + ")", zone); } }
private SifElement ReadSifElementFromElementNode( IElementDef def, XmlReader reader, IDtd dtd, SifElement parent, SifFormatter formatter, SifVersion version, IZone zone ) { SifElement element; try { element = SifElement.Create( parent, def ); } catch ( TypeLoadException tle ) { throw new AdkParsingException ( "Could not create an instance of " + def.FQClassName + " to wrap a " + reader.LocalName + " element because that class doesn't exist", zone, tle ); } catch ( Exception ex ) { throw new AdkParsingException ( "Could not create an instance of " + def.FQClassName, zone, ex ); } element.ElementDef = def; element.SifVersion = version; if ( parent != null ) { element = formatter.AddChild( parent, element, version ); } // Set the attributes to fields of the SifElement while ( reader.MoveToNextAttribute() ) { SetFieldValueFromAttribute( element, reader, dtd, version, formatter, zone ); } return element; }
/// <summary> /// Parses the SIF Version from the version attribute or namespace. If not able /// to parse the version, the default version is returned. /// </summary> /// <param name="reader"></param> /// <param name="dtd"></param> /// <param name="zone"></param> /// <param name="flags"></param> /// <param name="defaultVersion"></param> /// <returns></returns> private SifVersion ParseVersion( XmlReader reader, IDtd dtd, IZone zone, SifParserFlags flags, SifVersion defaultVersion) { SifVersion version; String verAttr = reader.GetAttribute( "Version" ); // Order of precedence: // 1) Version attribute of message // 2) The version passed in (if not null) // 3) The namespace version (if able to parse) // 4) The ADK SIF Version if ( verAttr != null ) { version = SifVersion.Parse( verAttr ); } else if ( defaultVersion != null ) { version = defaultVersion; } else { String namespc = reader.NamespaceURI; version = SifVersion.ParseXmlns( namespc ); if ( version == null ) { version = Adk.SifVersion; } } // Do validation on the version if ( !Adk.IsSIFVersionSupported( version ) ) { throw new SifException( SifErrorCategoryCode.Generic, SifErrorCodes.GENERIC_VERSION_NOT_SUPPORTED_3, string.Format( "SIF {0} not supported", version.ToString() ), reader.NamespaceURI, zone ); } else if ( zone != null && zone.Properties.StrictVersioning ) { if ( version.CompareTo( Adk.SifVersion ) != 0 ) { throw new SifException( SifErrorCategoryCode.Generic, SifErrorCodes.GENERIC_VERSION_NOT_SUPPORTED_3, "SIF " + version.ToString() + " message support disabled by this agent", string.Format( "This agent is running in strict SIF {0} mode", Adk.SifVersion.ToString() ), zone ); } } return version; }
private SifElement ParseElementStream( XmlReader reader, SifVersion version, IDtd dtd, IZone zone, SifParserFlags flags ) { bool legacyParse = version.CompareTo( SifVersion.SIF20 ) < 0; // The current SIFElement being parsed SifElement currentElement = null; // The actual tag name of the current element SifFormatter formatter = Adk.Dtd.GetFormatter( version ); reader.MoveToContent(); bool doneParsing = false; while ( !(reader.EOF || doneParsing) ) { switch ( reader.NodeType ) { case XmlNodeType.Element: if ( reader.LocalName == "SIF_Message" ) { // Special case for embedded SIF_Message envelopes if ( (flags & SifParserFlags.ExpectInnerEnvelope) != 0 ) { SifElement msgElement = ReadSIFMessageElement( reader, dtd, zone, SifParserFlags.None, version ); currentElement.AddChild( msgElement ); currentElement = msgElement; } else { throw new AdkParsingException ( "Unexpected SIF_Message encountered in parsing", zone ); } } else { String xmlName = reader.LocalName; if( xmlName == "Teacher" ) { Console.WriteLine( "Ready to break" ); } IElementDef foundDef = LookupElementDef( currentElement, reader, dtd, version, zone ); if (foundDef == null) { if (legacyParse) { ParseLegacyXML(reader, version, zone, currentElement, formatter, xmlName); continue; } else if (currentElement != null && currentElement.ElementDef.Name.Equals("XMLData")) { // Parse this into a DOM and set on the XMLData // element XmlReader nestedReader = reader.ReadSubtree(); XmlDocument doc = new XmlDocument(); doc.Load( nestedReader ); ((XMLData)currentElement).Xml = doc; continue; } else { String _tag = currentElement != null ? currentElement.ElementDef.Name + "/" + xmlName : xmlName; throw new SifException( SifErrorCategoryCode.Xml, SifErrorCodes.XML_GENERIC_VALIDATION_3, "Unknown element or attribute", _tag + " is not a recognized element of SIF " + version.ToString(), zone); } } if ( legacyParse ) { IElementVersionInfo evi = foundDef.GetVersionInfo( version ); if (evi != null) { IRenderSurrogate rs = evi.GetSurrogate(); if (rs != null) { using (XmlReader subtreeReader = reader.ReadSubtree()) { bool shouldContinue = true; subtreeReader.Read(); try { shouldContinue = rs.ReadRaw( subtreeReader, version, currentElement, formatter ); } catch ( AdkTypeParseException atpe ) { HandleTypeParseException( "Unable to parse value: " + atpe.Message, atpe, zone ); } subtreeReader.Close(); // advance to the next tag reader.Read(); if ( shouldContinue ) { continue; } else { throw new SifException( SifErrorCategoryCode.Xml, SifErrorCodes.XML_GENERIC_VALIDATION_3, "Unknown element or attribute", reader.LocalName + " was not able to be parsed by " + rs, zone ); } } } } } if ( foundDef.Field ) { SetFieldValueFromElement ( foundDef, currentElement, reader, version, formatter, zone ); // Advance to the next tag do { reader.Read(); } while ( !(reader.EOF || reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement) ); continue; } else if ( reader.IsEmptyElement ) { // The .Net XmlReader does not return an EndElement event for // tags with empty content. Therefore, this region of the code is // slightly different from Java ReadSifElementFromElementNode( foundDef, reader, dtd, currentElement, formatter, version, zone ); } else { currentElement = ReadSifElementFromElementNode( foundDef, reader, dtd, currentElement, formatter, version, zone ); } } break; case XmlNodeType.Text: if ( currentElement.ElementDef.HasSimpleContent ) { SetFieldValueFromElement( currentElement.ElementDef, currentElement, reader, version, formatter, zone ); // The XML Reader cursor is automatically advanced by this method, so we // need to continue on without calling read() continue; } break; case XmlNodeType.EndElement: if ( currentElement.Parent != null ) { currentElement = (SifElement) currentElement.Parent; while ( legacyParse && currentElement.ElementDef.IsCollapsed( version ) ) { currentElement = (SifElement) currentElement.Parent; } } if ( reader.LocalName == "SIF_Message" ) { // We need to return here. If we let the reader keep reading, and we are reading an embedded // SIF_Message, it will keep parsing the end tags and not let the stack of SifElement objects // propertly unwind. We're done anyway. doneParsing = true; } break; } // Advance the cursor reader.Read(); } if ( currentElement == null ) { return null; } else { // Now, unwind and pop off the top element parsed Element top = currentElement; Element current; while ( (current = top.Parent) != null ) { top = current; } return (SifElement) top; } }
private IElementDef LookupElementDef( SifElement parent, XmlReader reader, IDtd dtd, SifVersion version, IZone zone ) { // Lookup the ElementDef metadata in the SifDtd object for the // version of SIF we are parsing. First try looking up a ElementDef // for a field or complex object that is a child of another element, // such as StudentPersonal_Name, SIF_Ack_SIF_Header, etc. If none // found then look for a root-level element such as StudentPersonal, // SIF_Ack, etc. If still nothing is found we don't know how to // parse this element -- it is neither a top-level object element // nor a child field element for this version of SIF. String elementName = reader.LocalName; IElementDef def = null; if ( parent != null ) { def = dtd.LookupElementDef( parent.ElementDef, elementName ); } if ( def == null ) { def = dtd.LookupElementDef( elementName ); } // Beginning with SIF 1.5 *any* object can have a SIF_ExtendedElements // child, so we need to check for that case since the Adk metadata // does not add SIF_ExtendedElements to all object types if ( def == null && elementName.Equals( "SIF_ExtendedElements" ) ) { def = GlobalDTD.SIF_EXTENDEDELEMENTS; } // Beginning with SIF 2.0 *any* object can have a SIF_ExtendedElements // child, so we need to check for that case since the Adk metadata // does not add SIF_ExtendedElements to all object types if ( def == null && elementName.Equals( "SIF_Metadata" ) ) { // TODO: Add support for SIF_Metadata back in to the .NET ADK def = null; // DatamodelDTD.SIF_METADATA; } // Note: def returned can be null. return def; }
/// <summary> Initialize the Adk to use the specified version of SIF. /// /// Calling this method when the Adk has already been initialized has no effect. /// /// This method must be called at agent startup to initialize /// various resources of the Adk, establish global settings for the /// class framework, and set the default version of SIF to which /// all messages originating from the agent will conform. /// /// Beginning with Adk 1.5.0, this method also configures the global /// Adk <c>ServerLog</c> instance with a logging module that /// will be inherited by the ServerLog of all zones. It installs a /// single logging module implementation: <c>DefaultServerLogModule</c>. /// The behavior of this module is to report SIF_LogEntry objects to /// the zone integration server via an Add SIF_Event message whenever /// <c>ServerLog.reportLogEntry</c> is called on a zone and /// the agent is running in SIF 1.5 or later. DefaultServerLogModule /// also echos server log messages to the zone's local logging framework Category /// so that agents do not need to duplicate logging to both the server /// and local agent log. If you want to install a custom <i>ServerLogModule</i> /// implementation -- or need to adjust the settings of the default /// module installed when the Adk is initialized -- call the /// <c>Adk.getServerLog</c> method to obtain a reference to the /// root of the <c>ServerLog</c> chain, then call its methods /// to add and remove modules. Refer to the ServerLog class for more /// information on server logging. /// /// </summary> /// <param name="version">The version of SIF that will be used by the agent this /// session. Supported versions are enumerated by constants of the /// <see cref="OpenADK.Library.SifVersion"/> class. Once initialized, /// the version cannot be changed. /// </param> /// <param name="sdoLibraries">One or more of the constants defined by the SdoLibrary /// class, identifying the SIF Data Object libraries to be loaded into /// memory (e.g. SdoLibraryType.STUDENT | SdoLibraryType.HR ) /// /// </param> /// <exception cref="AdkException">If the ADK cannot be initialized</exception> /// <exception cref="OpenADK.Library.AdkNotSupportedException"> AdkNotSupportedException is thrown if the specified SIF /// version is not supported by the Adk, or if the <i>sdoLibraries</i> /// parameter is invalid /// </exception> public static void Initialize(SifVersion version, SIFVariant dataModel, int sdoLibraries) { if (Initialized) { return; } // TODO: This code could be done in more of a modular way so that it // doesn't need to be hand-edited each time a new SIFVariant is added. if (dataModel == SIFVariant.SIF_US) { sDtd = new OpenADK.Library.us.SifDtd(); } else if (dataModel == SIFVariant.SIF_UK) { sDtd = new OpenADK.Library.uk.SifDtd(); } else if (dataModel == SIFVariant.SIF_AU) { sDtd = new OpenADK.Library.au.SifDtd(); } //if (dataModel == null) //{ // Console.Out.WriteLine("ERROR - No variant DTD loaded"); //} //else //{ Console.Out.WriteLine("Using datamodel - " + dataModel.ToString("G")); //} try { InitLogging(); } catch (Exception e) { Console.Out.WriteLine(e); } if (version == null) { throw new ArgumentException("SifVersion cannot be null"); } sSingleton = new Adk(); // the default formatter for String APIs in the ADK is the SIF 1.x formatter // for backwards compatibility sSingleton.fDefaultFormatter = SifDtd.SIF_1X_FORMATTER; // // Set up the ServerLog // ServerLog sl = ServerLog; if (sl != null) { sl.AddLogger(new DefaultServerLogModule()); } // HTTP and HTTPS transports always available TransportPlugin tp = new HttpTransportPlugin(); sSingleton.fTransports[tp.Protocol] = tp; tp = new HttpsTransportPlugin(); sSingleton.fTransports[tp.Protocol] = tp; if (Debug != AdkDebugFlags.None) { sLog.Debug("Using Adk " + AdkVersion); } sSingleton.fVersion = version; //Dtd.LoadLibraries(sdoLibraries); ((DTDInternals)Dtd).LoadLibraries((int)sdoLibraries); }