- added object type implementation

git-svn-id: https://svn.apache.org/repos/asf/incubator/chemistry/dotcmis/trunk@1064131 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/DotCMIS/DotCMIS.csproj b/DotCMIS/DotCMIS.csproj
index a8f17c6..037c7bb 100644
--- a/DotCMIS/DotCMIS.csproj
+++ b/DotCMIS/DotCMIS.csproj
@@ -56,7 +56,9 @@
     <Compile Include="client\client-caches.cs" />

     <Compile Include="client\client-intf.cs" />

     <Compile Include="client\client-impl.cs" />

+    <Compile Include="client\client-objectfactory.cs" />

     <Compile Include="client\client-objects.cs" />

+    <Compile Include="client\client-types.cs" />

     <Compile Include="const.cs" />

     <Compile Include="data\data-impl.cs" />

     <Compile Include="data\data-intf.cs" />

diff --git a/DotCMIS/binding/converter.cs b/DotCMIS/binding/converter.cs
index 9fd836a..c261cc8 100644
--- a/DotCMIS/binding/converter.cs
+++ b/DotCMIS/binding/converter.cs
@@ -162,7 +162,7 @@
                 return null;

             }

 

-            TypeDefinition result = null;

+            AbstractTypeDefinition result = null;

             if (typeDef is cmisTypeDocumentDefinitionType)

             {

                 DocumentTypeDefinition docType = new DocumentTypeDefinition();

@@ -213,7 +213,7 @@
             result.DisplayName = typeDef.displayName;

             result.QueryName = typeDef.queryName;

             result.Description = typeDef.description;

-            result.BaseTypeId = (BaseTypeId?)CmisValue.SerializerToCmisEnum(typeDef.baseId);

+            result.BaseTypeId = (BaseTypeId)CmisValue.SerializerToCmisEnum(typeDef.baseId);

             result.ParentTypeId = typeDef.parentId;

             result.IsCreatable = typeDef.creatable;

             result.IsFileable = typeDef.fileable;

diff --git a/DotCMIS/client/client-impl.cs b/DotCMIS/client/client-impl.cs
index da9c2fe..b9cc86e 100644
--- a/DotCMIS/client/client-impl.cs
+++ b/DotCMIS/client/client-impl.cs
@@ -152,15 +152,18 @@
     public class Session : ISession

     {

         protected static IOperationContext FallbackContext = new OperationContext(null, false, true, false, IncludeRelationshipsFlag.None, null, true, null, true, 100);

-        protected IOperationContext context = FallbackContext;

 

         protected IDictionary<string, string> parameters;

-        protected ICache cache;

-

         private object sessionLock = new object();

 

         public ICmisBinding Binding { get; protected set; }

         public IRepositoryInfo RepositoryInfo { get; protected set; }

+        public string RepositoryId { get { return RepositoryInfo.Id; } }

+

+        public IObjectFactory ObjectFactory { get; protected set; }

+        protected ICache Cache { get; set; }

+

+        private IOperationContext context = FallbackContext;

         public IOperationContext DefaultContext

         {

             get

@@ -198,7 +201,8 @@
 

             this.parameters = parameters;

 

-            cache = CreateCache();

+            ObjectFactory = CreateObjectFactory();

+            Cache = CreateCache();

         }

 

         public void Connect()

@@ -254,12 +258,44 @@
             }

         }

 

+        protected IObjectFactory CreateObjectFactory()

+        {

+            try

+            {

+                string ofName;

+                Type ofType;

+

+                if (parameters.TryGetValue(SessionParameter.ObjectFactoryClass, out ofName))

+                {

+                    ofType = Type.GetType(ofName);

+                }

+                else

+                {

+                    ofType = typeof(ObjectFactory);

+                }

+

+                object ofObject = Activator.CreateInstance(ofType);

+                if (!(ofObject is IObjectFactory))

+                {

+                    throw new Exception("Class does not implement IObjectFactory!");

+                }

+

+                ((IObjectFactory)ofObject).Initialize(this, parameters);

+

+                return (IObjectFactory)ofObject;

+            }

+            catch (Exception e)

+            {

+                throw new ArgumentException("Unable to create object factory: " + e, e);

+            }

+        }

