From: Don M. <mc...@np...> - 2009-02-26 22:32:29
|
I've released a new, downloadable package for Java DIS enumerations, available at sourceforge. The Java code was generated from the EBV XML document (R35 release). The code is open source, and licensed under the permissive and non-viral BSD open source license. For example, this fragment from the EBV XML document: <enum length="8" id="2" cname="pduheader.pdutype" name="PDU Type" source="3.2"> <enumrow id="0" description="Other"/> <enumrow id="1" description="Entity State"/> <enumrow id="2" description="Fire"/> Has been translated into this fragment of Java code: public enum PduType { OTHER(0, "Other"), ENTITY_STATE(1, "Entity State"), FIRE(2, "Fire"), ... Enumerations are a new-ish feature of Java that were incorporated around JDK 1.5; they are more powerful than standard C enumerations. They are described by Sun here: http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html This makes it much easier for programmers to use enumerations in code. For example, switch statements can be made more readable: PduType type; ... switch(type) { case ENTITY_STATE: handleEntityStatePdu(); break; case FIRE: handleFirePdu(); break; ... and you can loop over all the valid enumerations in a type: for(PduType anEnum:PduType.values()) { } Programmers can also access the enumerated value and description, or go from an integer value to the enumerated object: CountryType aCountry = CountryType.UNITED_KINGDOM; aCountry.getValue(); // Returns the enumerated value for the UK, 224 aCountry.getDescription(); // Returns string "United Kingdom" aCountry.getInternetDomainCode() // Returns "UK" CountryType.getEnumerationForValue(225); // Returns the enumerated object CountryType.UNITED_STATES CountryType.getDescriptionForValue(248); // Returns the description of this enumerated value, "Clipperton Island (France)" Two file packages are available for download: disenum_bin_1.0.tar.gz contains only a jar file with the compiled classes and the javadoc documentation. Enumerations-1.0.tar.gz contains the full development directory and source code. This second package is useful mainly if you want to modify the source code and recompile it, add new enumerations from the EBV file, or tackle adding a C/C++ enumerations implementation. The full development directory is of course also available for anonymous checkout from sourceforge. https://sourceforge.net/project/showfiles.php?group_id=193363&package_id=311835&release_id=664300 Is the link to the pre-packaged downloadable files. The sourceforge home page of the project is at https://sourceforge.net/projects/open-dis/ As always, we welcome participation by others in this project, and hope that military simulation developers find it useful. Don McGregor The MOVES Institute http://www.movesinstitute.org/ mc...@np... |