2011-10-25 8 views
0

我々がいるProtobuf形式にCustomExceptionを表現しようとしている -java.lang.Exceptionをサポート/拡張するprotobufメッセージはありますか?

public class CustomRestException extends RuntimeException { 

private CustomRestErrorMessage customRestErrorMessage; 
public CustomRestException (CustomRestErrorMessage customRestErrorMessage, Throwable cause) { 
    super(cause); 
    this.customRestErrorMessage= customRestErrorMessage; 
} 
public CustomRestException (CustomRestErrorMessage customRestErrorMessage) { 
    this.customRestErrorMessage= customRestErrorMessage; 
} 
} 

public class CustomRestErrorMessage implements Serializable { 

    private String causeMessage = ""; 
    private String errorCode = ""; 
    private String errorMessage = ""; 
    private String errorSubCode = ""; 
    private String stackTrace = ""; 
} 

そして、ここではCustomRestExceptionProtos.protoが

option java_package = "com.company.my.exception"; 
option java_outer_classname = "CustomRestExceptionProtos"; 

message CustomRestProtoException 
{ 
    required CustomRestProtoErrorMessage customRestErrorMessage = 1; 
} 

message CustomRestProtoErrorMessage 
{ 
    required string errorCode = 1; 
    required string errorMessage = 2; 
    required string errorSubCode = 3; 
    required string causeMessage = 4;  
    required string stackTrace= 5; 
} 

ファイルであることは、型としてのjava.langを、この "CustomRestExceptionProtos" を表現することができます。 .protoファイルの例外?

答えて

0

あなたの質問を正しく理解している場合は、メッセージタイプCustomRestProtoExceptionから生成されたJavaクラスをjava.lang.Exceptionに設定します。

http://code.google.com/apis/protocolbuffers/docs/reference/java-generated.html#plugins

代替と簡単な方法はCustomRestProtoExceptionオブジェクトを保持するためのラッパーのJavaの例外サブクラスを導入するだろう:私はあなたがこれを達成するためかもしれない唯一の方法は、Javaコード生成を拡張するプラグインを書くことであると思います:

public class CustomRestException extends Exception 
{ 
    private CustomRestProtoException exception; 

    // usual constructors etc. 
} 
関連する問題