chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1061233 [10/15] - in /incubator/chemistry/dotcmis: branches/ tags/ trunk/ trunk/DotCMIS/ trunk/DotCMIS/Properties/ trunk/DotCMIS/Service References/ trunk/DotCMIS/Service References/CMISWebServicesReference/ trunk/DotCMIS/binding/ trunk/Do...
Date Thu, 20 Jan 2011 11:38:50 GMT
Added: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs?rev=1061233&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs Thu Jan 20 11:38:48 2011
@@ -0,0 +1,1576 @@
+using DotCMIS.CMISWebServicesReference;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using DotCMIS.Data;
+using DotCMIS.Data.Extensions;
+using System.Collections.Generic;
+using System.Xml;
+using DotCMIS.Enums;
+using System;
+using System.Reflection;
+using System.Xml.Serialization;
+using System.IO;
+
+namespace DotCMIS.Binding
+{
+    internal class Converter
+    {
+        /// <summary>
+        /// Converts a repository info.
+        /// </summary>
+        public static IRepositoryInfo Convert(cmisRepositoryInfoType repositotyInfo)
+        {
+            if (repositotyInfo == null)
+            {
+                return null;
+            }
+
+            RepositoryInfo result = new RepositoryInfo();
+            result.Id = repositotyInfo.repositoryId;
+            result.Name = repositotyInfo.repositoryName;
+            result.Description = repositotyInfo.repositoryDescription;
+            result.VendorName = repositotyInfo.vendorName;
+            result.ProductName = repositotyInfo.productName;
+            result.ProductVersion = repositotyInfo.productVersion;
+            result.RootFolderId = repositotyInfo.rootFolderId;
+            result.Capabilities = Convert(repositotyInfo.capabilities);
+            result.AclCapabilities = Convert(repositotyInfo.aclCapability);
+            result.LatestChangeLogToken = repositotyInfo.latestChangeLogToken;
+            result.CmisVersionSupported = repositotyInfo.cmisVersionSupported;
+            result.ThinClientUri = repositotyInfo.thinClientURI;
+            result.ChangesIncomplete = (repositotyInfo.changesIncompleteSpecified ? (bool?)repositotyInfo.changesIncomplete : null);
+            result.ChangesOnType = new List<BaseTypeId?>();
+            if (repositotyInfo.changesOnType != null)
+            {
+                foreach (enumBaseObjectTypeIds baseType in repositotyInfo.changesOnType)
+                {
+                    result.ChangesOnType.Add((BaseTypeId?)CmisValue.SerializerToCmisEnum(baseType));
+                }
+            }
+            result.PrincipalIdAnonymous = repositotyInfo.principalAnonymous;
+            result.PrincipalIdAnyone = repositotyInfo.principalAnyone;
+
+            ConvertExtension(repositotyInfo, result);
+
+            return result;
+        }
+
+        /// <summary>
+        /// Converts repository capabilities.
+        /// </summary>
+        public static IRepositoryCapabilities Convert(cmisRepositoryCapabilitiesType capabilities)
+        {
+            if (capabilities == null)
+            {
+                return null;
+            }
+
+            RepositoryCapabilities result = new RepositoryCapabilities();
+            result.ContentStreamUpdatesCapability = (CapabilityContentStreamUpdates)CmisValue.SerializerToCmisEnum(capabilities.capabilityContentStreamUpdatability);
+            result.ChangesCapability = (CapabilityChanges)CmisValue.SerializerToCmisEnum(capabilities.capabilityChanges);
+            result.RenditionsCapability = (CapabilityRenditions)CmisValue.SerializerToCmisEnum(capabilities.capabilityRenditions);
+            result.IsGetDescendantsSupported = capabilities.capabilityGetDescendants;
+            result.IsGetFolderTreeSupported = capabilities.capabilityGetFolderTree;
+            result.IsMultifilingSupported = capabilities.capabilityMultifiling;
+            result.IsUnfilingSupported = capabilities.capabilityUnfiling;
+            result.IsVersionSpecificFilingSupported = capabilities.capabilityVersionSpecificFiling;
+            result.IsPwcSearchableSupported = capabilities.capabilityPWCSearchable;
+            result.IsPwcUpdatableSupported = capabilities.capabilityPWCUpdatable;
+            result.IsAllVersionsSearchableSupported = capabilities.capabilityAllVersionsSearchable;
+            result.QueryCapability = (CapabilityQuery)CmisValue.SerializerToCmisEnum(capabilities.capabilityQuery);
+            result.JoinCapability = (CapabilityJoin)CmisValue.SerializerToCmisEnum(capabilities.capabilityJoin);
+            result.AclCapability = (CapabilityAcl)CmisValue.SerializerToCmisEnum(capabilities.capabilityACL);
+
+            ConvertExtension(capabilities, result);
+
+            return result;
+        }
+
+        /// <summary>
+        /// Converts ACL capabilities.
+        /// </summary>
+        public static IAclCapabilities Convert(cmisACLCapabilityType capabilities)
+        {
+            if (capabilities == null)
+            {
+                return null;
+            }
+
+            AclCapabilities result = new AclCapabilities();
+            result.SupportedPermissions = (SupportedPermissions)CmisValue.SerializerToCmisEnum(capabilities.supportedPermissions);
+            result.AclPropagation = (AclPropagation)CmisValue.SerializerToCmisEnum(capabilities.propagation);
+            result.Permissions = new List<IPermissionDefinition>();
+            if (capabilities.permissions != null)
+            {
+                foreach (cmisPermissionDefinition permission in capabilities.permissions)
+                {
+                    PermissionDefinition permDef = new PermissionDefinition();
+                    permDef.Id = permission.permission;
+                    permDef.Description = permission.description;
+                    result.Permissions.Add(permDef);
+
+                    ConvertExtension(permission, permDef);
+                }
+            }
+            result.PermissionMapping = new Dictionary<string, IPermissionMapping>();
+            if (capabilities.mapping != null)
+            {
+                foreach (cmisPermissionMapping mapping in capabilities.mapping)
+                {
+                    PermissionMapping permMap = new PermissionMapping();
+                    permMap.Key = GetXmlEnumAttributeValue(mapping.key);
+                    permMap.Permissions = new List<string>();
+                    if (mapping.permission != null)
+                    {
+                        foreach (string s in mapping.permission)
+                        {
+                            permMap.Permissions.Add(s);
+                        }
+                    }
+
+                    result.PermissionMapping[permMap.Key] = permMap;
+
+                    ConvertExtension(mapping, permMap);
+                }
+            }
+
+            ConvertExtension(capabilities, result);
+
+            return result;
+        }
+
+        public static ITypeDefinition Convert(cmisTypeDefinitionType typeDef)
+        {
+            if (typeDef == null)
+            {
+                return null;
+            }
+
+            TypeDefinition result = null;
+            if (typeDef is cmisTypeDocumentDefinitionType)
+            {
+                DocumentTypeDefinition docType = new DocumentTypeDefinition();
+                cmisTypeDocumentDefinitionType docTypeDef = (cmisTypeDocumentDefinitionType)typeDef;
+
+                docType.IsVersionable = docTypeDef.versionable;
+                docType.ContentStreamAllowed = (ContentStreamAllowed)CmisValue.SerializerToCmisEnum(docTypeDef.contentStreamAllowed);
+
+                result = docType;
+            }
+            else if (typeDef is cmisTypeFolderDefinitionType)
+            {
+                result = new FolderTypeDefinition();
+            }
+            else if (typeDef is cmisTypePolicyDefinitionType)
+            {
+                result = new PolicyTypeDefinition();
+            }
+            else if (typeDef is cmisTypeRelationshipDefinitionType)
+            {
+                RelationshipTypeDefinition relType = new RelationshipTypeDefinition();
+                cmisTypeRelationshipDefinitionType relTypeDef = (cmisTypeRelationshipDefinitionType)typeDef;
+
+                if (relTypeDef.allowedSourceTypes != null)
+                {
+                    relType.AllowedSourceTypeIds = new List<string>();
+                    foreach (string id in relTypeDef.allowedSourceTypes)
+                    {
+                        relType.AllowedSourceTypeIds.Add(id);
+                    }
+                }
+
+                if (relTypeDef.allowedTargetTypes != null)
+                {
+                    relType.AllowedTargetTypeIds = new List<string>();
+                    foreach (string id in relTypeDef.allowedTargetTypes)
+                    {
+                        relType.AllowedTargetTypeIds.Add(id);
+                    }
+                }
+
+                result = relType;
+            }
+
+            result.Id = typeDef.id;
+            result.LocalName = typeDef.localName;
+            result.LocalNamespace = typeDef.localNamespace;
+            result.DisplayName = typeDef.displayName;
+            result.QueryName = typeDef.queryName;
+            result.Description = typeDef.description;
+            result.BaseTypeId = (BaseTypeId?)CmisValue.SerializerToCmisEnum(typeDef.baseId);
+            result.ParentTypeId = typeDef.parentId;
+            result.IsCreatable = typeDef.creatable;
+            result.IsFileable = typeDef.fileable;
+            result.IsQueryable = typeDef.queryable;
+            result.IsFulltextIndexed = typeDef.fulltextIndexed;
+            result.IsIncludedInSupertypeQuery = typeDef.includedInSupertypeQuery;
+            result.IsControllablePolicy = typeDef.controllablePolicy;
+            result.IsControllableAcl = typeDef.controllableACL;
+
+            if (typeDef.Items != null)
+            {
+                foreach (cmisPropertyDefinitionType propertyDefinition in typeDef.Items)
+                {
+                    result.AddPropertyDefinition(Convert(propertyDefinition));
+                }
+            }
+
+            ConvertExtension(typeDef, result);
+
+            return result;
+        }
+
+        public static IPropertyDefinition Convert(cmisPropertyDefinitionType propDef)
+        {
+            if (propDef == null) { return null; }
+
+            PropertyDefinition result = null;
+            if (propDef is cmisPropertyBooleanDefinitionType)
+            {
+                PropertyBooleanDefinition pd = new PropertyBooleanDefinition();
+                cmisPropertyBooleanDefinitionType cpd = (cmisPropertyBooleanDefinitionType)propDef;
+
+                if (cpd.defaultValue != null && cpd.defaultValue.value != null)
+                {
+                    pd.DefaultValue = new List<bool>();
+                    foreach (bool value in cpd.defaultValue.value) { pd.DefaultValue.Add(value); }
+                }
+                if (cpd.choice != null)
+                {
+                    pd.Choices = new List<IChoice<bool>>();
+                    foreach (cmisChoiceBoolean c in cpd.choice) { pd.Choices.Add(ConvertChoice(c)); }
+                }
+
+                result = pd;
+            }
+            else if (propDef is cmisPropertyDateTimeDefinitionType)
+            {
+                PropertyDateTimeDefinition pd = new PropertyDateTimeDefinition();
+                cmisPropertyDateTimeDefinitionType cpd = (cmisPropertyDateTimeDefinitionType)propDef;
+
+                if (cpd.defaultValue != null && cpd.defaultValue.value != null)
+                {
+                    pd.DefaultValue = new List<DateTime>();
+                    foreach (DateTime value in cpd.defaultValue.value) { pd.DefaultValue.Add(value); }
+                }
+                if (cpd.choice != null)
+                {
+                    pd.Choices = new List<IChoice<DateTime>>();
+                    foreach (cmisChoiceDateTime c in cpd.choice) { pd.Choices.Add(ConvertChoice(c)); }
+                }
+
+                if (cpd.resolutionSpecified)
+                {
+                    pd.DateTimeResolution = (DateTimeResolution)CmisValue.SerializerToCmisEnum(cpd.resolution);
+                }
+
+                result = pd;
+            }
+            else if (propDef is cmisPropertyDecimalDefinitionType)
+            {
+                PropertyDecimalDefinition pd = new PropertyDecimalDefinition();
+                cmisPropertyDecimalDefinitionType cpd = (cmisPropertyDecimalDefinitionType)propDef;
+
+                if (cpd.defaultValue != null && cpd.defaultValue.value != null)
+                {
+                    pd.DefaultValue = new List<decimal>();
+                    foreach (decimal value in cpd.defaultValue.value) { pd.DefaultValue.Add(value); }
+                }
+                if (cpd.choice != null)
+                {
+                    pd.Choices = new List<IChoice<decimal>>();
+                    foreach (cmisChoiceDecimal c in cpd.choice) { pd.Choices.Add(ConvertChoice(c)); }
+                }
+
+                if (cpd.maxValueSpecified)
+                {
+                    pd.MaxValue = cpd.maxValue;
+                }
+                if (cpd.minValueSpecified)
+                {
+                    pd.MinValue = cpd.minValue;
+                }
+                if (cpd.precisionSpecified)
+                {
+                    pd.Precision = (DecimalPrecision)CmisValue.SerializerToCmisEnum(cpd.precision);
+                }
+
+                result = pd;
+            }
+            else if (propDef is cmisPropertyHtmlDefinitionType)
+            {
+                PropertyHtmlDefinition pd = new PropertyHtmlDefinition();
+                cmisPropertyHtmlDefinitionType cpd = (cmisPropertyHtmlDefinitionType)propDef;
+
+                if (cpd.defaultValue != null && cpd.defaultValue.value != null)
+                {
+                    pd.DefaultValue = new List<string>();
+                    foreach (string value in cpd.defaultValue.value) { pd.DefaultValue.Add(value); }
+                }
+                if (cpd.choice != null)
+                {
+                    pd.Choices = new List<IChoice<string>>();
+                    foreach (cmisChoiceHtml c in cpd.choice) { pd.Choices.Add(ConvertChoice(c)); }
+                }
+
+                result = pd;
+            }
+            else if (propDef is cmisPropertyIdDefinitionType)
+            {
+                PropertyIdDefinition pd = new PropertyIdDefinition();
+                cmisPropertyIdDefinitionType cpd = (cmisPropertyIdDefinitionType)propDef;
+
+                if (cpd.defaultValue != null && cpd.defaultValue.value != null)
+                {
+                    pd.DefaultValue = new List<string>();
+                    foreach (string value in cpd.defaultValue.value) { pd.DefaultValue.Add(value); }
+                }
+                if (cpd.choice != null)
+                {
+                    pd.Choices = new List<IChoice<string>>();
+                    foreach (cmisChoiceId c in cpd.choice) { pd.Choices.Add(ConvertChoice(c)); }
+                }
+
+                result = pd;
+            }
+            else if (propDef is cmisPropertyIntegerDefinitionType)
+            {
+                PropertyIntegerDefinition pd = new PropertyIntegerDefinition();
+                cmisPropertyIntegerDefinitionType cpd = (cmisPropertyIntegerDefinitionType)propDef;
+
+                if (cpd.defaultValue != null && cpd.defaultValue.value != null)
+                {
+                    pd.DefaultValue = new List<long>();
+                    foreach (string value in cpd.defaultValue.value) { pd.DefaultValue.Add(Int64.Parse(value)); }
+                }
+                if (cpd.choice != null)
+                {
+                    pd.Choices = new List<IChoice<long>>();
+                    foreach (cmisChoiceInteger c in cpd.choice) { pd.Choices.Add(ConvertChoice(c)); }
+                }
+
+                if (cpd.maxValue != null)
+                {
+                    pd.MaxValue = Int64.Parse(cpd.maxValue);
+                }
+                if (cpd.minValue != null)
+                {
+                    pd.MinValue = Int64.Parse(cpd.minValue);
+                }
+
+                result = pd;
+            }
+            else if (propDef is cmisPropertyStringDefinitionType)
+            {
+                PropertyStringDefinition pd = new PropertyStringDefinition();
+                cmisPropertyStringDefinitionType cpd = (cmisPropertyStringDefinitionType)propDef;
+
+                if (cpd.defaultValue != null && cpd.defaultValue.value != null)
+                {
+                    pd.DefaultValue = new List<string>();
+                    foreach (string value in cpd.defaultValue.value) { pd.DefaultValue.Add(value); }
+                }
+                if (cpd.choice != null)
+                {
+                    pd.Choices = new List<IChoice<string>>();
+                    foreach (cmisChoiceString c in cpd.choice) { pd.Choices.Add(ConvertChoice(c)); }
+                }
+
+                if (cpd.maxLength != null)
+                {
+                    pd.MaxLength = Int64.Parse(cpd.maxLength);
+                }
+
+                result = pd;
+            }
+            else if (propDef is cmisPropertyUriDefinitionType)
+            {
+                PropertyUriDefinition pd = new PropertyUriDefinition();
+                cmisPropertyUriDefinitionType cpd = (cmisPropertyUriDefinitionType)propDef;
+
+                if (cpd.defaultValue != null && cpd.defaultValue.value != null)
+                {
+                    pd.DefaultValue = new List<string>();
+                    foreach (string value in cpd.defaultValue.value) { pd.DefaultValue.Add(value); }
+                }
+                if (cpd.choice != null)
+                {
+                    pd.Choices = new List<IChoice<string>>();
+                    foreach (cmisChoiceUri c in cpd.choice) { pd.Choices.Add(ConvertChoice(c)); }
+                }
+
+                result = pd;
+            }
+
+            result.Id = propDef.id;
+            result.LocalName = propDef.localName;
+            result.LocalNamespace = propDef.localNamespace;
+            result.DisplayName = propDef.displayName;
+            result.QueryName = propDef.queryName;
+            result.Description = propDef.description;
+            result.PropertyType = (PropertyType?)CmisValue.SerializerToCmisEnum(propDef.propertyType);
+            result.Cardinality = (Cardinality?)CmisValue.SerializerToCmisEnum(propDef.cardinality);
+            result.Updatability = (Updatability?)CmisValue.SerializerToCmisEnum(propDef.updatability);
+            result.IsInherited = (propDef.inheritedSpecified ? (bool?)propDef.inherited : null);
+            result.IsRequired = propDef.required;
+            result.IsQueryable = propDef.queryable;
+            result.IsOrderable = propDef.orderable;
+            result.IsOpenChoice = (propDef.openChoiceSpecified ? (bool?)propDef.openChoice : null);
+
+            ConvertExtension(propDef, result);
+
+            return result;
+        }
+
+        private static IChoice<bool> ConvertChoice(cmisChoiceBoolean choice)
+        {
+            if (choice == null) { return null; }
+
+            Choice<bool> result = new Choice<bool>();
+            result.DisplayName = choice.displayName;
+            if (choice.value != null)
+            {
+                result.Value = new List<bool>();
+                foreach (bool v in choice.value) { result.Value.Add(v); }
+            }
+            if (choice.choice != null)
+            {
+                result.Choices = new List<IChoice<bool>>();
+                foreach (cmisChoiceBoolean sc in choice.choice) { result.Choices.Add(ConvertChoice(sc)); }
+            }
+
+            return result;
+        }
+
+        private static IChoice<DateTime> ConvertChoice(cmisChoiceDateTime choice)
+        {
+            if (choice == null) { return null; }
+
+            Choice<DateTime> result = new Choice<DateTime>();
+            result.DisplayName = choice.displayName;
+            if (choice.value != null)
+            {
+                result.Value = new List<DateTime>();
+                foreach (DateTime v in choice.value) { result.Value.Add(v); }
+            }
+            if (choice.choice != null)
+            {
+                result.Choices = new List<IChoice<DateTime>>();
+                foreach (cmisChoiceDateTime sc in choice.choice) { result.Choices.Add(ConvertChoice(sc)); }
+            }
+
+            return result;
+        }
+
+        private static IChoice<decimal> ConvertChoice(cmisChoiceDecimal choice)
+        {
+            if (choice == null) { return null; }
+
+            Choice<decimal> result = new Choice<decimal>();
+            result.DisplayName = choice.displayName;
+            if (choice.value != null)
+            {
+                result.Value = new List<decimal>();
+                foreach (decimal v in choice.value) { result.Value.Add(v); }
+            }
+            if (choice.choice != null)
+            {
+                result.Choices = new List<IChoice<decimal>>();
+                foreach (cmisChoiceDecimal sc in choice.choice) { result.Choices.Add(ConvertChoice(sc)); }
+            }
+
+            return result;
+        }
+
+        private static IChoice<string> ConvertChoice(cmisChoiceHtml choice)
+        {
+            if (choice == null) { return null; }
+
+            Choice<string> result = new Choice<string>();
+            result.DisplayName = choice.displayName;
+            if (choice.value != null)
+            {
+                result.Value = new List<string>();
+                foreach (string v in choice.value) { result.Value.Add(v); }
+            }
+            if (choice.choice != null)
+            {
+                result.Choices = new List<IChoice<string>>();
+                foreach (cmisChoiceHtml sc in choice.choice) { result.Choices.Add(ConvertChoice(sc)); }
+            }
+
+            return result;
+        }
+
+        private static IChoice<string> ConvertChoice(cmisChoiceId choice)
+        {
+            if (choice == null) { return null; }
+
+            Choice<string> result = new Choice<string>();
+            result.DisplayName = choice.displayName;
+            if (choice.value != null)
+            {
+                result.Value = new List<string>();
+                foreach (string v in choice.value) { result.Value.Add(v); }
+            }
+            if (choice.choice != null)
+            {
+                result.Choices = new List<IChoice<string>>();
+                foreach (cmisChoiceId sc in choice.choice) { result.Choices.Add(ConvertChoice(sc)); }
+            }
+
+            return result;
+        }
+
+        private static IChoice<long> ConvertChoice(cmisChoiceInteger choice)
+        {
+            if (choice == null) { return null; }
+
+            Choice<long> result = new Choice<long>();
+            result.DisplayName = choice.displayName;
+            if (choice.value != null)
+            {
+                result.Value = new List<long>();
+                foreach (string v in choice.value) { result.Value.Add(Int64.Parse(v)); }
+            }
+            if (choice.choice != null)
+            {
+                result.Choices = new List<IChoice<long>>();
+                foreach (cmisChoiceInteger sc in choice.choice) { result.Choices.Add(ConvertChoice(sc)); }
+            }
+
+            return result;
+        }
+
+        private static IChoice<string> ConvertChoice(cmisChoiceString choice)
+        {
+            if (choice == null) { return null; }
+
+            Choice<string> result = new Choice<string>();
+            result.DisplayName = choice.displayName;
+            if (choice.value != null)
+            {
+                result.Value = new List<string>();
+                foreach (string v in choice.value) { result.Value.Add(v); }
+            }
+            if (choice.choice != null)
+            {
+                result.Choices = new List<IChoice<string>>();
+                foreach (cmisChoiceString sc in choice.choice) { result.Choices.Add(ConvertChoice(sc)); }
+            }
+
+            return result;
+        }
+
+        private static IChoice<string> ConvertChoice(cmisChoiceUri choice)
+        {
+            if (choice == null) { return null; }
+
+            Choice<string> result = new Choice<string>();
+            result.DisplayName = choice.displayName;
+            if (choice.value != null)
+            {
+                result.Value = new List<string>();
+                foreach (string v in choice.value) { result.Value.Add(v); }
+            }
+            if (choice.choice != null)
+            {
+                result.Choices = new List<IChoice<string>>();
+                foreach (cmisChoiceUri sc in choice.choice) { result.Choices.Add(ConvertChoice(sc)); }
+            }
+
+            return result;
+        }
+
+
+        /// <summary>
+        /// Converts a type defintion list.
+        /// </summary> 
+        public static ITypeDefinitionList Convert(cmisTypeDefinitionListType typeDefList)
+        {
+            if (typeDefList == null) { return null; }
+
+            TypeDefinitionList result = new TypeDefinitionList();
+
+            if (typeDefList.types != null)
+            {
+                result.List = new List<ITypeDefinition>();
+                foreach (cmisTypeDefinitionType type in typeDefList.types)
+                {
+                    result.List.Add(Convert(type));
+                }
+            }
+
+            result.HasMoreItems = typeDefList.hasMoreItems;
+            result.NumItems = Int64.Parse(typeDefList.numItems);
+
+            ConvertExtension(typeDefList, result);
+
+            return result;
+        }
+
+        /// <summary>
+        /// Converts a type defintion container.
+        /// </summary> 
+        public static ITypeDefinitionContainer Convert(cmisTypeContainer typeDefCont)
+        {
+            if (typeDefCont == null) { return null; }
+
+            TypeDefinitionContainer result = new TypeDefinitionContainer();
+            result.TypeDefinition = Convert(typeDefCont.type);
+            if (typeDefCont.children != null)
+            {
+                result.Children = new List<ITypeDefinitionContainer>();
+                foreach (cmisTypeContainer container in typeDefCont.children)
+                {
+                    result.Children.Add(Convert(container));
+                }
+            }
+
+            ConvertExtension(typeDefCont, result);
+
+            return result;
+        }
+
+        public static IObjectData Convert(cmisObjectType cmisObject)
+        {
+            if (cmisObject == null) { return null; }
+
+            ObjectData result = new ObjectData();
+            result.Properties = Convert(cmisObject.properties);
+            result.AllowableActions = Convert(cmisObject.allowableActions);
+            if (cmisObject.relationship != null)
+            {
+                result.Relationships = new List<IObjectData>();
+                foreach (cmisObjectType co in cmisObject.relationship)
+                {
+                    result.Relationships.Add(Convert(co));
+                }
+            }
+            result.ChangeEventInfo = Convert(cmisObject.changeEventInfo);
+            result.IsExactAcl = cmisObject.exactACLSpecified ? (bool?)cmisObject.exactACL : null;
+            result.Acl = Convert(cmisObject.acl, result.IsExactAcl);
+            result.PolicyIds = Convert(cmisObject.policyIds);
+            if (cmisObject.rendition != null)
+            {
+                result.Renditions = new List<IRenditionData>();
+                foreach (cmisRenditionType rendition in cmisObject.rendition)
+                {
+                    result.Renditions.Add(Convert(rendition));
+                }
+            }
+
+            ConvertExtension(cmisObject, result);
+
+            return result;
+        }
+
+        public static IProperties Convert(cmisPropertiesType properties)
+        {
+            if (properties == null) { return null; }
+
+            Properties result = new Properties();
+            if (properties.Items != null)
+            {
+                foreach (cmisProperty property in properties.Items)
+                {
+                    result.AddProperty(Convert(property));
+                }
+            }
+
+            ConvertExtension(properties, result);
+
+            return result;
+        }
+        public static IPropertyData Convert(cmisProperty property)
+        {
+            if (property == null) { return null; }
+
+            PropertyData result = null;
+            if (property is cmisPropertyString)
+            {
+                result = new PropertyString();
+                if (((cmisPropertyString)property).value != null)
+                {
+                    ((PropertyString)result).Values = new List<string>();
+                    foreach (string value in ((cmisPropertyString)property).value)
+                    {
+                        ((PropertyString)result).Values.Add(value);
+                    }
+                }
+            }
+            else if (property is cmisPropertyId)
+            {
+                result = new PropertyId();
+                if (((cmisPropertyId)property).value != null)
+                {
+                    ((PropertyId)result).Values = new List<string>();
+                    foreach (string value in ((cmisPropertyId)property).value)
+                    {
+                        ((PropertyId)result).Values.Add(value);
+                    }
+                }
+            }
+            else if (property is cmisPropertyInteger)
+            {
+                result = new PropertyInteger();
+                if (((cmisPropertyInteger)property).value != null)
+                {
+                    ((PropertyInteger)result).Values = new List<long>();
+                    foreach (string value in ((cmisPropertyInteger)property).value)
+                    {
+                        ((PropertyInteger)result).Values.Add(Int64.Parse(value));
+                    }
+                }
+            }
+            else if (property is cmisPropertyBoolean)
+            {
+                result = new PropertyBoolean();
+                if (((cmisPropertyBoolean)property).value != null)
+                {
+                    ((PropertyBoolean)result).Values = new List<bool>();
+                    foreach (bool value in ((cmisPropertyBoolean)property).value)
+                    {
+                        ((PropertyBoolean)result).Values.Add(value);
+                    }
+                }
+            }
+            else if (property is cmisPropertyDateTime)
+            {
+                result = new PropertyDateTime();
+                if (((cmisPropertyDateTime)property).value != null)
+                {
+                    ((PropertyDateTime)result).Values = new List<DateTime>();
+                    foreach (DateTime value in ((cmisPropertyDateTime)property).value)
+                    {
+                        ((PropertyDateTime)result).Values.Add(value);
+                    }
+                }
+            }
+            else if (property is cmisPropertyDecimal)
+            {
+                result = new PropertyDecimal();
+                if (((cmisPropertyDecimal)property).value != null)
+                {
+                    ((PropertyDecimal)result).Values = new List<decimal>();
+                    foreach (decimal value in ((cmisPropertyDecimal)property).value)
+                    {
+                        ((PropertyDecimal)result).Values.Add(value);
+                    }
+                }
+            }
+            else if (property is cmisPropertyHtml)
+            {
+                result = new PropertyHtml();
+                if (((cmisPropertyHtml)property).value != null)
+                {
+                    ((PropertyHtml)result).Values = new List<string>();
+                    foreach (string value in ((cmisPropertyHtml)property).value)
+                    {
+                        ((PropertyHtml)result).Values.Add(value);
+                    }
+                }
+            }
+            else if (property is cmisPropertyUri)
+            {
+                result = new PropertyUri();
+                if (((cmisPropertyUri)property).value != null)
+                {
+                    ((PropertyUri)result).Values = new List<string>();
+                    foreach (string value in ((cmisPropertyUri)property).value)
+                    {
+                        ((PropertyUri)result).Values.Add(value);
+                    }
+                }
+            }
+
+            result.Id = property.propertyDefinitionId;
+            result.LocalName = property.localName;
+            result.DisplayName = property.displayName;
+            result.QueryName = property.queryName;
+
+            ConvertExtension(property, result);
+
+            return result;
+        }
+
+
+        public static cmisPropertiesType Convert(IProperties properties)
+        {
+            if (properties == null) { return null; }
+
+            cmisPropertiesType result = new cmisPropertiesType();
+            if (properties.PropertyList != null)
+            {
+                result.Items = new cmisProperty[properties.PropertyList.Count];
+                for (int i = 0; i < properties.PropertyList.Count; i++)
+                {
+                    result.Items[i] = Convert(properties.PropertyList[i]);
+                }
+            }
+
+            ConvertExtension(properties, result);
+
+            return result;
+        }
+
+        public static cmisProperty Convert(IPropertyData property)
+        {
+            if (property == null) { return null; }
+
+            cmisProperty result = null;
+
+            if (property is IPropertyString)
+            {
+                result = new cmisPropertyString();
+                IList<string> propValues = ((IPropertyString)property).Values;
+                if (propValues != null)
+                {
+                    ((cmisPropertyString)result).value = new string[propValues.Count];
+                    for (int i = 0; i < propValues.Count; i++)
+                    {
+                        ((cmisPropertyString)result).value[i] = propValues[i];
+                    }
+                }
+            }
+            else if (property is IPropertyId)
+            {
+                result = new cmisPropertyId();
+                IList<string> propValues = ((IPropertyId)property).Values;
+                if (propValues != null)
+                {
+                    ((cmisPropertyId)result).value = new string[propValues.Count];
+                    for (int i = 0; i < propValues.Count; i++)
+                    {
+                        ((cmisPropertyId)result).value[i] = propValues[i];
+                    }
+                }
+            }
+            else if (property is IPropertyInteger)
+            {
+                result = new cmisPropertyInteger();
+                IList<long> propValues = ((IPropertyInteger)property).Values;
+                if (propValues != null)
+                {
+                    ((cmisPropertyInteger)result).value = new string[propValues.Count];
+                    for (int i = 0; i < propValues.Count; i++)
+                    {
+                        ((cmisPropertyInteger)result).value[i] = propValues[i].ToString();
+                    }
+                }
+            }
+            else if (property is IPropertyBoolean)
+            {
+                result = new cmisPropertyInteger();
+                IList<bool> propValues = ((IPropertyBoolean)property).Values;
+                if (propValues != null)
+                {
+                    ((cmisPropertyBoolean)result).value = new bool[propValues.Count];
+                    for (int i = 0; i < propValues.Count; i++)
+                    {
+                        ((cmisPropertyBoolean)result).value[i] = propValues[i];
+                    }
+                }
+            }
+            else if (property is IPropertyDateTime)
+            {
+                result = new cmisPropertyDateTime();
+                IList<DateTime> propValues = ((IPropertyDateTime)property).Values;
+                if (propValues != null)
+                {
+                    ((cmisPropertyDateTime)result).value = new DateTime[propValues.Count];
+                    for (int i = 0; i < propValues.Count; i++)
+                    {
+                        ((cmisPropertyDateTime)result).value[i] = propValues[i];
+                    }
+                }
+            }
+            else if (property is IPropertyDecimal)
+            {
+                result = new cmisPropertyDecimal();
+                IList<decimal> propValues = ((IPropertyDecimal)property).Values;
+                if (propValues != null)
+                {
+                    ((cmisPropertyDecimal)result).value = new decimal[propValues.Count];
+                    for (int i = 0; i < propValues.Count; i++)
+                    {
+                        ((cmisPropertyDecimal)result).value[i] = propValues[i];
+                    }
+                }
+            }
+            else if (property is IPropertyHtml)
+            {
+                result = new cmisPropertyHtml();
+                IList<string> propValues = ((IPropertyHtml)property).Values;
+                if (propValues != null)
+                {
+                    ((cmisPropertyHtml)result).value = new string[propValues.Count];
+                    for (int i = 0; i < propValues.Count; i++)
+                    {
+                        ((cmisPropertyHtml)result).value[i] = propValues[i];
+                    }
+                }
+            }
+            else if (property is IPropertyUri)
+            {
+                result = new cmisPropertyUri();
+                IList<string> propValues = ((IPropertyUri)property).Values;
+                if (propValues != null)
+                {
+                    ((cmisPropertyUri)result).value = new string[propValues.Count];
+                    for (int i = 0; i < propValues.Count; i++)
+                    {
+                        ((cmisPropertyUri)result).value[i] = propValues[i];
+                    }
+                }
+            }
+
+            result.propertyDefinitionId = property.Id;
+            result.localName = property.LocalName;
+            result.displayName = property.DisplayName;
+            result.queryName = property.QueryName;
+
+            ConvertExtension(property, result);
+
+            return result;
+        }
+
+        public static IAllowableActions Convert(cmisAllowableActionsType allowableActions)
+        {
+            if (allowableActions == null) { return null; }
+
+            AllowableActions result = new AllowableActions();
+            result.Actions = new HashSet<string>();
+
+            if (allowableActions.canDeleteObject && allowableActions.canDeleteObjectSpecified)
+            { result.Actions.Add(Actions.CanDeleteObject); }
+
+            if (allowableActions.canUpdateProperties && allowableActions.canUpdatePropertiesSpecified)
+            { result.Actions.Add(Actions.CanUpdateProperties); }
+
+            if (allowableActions.canGetFolderTree && allowableActions.canGetFolderTreeSpecified)
+            { result.Actions.Add(Actions.CanGetFolderTree); }
+
+            if (allowableActions.canGetProperties && allowableActions.canGetPropertiesSpecified)
+            { result.Actions.Add(Actions.CanGetProperties); }
+
+            if (allowableActions.canGetObjectRelationships && allowableActions.canGetObjectRelationshipsSpecified)
+            { result.Actions.Add(Actions.CanGetObjectRelationships); }
+
+            if (allowableActions.canGetObjectParents && allowableActions.canGetObjectParentsSpecified)
+            { result.Actions.Add(Actions.CanGetObjectParents); }
+
+            if (allowableActions.canGetFolderParent && allowableActions.canGetFolderParentSpecified)
+            { result.Actions.Add(Actions.CanGetFolderParent); }
+
+            if (allowableActions.canGetDescendants && allowableActions.canGetDescendantsSpecified)
+            { result.Actions.Add(Actions.CanGetDescendants); }
+
+            if (allowableActions.canMoveObject && allowableActions.canMoveObjectSpecified)
+            { result.Actions.Add(Actions.CanMoveObject); }
+
+            if (allowableActions.canDeleteContentStream && allowableActions.canDeleteContentStreamSpecified)
+            { result.Actions.Add(Actions.CanDeleteContentStream); }
+
+            if (allowableActions.canCheckOut && allowableActions.canCheckOutSpecified)
+            { result.Actions.Add(Actions.CanCheckOut); }
+
+            if (allowableActions.canCancelCheckOut && allowableActions.canCancelCheckOutSpecified)
+            { result.Actions.Add(Actions.CanCancelCheckOut); }
+
+            if (allowableActions.canCheckIn && allowableActions.canCheckInSpecified)
+            { result.Actions.Add(Actions.CanCheckIn); }
+
+            if (allowableActions.canSetContentStream && allowableActions.canSetContentStreamSpecified)
+            { result.Actions.Add(Actions.CanSetContentStream); }
+
+            if (allowableActions.canGetAllVersions && allowableActions.canGetAllVersionsSpecified)
+            { result.Actions.Add(Actions.CanGetAllVersions); }
+
+            if (allowableActions.canAddObjectToFolder && allowableActions.canAddObjectToFolderSpecified)
+            { result.Actions.Add(Actions.CanAddObjectToFolder); }
+
+            if (allowableActions.canRemoveObjectFromFolder && allowableActions.canRemoveObjectFromFolderSpecified)
+            { result.Actions.Add(Actions.CanRemoveObjectFromFolder); }
+
+            if (allowableActions.canGetContentStream && allowableActions.canGetContentStreamSpecified)
+            { result.Actions.Add(Actions.CanGetContentStream); }
+
+            if (allowableActions.canApplyPolicy && allowableActions.canApplyPolicySpecified)
+            { result.Actions.Add(Actions.CanApplyPolicy); }
+
+            if (allowableActions.canGetAppliedPolicies && allowableActions.canGetAppliedPoliciesSpecified)
+            { result.Actions.Add(Actions.CanGetAppliedPolicies); }
+
+            if (allowableActions.canRemovePolicy && allowableActions.canRemovePolicySpecified)
+            { result.Actions.Add(Actions.CanRemovePolicy); }
+
+            if (allowableActions.canGetChildren && allowableActions.canGetChildrenSpecified)
+            { result.Actions.Add(Actions.CanGetChildren); }
+
+            if (allowableActions.canCreateDocument && allowableActions.canCreateDocumentSpecified)
+            { result.Actions.Add(Actions.CanCreateDocument); }
+
+            if (allowableActions.canCreateFolder && allowableActions.canCreateFolderSpecified)
+            { result.Actions.Add(Actions.CanCreateFolder); }
+
+            if (allowableActions.canCreateRelationship && allowableActions.canCreateRelationshipSpecified)
+            { result.Actions.Add(Actions.CanCreateRelationship); }
+
+            if (allowableActions.canDeleteTree && allowableActions.canDeleteTreeSpecified)
+            { result.Actions.Add(Actions.CanDeleteTree); }
+
+            if (allowableActions.canGetRenditions && allowableActions.canGetRenditionsSpecified)
+            { result.Actions.Add(Actions.CanGetRenditions); }
+
+            if (allowableActions.canGetACL && allowableActions.canGetACLSpecified)
+            { result.Actions.Add(Actions.CanGetAcl); }
+
+            if (allowableActions.canApplyACL && allowableActions.canApplyACLSpecified)
+            { result.Actions.Add(Actions.CanApplyAcl); }
+
+            ConvertExtension(allowableActions, result);
+
+            return result;
+        }
+
+        public static IAcl Convert(cmisAccessControlListType acl, bool? isExact)
+        {
+            if (acl == null) { return null; }
+
+            Acl result = new Acl();
+            if (acl.permission != null)
+            {
+                result.Aces = new List<IAce>();
+                foreach (cmisAccessControlEntryType ace in acl.permission)
+                {
+                    result.Aces.Add(Convert(ace));
+                }
+            }
+            result.IsExact = isExact;
+
+            ConvertExtension(acl, result);
+
+            return result;
+        }
+
+
+        public static IAcl Convert(cmisACLType acl)
+        {
+            if (acl == null) { return null; }
+
+            Acl result = new Acl();
+            if (acl.ACL != null && acl.ACL.permission != null)
+            {
+                result.Aces = new List<IAce>();
+                foreach (cmisAccessControlEntryType ace in acl.ACL.permission)
+                {
+                    result.Aces.Add(Convert(ace));
+                }
+            }
+            result.IsExact = (acl.exactSpecified ? (bool?)acl.exactSpecified : null);
+
+            ConvertExtension(acl, result);
+
+            return result;
+        }
+
+
+        public static IAce Convert(cmisAccessControlEntryType ace)
+        {
+            if (ace == null) { return null; }
+
+            Ace result = new Ace();
+            if (ace.principal != null)
+            {
+                Principal principal = new Principal();
+                principal.Id = ace.principal.principalId;
+                result.Principal = principal;
+
+                ConvertExtension(ace.principal, principal);
+            }
+            if (ace.permission != null)
+            {
+                result.Permissions = new List<string>();
+                foreach (string permission in ace.permission)
+                {
+                    result.Permissions.Add(permission);
+                }
+            }
+            result.IsDirect = ace.direct;
+
+            ConvertExtension(ace, result);
+
+            return result;
+        }
+
+        public static cmisAccessControlListType Convert(IAcl acl)
+        {
+            if (acl == null) { return null; }
+
+            cmisAccessControlListType result = new cmisAccessControlListType();
+            if (acl.Aces != null)
+            {
+                result.permission = new cmisAccessControlEntryType[acl.Aces.Count];
+                for (int i = 0; i < acl.Aces.Count; i++)
+                {
+                    result.permission[i] = Convert(acl.Aces[i]);
+                }
+            }
+
+            ConvertExtension(acl, result);
+
+            return result;
+        }
+
+        public static cmisAccessControlEntryType Convert(IAce ace)
+        {
+            if (ace == null) { return null; }
+
+            cmisAccessControlEntryType result = new cmisAccessControlEntryType();
+            if (ace.Principal != null)
+            {
+                result.principal = new cmisAccessControlPrincipalType();
+                result.principal.principalId = ace.Principal.Id;
+
+                ConvertExtension(ace.Principal, result.principal);
+            }
+            if (ace.Permissions != null)
+            {
+                result.permission = new string[ace.Permissions.Count];
+                for (int i = 0; i < ace.Permissions.Count; i++)
+                {
+                    result.permission[i] = ace.Permissions[i];
+                }
+            }
+            result.direct = ace.IsDirect;
+
+            ConvertExtension(ace, result);
+
+            return result;
+        }
+
+
+        public static IPolicyIdList Convert(cmisListOfIdsType policyIdList)
+        {
+            if (policyIdList == null) { return null; }
+
+            PolicyIdList result = new PolicyIdList();
+            if (policyIdList.id != null)
+            {
+                result.PolicyIds = new List<string>();
+                foreach (string id in policyIdList.id)
+                {
+                    result.PolicyIds.Add(id);
+                }
+            }
+
+            ConvertExtension(policyIdList, result);
+
+            return result;
+        }
+
+        public static cmisListOfIdsType ConvertPolicies(IList<string> policyIds)
+        {
+            if (policyIds == null) { return null; }
+
+            cmisListOfIdsType result = new cmisListOfIdsType();
+            result.id = new string[policyIds.Count];
+            for (int i = 0; i < policyIds.Count; i++)
+            {
+                result.id[i] = policyIds[i];
+            }
+
+            return result;
+        }
+
+
+        public static IRenditionData Convert(cmisRenditionType rendition)
+        {
+            if (rendition == null) { return null; }
+
+            RenditionData result = new RenditionData();
+            result.StreamId = rendition.streamId;
+            result.MimeType = rendition.mimetype;
+            result.Length = Int64.Parse(rendition.length);
+            result.Kind = rendition.kind;
+            result.Title = rendition.title;
+            result.Height = Int64.Parse(rendition.height);
+            result.Width = Int64.Parse(rendition.width);
+            result.RenditionDocumentId = rendition.renditionDocumentId;
+
+            ConvertExtension(rendition, result);
+
+            return result;
+        }
+
+        public static IChangeEventInfo Convert(cmisChangeEventType changeEvent)
+        {
+            if (changeEvent == null) { return null; }
+
+            ChangeEventInfo result = new ChangeEventInfo();
+            result.ChangeType = (ChangeType)CmisValue.SerializerToCmisEnum(changeEvent.changeType);
+            result.ChangeTime = changeEvent.changeTime;
+
+            ConvertExtension(changeEvent, result);
+
+            return result;
+        }
+
+        public static IObjectInFolderList Convert(cmisObjectInFolderListType list)
+        {
+            if (list == null) { return null; }
+
+            ObjectInFolderList result = new ObjectInFolderList();
+            if (list.objects != null)
+            {
+                result.Objects = new List<IObjectInFolderData>();
+                foreach (cmisObjectInFolderType fo in list.objects)
+                {
+                    result.Objects.Add(Convert(fo));
+                }
+            }
+            result.HasMoreItems = list.hasMoreItems;
+            if (list.numItems != null)
+            {
+                result.NumItems = Int64.Parse(list.numItems);
+            }
+
+            ConvertExtension(list, result);
+
+            return result;
+        }
+
+
+        public static IObjectInFolderData Convert(cmisObjectInFolderType objectInFolder)
+        {
+            if (objectInFolder == null) { return null; }
+
+            ObjectInFolderData result = new ObjectInFolderData();
+            result.Object = Convert(objectInFolder.@object);
+            result.PathSegment = objectInFolder.pathSegment;
+
+            ConvertExtension(objectInFolder, result);
+
+            return result;
+        }
+
+        public static IObjectInFolderContainer Convert(cmisObjectInFolderContainerType container)
+        {
+            if (container == null) { return null; }
+
+            ObjectInFolderContainer result = new ObjectInFolderContainer();
+            result.Object = Convert(container.objectInFolder);
+            if (container.children != null)
+            {
+                result.Children = new List<IObjectInFolderContainer>();
+                foreach (cmisObjectInFolderContainerType child in container.children)
+                {
+                    result.Children.Add(Convert(child));
+                }
+            }
+
+            ConvertExtension(container, result);
+
+            return result;
+        }
+
+        public static IObjectParentData Convert(cmisObjectParentsType parent)
+        {
+            if (parent == null) { return null; }
+
+            ObjectParentData result = new ObjectParentData();
+            result.Object = Convert(parent.@object);
+            result.RelativePathSegment = parent.relativePathSegment;
+
+            ConvertExtension(parent, result);
+
+            return result;
+        }
+
+        public static IObjectList Convert(cmisObjectListType list)
+        {
+            if (list == null) { return null; }
+
+            ObjectList result = new ObjectList();
+            if (list.objects != null)
+            {
+                result.Objects = new List<IObjectData>();
+                foreach (cmisObjectType obj in list.objects)
+                {
+                    result.Objects.Add(Convert(obj));
+                }
+            }
+
+            result.HasMoreItems = list.hasMoreItems;
+            result.NumItems = Int64.Parse(list.numItems);
+
+            ConvertExtension(list, result);
+
+            return result;
+        }
+
+        public static IContentStream Convert(cmisContentStreamType contentStream)
+        {
+            if (contentStream == null) { return null; }
+
+            ContentStream result = new ContentStream();
+            if (contentStream.length != null)
+            {
+                result.Length = Int64.Parse(contentStream.length);
+            }
+            result.MimeType = contentStream.mimeType;
+            result.FileName = contentStream.filename;
+            // Todo: enable real streaming
+            result.Stream = new MemoryStream(contentStream.stream);
+
+            ConvertExtension(contentStream, result);
+
+            return result;
+        }
+
+        public static cmisContentStreamType Convert(IContentStream contentStream)
+        {
+            if (contentStream == null) { return null; }
+
+            cmisContentStreamType result = new cmisContentStreamType();
+            result.length = contentStream.Length.ToString();
+            result.mimeType = contentStream.MimeType;
+            result.filename = contentStream.FileName;
+            if (contentStream.Stream != null)
+            {
+                if (contentStream.Stream is MemoryStream)
+                {
+                    result.stream = ((MemoryStream)contentStream.Stream).ToArray();
+                }
+                else
+                {
+                    MemoryStream memStream = new MemoryStream();
+                    byte[] buffer = new byte[4096];
+                    int bytes;
+                    while ((bytes = contentStream.Stream.Read(buffer, 0, buffer.Length)) > 0)
+                    {
+                        memStream.Write(buffer, 0, bytes);
+                    }
+                    result.stream = memStream.ToArray();
+                }
+            }
+
+            return result;
+        }
+
+        public static IFailedToDeleteData Convert(deleteTreeResponseFailedToDelete failedToDelete)
+        {
+            if (failedToDelete == null) { return null; }
+
+            FailedToDeleteData result = new FailedToDeleteData();
+            if (failedToDelete.objectIds != null)
+            {
+                result.Ids = new List<string>();
+                foreach (string id in failedToDelete.objectIds)
+                {
+                    result.Ids.Add(id);
+                }
+            }
+
+            ConvertExtension(failedToDelete, result);
+
+            return result;
+        }
+
+        public static T[] ConvertList<T>(IList<T> list)
+        {
+            if (list == null) { return null; }
+
+            T[] result = new T[list.Count];
+            for (int i = 0; i < list.Count; i++)
+            {
+                result[i] = list[i];
+            }
+
+            return result;
+        }
+
+        /// <summary>
+        /// Converts an extension.
+        /// </summary> 
+        public static void ConvertExtension(object source, IExtensionsData target)
+        {
+            if (source == null || target == null) { return; }
+
+            Type type = source.GetType();
+            PropertyInfo propInfo = type.GetProperty("Any");
+            if (propInfo == null)
+            {
+                return;
+            }
+
+            XmlElement[] elements = (XmlElement[])propInfo.GetValue(source, null);
+            if (elements == null)
+            {
+                return;
+            }
+
+            target.Extensions = new List<ICmisExtensionElement>();
+            foreach (XmlElement xmlElement in elements)
+            {
+                ICmisExtensionElement element = CreateCmisExtensionElement(xmlElement);
+                if (element != null)
+                {
+                    target.Extensions.Add(element);
+                }
+            }
+        }
+
+        private static ICmisExtensionElement CreateCmisExtensionElement(XmlNode xmlElement)
+        {
+            CmisExtensionElement result = new CmisExtensionElement();
+            result.Name = xmlElement.Name;
+            result.Namespace = xmlElement.NamespaceURI;
+
+            if (xmlElement.Attributes != null && xmlElement.Attributes.Count > 0)
+            {
+                result.Attributes = new Dictionary<string, string>();
+                foreach (XmlAttribute attr in xmlElement.Attributes)
+                {
+                    result.Attributes[attr.Name] = attr.Value;
+                }
+            }
+
+            if (xmlElement.HasChildNodes)
+            {
+                result.Children = new List<ICmisExtensionElement>();
+                foreach (XmlNode node in xmlElement.ChildNodes)
+                {
+                    ICmisExtensionElement element = CreateCmisExtensionElement(node);
+                    if (element != null)
+                    {
+                        result.Children.Add(element);
+                    }
+                }
+            }
+            else
+            {
+                result.Value = xmlElement.Value;
+            }
+
+            return result;
+        }
+
+        /// <summary>
+        /// Converts an extension.
+        /// </summary>
+        public static cmisExtensionType ConvertExtension(IExtensionsData extension)
+        {
+            if (extension == null || extension.Extensions == null) { return null; }
+
+            XmlDocument doc = new XmlDocument();
+
+            List<XmlElement> elements = new List<XmlElement>();
+            foreach (ICmisExtensionElement element in extension.Extensions)
+            {
+                if (element == null) { continue; }
+                elements.Add(CreateXmlElement(doc, element));
+            }
+
+            cmisExtensionType result = new cmisExtensionType();
+            result.Any = elements.ToArray();
+
+            return result;
+        }
+
+        public static void ConvertExtension(IExtensionsData source, object target)
+        {
+            if (source == null || source.Extensions == null || target == null)
+            {
+                return;
+            }
+
+            Type type = target.GetType();
+            PropertyInfo propInfo = type.GetProperty("Any");
+            if (propInfo == null)
+            {
+                return;
+            }
+
+            XmlDocument doc = new XmlDocument();
+
+            List<XmlElement> elements = new List<XmlElement>();
+            foreach (ICmisExtensionElement element in source.Extensions)
+            {
+                if (element == null) { continue; }
+                elements.Add(CreateXmlElement(doc, element));
+            }
+
+            propInfo.SetValue(target, elements.ToArray(), null);
+        }
+
+        private static XmlElement CreateXmlElement(XmlDocument doc, ICmisExtensionElement element)
+        {
+            if (element == null)
+            {
+                return null;
+            }
+
+            XmlElement result = doc.CreateElement(element.Name, element.Namespace);
+
+            if (element.Attributes != null)
+            {
+                foreach (string key in element.Attributes.Keys)
+                {
+                    XmlAttribute attr = doc.CreateAttribute(key);
+                    attr.Value = element.Attributes[key];
+                    result.Attributes.Append(attr);
+                }
+            }
+
+            if (element.Value != null)
+            {
+                result.Value = element.Value;
+            }
+            else if (element.Children != null)
+            {
+                List<XmlElement> children = new List<XmlElement>();
+                foreach (ICmisExtensionElement child in element.Children)
+                {
+                    XmlElement xml = CreateXmlElement(doc, child);
+                    if (xml != null)
+                    {
+                        result.AppendChild(xml);
+                    }
+                }
+            }
+
+            return result;
+        }
+
+        public static string GetXmlEnumAttributeValue(Enum xsdEnum)
+        {
+            FieldInfo fieldInfo = xsdEnum.GetType().GetField(xsdEnum.ToString());
+            XmlEnumAttribute[] xmlAttr = fieldInfo.GetCustomAttributes(typeof(XmlEnumAttribute), false) as XmlEnumAttribute[];
+
+            if (xmlAttr.Length == 0)
+            {
+                return null;
+            }
+
+            return xmlAttr[0].Name;
+        }
+    }
+}

