/// <exception cref="Exception">Thrown when...</exception> public void Parse() { if (doc == null) { throw new Exception("Input stream is not valid"); } vocabulary = (from v in doc.Descendants(ELEMENT_VOCABULARY_DESCRIPTION) select new Vocabulary { vocabularyIRI = (string)v.Attribute(ATTRIBUTE_PROPERTY_TARGET).Value, aspects = (from aspects in v.Descendants(ELEMENT_ASPECTS) select (string)aspects.Attribute(ELEMENT_ASPECT)).ToArray<string>(), properties = new Dictionary<string,VocabularyProperty>(), vocabularyVariables = new Dictionary<string,VocabularyVariable>(), }).First<Vocabulary>(); XElement vocDescrXElement = doc.Descendants(ELEMENT_VOCABULARY_DESCRIPTION).First<XElement>(); XElement propertiesXElement = vocDescrXElement.Descendants(ELEMENT_PROPERTIES).First<XElement>(); VocabularyProperty[] vocabularyProperties = (from prop in propertiesXElement.Descendants(ELEMENT_PROPERTY) //where prop.Attribute(ATTRIBUTE_PROPERTY_DATA_TYPE) != null select new VocabularyProperty { aspects = prop.Attribute(ATTRIBUTE_PROPERTY_ASPECTS).Value.Replace(" ", "").Split(",".ToCharArray()), defaultAspect = prop.Attribute(ATTRIBUTE_PROPERTY_DEFAULT_ASPECT).Value, //expr = prop.Attribute(ATTRIBUTE_PROPERTY_EXPR).Value, name = prop.Attribute(ATTRIBUTE_PROPERTY_NAME).Value, type = prop.Attribute(ATTRIBUTE_PROPERTY_DATA_TYPE).Value, }).ToArray<VocabularyProperty>(); foreach (VocabularyProperty vp in vocabularyProperties) { vocabulary.properties.Add(vp.name, vp); } try { XElement variablesXElement = vocDescrXElement.Descendants(ELEMENT_VARIABLES).First<XElement>(); VocabularyVariable[] vocabularyVariables = (from var in variablesXElement.Descendants(ELEMENT_VARIABLE) select new VocabularyVariable { aspect = var.Attribute(ATTRIBUTE_PROPERTY_ASPECT).Value, id = var.Attribute(ATTRIBUTE_PROPERTY_ID).Value, name = var.Attribute(ATTRIBUTE_PROPERTY_NAME).Value, vocabulary = var.Attribute(ATTRIBUTE_PROPERTY_VOCABULARY).Value, }).ToArray<VocabularyVariable>(); foreach (VocabularyVariable vv in vocabularyVariables) { vocabulary.vocabularyVariables.Add(vv.id, vv); } } catch (Exception ex) { //TODO: Handle this Exception } }
/// <exception cref="W3c.Ddr.Exceptions.NameException">Thrown when an aspect or property or vocabulary is not recognized</exception> public VocabularyProperty ExistProperty(String propertyName, String aspect, String vocabularyIRI, bool throwsException) { String realAspect = aspect; VocabularyProperty vocabularyProperty = (VocabularyProperty)vocabularyPropertyCache.GetCachedElement(propertyName + aspect + vocabularyIRI); if (vocabularyProperty == null) { Vocabulary vocabulary = new Vocabulary(); if (vocabularies.TryGetValue(vocabularyIRI, out vocabulary)) { Dictionary<String, VocabularyProperty> propertyMap = vocabulary.properties; if (propertyMap.TryGetValue(propertyName, out vocabularyProperty)) { if (realAspect != null && realAspect.Trim().Length > 0) { if (vocabularyProperty.aspects.Contains(realAspect)) { vocabularyPropertyCache.SetCachedElement(propertyName + aspect + vocabularyIRI, vocabularyProperty); return vocabularyProperty; } else { if (throwsException) { throw new NameException(NameException.ASPECT_NOT_RECOGNIZED, "unknow \"" + realAspect + "\" aspect"); } return null; } } else { return vocabularyProperty; } } else { if (throwsException) { throw new NameException(NameException.PROPERTY_NOT_RECOGNIZED, "unknow \"" + propertyName + "\" property"); } return null; } } else { if (throwsException) { throw new NameException(NameException.VOCABULARY_NOT_RECOGNIZED, "unknow \"" + vocabularyIRI + "\" vacabulary"); } return null; } } else { return vocabularyProperty; } }