You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hivemind.apache.org by Ryan Slack <ry...@evine.ca> on 2006/08/02 21:05:30 UTC

1.5 enum translator

I thought the following translator for Java 1.5 Enum might find a place
in either the framework or library. The only catch is that it must be
complied with a 1.5 jdk (calls java.lang.Enum.valueOf), although it will
work with -source 1.1. Is HiveMind is required to compile with a 1.4/3/2
jkd? Anyway, do with what you will.

--Ryan Slack


import org.apache.hivemind.schema.Translator;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.Location;
import org.apache.hivemind.ApplicationRuntimeException;

public class EnumTranslator implements Translator{
  public java.lang.Object translate(Module contributingModule,
                             java.lang.Class propertyType,
                             java.lang.String inputValue,
                             Location location){
    try{
      return java.lang.Enum.valueOf(propertyType,inputValue);
    }catch(IllegalArgumentException ex){
      throw new ApplicationRuntimeException(ex.getMessage(),location,ex);
    }catch(NullPointerException ex){
      if(propertyType==null){
        throw new ApplicationRuntimeException("no Enum type
provied",location,ex);
      }else if(inputValue==null){
        throw new ApplicationRuntimeException("null is not an
Enum",location,ex);
      }
    }
    return null; //should not be reachable. Maybe throw a RuntimeException?
  }
}


Re: 1.5 enum translator

Posted by Achim Hügen <ac...@gmx.de>.
Jdk 1.4 is used for building the distributions.
I don't know if it is possible to compile with jdk 1.5 for use with jdk 1.4.
There can be subtle problems. For example parts of hivemind are not
compatible with jdk 1.3 although 1.3 compatibility mode was used.

Achim

Ryan Slack schrieb:
> I thought the following translator for Java 1.5 Enum might find a place
> in either the framework or library. The only catch is that it must be
> complied with a 1.5 jdk (calls java.lang.Enum.valueOf), although it will
> work with -source 1.1. Is HiveMind is required to compile with a 1.4/3/2
> jkd? Anyway, do with what you will.
>
> --Ryan Slack
>
>
> import org.apache.hivemind.schema.Translator;
> import org.apache.hivemind.internal.Module;
> import org.apache.hivemind.Location;
> import org.apache.hivemind.ApplicationRuntimeException;
>
> public class EnumTranslator implements Translator{
>   public java.lang.Object translate(Module contributingModule,
>                              java.lang.Class propertyType,
>                              java.lang.String inputValue,
>                              Location location){
>     try{
>       return java.lang.Enum.valueOf(propertyType,inputValue);
>     }catch(IllegalArgumentException ex){
>       throw new ApplicationRuntimeException(ex.getMessage(),location,ex);
>     }catch(NullPointerException ex){
>       if(propertyType==null){
>         throw new ApplicationRuntimeException("no Enum type
> provied",location,ex);
>       }else if(inputValue==null){
>         throw new ApplicationRuntimeException("null is not an
> Enum",location,ex);
>       }
>     }
>     return null; //should not be reachable. Maybe throw a RuntimeException?
>   }
> }
>
>
>