+

         public void Clear()

         {

             Lock();

             try

             {

-                cache = CreateCache();

+                Cache = CreateCache();

                 Binding.ClearAllCaches();

             }

             finally

@@ -288,14 +324,13 @@
             return new ObjectId(id);

         }

 

-        // services

-

-        public IObjectFactory ObjectFactory { get; protected set; }

-

         // types

 

         public IObjectType GetTypeDefinition(string typeId)

-        { throw new CmisNotSupportedException("Client not implemented!"); }

+        {

+            ITypeDefinition typeDefinition = Binding.GetRepositoryService().GetTypeDefinition(RepositoryId, typeId, null);

+            return ObjectFactory.ConvertTypeDefinition(typeDefinition);

+        }

 

         public IItemIterable<IObjectType> GetTypeChildren(string typeId, bool includePropertyDefinitions)

         { throw new CmisNotSupportedException("Client not implemented!"); }

diff --git a/DotCMIS/client/client-intf.cs b/DotCMIS/client/client-intf.cs
index 9bc7d8d..4de4142 100644
--- a/DotCMIS/client/client-intf.cs
+++ b/DotCMIS/client/client-intf.cs
@@ -175,12 +175,32 @@
     public interface IObjectType : ITypeDefinition

     {

         bool IsBaseType { get; }

-        IObjectType BaseType { get; }

-        IObjectType ParentType { get; }

+        IObjectType GetBaseType();

+        IObjectType GetParentType();

         IItemIterable<IObjectType> GetChildren();

         IList<ITree<IObjectType>> GetDescendants(int depth);

     }

 

+    public interface IDocumentType : IObjectType

+    {

+        bool? IsVersionable { get; }

+        ContentStreamAllowed? ContentStreamAllowed { get; }

+    }

+

+    public interface IFolderType : IObjectType

+    {

+    }

+

+    public interface IRelationshipType : IObjectType

+    {

+        IList<IObjectType> GetAllowedSourceTypes { get; }

+        IList<IObjectType> GetAllowedTargetTypes { get; }

+    }

+

+    public interface IPolicyType : IObjectType

+    {

+    }

