//@SuppressWarnings({"unchecked"})
        public void AddComponent(XmlElement parent, PropertyAuditingData propertyAuditingData,
            IValue value, ICompositeMapperBuilder mapper, String entityName,
            EntityXmlMappingData xmlMappingData, bool firstPass)
        {
            Component prop_component = (Component) value;

            ICompositeMapperBuilder componentMapper = mapper.AddComponent(propertyAuditingData.getPropertyData(),
                    prop_component.ComponentClassName);

            // The property auditing data must be for a component.
            ComponentAuditingData componentAuditingData = (ComponentAuditingData) propertyAuditingData;

            // Adding all properties of the component
            IEnumerator<Property> properties = (IEnumerator<Property>) prop_component.PropertyIterator.GetEnumerator();
            while (properties.MoveNext()) {
                Property property = properties.Current;

                PropertyAuditingData componentPropertyAuditingData =
                        componentAuditingData.getPropertyAuditingData(property.Name);

                // Checking if that property is audited
                if (componentPropertyAuditingData != null) {
                    mainGenerator.AddValue(parent, property.Value, componentMapper, entityName, xmlMappingData,
                            componentPropertyAuditingData, property.IsInsertable, firstPass);
                }
            }
        }
        private void AddCustomValue(XmlElement parent, PropertyAuditingData propertyAuditingData,
            IValue value, ISimpleMapperBuilder mapper, bool insertable, bool key)
        {
            if (parent != null) {
                XmlElement prop_mapping = MetadataTools.AddProperty(parent, propertyAuditingData.Name,
                        null, insertable, key);

                //CustomType propertyType = (CustomType) value.getType();

                XmlElement type_mapping = parent.OwnerDocument.CreateElement("type");
                prop_mapping.AppendChild(type_mapping);
                type_mapping.SetAttribute("name", value.GetType().Name);

                if (value is SimpleValue) {
                    IDictionary<string, string> typeParameters = ((SimpleValue)value).TypeParameters;
                    if (typeParameters != null) {
                        foreach (KeyValuePair<string,string> paramKeyValue in typeParameters) {
                            XmlElement type_param = parent.OwnerDocument.CreateElement("param");
                            type_param.SetAttribute("name", (String) paramKeyValue.Key);
                            type_param["name"].Value =  paramKeyValue.Value;
                        }
                    }
                }

                MetadataTools.AddColumns(prop_mapping, (IEnumerator<ISelectable>)value.ColumnIterator);
            }

            if (mapper != null) {
                mapper.Add(propertyAuditingData.getPropertyData());
            }
        }
        //@SuppressWarnings({"unchecked"})
        public void AddOneToOneNotOwning(PropertyAuditingData propertyAuditingData, IValue value,
            ICompositeMapperBuilder mapper, String entityName)
        {
            OneToOne propertyValue = (OneToOne)value;

            String owningReferencePropertyName = propertyValue.ReferencedPropertyName; // mappedBy
            EntityConfiguration configuration = mainGenerator.EntitiesConfigurations[entityName];
            if (configuration == null) {
                throw new MappingException("An audited relation to a non-audited entity " + entityName + "!");
            }

            IdMappingData ownedIdMapping = configuration.IdMappingData;

            if (ownedIdMapping == null) {
                throw new MappingException("An audited relation to a non-audited entity " + entityName + "!");
            }

            String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(owningReferencePropertyName);
            String referencedEntityName = propertyValue.ReferencedEntityName;

            // Generating the id mapper for the relation
            IIdMapper ownedIdMapper = ownedIdMapping.IdMapper.PrefixMappedProperties(lastPropertyPrefix);

            // Storing information about this relation
            mainGenerator.EntitiesConfigurations[entityName].AddToOneNotOwningRelation(
                    propertyAuditingData.Name, owningReferencePropertyName,
                    referencedEntityName, ownedIdMapper);

            // Adding mapper for the id
            PropertyData propertyData = propertyAuditingData.getPropertyData();
            mapper.AddComposite(propertyData, new OneToOneNotOwningMapper(owningReferencePropertyName,
                    referencedEntityName, propertyData));
        }
            private void AddSimpleValue(XmlElement parent, PropertyAuditingData propertyAuditingData,
                                    IValue value, ISimpleMapperBuilder mapper, bool insertable, bool key)
            {
		    if (parent != null) {
                XmlElement prop_mapping = MetadataTools.AddProperty(parent, propertyAuditingData.Name,
                        value.Type.Name, propertyAuditingData.ForceInsertable || insertable, key);
                MetadataTools.AddColumns(prop_mapping, (IEnumerator<ISelectable>)value.ColumnIterator.GetEnumerator());
		    }

		    // A null mapper means that we only want to add xml mappings
		    if (mapper != null) {
			    mapper.Add(propertyAuditingData.getPropertyData());
		    }
	    }
        //@SuppressWarnings({"unchecked"})
        public void AddToOne(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value,
            ICompositeMapperBuilder mapper, String entityName, bool insertable)
        {
            String referencedEntityName = ((ToOne)value).ReferencedEntityName;

            IdMappingData idMapping = mainGenerator.GetReferencedIdMappingData(entityName, referencedEntityName,
                    propertyAuditingData, true);

            String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(propertyAuditingData.Name);

            // Generating the id mapper for the relation
            IIdMapper relMapper = idMapping.IdMapper.PrefixMappedProperties(lastPropertyPrefix);

            // Storing information about this relation
            mainGenerator.EntitiesConfigurations[entityName].AddToOneRelation(
                    propertyAuditingData.Name, referencedEntityName, relMapper, insertable);

            // If the property isn't insertable, checking if this is not a "fake" bidirectional many-to-one relationship,
            // that is, when the one side owns the relation (and is a collection), and the many side is non insertable.
            // When that's the case and the user specified to store this relation without a middle table (using
            // @AuditMappedBy), we have to make the property insertable for the purposes of Envers. In case of changes to
            // the entity that didn't involve the relation, it's value will then be stored properly. In case of changes
            // to the entity that did involve the relation, it's the responsibility of the collection side to store the
            // proper data.
            bool nonInsertableFake;
            if (!insertable && propertyAuditingData.ForceInsertable) {
                nonInsertableFake = true;
                insertable = true;
            } else {
                nonInsertableFake = false;
            }

            // Adding an element to the mapping corresponding to the references entity id's
            // Use OwnerDocument.ImportNode() instead of XmlNode.Clone();
            XmlElement properties = (XmlElement)parent.OwnerDocument.ImportNode(idMapping.XmlRelationMapping,true);
            properties.SetAttribute("name",propertyAuditingData.Name);

            MetadataTools.PrefixNamesInPropertyElement(properties, lastPropertyPrefix,
                    MetadataTools.GetColumnNameEnumerator((IEnumerator<ISelectable>)value.ColumnIterator.GetEnumerator()), false, insertable);
            parent.AppendChild(properties);

            // Adding mapper for the id
            PropertyData propertyData = propertyAuditingData.getPropertyData();
            mapper.AddComposite(propertyData, new ToOneIdMapper(relMapper,propertyData,referencedEntityName,nonInsertableFake));
        }