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

Commit 0928df7

Browse files
Jesse CorettaJesse Coretta
Jesse Coretta
authored and
Jesse Coretta
committed
new features, adjust AttributeType.SetObsolete
1 parent 068e3ed commit 0928df7

File tree

9 files changed

+98
-6
lines changed

9 files changed

+98
-6
lines changed

at.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,24 +1479,26 @@ func (r AttributeType) SetNoUserModification(x any) AttributeType {
14791479
}
14801480

14811481
/*
1482-
SetObsolete assigns the input value to the underlying OBSOLETE clause within
1483-
the receiver.
1484-
1485-
Input types may be bool, or string representations of bool. When strings
1486-
are used, case is not significant.
1482+
SetObsolete sets the receiver's obsolescence state to true.
14871483
14881484
Obsolescence cannot be unset.
14891485
14901486
This is a fluent method.
14911487
*/
14921488
func (r AttributeType) SetObsolete(x any) AttributeType {
14931489
if !r.IsZero() {
1494-
r.attributeType.setBoolean(`obs`, x)
1490+
r.attributeType.setObsolete()
14951491
}
14961492

14971493
return r
14981494
}
14991495

1496+
func (r *attributeType) setObsolete() {
1497+
if !r.Obsolete {
1498+
r.Obsolete = true
1499+
}
1500+
}
1501+
15001502
func (r *attributeType) setBoolean(t string, x any) {
15011503

15021504
var Bool bool

dc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ func (r DITContentRules) Compliant() bool {
445445
/*
446446
StructuralClass returns the STRUCTURAL [ObjectClass] set within the
447447
receiver instance, or a zero instance if unset.
448+
449+
This method is essentially the inverse of [ObjectClass.EnforcedBy].
448450
*/
449451
func (r DITContentRule) StructuralClass() (soc ObjectClass) {
450452
if !r.IsZero() {

dc_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ func TestDITContentRule_codecov(t *testing.T) {
353353
t.Errorf("%s failed: expected success, got %v", t.Name(), err)
354354
return
355355
}
356+
def.StructuralClass().EnforcedBy()
356357
_ = def.macro()
357358
def.setOID(`2.5.6.2`)
358359

ds.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ func (r *dITStructureRule) replace(x DITStructureRule) {
9696
r.data = x.dITStructureRule.data
9797
}
9898

99+
/*
100+
NamedObjectClass returns the "namedObjectClass" of the receiver instance.
101+
102+
The "namedObjectClass" describes the STRUCTURAL [ObjectClass] specified
103+
in the receiver's [NameForm] instance, and is described in [ITU-T Rec.
104+
X.501 clause 13.7.5].
105+
106+
[ITU-T Rec. X.501 clause 13.7.5]: https://www.itu.int/rec/T-REC-X.501
107+
*/
108+
func (r DITStructureRule) NamedObjectClass() (noc ObjectClass) {
109+
noc = r.Form().OC()
110+
return
111+
}
112+
99113
/*
100114
SetData assigns x to the receiver instance. This is a general-use method and has no
101115
specific intent beyond convenience. The contents may be subsequently accessed via the

ds_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import (
55
"testing"
66
)
77

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

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

2431
/*
2532
This example demonstrates the creation of a [DITStructureRule].
33+
34+
Note: this example assumes a legitimate schema variable is defined
35+
in place of the fictional "mySchema" var shown here for simplicity.
2636
*/
2737
func ExampleNewDITStructureRule() {
2838
// First create a name form that requires an
@@ -53,6 +63,21 @@ func ExampleNewDITStructureRule() {
5363
// FORM fictionalPersonForm )
5464
}
5565

66+
/*
67+
This example demonstrates the means of accessing the STRUCTURAL [ObjectClass]
68+
instance held by the [NameForm] instance assigned to the [DITStructureRule]
69+
instance.
70+
71+
Note: this example assumes a legitimate schema variable is defined
72+
in place of the fictional "mySchema" var shown here for simplicity.
73+
*/
74+
func ExampleDITStructureRule_NamedObjectClass() {
75+
ds := mySchema.DITStructureRules().Get(1) // Integer Identifier #1
76+
noc := ds.NamedObjectClass()
77+
fmt.Println(noc.OID())
78+
// Output: uddiBusinessEntity
79+
}
80+
5681
/*
5782
This example demonstrates a compliancy check of a [DITStructureRule]
5883
instance.

nf.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,27 @@ func (r *nameForm) replace(x NameForm) {
189189
r.data = x.nameForm.data
190190
}
191191

192+
/*
193+
EnforcedBy returns an instance of [DITStructureRules] containing all
194+
[DITStructureRule] instances which enforce the receiver instance. A
195+
return value with an integer length of zero (0) indicates that there
196+
are no [DITStructureRule] instances which bear the receiver instance
197+
through the 'FORM' clause at present.
198+
*/
199+
func (r NameForm) EnforcedBy() (dsr DITStructureRules) {
200+
if !r.Schema().IsZero() {
201+
dsr = NewDITStructureRules()
202+
rules := r.Schema().DITStructureRules()
203+
for i := 0; i < rules.Len(); i++ {
204+
if ds := rules.Index(i); ds.Form().IsIdentifiedAs(r.OID()) {
205+
dsr.Push(ds)
206+
}
207+
}
208+
}
209+
210+
return
211+
}
212+
192213
/*
193214
IsIdentifiedAs returns a Boolean value indicative of whether id matches
194215
either the numericOID or descriptor of the receiver instance. Case is

nf_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ func TestNameForm_codecov(t *testing.T) {
347347
_ = def.Name()
348348
_ = def.Names()
349349
_ = def.Extensions()
350+
_ = def.EnforcedBy()
350351
_ = def.Must()
351352
_ = def.May()
352353
_ = def.Schema()
@@ -395,6 +396,8 @@ func TestNameForm_codecov(t *testing.T) {
395396
t.Errorf("%s failed: expected success, got %v", t.Name(), err)
396397
return
397398
}
399+
def.EnforcedBy()
400+
398401
_ = def.macro()
399402
def.setOID(`2.5.13.2`)
400403

oc.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,28 @@ func (r ObjectClass) macro() (m []string) {
146146
return
147147
}
148148

149+
/*
150+
EnforcedBy returns the [DITContentRule] instance which bears the same
151+
numeric OID held by the receiver instance, which must be a STRUCTURAL
152+
[ObjectClass].
153+
154+
This method is essentially the inverse of [DITContentRule.StructuralClass].
155+
156+
A schema can only contain one (1) such [DITContentRule] per STRUCTURAL
157+
[ObjectClass].
158+
159+
If the return instance is zero, this means that either the receiver is
160+
not a STRUCTURAL [ObjectClass], or that no [DITContentRule] bearing the
161+
receiver's numeric OID is currently in force.
162+
*/
163+
func (r ObjectClass) EnforcedBy() (dcr DITContentRule) {
164+
if !r.Schema().IsZero() && r.Kind() == StructuralKind {
165+
dcr = r.Schema().DITContentRules().Get(r.NumericOID())
166+
}
167+
168+
return
169+
}
170+
149171
/*
150172
SetName assigns the provided names to the receiver instance.
151173

oc_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ func TestObjectClass_codecov(t *testing.T) {
440440
bmr.cast().Push(NewObjectClass().SetSchema(mySchema))
441441
bmr.cast().Push(NewObjectClass().SetSchema(mySchema).SetNumericOID(`1.2.3.4.5`))
442442
var bad ObjectClass
443+
bad.EnforcedBy()
443444
bmr.cast().Push(bad)
444445

445446
ObjectClasses(bmr.cast()).oIDsStringerPretty(0)
@@ -530,6 +531,7 @@ func TestObjectClass_codecov(t *testing.T) {
530531
def.SetMust(rune(11))
531532
def.SetMay(mySchema.AttributeTypes().Get(`cn`))
532533
def.SetMay(rune(11))
534+
def.EnforcedBy()
533535
def.SetSuperClass(mySchema.ObjectClasses().Get(`top`))
534536
def.SetSuperClass(rune(11))
535537
def.SetSuperClass(ObjectClass{})

0 commit comments

Comments
 (0)