FieldReadWriter for strings stored in multilingual props of an object.
Inheritance: OwnStringPropReadWriter
Example #1
0
		static public FieldReadWriter Create(XmlNode node, FdoCache cache, int hvoRootObj)
		{
			string transduceField = XmlUtils.GetOptionalAttributeValue(node, "transduce");
			if (string.IsNullOrEmpty(transduceField))
				return null;
			string[] parts = transduceField.Split('.');
			if (parts.Length != 2 && parts.Length != 3)
				return null;
			string className = parts[0];
			string fieldName = parts[1];

			IFwMetaDataCache mdc = cache.DomainDataByFlid.MetaDataCache;
			int clid = mdc.GetClassId(className);
			if (clid == 0)
				return null;
			int flid = mdc.GetFieldId2(clid, fieldName, true);
			int ws = WritingSystemServices.GetWritingSystem(cache, node, null, hvoRootObj, flid, 0).Handle;
			if (parts.Length == 2)
			{
				FieldReadWriter frw;
				// parts are divided into class.propname
				if (DoItMethod.IsMultilingual(flid, mdc))
					frw = new OwnMlPropReadWriter(cache, flid, ws);
				else
					frw = new OwnStringPropReadWriter(cache, flid, GetWsFromMetaData(ws, flid, cache));
				frw.InitForGhostItems(cache, node);
				return frw;
			}

			// parts.Length is 3. We have class.objectpropname.propname
			int clidDst = mdc.GetDstClsId(flid);
			int fieldType = mdc.GetFieldType(flid);
			int flid2 = mdc.GetFieldId2(clidDst, parts[2], true);
			int clidCreate = clidDst;	// default
			string createClassName = XmlUtils.GetOptionalAttributeValue(node, "transduceCreateClass");
			if (createClassName != null)
				clidCreate = mdc.GetClassId(createClassName);
			if (DoItMethod.IsMultilingual(flid2, mdc))
			{
				Debug.Assert(ws != 0);
				// If it's a multilingual field and we didn't get a writing system, we can't transduce this field.
				if (ws == 0)
					return null;
				if (fieldType == (int)CellarPropertyType.OwningAtomic)
					return new OwnAtomicMlPropReadWriter(cache, flid2, ws, flid, clidCreate);
				else if (fieldType == (int)CellarPropertyType.OwningSequence)
					return new OwnSeqMlPropReadWriter(cache, flid2, ws, flid, clidCreate);
				else
					return null; // can't handle yet
			}
			else
			{
				if (fieldType == (int)CellarPropertyType.OwningAtomic)
					return new OwnAtomicStringPropReadWriter(cache, flid2, ws, flid, clidCreate);
				else if (fieldType == (int)CellarPropertyType.OwningSequence)
					return new OwnSeqStringPropReadWriter(cache, flid2, ws, flid, clidCreate);
				else
					return null; // can't handle yet
			}

		}