Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
new features, adjust AttributeType.SetObsolete
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Coretta authored and Jesse Coretta committed Nov 6, 2024
1 parent 068e3ed commit 0928df7
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 6 deletions.
14 changes: 8 additions & 6 deletions at.go
Original file line number Diff line number Diff line change
Expand Up @@ -1479,24 +1479,26 @@ func (r AttributeType) SetNoUserModification(x any) AttributeType {
}

/*
SetObsolete assigns the input value to the underlying OBSOLETE clause within
the receiver.
Input types may be bool, or string representations of bool. When strings
are used, case is not significant.
SetObsolete sets the receiver's obsolescence state to true.
Obsolescence cannot be unset.
This is a fluent method.
*/
func (r AttributeType) SetObsolete(x any) AttributeType {
if !r.IsZero() {
r.attributeType.setBoolean(`obs`, x)
r.attributeType.setObsolete()
}

return r
}

func (r *attributeType) setObsolete() {
if !r.Obsolete {
r.Obsolete = true
}
}

func (r *attributeType) setBoolean(t string, x any) {

var Bool bool
Expand Down
2 changes: 2 additions & 0 deletions dc.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ func (r DITContentRules) Compliant() bool {
/*
StructuralClass returns the STRUCTURAL [ObjectClass] set within the
receiver instance, or a zero instance if unset.
This method is essentially the inverse of [ObjectClass.EnforcedBy].
*/
func (r DITContentRule) StructuralClass() (soc ObjectClass) {
if !r.IsZero() {
Expand Down
1 change: 1 addition & 0 deletions dc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func TestDITContentRule_codecov(t *testing.T) {
t.Errorf("%s failed: expected success, got %v", t.Name(), err)
return
}
def.StructuralClass().EnforcedBy()
_ = def.macro()
def.setOID(`2.5.6.2`)

Expand Down
14 changes: 14 additions & 0 deletions ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ func (r *dITStructureRule) replace(x DITStructureRule) {
r.data = x.dITStructureRule.data
}

/*
NamedObjectClass returns the "namedObjectClass" of the receiver instance.
The "namedObjectClass" describes the STRUCTURAL [ObjectClass] specified
in the receiver's [NameForm] instance, and is described in [ITU-T Rec.
X.501 clause 13.7.5].
[ITU-T Rec. X.501 clause 13.7.5]: https://www.itu.int/rec/T-REC-X.501
*/
func (r DITStructureRule) NamedObjectClass() (noc ObjectClass) {
noc = r.Form().OC()
return
}

/*
SetData assigns x to the receiver instance. This is a general-use method and has no
specific intent beyond convenience. The contents may be subsequently accessed via the
Expand Down
25 changes: 25 additions & 0 deletions ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import (
"testing"
)

/*
This example demonstrates an analysis of a distinguished name to determine
whether it honors the receiver instance of [DITStructureRule].
Note: this example assumes a legitimate schema variable is defined
in place of the fictional "mySchema" var shown here for simplicity.
*/
func ExampleDITStructureRule_Govern() {
dn := `dc=example,dc=com` // flattened context (1 comma)

Expand All @@ -23,6 +30,9 @@ func ExampleDITStructureRule_Govern() {

/*
This example demonstrates the creation of a [DITStructureRule].
Note: this example assumes a legitimate schema variable is defined
in place of the fictional "mySchema" var shown here for simplicity.
*/
func ExampleNewDITStructureRule() {
// First create a name form that requires an
Expand Down Expand Up @@ -53,6 +63,21 @@ func ExampleNewDITStructureRule() {
// FORM fictionalPersonForm )
}

/*
This example demonstrates the means of accessing the STRUCTURAL [ObjectClass]
instance held by the [NameForm] instance assigned to the [DITStructureRule]
instance.
Note: this example assumes a legitimate schema variable is defined
in place of the fictional "mySchema" var shown here for simplicity.
*/
func ExampleDITStructureRule_NamedObjectClass() {
ds := mySchema.DITStructureRules().Get(1) // Integer Identifier #1
noc := ds.NamedObjectClass()
fmt.Println(noc.OID())
// Output: uddiBusinessEntity
}

/*
This example demonstrates a compliancy check of a [DITStructureRule]
instance.
Expand Down
21 changes: 21 additions & 0 deletions nf.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ func (r *nameForm) replace(x NameForm) {
r.data = x.nameForm.data
}

/*
EnforcedBy returns an instance of [DITStructureRules] containing all
[DITStructureRule] instances which enforce the receiver instance. A
return value with an integer length of zero (0) indicates that there
are no [DITStructureRule] instances which bear the receiver instance
through the 'FORM' clause at present.
*/
func (r NameForm) EnforcedBy() (dsr DITStructureRules) {
if !r.Schema().IsZero() {
dsr = NewDITStructureRules()
rules := r.Schema().DITStructureRules()
for i := 0; i < rules.Len(); i++ {
if ds := rules.Index(i); ds.Form().IsIdentifiedAs(r.OID()) {
dsr.Push(ds)
}
}
}

return
}

/*
IsIdentifiedAs returns a Boolean value indicative of whether id matches
either the numericOID or descriptor of the receiver instance. Case is
Expand Down
3 changes: 3 additions & 0 deletions nf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ func TestNameForm_codecov(t *testing.T) {
_ = def.Name()
_ = def.Names()
_ = def.Extensions()
_ = def.EnforcedBy()
_ = def.Must()
_ = def.May()
_ = def.Schema()
Expand Down Expand Up @@ -395,6 +396,8 @@ func TestNameForm_codecov(t *testing.T) {
t.Errorf("%s failed: expected success, got %v", t.Name(), err)
return
}
def.EnforcedBy()

_ = def.macro()
def.setOID(`2.5.13.2`)

Expand Down
22 changes: 22 additions & 0 deletions oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ func (r ObjectClass) macro() (m []string) {
return
}

/*
EnforcedBy returns the [DITContentRule] instance which bears the same
numeric OID held by the receiver instance, which must be a STRUCTURAL
[ObjectClass].
This method is essentially the inverse of [DITContentRule.StructuralClass].
A schema can only contain one (1) such [DITContentRule] per STRUCTURAL
[ObjectClass].
If the return instance is zero, this means that either the receiver is
not a STRUCTURAL [ObjectClass], or that no [DITContentRule] bearing the
receiver's numeric OID is currently in force.
*/
func (r ObjectClass) EnforcedBy() (dcr DITContentRule) {
if !r.Schema().IsZero() && r.Kind() == StructuralKind {
dcr = r.Schema().DITContentRules().Get(r.NumericOID())
}

return
}

/*
SetName assigns the provided names to the receiver instance.
Expand Down
2 changes: 2 additions & 0 deletions oc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ func TestObjectClass_codecov(t *testing.T) {
bmr.cast().Push(NewObjectClass().SetSchema(mySchema))
bmr.cast().Push(NewObjectClass().SetSchema(mySchema).SetNumericOID(`1.2.3.4.5`))
var bad ObjectClass
bad.EnforcedBy()
bmr.cast().Push(bad)

ObjectClasses(bmr.cast()).oIDsStringerPretty(0)
Expand Down Expand Up @@ -530,6 +531,7 @@ func TestObjectClass_codecov(t *testing.T) {
def.SetMust(rune(11))
def.SetMay(mySchema.AttributeTypes().Get(`cn`))
def.SetMay(rune(11))
def.EnforcedBy()
def.SetSuperClass(mySchema.ObjectClasses().Get(`top`))
def.SetSuperClass(rune(11))
def.SetSuperClass(ObjectClass{})
Expand Down

0 comments on commit 0928df7

Please sign in to comment.