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

Commit

Permalink
Add subordinate type/class/rule access
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseCoretta committed Jul 17, 2024
1 parent c91a342 commit 02f1e99
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 5 deletions.
28 changes: 28 additions & 0 deletions at.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,34 @@ func (r AttributeType) SuperType() (sup AttributeType) {
return
}

/*
SubTypes returns an instance of [AttributeTypes] containing slices of
[AttributeType] instances that are direct subordinates to the receiver
instance. As such, this method is essentially the inverse of the
[AttributeType.SuperType] method.
The super chain is NOT traversed beyond immediate subordinate instances.
Note that the relevant [Schema] instance must have been set using the
[AttributeType.SetSchema] method prior to invocation of this method.
Should this requirement remain unfulfilled, the return instance will
be a zero instance.
*/
func (r AttributeType) SubTypes() (subs AttributeTypes) {
if !r.IsZero() {
subs = NewAttributeTypeOIDList()
ats := r.schema().AttributeTypes()
for i := 0; i < ats.Len(); i++ {
typ := ats.Index(i)
if typ.SuperType().NumericOID() == r.NumericOID() {
subs.Push(typ)
}
}
}

return
}

/*
SuperChain returns an [AttributeTypes] stack of [AttributeType] instances
which make up the super type chain of the receiver instance.
Expand Down
14 changes: 14 additions & 0 deletions at_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ func ExampleAttributeType_SuperChain() {
// Output: name
}

/*
This example demonstrates the means of accessing all subordinate type
instances of the receiver instance.
In essence, this method is the opposite of the [AttributeType.SuperType]
method and may return zero (0) or more [AttributeType] instances within
the return [AttributeTypes] instance.
*/
func ExampleAttribute_SubTypes() {
def := mySchema.AttributeTypes().Get(`name`)
fmt.Printf("%d subordinate types found", def.SubTypes().Len())
// Output: 15 subordinate types found
}

/*
This example demonstrates a compliancy check of the "name" [AttributeType].
Expand Down
39 changes: 38 additions & 1 deletion ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func (r Schema) DITStructureRules() (dss DITStructureRules) {
return
}

func (r DITStructureRule) schema() (s Schema) {
if !r.IsZero() {
s = r.dITStructureRule.schema
}

return
}

/*
Replace overrides the receiver with x. Both must bear an identical
numeric rule ID and x MUST be compliant.
Expand Down Expand Up @@ -216,7 +224,7 @@ func (r DITStructureRule) Compliant() bool {
// structural class. If zero, we can bail
// right now, as the upcoming section does
// not apply.
dc := r.schema.DITContentRules().Get(form.OC().OID())
dc := r.schema().DITContentRules().Get(form.OC().OID())
if dc.IsZero() {
return true
}
Expand Down Expand Up @@ -265,6 +273,35 @@ func (r DITStructureRule) SuperRules() (sup DITStructureRules) {
return
}

/*
SubRules returns an instance of [DITStructureRules] containing slices of
[DITStructureRule] instances that are direct subordinates to the receiver
instance. As such, this method is essentially the inverse of the
[DITStructureRule.SuperRules] method.
The super chain is NOT traversed beyond immediate subordinate instances.
Note that the relevant [Schema] instance must have been set using the
[DITStructureRule.SetSchema] method prior to invocation of this method.
Should this requirement remain unfulfilled, the return instance will
be a zero instance.
*/
func (r DITStructureRule) SubRules() (subs DITStructureRules) {
if !r.IsZero() {
subs = NewDITStructureRuleIDList()
dsrs := r.schema().DITStructureRules()
for i := 0; i < dsrs.Len(); i++ {
typ := dsrs.Index(i)
supers := typ.SuperRules()
if got := supers.Get(r.RuleID()); !got.IsZero() {
subs.Push(typ)
}
}
}

return
}

/*
ID returns the string representation of the principal name OR rule ID
held by the receiver instance.
Expand Down
19 changes: 15 additions & 4 deletions ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,32 @@ The [DITStructureRule.NumericOID] method only exists to satisfy Go's interface
signature requirements with regards to the [Definition] interface type.
*/
func ExampleDITStructureRule_SuperRules() {
def := mySchema.DITStructureRules().Get(2)
def := mySchema.DITStructureRules().Get(2) // or 'dotNotArcStructure'
fmt.Println(def.SuperRules())
// Output: 0
}

/*
This example demonstrates the means of accessing all subordinate rule
instances of the receiver instance.
In essence, this method is the opposite of the [DITStructureRule.SuperRules]
method and may return zero (0) or more [DITStructureRule] instances within
the return [DITStructureRules] instance.
*/
func ExampleDITStructureRule_SubRules() {
def := mySchema.DITStructureRules().Get(0)
fmt.Printf("%d subordinate rules found", def.SubRules().Len())
// Output: 2 subordinate rules found
}

/*
This example demonstrates the means of calling the Nth [DITStructureRule]
slice instance from the [DITStructureRules] collection instance in which
it resides.
This method should not be confused with [DITStructureRules.Get], which
deals with unsigned rule IDs and names of definitions -- not indices.
The [DITStructureRule.NumericOID] method only exists to satisfy Go's interface
signature requirements with regards to the [Definition] interface type.
*/
func ExampleDITStructureRules_Index() {
defs := mySchema.DITStructureRules()
Expand Down
37 changes: 37 additions & 0 deletions oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,43 @@ func (r ObjectClass) SuperClasses() (sups ObjectClasses) {
return
}

/*
SubClasses returns an instance of [ObjectClasses] containing slices of
[ObjectClass] instances that are direct subordinates to the receiver
instance. As such, this method is essentially the inverse of the
[ObjectClass.SuperClasses] method.
The super chain is NOT traversed beyond immediate subordinate instances.
Note that the relevant [Schema] instance must have been set using the
[ObjectClass.SetSchema] method prior to invocation of this method.
Should this requirement remain unfulfilled, the return instance will
be a zero instance.
*/
func (r ObjectClass) SubClasses() (subs ObjectClasses) {
if !r.IsZero() {
subs = NewObjectClassOIDList()
ocs := r.schema().ObjectClasses()
for i := 0; i < ocs.Len(); i++ {
typ := ocs.Index(i)
supers := typ.SuperClasses()
if got := supers.Get(r.NumericOID()); !got.IsZero() {
subs.Push(typ)
}
}
}

return
}

func (r ObjectClass) schema() (s Schema) {
if !r.IsZero() {
s = r.objectClass.schema
}

return
}

/*
SuperChain returns an [ObjectClasses] stack of [ObjectClass] instances
which make up the super type chain of the receiver instance.
Expand Down
14 changes: 14 additions & 0 deletions oc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ func ExampleObjectClass_SuperClassOf() {
// Output: true
}

/*
This example demonstrates the means of accessing all subordinate class
instances of the receiver instance.
In essence, this method is the opposite of the [ObjectClass.SuperClasses]
method and may return zero (0) or more [ObjectClasses] instances within
the return [ObjectClasses] instance.
*/
func ExampleObjectClass_SubClasses() {
def := mySchema.ObjectClasses().Get(`top`)
fmt.Printf("%d subordinate classes found", def.SubClasses().Len())
// Output: 49 subordinate classes found
}

/*
This example demonstrates the means of gathering references to every
superior [ObjectClass] in the relevant super class chain.
Expand Down

0 comments on commit 02f1e99

Please sign in to comment.