+

     public interface IItemIterable<T>

     {

         IItemIterable<T> SkipTo(long position);

diff --git a/DotCMIS/client/client-objectfactory.cs b/DotCMIS/client/client-objectfactory.cs
new file mode 100644
index 0000000..43d6d63
--- /dev/null
+++ b/DotCMIS/client/client-objectfactory.cs
@@ -0,0 +1,93 @@
+/*

+ * 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 System.Linq;

+using System.Text;

+using DotCMIS.Data;

+using System.IO;

+using DotCMIS.Enums;

+using DotCMIS.Exceptions;

+

+namespace DotCMIS.Client

+{

+    public class ObjectFactory : IObjectFactory

+    {

+        private ISession session;

+

+        public void Initialize(ISession session, IDictionary<string, string> parameters)

+        {

+            this.session = session;

+        }

+

+        // ACL and ACE

+        public IAcl ConvertAces(IList<IAce> aces) { return null; }

+        public IAcl CreateAcl(IList<IAce> aces) { return null; }

+        public IAce CreateAce(string principal, List<string> permissions) { return null; }

+

+        // policies

+        public IList<string> ConvertPolicies(IList<IPolicy> policies) { return null; }

+

+        // renditions

+        public IRendition ConvertRendition(string objectId, IRenditionData rendition) { return null; }

+

+        // content stream

+        public IContentStream CreateContentStream(string filename, long length, string mimetype, Stream stream) { return null; }

+        public IContentStream ConvertContentStream(IContentStream contentStream) { return null; }

+

+        // types

+        public IObjectType ConvertTypeDefinition(ITypeDefinition typeDefinition)

+        {

+            if (typeDefinition is IDocumentTypeDefinition)

+            {

+                return new DocumentType(session, (IDocumentTypeDefinition)typeDefinition);

+            }

+            else if (typeDefinition is IFolderTypeDefinition)

+            {

+                return new FolderType(session, (IFolderTypeDefinition)typeDefinition);

+            }

+            else if (typeDefinition is IRelationshipTypeDefinition)

+            {

+                return new RelationshipType(session, (IRelationshipTypeDefinition)typeDefinition);

+            }

+            else if (typeDefinition is IPolicyTypeDefinition)

+            {

+                return new PolicyType(session, (IPolicyTypeDefinition)typeDefinition);

+            }

+            else

+            {

+                throw new CmisRuntimeException("Unknown base type!");

+            }

+        }

+

+        public IObjectType GetTypeFromObjectData(IObjectData objectData) { return null; }

+

+        // properties

+        public IProperty CreateProperty(IPropertyDefinition type, IList<object> values) { return null; }

+        public IDictionary<string, IProperty> ConvertProperties(IObjectType objectType, IProperties properties) { return null; }

+        public IProperties ConvertProperties(IDictionary<string, object> properties, IObjectType type, HashSet<Updatability> updatabilityFilter) { return null; }

+        public IList<IPropertyData> ConvertQueryProperties(IProperties properties) { return null; }

+

+        // objects

+        public ICmisObject ConvertObject(IObjectData objectData, IOperationContext context) { return null; }

+        public IQueryResult ConvertQueryResult(IObjectData objectData) { return null; }

+        public IChangeEvent ConvertChangeEvent(IObjectData objectData) { return null; }

+        public IChangeEvents ConvertChangeEvents(String changeLogToken, IObjectList objectList) { return null; }

+    }

+}

diff --git a/DotCMIS/client/client-types.cs b/DotCMIS/client/client-types.cs
new file mode 100644
index 0000000..c559981
--- /dev/null
+++ b/DotCMIS/client/client-types.cs
@@ -0,0 +1,205 @@
+/*

+ * 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 System.Linq;

+using System.Text;

+using DotCMIS.Enums;

+using DotCMIS.Data;

+

+namespace DotCMIS.Client

+{

+    internal class ObjectTypeHelper

+    {

+        private ISession session;

+        private IObjectType objectType;

+        private IObjectType baseType;

+        private IObjectType parentType;

+

+        public ObjectTypeHelper(ISession session, IObjectType objectType)

+        {

+            this.session = session;

+            this.objectType = objectType;

+        }

+

+        public ISession Session { get { return session; } }

+

+        public bool IsBaseType { get { return objectType.ParentTypeId == null; } }

+

+        public IObjectType GetBaseType()

+        {

+            if (IsBaseType) { return null; }

+            if (baseType != null) { return baseType; }

+

+            baseType = session.GetTypeDefinition(objectType.BaseTypeId.GetCmisValue());

+

+            return baseType;

+        }

+

+        public IObjectType GetParentType()

+        {

+            if (parentType != null) { return parentType; }

+            if (objectType.ParentTypeId == null) { return null; }

+

+            parentType = session.GetTypeDefinition(objectType.ParentTypeId);

+

+            return parentType;

+        }

+

+        public IItemIterable<IObjectType> GetChildren()

+        {

+            return session.GetTypeChildren(objectType.Id, true);

+        }

+

+        public IList<ITree<IObjectType>> GetDescendants(int depth)

+        {

+            return session.GetTypeDescendants(objectType.Id, depth, true);

+        }

+    }

+

+    public class DocumentType : DocumentTypeDefinition, IDocumentType

+    {

+        private ObjectTypeHelper helper;

+

+        public DocumentType(ISession session, IDocumentTypeDefinition typeDefinition)

+        {

+            Initialize(typeDefinition);

+            ContentStreamAllowed = typeDefinition.ContentStreamAllowed;

+            IsVersionable = typeDefinition.IsVersionable;

+            helper = new ObjectTypeHelper(session, this);

+        }

+

+        public IObjectType GetBaseType() { return helper.GetBaseType(); }

+

+        public IItemIterable<IObjectType> GetChildren() { return helper.GetChildren(); }

+

+        public IList<ITree<IObjectType>> GetDescendants(int depth) { return helper.GetDescendants(depth); }

+

+        public IObjectType GetParentType() { return helper.GetParentType(); }

+

+        public bool IsBaseType { get { return helper.IsBaseType; } }

+    }

+

+    public class FolderType : FolderTypeDefinition, IFolderType

+    {

+        private ObjectTypeHelper helper;

+

+        public FolderType(ISession session, IFolderTypeDefinition typeDefinition)

+        {

+            Initialize(typeDefinition);

+            helper = new ObjectTypeHelper(session, this);

+        }

+

+        public IObjectType GetBaseType() { return helper.GetBaseType(); }

+

+        public IItemIterable<IObjectType> GetChildren() { return helper.GetChildren(); }

+

+        public IList<ITree<IObjectType>> GetDescendants(int depth) { return helper.GetDescendants(depth); }

+

+        public IObjectType GetParentType() { return helper.GetParentType(); }

+

+        public bool IsBaseType { get { return helper.IsBaseType; } }

+    }

+

+    public class RelationshipType : RelationshipTypeDefinition, IRelationshipType

+    {

+        private ObjectTypeHelper helper;

+        private IList<IObjectType> allowedSourceTypes;

+        private IList<IObjectType> allowedTargetTypes;

+

+        public RelationshipType(ISession session, IRelationshipTypeDefinition typeDefinition)

+        {

+            Initialize(typeDefinition);

+            helper = new ObjectTypeHelper(session, this);

+        }

+

+        public IObjectType GetBaseType() { return helper.GetBaseType(); }

+

+        public IItemIterable<IObjectType> GetChildren() { return helper.GetChildren(); }

+

+        public IList<ITree<IObjectType>> GetDescendants(int depth) { return helper.GetDescendants(depth); }

+

+        public IObjectType GetParentType() { return helper.GetParentType(); }

+

+        public bool IsBaseType { get { return helper.IsBaseType; } }

+

+        public IList<IObjectType> GetAllowedSourceTypes

+        {

+            get

+            {

+                if (allowedSourceTypes == null)

+                {

+                    IList<string> ids = AllowedSourceTypeIds;

+                    IList<IObjectType> types = new List<IObjectType>(ids == null ? 0 : ids.Count);

+                    if (ids != null)

+                    {

+                        foreach (String id in ids)

+                        {

+                            types.Add(helper.Session.GetTypeDefinition(id));

+                        }

+                    }

+                    allowedSourceTypes = types;

+                }

+                return allowedSourceTypes;

+            }

+        }

+

+        public IList<IObjectType> GetAllowedTargetTypes

+        {

+            get

+            {

+                if (allowedTargetTypes == null)

+                {

+                    IList<string> ids = AllowedTargetTypeIds;

+                    IList<IObjectType> types = new List<IObjectType>(ids == null ? 0 : ids.Count);

+                    if (ids != null)

+                    {

+                        foreach (String id in ids)

+                        {

+                            types.Add(helper.Session.GetTypeDefinition(id));

+                        }

+                    }

+                    allowedTargetTypes = types;

+                }

+                return allowedTargetTypes;

+            }

+        }

+    }

+

+    public class PolicyType : PolicyTypeDefinition, IPolicyType

+    {

+        private ObjectTypeHelper helper;

+

+        public PolicyType(ISession session, IPolicyTypeDefinition typeDefinition)

+        {

+            Initialize(typeDefinition);

+            helper = new ObjectTypeHelper(session, this);

+        }

+

+        public IObjectType GetBaseType() { return helper.GetBaseType(); }

+

+        public IItemIterable<IObjectType> GetChildren() { return helper.GetChildren(); }

+

+        public IList<ITree<IObjectType>> GetDescendants(int depth) { return helper.GetDescendants(depth); }

+

+        public IObjectType GetParentType() { return helper.GetParentType(); }

+

+        public bool IsBaseType { get { return helper.IsBaseType; } }

+    }

+}

diff --git a/DotCMIS/const.cs b/DotCMIS/const.cs
index 31afcee..4d81286 100644
--- a/DotCMIS/const.cs
+++ b/DotCMIS/const.cs
@@ -62,6 +62,7 @@
         public const string MessageSize = "org.apache.chemistry.dotcmis.binding.message.size";

 

         // session parameter

+        public const string ObjectFactoryClass = "org.apache.chemistry.dotcmis.objectfactory.classname";

         public const string CacheClass = "org.apache.chemistry.dotcmis.cache.classname";

         public const string RepositoryId = "org.apache.chemistry.dotcmis.session.repository.id";

     }

diff --git a/DotCMIS/data/data-impl.cs b/DotCMIS/data/data-impl.cs
index 86ec88c..6aaa1ab 100644
--- a/DotCMIS/data/data-impl.cs
+++ b/DotCMIS/data/data-impl.cs
@@ -107,7 +107,7 @@
         public IList<string> Permissions { get; set; }

     }

 

-    public abstract class TypeDefinition : ExtensionsData, ITypeDefinition

+    public abstract class AbstractTypeDefinition : ExtensionsData, ITypeDefinition

     {

         private List<IPropertyDefinition> propertyDefintionList = new List<IPropertyDefinition>();

         private Dictionary<string, IPropertyDefinition> propertyDefintionDict = new Dictionary<string, IPropertyDefinition>();

@@ -118,7 +118,7 @@
         public string DisplayName { get; set; }

         public string QueryName { get; set; }

         public string Description { get; set; }

-        public BaseTypeId? BaseTypeId { get; set; }

+        public BaseTypeId BaseTypeId { get; set; }

         public string ParentTypeId { get; set; }

         public bool? IsCreatable { get; set; }

         public bool? IsFileable { get; set; }

@@ -144,6 +144,34 @@
             }

         }

 

+        public void Initialize(ITypeDefinition typeDefinition)

+        {

+            Id = typeDefinition.Id;

+            LocalName = typeDefinition.LocalName;

+            LocalNamespace = typeDefinition.LocalNamespace;

+            DisplayName = typeDefinition.DisplayName;

+            QueryName = typeDefinition.QueryName;

+            Description = typeDefinition.Description;

+            BaseTypeId = typeDefinition.BaseTypeId;

+            ParentTypeId = typeDefinition.ParentTypeId;

+            IsCreatable = typeDefinition.IsCreatable;

+            IsFileable = typeDefinition.IsFileable;

+            IsQueryable = typeDefinition.IsQueryable;

+            IsFulltextIndexed = typeDefinition.IsFulltextIndexed;

+            IsIncludedInSupertypeQuery = typeDefinition.IsIncludedInSupertypeQuery;

+            IsControllablePolicy = typeDefinition.IsControllablePolicy;

+            IsControllableAcl = typeDefinition.IsControllableAcl;

+

+

+            if (typeDefinition.PropertyDefintions != null)

+            {

+                foreach (IPropertyDefinition propDef in typeDefinition.PropertyDefintions)

+                {

+                    AddPropertyDefinition(propDef);

+                }

+            }

+        }

+

         public void AddPropertyDefinition(IPropertyDefinition propertyDefinition)

         {

             if (propertyDefinition == null || propertyDefinition.Id == null)

@@ -156,21 +184,21 @@
         }

     }

 

-    public class DocumentTypeDefinition : TypeDefinition, IDocumentTypeDefinition

+    public class DocumentTypeDefinition : AbstractTypeDefinition, IDocumentTypeDefinition

     {

         public bool? IsVersionable { get; set; }

         public ContentStreamAllowed? ContentStreamAllowed { get; set; }

     }

 

-    public class FolderTypeDefinition : TypeDefinition, IFolderTypeDefinition

+    public class FolderTypeDefinition : AbstractTypeDefinition, IFolderTypeDefinition

     {

     }

 

-    public class PolicyTypeDefinition : TypeDefinition, IPolicyTypeDefinition

+    public class PolicyTypeDefinition : AbstractTypeDefinition, IPolicyTypeDefinition

     {

     }

 

-    public class RelationshipTypeDefinition : TypeDefinition, IRelationshipTypeDefinition

+    public class RelationshipTypeDefinition : AbstractTypeDefinition, IRelationshipTypeDefinition

     {

         public IList<string> AllowedSourceTypeIds { get; set; }

         public IList<string> AllowedTargetTypeIds { get; set; }

diff --git a/DotCMIS/data/data-intf.cs b/DotCMIS/data/data-intf.cs
index fbbd8cd..d243b9e 100644
--- a/DotCMIS/data/data-intf.cs
+++ b/DotCMIS/data/data-intf.cs
@@ -91,7 +91,7 @@
         string DisplayName { get; }

         string QueryName { get; }

         string Description { get; }

-        BaseTypeId? BaseTypeId { get; }

+        BaseTypeId BaseTypeId { get; }

         string ParentTypeId { get; }

         bool? IsCreatable { get; }

         bool? IsFileable { get; }