/*
* 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 PortCMIS.Data;
using PortCMIS.Enums;
using System;
using System.Collections.Generic;
namespace PortCMIS.Client.Impl
{
///
/// Helper for all type implementations.
///
internal class ObjectTypeHelper
{
private readonly ISession session;
private readonly 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 || objectType.ParentTypeId.Length == 0; } }
public IObjectType BaseType
{
get
{
if (IsBaseType) { return null; }
if (baseType != null) { return baseType; }
baseType = session.GetTypeDefinition(objectType.BaseTypeId.GetCmisValue());
return baseType;
}
}
public IObjectType ParentType
{
get
{
if (parentType != null) { return parentType; }
if (objectType.ParentTypeId == null) { return null; }
parentType = session.GetTypeDefinition(objectType.ParentTypeId);
return parentType;
}
}
public IItemEnumerable GetChildren()
{
return session.GetTypeChildren(objectType.Id, true);
}
public IList> GetDescendants(int depth)
{
return session.GetTypeDescendants(objectType.Id, depth, true);
}
}
///
/// Document type implementation.
///
public class DocumentType : DocumentTypeDefinition, IDocumentType
{
private readonly ObjectTypeHelper helper;
///
/// Constructor.
///
/// the related session object
/// the low-level type definition
public DocumentType(ISession session, IDocumentTypeDefinition typeDefinition)
{
Initialize(typeDefinition);
ContentStreamAllowed = typeDefinition.ContentStreamAllowed;
IsVersionable = typeDefinition.IsVersionable;
helper = new ObjectTypeHelper(session, this);
}
///
public virtual IObjectType BaseType { get { return helper.BaseType; } }
///
public virtual IObjectType ParentType { get { return helper.ParentType; } }
///
public virtual IItemEnumerable GetChildren() { return helper.GetChildren(); }
///
public virtual IList> GetDescendants(int depth) { return helper.GetDescendants(depth); }
///
public virtual bool IsBaseType { get { return helper.IsBaseType; } }
}
///
/// Folder type implementation.
///
public class FolderType : FolderTypeDefinition, IFolderType
{
private readonly ObjectTypeHelper helper;
///
/// Constructor.
///
/// the related session object
/// the low-level type definition
public FolderType(ISession session, IFolderTypeDefinition typeDefinition)
{
Initialize(typeDefinition);
helper = new ObjectTypeHelper(session, this);
}
///
public virtual IObjectType BaseType { get { return helper.BaseType; } }
///
public virtual IObjectType ParentType { get { return helper.ParentType; } }
///
public virtual IItemEnumerable GetChildren() { return helper.GetChildren(); }
///
public virtual IList> GetDescendants(int depth) { return helper.GetDescendants(depth); }
///
public virtual bool IsBaseType { get { return helper.IsBaseType; } }
}
///
/// Relationship type implementation.
///
public class RelationshipType : RelationshipTypeDefinition, IRelationshipType
{
private readonly ObjectTypeHelper helper;
private IList allowedSourceTypes;
private IList allowedTargetTypes;
///
/// Constructor.
///
/// the related session object
/// the low-level type definition
public RelationshipType(ISession session, IRelationshipTypeDefinition typeDefinition)
{
Initialize(typeDefinition);
helper = new ObjectTypeHelper(session, this);
}
///
public virtual IObjectType BaseType { get { return helper.BaseType; } }
///
public virtual IObjectType ParentType { get { return helper.ParentType; } }
///
public virtual IItemEnumerable GetChildren() { return helper.GetChildren(); }
///
public virtual IList> GetDescendants(int depth) { return helper.GetDescendants(depth); }
///
public virtual bool IsBaseType { get { return helper.IsBaseType; } }
///
public virtual IList GetAllowedSourceTypes
{
get
{
if (allowedSourceTypes == null)
{
IList ids = AllowedSourceTypeIds;
IList types = new List(ids == null ? 0 : ids.Count);
if (ids != null)
{
foreach (String id in ids)
{
types.Add(helper.Session.GetTypeDefinition(id));
}
}
allowedSourceTypes = types;
}
return allowedSourceTypes;
}
}
///
public virtual IList GetAllowedTargetTypes
{
get
{
if (allowedTargetTypes == null)
{
IList ids = AllowedTargetTypeIds;
IList types = new List(ids == null ? 0 : ids.Count);
if (ids != null)
{
foreach (string id in ids)
{
types.Add(helper.Session.GetTypeDefinition(id));
}
}
allowedTargetTypes = types;
}
return allowedTargetTypes;
}
}
}
///
/// Policy type implementation.
///
public class PolicyType : PolicyTypeDefinition, IPolicyType
{
private readonly ObjectTypeHelper helper;
///
/// Constructor.
///
/// the related session object
/// the low-level type definition
public PolicyType(ISession session, IPolicyTypeDefinition typeDefinition)
{
Initialize(typeDefinition);
helper = new ObjectTypeHelper(session, this);
}
///
public virtual IObjectType BaseType { get { return helper.BaseType; } }
///
public virtual IObjectType ParentType { get { return helper.ParentType; } }
///
public virtual IItemEnumerable GetChildren() { return helper.GetChildren(); }
///
public virtual IList> GetDescendants(int depth) { return helper.GetDescendants(depth); }
///
public virtual bool IsBaseType { get { return helper.IsBaseType; } }
}
///
/// Item type implementation.
///
public class ItemType : ItemTypeDefinition, IItemType
{
private readonly ObjectTypeHelper helper;
///
/// Constructor.
///
/// the related session object
/// the low-level type definition
public ItemType(ISession session, IItemTypeDefinition typeDefinition)
{
Initialize(typeDefinition);
helper = new ObjectTypeHelper(session, this);
}
///
public virtual IObjectType BaseType { get { return helper.BaseType; } }
///
public virtual IObjectType ParentType { get { return helper.ParentType; } }
///
public virtual IItemEnumerable GetChildren() { return helper.GetChildren(); }
///
public virtual IList> GetDescendants(int depth) { return helper.GetDescendants(depth); }
///
public virtual bool IsBaseType { get { return helper.IsBaseType; } }
}
///
/// Secondary type implementation.
///
public class SecondaryType : SecondaryTypeDefinition, ISecondaryType
{
private readonly ObjectTypeHelper helper;
///
/// Constructor.
///
/// the related session object
/// the low-level type definition
public SecondaryType(ISession session, ISecondaryTypeDefinition typeDefinition)
{
Initialize(typeDefinition);
helper = new ObjectTypeHelper(session, this);
}
///
public virtual IObjectType BaseType { get { return helper.BaseType; } }
///
public virtual IObjectType ParentType { get { return helper.ParentType; } }
///
public virtual IItemEnumerable GetChildren() { return helper.GetChildren(); }
///
public virtual IList> GetDescendants(int depth) { return helper.GetDescendants(depth); }
///
public virtual bool IsBaseType { get { return helper.IsBaseType; } }
}
}