/******************************************************************************
* The MIT License
* Copyright (c) 2003 Novell Inc. www.novell.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
//
// Novell.Directory.Ldap.LdapMatchingRuleSchema.cs
//
// Author:
// Sunil Kumar (Sunilk@novell.com)
//
// (C) 2003 Novell, Inc (http://www.novell.com)
//
using System;
using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser;
namespace Novell.Directory.Ldap
{
/// The schematic definition of a particular matching rule
/// in a particular Directory Server.
///
/// The LdapMatchingRuleSchema class represents the definition of a mathcing
/// rule. It is used to query matching rule syntax, and to add or delete a
/// matching rule definition in a directory.
///
/// Novell eDirectory does not currently allow matching rules to be added
/// or deleted from the schema.
///
///
///
///
///
///
///
///
public class LdapMatchingRuleSchema:LdapSchemaElement
{
/// Returns the OIDs of the attributes to which this rule applies.
///
///
/// The OIDs of the attributes to which this matching rule applies.
///
virtual public System.String[] Attributes
{
get
{
return attributes;
}
}
/// Returns the OID of the syntax that this matching rule is valid for.
///
///
/// The OID of the syntax that this matching rule is valid for.
///
virtual public System.String SyntaxString
{
get
{
return syntaxString;
}
}
private System.String syntaxString;
private System.String[] attributes;
/// Constructs a matching rule definition for adding to or deleting from
/// a directory.
///
///
/// The names of the attribute.
///
///
/// Object Identifier of the attribute - in
/// dotted-decimal format.
///
///
/// Optional description of the attribute.
///
///
/// The OIDs of attributes to which the rule applies.
/// This parameter may be null. All attributes added to
/// this array must use the same syntax.
///
///
/// true if this matching rule is obsolete.
///
///
///
/// The unique object identifer of the syntax of the
/// attribute, in dotted numerical format.
///
///
public LdapMatchingRuleSchema(System.String[] names, System.String oid, System.String description, System.String[] attributes, bool obsolete, System.String syntaxString):base(LdapSchema.schemaTypeNames[LdapSchema.MATCHING])
{
base.names = new System.String[names.Length];
names.CopyTo(base.names, 0);
base.oid = oid;
base.description = description;
base.obsolete = obsolete;
this.attributes = new System.String[attributes.Length];
attributes.CopyTo(this.attributes, 0);
this.syntaxString = syntaxString;
base.Value = formatString();
return ;
}
/// Constructs a matching rule definition from the raw string values
/// returned from a schema query for "matchingRule" and for
/// "matchingRuleUse" for the same rule.
///
///
/// The raw string value returned on a directory
/// query for "matchingRule".
///
///
/// The raw string value returned on a directory
/// query for "matchingRuleUse".
///
public LdapMatchingRuleSchema(System.String rawMatchingRule, System.String rawMatchingRuleUse):base(LdapSchema.schemaTypeNames[LdapSchema.MATCHING])
{
try
{
SchemaParser matchParser = new SchemaParser(rawMatchingRule);
base.names = new System.String[matchParser.Names.Length];
matchParser.Names.CopyTo(base.names, 0);
base.oid = matchParser.ID;
base.description = matchParser.Description;
base.obsolete = matchParser.Obsolete;
this.syntaxString = matchParser.Syntax;
if ((System.Object) rawMatchingRuleUse != null)
{
SchemaParser matchUseParser = new SchemaParser(rawMatchingRuleUse);
this.attributes = matchUseParser.Applies;
}
base.Value = formatString();
}
catch (System.IO.IOException e)
{
}
return ;
}
/// Returns a string in a format suitable for directly adding to a
/// directory, as a value of the particular schema element attribute.
///
///
/// A string representation of the attribute's definition.
///
protected internal override System.String formatString()
{
System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
System.String token;
System.String[] strArray;
if ((System.Object) (token = ID) != null)
{
valueBuffer.Append(token);
}
strArray = Names;
if (strArray != null)
{
valueBuffer.Append(" NAME ");
if (strArray.Length == 1)
{
valueBuffer.Append("'" + strArray[0] + "'");
}
else
{
valueBuffer.Append("( ");
for (int i = 0; i < strArray.Length; i++)
{
valueBuffer.Append(" '" + strArray[i] + "'");
}
valueBuffer.Append(" )");
}
}
if ((System.Object) (token = Description) != null)
{
valueBuffer.Append(" DESC ");
valueBuffer.Append("'" + token + "'");
}
if (Obsolete)
{
valueBuffer.Append(" OBSOLETE");
}
if ((System.Object) (token = SyntaxString) != null)
{
valueBuffer.Append(" SYNTAX ");
valueBuffer.Append(token);
}
valueBuffer.Append(" )");
return valueBuffer.ToString();
}
}
}