[MDSAL-76] Generated Java Enumerations should contain mapping to the string counter part Created: 19/Mar/15  Updated: 09/Mar/18  Resolved: 10/Mar/17

Status: Resolved
Project: mdsal
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement
Reporter: Devin Avery Assignee: Ryan Goulding
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Issue Links:
Blocks
is blocked by MDSAL-40 Milestone: Implement Binding Specific... Resolved

 Description   

The ask:

As a developer, I want the string value for a given enumeration to be accessible from the generated java binding type, so I can use the raw string value as needed (for example to pass to a southbound plugin).

Specifically, if we have a type definition like this:

leaf testEnum {
type enumeration

{ enum "value-one"; enum "value-two"; }

}

today it generates an inner enumeration class like this:

public enum TestEnum

{ ValueOne(0), ValueTwo(1) ; ... }

What would be great as it would drastically simplify things, would be for the string value to also be included, and accessible from the generated class. For example, the above type would generate:

public enum TestEnum {
ValueOne(0, "value-one"),
ValueTwo(1, "value-two")
;

String getName()

{ ... }

static TestEnum forValue( String name ){ ... }

...
}

. Today the only way to get the mapping is to get the schema context for the module, drill down to the specific definition for the enum, and then manually create a map between the enumPair schema definition and the TestEnum class via the "value".



 Comments   
Comment by Robert Varga [ 19/Mar/15 ]

This is a change to the bindings specification, although compatible. Targetting to next release as we are just a few hours from API freeze.

Comment by Ryan Goulding [ 01/Jun/16 ]

It looks like this is already part of the binding spec; am I missing something:
https://github.com/opendaylight/mdsal/blob/master/binding/mdsal-binding-generator-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/Enumeration.java

Comment by Ryan Goulding [ 01/Jun/16 ]

Nevermind a quick test proved otherwise. This will require exposing the "raw" data from yangtools and then outputting in mdsal binding generator. I have a draft change in the works that appears to work.

Comment by Robert Varga [ 20/Jun/16 ]

https://git.opendaylight.org/gerrit/39733
https://git.opendaylight.org/gerrit/39734

Generated at Wed Feb 07 20:08:35 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.