Used to help facilitate the building of ObjectClassInfo objects.
示例#1
0
 public void TestObjectClassInfo()
 {
     ConnectorAttributeInfoBuilder builder = new ConnectorAttributeInfoBuilder();
     builder.Name = ("foo");
     builder.ValueType = (typeof(String));
     builder.Required = (true);
     builder.Readable = (true);
     builder.Updateable = (true);
     builder.MultiValued = (true);
     ObjectClassInfoBuilder obld = new ObjectClassInfoBuilder();
     obld.ObjectType = ObjectClass.ACCOUNT_NAME;
     obld.IsContainer = true;
     obld.AddAttributeInfo(builder.Build());
     ObjectClassInfo v1 = obld.Build();
     ObjectClassInfo v2 = (ObjectClassInfo)CloneObject(v1);
     Assert.AreEqual(v1, v2);
     Assert.IsTrue(v2.IsContainer);
 }
示例#2
0
        private static void Merge(IDictionary<ObjectClass, ObjectClassInfo> target, IDictionary<ObjectClass, ObjectClassInfo> source)
        {
            foreach (ObjectClass oc in source.Keys)
            {
                ObjectClassInfo sourceOCI = source[oc];
                if (!target.ContainsKey(oc))
                {
                    ObjectClassInfoBuilder builder = new ObjectClassInfoBuilder();
                    builder.ObjectType = sourceOCI.ObjectType;
                    builder.IsContainer = sourceOCI.IsContainer;
                    builder.AddAllAttributeInfo(sourceOCI.ConnectorAttributeInfos);
                    ObjectClassInfo targetOCI = builder.Build();
                    LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "Adding object class info {0}", targetOCI.ObjectType);
                    target.Add(oc, targetOCI);
                }
                else
                {
                    ObjectClassInfo targetOCI = target[oc];
                    if (!targetOCI.ObjectType.Equals(sourceOCI.ObjectType))
                    {
                        throw new ArgumentException("Incompatible ObjectType for object class " + oc);
                    }
                    if (targetOCI.IsContainer != sourceOCI.IsContainer)
                    {
                        throw new ArgumentException("Incompatible Container flag for object class " + oc);
                    }
                    ObjectClassInfoBuilder builder = new ObjectClassInfoBuilder();
                    builder.ObjectType = targetOCI.ObjectType;
                    builder.IsContainer = targetOCI.IsContainer;
                    builder.AddAllAttributeInfo(targetOCI.ConnectorAttributeInfos);
                    foreach (ConnectorAttributeInfo info in sourceOCI.ConnectorAttributeInfos)
                    {
                        if (info.Is(Name.NAME))
                        {
                            // The __NAME__ attribute is a special one and has to be provided on each object class.
                            // So, even if we just want to extend an object class with a few attributes, we have to provide
                            // artificial __NAME__ attribute there. When merging, we simply skip it.
                            continue;
                        }

                        foreach (ConnectorAttributeInfo existingInfo in targetOCI.ConnectorAttributeInfos)
                        {
                            if (existingInfo.Is(info.Name))
                            {
                                throw new ArgumentException("Attempted to redefine attribute " + info.Name);
                            }
                        }
                        LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Adding connector attribute info {0}:{1}", info.Name, info.ValueType);
                        builder.AddAttributeInfo(info);
                    }
                    ObjectClassInfo targetRebuilt = builder.Build();
                    LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "Replacing object class info {0}", targetOCI.ObjectType);
                    target.Remove(oc);
                    target.Add(oc, targetRebuilt);
                }
            }
        }
示例#3
0
 public void TestSchema()
 {
     OperationOptionInfo opInfo =
         new OperationOptionInfo("name", typeof(int?));
     ObjectClassInfoBuilder bld = new ObjectClassInfoBuilder();
     bld.ObjectType = ObjectClass.ACCOUNT_NAME;
     ObjectClassInfo info = bld.Build();
     ICollection<ObjectClassInfo> temp = CollectionUtil.NewSet(info);
     IDictionary<SafeType<APIOperation>, ICollection<ObjectClassInfo>> map =
         new Dictionary<SafeType<APIOperation>, ICollection<ObjectClassInfo>>();
     map[SafeType<APIOperation>.Get<CreateApiOp>()] = temp;
     ICollection<OperationOptionInfo> temp2 = CollectionUtil.NewSet(opInfo);
     IDictionary<SafeType<APIOperation>, ICollection<OperationOptionInfo>> map2 =
         new Dictionary<SafeType<APIOperation>, ICollection<OperationOptionInfo>>();
     map2[SafeType<APIOperation>.Get<CreateApiOp>()] = temp2;
     Schema v1 = new Schema(CollectionUtil.NewSet(info),
             CollectionUtil.NewSet(opInfo),
             map,
             map2);
     Schema v2 = (Schema)CloneObject(v1);
     Assert.AreEqual(v1, v2);
     Assert.AreEqual(info, v2.ObjectClassInfo.First());
     Assert.AreEqual(1, v2.SupportedObjectClassesByOperation.Count);
     Assert.AreEqual(1, v2.SupportedOptionsByOperation.Count);
     Assert.AreEqual(1, v2.OperationOptionInfo.Count);
 }
示例#4
0
 /// <summary>
 /// Adds another ObjectClassInfo to the schema.
 /// </summary>
 /// <remarks>
 /// Also, adds this
 /// to the set of supported classes for every operation defined by
 /// the Connector.
 /// </remarks>
 /// <exception cref="IllegalStateException">If already defined</exception>
 public void DefineObjectClass(String type, ICollection<ConnectorAttributeInfo> attrInfo)
 {
     ObjectClassInfoBuilder bld = new ObjectClassInfoBuilder();
     bld.ObjectType = type;
     bld.AddAllAttributeInfo(attrInfo);
     ObjectClassInfo obj = bld.Build();
     DefineObjectClass(obj);
 }