Added: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/http.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/http.cs?rev=1061233&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/http.cs (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/http.cs Thu Jan 20 11:38:48 2011
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Net;
+using DotCMIS.Binding.Impl;
+using DotCMIS.Enums;
+using DotCMIS.Exceptions;
+using System.Web;
+using System.Text;
+
+namespace DotCMIS.Binding
+{
+    internal static class HttpUtils
+    {
+        public delegate void Output(Stream stream);
+
+        public static Response InvokeGET(UrlBuilder url, BindingSession session)
+        {
+            return Invoke(url, "GET", null, null, session, null, null);
+        }
+
+        public static Response InvokeGET(UrlBuilder url, BindingSession session, int? offset, int? length)
+        {
+            return Invoke(url, "GET", null, null, session, offset, length);
+        }
+
+        public static Response InvokePOST(UrlBuilder url, String contentType, Output writer, BindingSession session)
+        {
+            return Invoke(url, "POST", contentType, writer, session, null, null);
+        }
+
+        public static Response InvokePUT(UrlBuilder url, String contentType, Output writer, BindingSession session)
+        {
+            return Invoke(url, "PUT", contentType, writer, session, null, null);
+        }
+
+        public static Response InvokeDELETE(UrlBuilder url, BindingSession session)
+        {
+            return Invoke(url, "DELETE", null, null, session, null, null);
+        }
+
+        private static Response Invoke(UrlBuilder url, String method, String contentType, Output writer, BindingSession session,
+                int? offset, int? length)
+        {
+            try
+            {
+                // log before connect
+                Trace.WriteLine(method + " " + url);
+
+                // create connection           
+                HttpWebRequest conn = (HttpWebRequest)WebRequest.Create(url.Url);
+                conn.Method = method;
+
+                // set content type
+                if (contentType != null)
+                {
+                    conn.ContentType = contentType;
+                }
+
+                // authenticate
+                AbstractAuthenticationProvider authProvider = session.GetAuthenticationProvider();
+                if (authProvider != null)
+                {
+                    conn.PreAuthenticate = true;
+                    authProvider.Authenticate(conn);
+                }
+
+                // range
+                if (offset != null && length != null)
+                {
+                    conn.AddRange(offset ?? 0, offset + length - 1 ?? 0);
+                }
+                else if (offset != null)
+                {
+                    conn.AddRange(offset ?? 0);
+                }
+
+                // send data
+                if (writer != null)
+                {
+                    conn.SendChunked = true;
+                    conn.AllowWriteStreamBuffering = false;
+                    Stream requestStream = conn.GetRequestStream();
+                    writer(requestStream);
+                    requestStream.Close();
+                }
+
+                // connect
+                try
+                {
+                    HttpWebResponse response = (HttpWebResponse)conn.GetResponse();
+                    return new Response(response);
+                }
+                catch (WebException we)
+                {
+                    return new Response(we);
+                }
+            }
+            catch (Exception e)
+            {
+                throw new CmisConnectionException("Cannot access " + url + ": " + e.Message, e);
+            }
+        }
+
+        internal class Response
+        {
+            private WebResponse response;
+
+            public HttpStatusCode StatusCode { get; private set; }
+            public string Message { get; private set; }
+            public Stream Stream { get; private set; }
+            public string ErrorContent { get; private set; }
+            public string ContentType { get; private set; }
+            public long? ContentLength { get; private set; }
+
+            public Response(HttpWebResponse httpResponse)
+            {
+                this.response = httpResponse;
+                StatusCode = httpResponse.StatusCode;
+                Message = httpResponse.StatusDescription;
+                ContentType = httpResponse.ContentType;
+                ContentLength = httpResponse.ContentLength == -1 ? null : (long?)httpResponse.ContentLength;
+
+                if (httpResponse.StatusCode == HttpStatusCode.OK ||
+                    httpResponse.StatusCode == HttpStatusCode.Created ||
+                    httpResponse.StatusCode == HttpStatusCode.NonAuthoritativeInformation ||
+                    httpResponse.StatusCode == HttpStatusCode.PartialContent)
+                {
+                    Stream = new BufferedStream(httpResponse.GetResponseStream(), 64 * 1024);
+                }
+                else
+                {
+                    try { httpResponse.Close(); }
+                    catch (Exception) { }
+                }
+            }
+
+            public Response(WebException exception)
+            {
+                response = exception.Response;
+
+                if (response is HttpWebResponse)
+                {
+                    HttpWebResponse httpResponse = (HttpWebResponse)response;
+                    StatusCode = httpResponse.StatusCode;
+                    Message = httpResponse.StatusDescription;
+                    ContentType = httpResponse.ContentType;
+
+                    if (ContentType != null && ContentType.ToLower().StartsWith("text/"))
+                    {
+                        StringBuilder sb = new StringBuilder();
+
+                        using (StreamReader sr = new StreamReader(httpResponse.GetResponseStream()))
+                        {
+                            string s;
+                            while ((s = sr.ReadLine()) != null)
+                            {
+                                sb.Append(s);
+                                sb.Append('\n');
+                            }
+                        }
+
+                        ErrorContent = sb.ToString();
+                    }
+                }
+                else
+                {
+                    StatusCode = HttpStatusCode.InternalServerError;
+                    Message = exception.Status.ToString();
+                }
+
+                try { response.Close(); }
+                catch (Exception) { }
+            }
+        }
+    }
+
+    internal class UrlBuilder
+    {
+        private UriBuilder uri;
+
+        public Uri Url
+        {
+            get { return uri.Uri; }
+        }
+
+        public UrlBuilder(string url)
+        {
+            if (url == null)
+            {
+                throw new ArgumentNullException("url");
+            }
+
+            uri = new UriBuilder(url);
+        }
+
+        public UrlBuilder AddParameter(string name, object value)
+        {
+            if ((name == null) || (value == null))
+            {
+                return this;
+            }
+
+            string valueStr = HttpUtility.UrlEncode(NormalizeParameter(value));
+
+            if (uri.Query != null && uri.Query.Length > 1)
+            {
+                uri.Query = uri.Query.Substring(1) + "&" + name + "=" + valueStr;
+            }
+            else
+            {
+                uri.Query = name + "=" + valueStr;
+            }
+
+            return this;
+        }
+
+        public static string NormalizeParameter(object value)
+        {
+            if (value == null)
+            {
+                return null;
+            }
+            else if (value is Enum)
+            {
+                return ((Enum)value).GetCmisValue();
+            }
+            else if (value is bool)
+            {
+                return (bool)value ? "true" : "false";
+            }
+
+            return value.ToString();
+        }
+
+        public override string ToString()
+        {
+            return Url.ToString();
+        }
+    }
+}

Added: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/services.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/services.cs?rev=1061233&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/services.cs (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/services.cs Thu Jan 20 11:38:48 2011
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+using System.Collections.Generic;
+using DotCMIS.Data;
+using DotCMIS.Data.Extensions;
+using DotCMIS.Enums;
+
+namespace DotCMIS.Binding.Services
+{
+    public interface IRepositoryService
+    {
+        IList<IRepositoryInfo> GetRepositoryInfos(IExtensionsData extension);
+
+        IRepositoryInfo GetRepositoryInfo(string repositoryId, IExtensionsData extension);
+
+        ITypeDefinitionList GetTypeChildren(string repositoryId, string typeId, bool? includePropertyDefinitions,
+            long? maxItems, long? skipCount, IExtensionsData extension);
+
+        IList<ITypeDefinitionContainer> GetTypeDescendants(string repositoryId, string typeId, long? depth,
+            bool? includePropertyDefinitions, IExtensionsData extension);
+
+        ITypeDefinition GetTypeDefinition(string repositoryId, string typeId, IExtensionsData extension);
+    }
+
+    public interface INavigationService
+    {
+        IObjectInFolderList GetChildren(string repositoryId, string folderId, string filter, string orderBy,
+            bool? includeAllowableActions, IncludeRelationships? includeRelationships, string renditionFilter,
+            bool? includePathSegment, long? maxItems, long? skipCount, IExtensionsData extension);
+
+        IList<IObjectInFolderContainer> GetDescendants(string repositoryId, string folderId, long? depth, string filter,
+            bool? includeAllowableActions, IncludeRelationships? includeRelationships, string renditionFilter,
+            bool? includePathSegment, IExtensionsData extension);
+
+        IList<IObjectInFolderContainer> GetFolderTree(string repositoryId, string folderId, long? depth, string filter,
+            bool? includeAllowableActions, IncludeRelationships? includeRelationships, string renditionFilter,
+            bool? includePathSegment, IExtensionsData extension);
+
+        IList<IObjectParentData> GetObjectParents(string repositoryId, string objectId, string filter,
+            bool? includeAllowableActions, IncludeRelationships? includeRelationships, string renditionFilter,
+            bool? includeRelativePathSegment, IExtensionsData extension);
+
+        IObjectData GetFolderParent(string repositoryId, string folderId, string filter, ExtensionsData extension);
+
+        IObjectList GetCheckedOutDocs(string repositoryId, string folderId, string filter, string orderBy,
+            bool? includeAllowableActions, IncludeRelationships? includeRelationships, string renditionFilter,
+            long? maxItems, long? skipCount, IExtensionsData extension);
+    }
+
+    public interface IObjectService
+    {
+        string CreateDocument(string repositoryId, IProperties properties, string folderId, IContentStream contentStream,
+            VersioningState? versioningState, IList<string> policies, IAcl addAces, IAcl removeAces, IExtensionsData extension);
+
+        string CreateDocumentFromSource(string repositoryId, string sourceId, IProperties properties, string folderId,
+            VersioningState? versioningState, IList<string> policies, IAcl addAces, IAcl removeAces, IExtensionsData extension);
+
+        string CreateFolder(string repositoryId, IProperties properties, string folderId, IList<string> policies,
+            IAcl addAces, IAcl removeAces, IExtensionsData extension);
+
+        string CreateRelationship(string repositoryId, IProperties properties, IList<string> policies, IAcl addAces,
+            IAcl removeAces, IExtensionsData extension);
+
+        string CreatePolicy(string repositoryId, IProperties properties, string folderId, IList<string> policies,
+            IAcl addAces, IAcl removeAces, IExtensionsData extension);
+
+        IAllowableActions GetAllowableActions(string repositoryId, string objectId, IExtensionsData extension);
+
+        IProperties GetProperties(string repositoryId, string objectId, string filter, IExtensionsData extension);
+
+        IList<IRenditionData> GetRenditions(string repositoryId, string objectId, string renditionFilter,
+            long? maxItems, long? skipCount, IExtensionsData extension);
+
+        IObjectData GetObject(string repositoryId, string objectId, string filter, bool? includeAllowableActions,
+            IncludeRelationships? includeRelationships, string renditionFilter, bool? includePolicyIds,
+            bool? includeAcl, IExtensionsData extension);
+
+        IObjectData GetObjectByPath(string repositoryId, string path, string filter, bool? includeAllowableActions,
+            IncludeRelationships? includeRelationships, string renditionFilter, bool? includePolicyIds, bool? includeAcl,
+            IExtensionsData extension);
+
+        IContentStream GetContentStream(string repositoryId, string objectId, string streamId, long? offset, long? length,
+            IExtensionsData extension);
+
+        void UpdateProperties(string repositoryId, ref string objectId, ref string changeToken, IProperties properties,
+            IExtensionsData extension);
+
+        void MoveObject(string repositoryId, ref string objectId, string targetFolderId, string sourceFolderId,
+            IExtensionsData extension);
+
+        void DeleteObject(string repositoryId, string objectId, bool? allVersions, IExtensionsData extension);
+
+        IFailedToDeleteData DeleteTree(string repositoryId, string folderId, bool? allVersions, UnfileObject? unfileObjects,
+            bool? continueOnFailure, ExtensionsData extension);
+
+        void SetContentStream(string repositoryId, ref string objectId, bool? overwriteFlag, ref string changeToken,
+            IContentStream contentStream, IExtensionsData extension);
+
+        void DeleteContentStream(string repositoryId, ref string objectId, ref string changeToken, IExtensionsData extension);
+    }
+
+    public interface IVersioningService
+    {
+        void CheckOut(string repositoryId, ref string objectId, IExtensionsData extension, out bool? contentCopied);
+
+        void CancelCheckOut(string repositoryId, string objectId, IExtensionsData extension);
+
+        void CheckIn(string repositoryId, ref string objectId, bool? major, IProperties properties,
+            IContentStream contentStream, string checkinComment, List<string> policies, IAcl addAces, IAcl removeAces,
+            IExtensionsData extension);
+
+        IObjectData GetObjectOfLatestVersion(string repositoryId, string objectId, string versionSeriesId, bool major,
+            string filter, bool? includeAllowableActions, IncludeRelationships? includeRelationships,
+            string renditionFilter, bool? includePolicyIds, bool? includeAcl, IExtensionsData extension);
+
+        IProperties GetPropertiesOfLatestVersion(string repositoryId, string objectId, string versionSeriesId, bool major,
+            string filter, IExtensionsData extension);
+
+        IList<IObjectData> GetAllVersions(string repositoryId, string objectId, string versionSeriesId, string filter,
+            bool? includeAllowableActions, IExtensionsData extension);
+    }
+
+    public interface IRelationshipService
+    {
+        IObjectList GetObjectRelationships(string repositoryId, string objectId, bool? includeSubRelationshipTypes,
+            RelationshipDirection? relationshipDirection, string typeId, string filter, bool? includeAllowableActions,
+            long? maxItems, long? skipCount, IExtensionsData extension);
+    }
+
+    public interface IDiscoveryService
+    {
+        IObjectList Query(string repositoryId, string statement, bool? searchAllVersions,
+           bool? includeAllowableActions, IncludeRelationships? includeRelationships, string renditionFilter,
+           long? maxItems, long? skipCount, IExtensionsData extension);
+
+        IObjectList GetContentChanges(string repositoryId, ref string changeLogToken, bool? includeProperties,
+           string filter, bool? includePolicyIds, bool? includeAcl, long? maxItems, IExtensionsData extension);
+    }
+
+    public interface IMultiFilingService
+    {
+        void AddObjectToFolder(string repositoryId, string objectId, string folderId, bool? allVersions, IExtensionsData extension);
+
+        void RemoveObjectFromFolder(string repositoryId, string objectId, string folderId, IExtensionsData extension);
+    }
+
+    public interface IAclService
+    {
+        IAcl GetAcl(string repositoryId, string objectId, bool? onlyBasicPermissions, IExtensionsData extension);
+
+        IAcl ApplyAcl(string repositoryId, string objectId, IAcl addAces, IAcl removeAces, AclPropagation? aclPropagation,
+            IExtensionsData extension);
+    }
+
+    public interface IPolicyService
+    {
+        void ApplyPolicy(string repositoryId, string policyId, string objectId, IExtensionsData extension);
+
+        void RemovePolicy(string repositoryId, string policyId, string objectId, IExtensionsData extension);
+
+        IList<IObjectData> GetAppliedPolicies(string repositoryId, string objectId, string filter, IExtensionsData extension);
+    }
+}



Mime
View raw message