On 21/09/2010 13:44, Wolfgang Laun wrote:
I find that the implementation shown below is more Java-ish. It would have some
advantages when branching based on a ResourceType value, etc. No errors show
up when I use this in Eclipse.
The reason is that enums cannot be extended, so it would make it impossible for sub modules to add new types without changing core.

Mark

YMMV.
-W

public enum ResourceType {

    DRL       ( "Drools Rule Language",          "drl"  ),
    XDRL      ( "Drools XML Rule Language",      "xdrl" ),
    DSL       ( "Drools DSL",                    "dsl"  ),
    DSLR      ( "Drools DSL Rule",               "dslr" ),
    DRF       ( "Drools Rule Flow Language",     "rf"   ),
    BPMN2     ( "Drools BPMN2 Language",         "bpmn" ),
    DTABLE    ( "Decision Table",                "xls"  ),
    PKG       ( "Binary Package",                "pkg"  ),
    BRL       ( "Drools Business Rule Language", "brl"  ),
    CHANGE_SET( "Change Set",                    "xcs"  ),
    XSD       ( "XSD",                           "xsd"  );   

    private String  description;
    private String  defaultExtension;

    ResourceType( String description, String defaultExtension ) {
        this.description = description;
        this.defaultExtension = defaultExtension;
    }

    public static ResourceType getResourceType(final String resourceName) {
        return valueOf( resourceName );
    }

    public static ResourceType determineResourceType( final String resourceName ) {
        try{
            return valueOf( resourceName );
        } catch( Exception iae ){
            return null;
        }
    }

    public boolean matchesExtension( String resourceName ) {
        return resourceName != null && resourceName.endsWith( "."+defaultExtension );
    }

    public String getDefaultExtension() {
        return defaultExtension;
    }

    public String getDescription() {
        return description;
    }

    public String getName() {
        return this.name();
    }

    @Override
    public String toString() {
        return "ResourceType = '" + this.description + "'";
    }
}

_______________________________________________ rules-dev mailing list rules-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-dev