找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 2854|回复: 10

[webOS开发] Service 的修改方法

[复制链接]
发表于 2009-7-25 17:56 | 显示全部楼层 |阅读模式
谢谢捧场2 Q6 G! w' F( x; Y

6 _; S4 ]7 o0 H5 l) ]* ][ 本帖最后由 mfly 于 2009-7-31 16:09 编辑 ]

评分

参与人数 1威望 +50 收起 理由
CyberVsQ + 50 谢谢分享

查看全部评分

回复

使用道具 举报

发表于 2009-7-25 20:59 | 显示全部楼层
支持!!!
回复 支持 反对

使用道具 举报

发表于 2009-7-26 01:04 | 显示全部楼层
谢谢分享
回复 支持 反对

使用道具 举报

发表于 2009-7-26 01:09 | 显示全部楼层
Services 這一个我还是似懂非懂.
回复 支持 反对

使用道具 举报

发表于 2009-7-26 22:17 | 显示全部楼层
用这个方法,结果出现这样,哪里不对呢?请指教,谢谢
  1. package com.palm.messagingrouter;
    ' Z4 y$ F, G; K( y8 q$ W( \5 t" R- {
  2.   ?& h# T4 A7 R, C0 G8 F. _$ E0 ]
  3. import Association.Many;
    2 |$ c- m9 o% K
  4. import com.palm.oasis.util.ZoneLogger;
    5 W! ?! [# ~% R
  5. 3 A% \' h0 c% r- g) X
  6. public class SmsMessageSegmentContainer extends MessageSegmentContainer2 W% e- o# z4 r) D* J1 @
  7.   implements MessagingRouterJsonConstants, MessagingRouterTilConstants
    . n- w9 z- j% ^
  8. {& s  e  W% e- G" r+ u# G6 @$ N1 F
  9.   private static final long serialVersionUID = 1L;% Z( \6 H: A" ?) v
  10.   private String completeMsgString;
    0 a* ^4 r0 c* s5 |# D
  11.   private String bodyEncoding;/ D5 W* a0 k+ i" }( m" a5 K9 p0 F8 w
  12.   protected static ZoneLogger logger;
    & ^$ Z* R& v; V* P+ W" |5 G9 ^
  13.   Many segments;
    ! Y3 P) K, X% Z
  14. ) b, F, K4 r5 J$ k. g" s/ x0 F& Z
  15.   public SmsMessageSegmentContainer()+ I5 m' b$ l9 h
  16.   {
    8 A( H7 I6 }; S4 P+ C! i
  17.   }
    4 D2 p2 M) Q8 q- m8 n* s8 X7 [0 v. c
  18. 1 E( @% N$ c' S
  19.   public SmsMessageSegmentContainer(long messageId, int totalSegments, String bodyEncoding)
    " h8 M1 a8 C4 k' y
  20.   {& I/ w: h8 h8 h- Z2 |- C6 |* B
  21.   }
    / ~" E) g4 d+ p. i+ l

  22. , |/ l- W2 S& B: b0 {$ H
  23.   SmsMessageSegmentContainer(String messageId, int totalSegments, String bodyEncoding)
    5 S7 ?  N) C) w: @  R7 C6 C* @
  24.   {9 v! L/ p2 k; L$ B" B( g+ s
  25.   }5 Q: K' t0 m- N; r* }# g
  26. + n" Q. R2 S; b: ~# }
  27.   public String getBodyEncoding()
    + X/ |' ]" Z2 l8 B2 z' U
  28.   {; X$ Q) f1 s- y0 A8 S  Q
  29.     throw new Error("Unresolved compilation problem: \n");
    2 N$ Z$ w9 R8 {$ A9 ^) ^
  30.   }
    3 B0 I. U5 N7 y4 a

  31. 7 @0 @' W% s  O* x- E" ^- R
  32.   protected boolean isPrintableChar(char ch)
    : z+ U- z7 Q  y4 b+ y) p$ F
  33.   {7 X$ h& x5 \- \1 u, d9 ~
  34.     throw new Error("Unresolved compilation problem: \n");( @" T' m6 z- ^2 f6 E/ u
  35.   }
    " m" K& n# `0 J; e2 a! f8 o; @

  36. * R" U& W. {1 U2 E$ w
  37.   public boolean isMessageComplete()
    9 p' Z1 ~0 W. o
  38.   {8 T6 ~- U: v& _5 S* @9 j
  39.     throw new Error("Unresolved compilation problem: \n\tMany cannot be resolved to a type\n");1 O) W" y# ^0 Q" o; d$ H
  40.   }8 B+ O. O2 c( j5 }/ R$ o9 v5 V' {

  41. ) c( _+ R: {& |+ v
  42.   public String getCompletedBody()5 a6 O6 ~) p! ~3 J( B1 M3 C9 R
  43.   {; l( C2 S# i5 t( b( G
  44.     throw new Error("Unresolved compilation problem: \n");! |, B" E; X9 K6 w) Y
  45.   }
    / y3 T% J! ^9 `8 l$ `
  46. 2 G) t8 U- J" R7 P9 I/ a# U
  47.   public void addNewSegment(SmsMessageFromTil msgSegment)
    " m& N- X2 t1 a  f0 [
  48.   {
    6 U' [0 C% Y' z; }9 \* d8 M
  49.     throw new Error("Unresolved compilation problems: \n\tMany cannot be resolved to a type\n\tMany cannot be resolved to a type\n");
    " U/ w/ w" H0 ?/ h9 w& a& O
  50.   }- w8 n+ ]4 ^" D$ T* ]* G+ D# u

  51. , i! J1 u4 C* o& C! P0 y
  52.   private String convertToJson(boolean doHidePrivateData)4 Z* S2 q- ?) \$ X5 V' e
  53.   {
    5 R4 x7 z- v+ B/ z
  54.     throw new Error("Unresolved compilation problems: \n\tMany cannot be resolved to a type\n\tSyntax error on token ":", ; expected\n\tSyntax error, insert "AssignmentOperator Expression" to complete Assignment\n\tSyntax error, insert ";" to complete Statement\n\tString cannot be resolved\n\tjsonString cannot be resolved\n\tjsonString cannot be resolved\n\tjsonString cannot be resolved\n");
    , \4 c8 U6 ]+ n! f
  55.   }( f1 b0 s: g& r

  56. 6 e& p, T/ W) T; r
  57.   public String toJSONString()
    5 O4 g5 y+ O/ i$ N$ c" W$ ?( B
  58.   {8 G- U3 L2 Y# E4 }; h/ k
  59.     throw new Error("Unresolved compilation problem: \n");
    & `0 z8 D0 ~5 J+ q( Q
  60.   }0 M8 D- p$ P: E5 l. y

  61. 9 U" W: |4 [" ]0 B5 u7 ]0 m5 k
  62.   public String toDebugJSONString()
    ; e& ]: ?6 h6 R, |) k6 z
  63.   {5 R4 f, w( m$ o% D& S. i
  64.     throw new Error("Unresolved compilation problem: \n");
    4 F! f/ s% J; f4 r' n( o
  65.   }# H" [% \: l" x' B
  66. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2009-7-26 22:23 | 显示全部楼层

原始代码是这样的

  1. package com.palm.messagingrouter;
    9 i4 W& l; W; P+ l' u; O% v
  2. ' ]5 Q) p  ?5 B  j
  3. import com.palm.oasis.activerecord.ActiveRecord;: v' }/ G% V2 m4 y9 g" q) v
  4. import com.palm.oasis.activerecord.ActiveRecordException;
    - R+ U0 Y0 \/ ^" \* o0 t) `
  5. import com.palm.oasis.activerecord.Association.Many;8 E1 p4 s! [! h, T2 n( \* f
  6. import com.palm.oasis.activerecord.Batch;
    & ?# W1 K# U' C# ]
  7. import com.palm.oasis.activerecord.SqlFind;
    ; Q' E+ a, x0 G+ o, h5 ]
  8. import com.palm.oasis.util.Base64;% N6 R# H0 A8 r2 P8 Y
  9. import com.palm.oasis.util.ServiceLogger;* a0 k& G) s6 C. V/ ~' x: [( K9 C
  10. import com.palm.oasis.util.ZoneLogger;8 [9 z/ o! s" [! e
  11. import java.io.ByteArrayOutputStream;
    " `/ A: U' K- I; y7 H( F+ ~: P
  12. import java.io.IOException;
      V: M9 z+ Q- w. J4 M* M
  13. import java.io.PrintStream;% E  {' ]2 j9 P+ r; R
  14. import java.util.Iterator;% A  H- k* _) L& n/ T1 a, b, T6 P/ Y: Q
  15. import java.util.List;( V9 L( t1 W: s
  16. import org.json.JSONException;
    / M% K' B, I4 h5 x9 x
  17. import org.json.JSONObject;1 D+ a/ e8 @8 r( h1 @" Y+ c

  18. 5 f) A! j7 T: B/ @
  19. public class SmsMessageSegmentContainer extends MessageSegmentContainer  q/ H  l( B' k9 e! K; l  C" e( y
  20.   implements MessagingRouterJsonConstants, MessagingRouterTilConstants+ O8 f9 ~; ^: p3 b2 s
  21. {
      [# w2 E2 G0 ]/ X3 N% l+ F
  22.   private static final long serialVersionUID = 1L;( ^. h! {  P) |
  23.   private String completeMsgString;
    , F' h6 J2 x' h+ ~
  24.   private String bodyEncoding;
    : N- ]* m+ L% N; h/ |# K( N( v2 _1 S6 r
  25.   protected static ZoneLogger logger = MessagingRouterService.getLogger(SmsMessageSegmentContainer.class.getSimpleName());
    8 u3 r  Z$ a; t& Q
  26.   Association.Many segments;: m$ N" j' Z' `* `" S
  27. 2 W9 K6 @# E9 t' Y
  28.   public SmsMessageSegmentContainer()% ]1 M" O& c# T/ x, q
  29.   {
    . s2 T, d2 o- [- a$ S
  30.     this.completeMsgString = null;! V" p* H) ^4 [' i) U, u
  31.     this.bodyEncoding = null;
    ) _1 X: e* G  Z: N7 B& `6 k$ }+ c
  32.     this.segments = hasMany(SmsMessageFromTil.class, 1);- u6 ~* Y8 k: ^3 {
  33.   }8 b9 c# J9 @+ \: ?

  34. & Q9 p3 R; f2 o8 w
  35.   public SmsMessageSegmentContainer(long messageId, int totalSegments, String bodyEncoding)! H% z: {5 ?3 e- x2 j
  36.   {+ o+ S2 v! t# p* C; m" d
  37.     super(System.currentTimeMillis(), messageId, totalSegments);1 t) ^. S) t! P! g
  38.     this.completeMsgString = null;# b$ V( Q/ f: `
  39.     this.bodyEncoding = null;
    1 @9 ^  |4 Q  M$ b
  40.     this.segments = hasMany(SmsMessageFromTil.class, 1);9 O# m1 g/ h6 A. k3 ]
  41.     this.bodyEncoding = bodyEncoding;. z6 s8 ?- e1 a/ s! g
  42.   }$ C* Y; j+ I+ U& K7 s& Q

  43. / p" D/ e& B* |- C
  44.   SmsMessageSegmentContainer(String messageId, int totalSegments, String bodyEncoding)+ T; G1 ~4 n7 Q+ T' t7 ?( \
  45.   {
    . N0 x+ x: V# |1 C2 s3 v9 g7 c
  46.     super(System.currentTimeMillis(), Integer.parseInt(messageId), totalSegments);6 ^+ t. y. G2 h' r% N% I* J
  47.     this.completeMsgString = null;
    . n8 a0 z+ f8 Q* t5 }, M$ l6 ~; W  b
  48.     this.bodyEncoding = null;
    2 E! @7 [: c( \; g! F
  49.     this.segments = hasMany(SmsMessageFromTil.class, 1);/ s5 ~- _2 |) f- H, z7 X
  50.     this.bodyEncoding = bodyEncoding;! W2 n: m/ s6 v. _  t. z0 A
  51.   }
    4 @; O) Z9 ?# ^, ^# {1 D/ A

  52. * j# R6 N" d4 B& {
  53.   public String getBodyEncoding()! R4 M. I' Z3 D
  54.   {0 A4 L9 S% S1 X1 v" Q8 Y; p
  55.     return this.bodyEncoding;
    : \# f0 H7 c- I! y1 {
  56.   }
    . `2 O+ N5 j8 [( p+ x
  57. / L- n$ i4 Y$ }' N& V3 T
  58.   protected boolean isPrintableChar(char ch)
    9 P) r: G/ u! @3 B* _* E
  59.   {
    8 D$ _3 t2 \) Z& n1 d% o! [
  60.     boolean isItPrintableChar = false;( @) H$ [2 ^! O" Z
  61.     if ((ch >= ' ') && (ch <= '~')) {
    1 }; n6 y2 X+ }, g2 j
  62.       isItPrintableChar = true;) G+ }9 w5 ]: ?4 r7 ]" _3 c
  63.     }8 r- E3 _, J. F3 W+ b3 w
  64.     else if ((ch >= 128) && (ch <= 168)) {+ J# F7 T6 \! \( V3 M
  65.       isItPrintableChar = true;+ L1 F' O& i. b  {4 }& I; H
  66.     }' f" c, a1 g! \* ], \
  67.     else if ((ch >= 224) && (ch <= 247))
    # X" \) s: p/ A6 I6 G1 O) J
  68.       isItPrintableChar = true;* y# Z4 I  h: F5 D+ w  k4 p2 O0 ?& c9 }; `
  69.     return isItPrintableChar;
    ( @- l4 X6 R: q8 I% W2 A0 B- t, c
  70.   }% P4 Y4 [0 j# f& w, B

  71. # b6 X) M  e5 m
  72.   public boolean isMessageComplete()
    # n8 ~$ S$ W  k$ t* s  r
  73.   {
    6 [1 W$ P2 E" q4 g- p; n
  74.     if (!(this.isMessageComplete))
    3 Y6 y! w& s! F; i! r
  75.       try/ r( A) O  J: E8 |+ ?
  76.       {- q3 n9 Q4 F8 f
  77.         synchronized (SmsMessageSegmentContainer.class)  Y; I- K7 q. w: P+ J& R% ^
  78.         {
    ; p/ Z* v5 x7 D7 ~) N4 Y' V
  79.           List listSmsSegments = ActiveRecord.find(this.segments.sqlAll().orderBy("segmentNumber ASC"));7 l  E+ f; M0 `  R5 Y
  80.           if ((listSmsSegments != null) && (listSmsSegments.size() == this.totalSegments))- b) H3 V6 @6 }+ @' z
  81.           {' s7 f9 |4 n# m
  82.             this.isMessageComplete = true;
      d( {. w! l/ A# z  c/ i
  83.             logger.fine("At this point all SMS message segments have been recieved so we are going to put it all together");
    9 v2 J' F, r8 D& p- Y; R! G- C6 U1 X
  84.             StringBuilder msgString = new StringBuilder(160 * this.totalSegments);
    . ]8 @' T" Z" z! s* ~  K
  85.             if (msgString != null)& ?+ ]1 s& `" H$ I( w4 U5 p3 z
  86.             {& t" q- R7 {, P2 h5 `& d' S
  87.               if ("bbin".equals(this.bodyEncoding))& c4 z& [5 y# [# s+ b; w  P
  88.               {
    3 b# w, Z5 Y# v3 p
  89.                 ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    . r  G3 O% ^. _0 q+ Z+ U
  90.                 Iterator i$ = listSmsSegments.iterator();
    % F4 m* ]( c8 T, z! ~9 u2 h, J

  91.   Q5 e# {' {" [# }
  92.                 while (i$.hasNext())
    / }1 Z: o  m8 S( X" `! M
  93.                 {) K# T7 u* {; s, E
  94.                   SmsMessageFromTil msg = (SmsMessageFromTil)i$.next();& S. B. J/ ~6 M& v
  95.                   if ((msg.getBody() != null) && (msg.getBody().length() != 0));
    . m4 t4 {2 U7 o
  96.                   byteOut.write(Base64.decode(msg.getBody()));
      Z' j' E: ~, e* Z+ a6 r- b& p" c
  97.                 }' u: I5 l! v9 L, ]6 [. f+ G  U
  98.                 char[] testArray = byteOut.toString().toCharArray();% c. |- Z8 k% L! O, s/ j& a4 H
  99.                 boolean isAllCharsPrintable = true;
    6 S% _% n- _. z. M8 H& B
  100.                 int i = 0;$ T# ?2 m3 f, T
  101.                 for (i = 0; (i < testArray.length) && (isAllCharsPrintable); ++i) {
    / \5 W7 b7 v/ S5 \
  102.                   if (!(isPrintableChar(testArray[i])))+ J  x5 }  m7 m( Q
  103.                     isAllCharsPrintable = false;9 w1 f, Q/ \  ~5 M! d) d0 K
  104.                 }
    ( u8 U% H7 f7 `9 O* m1 N
  105.                 if (isAllCharsPrintable)
    6 {! }! m' [' w# Q! V( l& g! w# f
  106.                   this.completeMsgString = byteOut.toString() + "";- N' _; [  a& J
  107.                 else8 r$ K; y9 f8 x5 `
  108.                   this.completeMsgString = Base64.encodeBytes(byteOut.toByteArray()) + "";7 ]8 g+ z6 D* X* O0 c8 [4 t
  109.                 System.out.println(this.completeMsgString);2 |9 r9 D" i5 j8 o2 r$ `0 J
  110.               }
    4 F; T3 t1 u6 t& x" b
  111.               else {
    + E3 M9 V  w$ `% N& n
  112.                 Iterator i$ = listSmsSegments.iterator();
    5 v) W8 g& X5 B$ n0 u
  113.   G4 k! H. [) N: H4 R
  114.                 while (i$.hasNext())
    6 K) N5 Q4 i) W, C9 V5 R( q5 m. e; B" \% E
  115.                 {
    2 F$ o* G6 E  W4 a1 g
  116.                   SmsMessageFromTil msg = (SmsMessageFromTil)i$.next();
    ' A6 j0 X' T( S/ ]5 O$ @
  117.                   if ((msg.getBody() != null) && (msg.getBody().length() != 0));1 ?) w9 Y5 n+ j3 h) a
  118.                   msgString.append(TilUtils.decodeString(msg.getBodyEncoding(), msg.getBody()));- ?2 `& k$ Q; D8 H; K! ?
  119.                 }
    & I1 t2 m) `. c9 A! |/ [6 K
  120.                 this.completeMsgString = msgString.toString() + "";
    4 Q" m: X; O; M% u6 M1 S( K
  121.               }
    " H, O2 s5 |% W+ G6 @4 g
  122.             }
    , H1 ?. u: v/ t* T  b& Y9 o
  123.             else {
    + K) i" U- @0 T6 w: e
  124.               logger.severe("Error allocating memory to put Segmented SMS Message Together");8 V; Q/ a' [3 N. S
  125.             }( S2 V0 g' }8 f+ R8 X+ d
  126.           }$ h( V5 A& y6 K. H* i( |
  127.           else if ((listSmsSegments != null) && (listSmsSegments.size() > this.totalSegments)) {' M+ E0 j8 f( K5 D, e* F$ H
  128.             logger.severe("Too many SMS message segments found so assuming corrupted for " + this.segMsgContainerId + " in DB.  We found:" + listSmsSegments.size() + " but we expected: " + this.totalSegments); }
    - j4 ~4 @# ?7 v1 B
  129.           listSmsSegments = null;2 {5 _* `. p2 C" v2 y+ X1 N* Q
  130.         }% K( ~" B' b% ?$ k
  131.       }
    6 X& z# K4 `' O* f; `/ `
  132.       catch (ActiveRecordException e)4 I" B5 V0 g' |; e% R" g( Y1 W
  133.       {2 k/ i* M! ?. u7 f4 n
  134.         logger.warning("SMS Message couldn't be retrieved from the database at this time.");" A# L6 |$ B, h8 a% r3 F0 W0 i
  135.       }
    . j2 _, O1 @) ^7 B
  136.       catch (NullPointerException e)
    $ w; x: k; o- f& u( Y
  137.       {
    1 O& O& z) q- R0 S
  138.         logger.severe("Null Pointer Error putting Segmented SMS Message Together");
    & n5 I" N% s* g+ \
  139.       }- b/ z; X: V4 A- Q: q  Q
  140.       catch (IOException e). \4 b. Q( {% S( e$ `5 P' z' }
  141.       {4 {7 b4 G) q0 h* M5 s- P5 @. c
  142.         logger.severe("Error Decoding Binary Message");( b  i  p9 ?7 O0 j
  143.       }8 ]% B9 {4 c+ j- y2 w
  144.     return this.isMessageComplete;( M7 I; R; Z2 s! K( T5 t+ J
  145.   }, R/ H0 J) P# y! A- O' D
  146. 9 M- H  h9 ^' s4 D+ s0 Z
  147.   public String getCompletedBody(); ]( B$ D8 S4 s, L0 X, F2 }
  148.   {$ L2 Y' I# j. z; H6 W7 ]# k8 n! \
  149.     if (!(isMessageComplete()))
    4 E1 v& \7 A& o+ V
  150.       logger.warning("Message Not yet Complete so you should call this after testing with isMessageComplete");
    ; n* |- s2 y+ h6 k
  151.     return this.completeMsgString;( }* G2 ~) g- y7 J' c( `/ o
  152.   }& [) I, h" {2 A4 d( o4 X
  153. % V6 q9 Q8 B, ?0 F' S. T
  154.   public void addNewSegment(SmsMessageFromTil msgSegment)6 U* B9 v3 @  `
  155.   {
    " D$ Y* o0 S2 s& z& K
  156.     try, Z& _: i+ U+ W! I  I" i
  157.     {
    ' k! i0 t9 l9 M
  158.       if (logger.getLogger().isFinerLoggable)
    $ d' A/ }! }$ ~; O
  159.         logger.finer("Attempting to Adding new SMS Message with MessageId:" + msgSegment.getMessageId() + " with SegmentNo:" + msgSegment.getSegmentNumber() + " of Total Segments:" + msgSegment.getTotalNumberOfSegments());
    ' k: ~0 l/ s, Z, \  a. m
  160.       synchronized (SmsMessageSegmentContainer.class)
    - ~) x( K( r( J- H6 ^8 G8 v
  161.       {) e( {" U8 a: S2 @, [
  162.         int numSegmentsAlreadyStoredWithThatSegNumber = ActiveRecord.count(this.segments.sqlAll().where("segmentNumber=?", new Object[] { $ F8 O- ~  L7 a" ~$ S2 b' q( i
  163.           Integer.valueOf(msgSegment.getSegmentNumber()) }));* y. p2 w9 }, s( ]/ d0 I
  164. ( P# J/ {2 m) w
  165.         if (numSegmentsAlreadyStoredWithThatSegNumber == 0)) ?+ P; W! b1 u2 r6 a( N; E8 s
  166.         {7 J6 h# Q) e/ _. e4 |4 a
  167.           logger.finer("New SMS Segmeted Accepted.  Adding it to SMS Container");4 h" Z" B% e! a' ?( _
  168.           logger.finer("saving segment to message holder");
    ; E0 W. J  `% M, W" K
  169.           Batch batch = new Batch();. T/ @" ^8 O) }- G. ^& G
  170.           this.segments.push(batch, msgSegment);9 O1 e5 ^* v, u0 O' c# f& {
  171.           msgSegment.save(batch);( u8 v& S9 w, j2 c
  172.           if (0L != msgSegment.getTimeStamp())6 a$ t! _/ p9 w
  173.             setTimeStampLastReceivedSegment(msgSegment.getTimeStamp());
    ) f/ R3 I0 W% k0 x+ O3 ^
  174.           save(batch);
    5 z2 c$ s. ^% |  j
  175.           batch.execute();
    : o: ^/ S7 @& J2 m0 c. C, L
  176.         }
    ; N% h( J! ]7 e( F$ s
  177.         else {
    - Y$ H8 H/ z- k' c9 K
  178.           logger.warning("Found duplicate SMS Message segment already saved");
    & t" x% `1 r1 [
  179.         }$ h+ K1 L: W+ d4 H+ W. i
  180.       }
    * ~  I' m) M4 `7 W% ^+ b8 a$ d' o
  181.     }# C8 C- \) W$ b  P- v: x: w! v
  182.     catch (ActiveRecordException e)8 _1 G( J* O- Z' n: W
  183.     {- @4 ~! C7 H" u" G6 ~, e2 V
  184.       logger.severe("Error saving SMS Message Segment.  Data will probably be lost.");& o( y; p  T* i; e
  185.     }
    , X1 T  ]! X, p8 P! m
  186.   }4 r$ s, h' [' O# q3 k( }2 S" V9 A4 R

  187.   v3 ]8 y& _' g5 {2 r5 R
  188.   private String convertToJson(boolean doHidePrivateData)9 D6 i; Z% q: g* E
  189.   {
    / ]9 Z7 d( U; g; r8 s; F
  190.     JSONObject smsJson = new JSONObject();
    ! B4 a& H: ?# ^/ k" A
  191.     SmsMessageFromTil msgSeg = null;/ j! I! b* Z' m; `1 q
  192.     try
    & o; i: m& N1 V9 K2 b6 d% M
  193.     {& [6 p% {. ^: M
  194.       msgSeg = (SmsMessageFromTil)this.segments.findFirst();
    % K; ]( y; @9 S4 D
  195.       if (msgSeg != null)
    3 D. P' ?3 @' N( {$ G6 o
  196.       {: ^  e4 d  I7 C0 @/ U
  197.         if (doHidePrivateData)
    & p9 V$ v0 N3 V" z1 Q6 _( o& B" V, \
  198.         {
    4 l$ A& D8 F/ a# Q
  199.           smsJson.put("body", "This has been hidden for logging");
    2 v- E2 l: B4 L4 v$ X
  200.           smsJson.put("address", "555-333-4444");4 S4 Z1 ^. ^# f
  201.           smsJson.put("callbackNumber", "555-333-4444");
    5 d9 w' ~& Z+ d5 Y; K" }5 L
  202.         }
    6 y5 |0 F' _% s6 h4 {! L  o
  203.         else {
    9 M5 |1 p% _; `: C
  204.           smsJson.put("body", getCompletedBody());
    ( H& J# q* ?6 ?) H9 a
  205.           smsJson.put("address", msgSeg.getWhoIsItFrom());$ m- n5 E0 J& k2 J4 U# ~7 Q9 M6 f1 s
  206.           smsJson.put("callbackNumber", msgSeg.getCallbackNumber());
    ' o7 k( s* _- X' W1 N2 S0 i
  207.         }- f2 k" r/ t3 e& Y  o
  208.         smsJson.put("networkMsgId", msgSeg.getMessageId());
      q+ K* c- }2 K5 R4 P
  209.         smsJson.put("deliveryReportOptions", msgSeg.getDeliveryReportOptions());  i& g9 ~* B* c3 p- E
  210.         smsJson.put("timeStamp", msgSeg.getTimeStamp());0 Y* H" i. M6 K9 D" e2 v) @" \" F
  211.         if (msgSeg.isThisMessageFromAGsmNetwork())) n4 L& ~7 z. v( P
  212.         {. p9 K9 h6 _9 o: z; n% i" G
  213.           smsJson.put("priority", msgSeg.getSmsClassInfo());
    1 A! ]( J3 {; ?. G. K% k
  214.           if (msgSeg.isFromSim())
      \5 f6 H0 I' H/ ]
  215.             smsJson.put("isFromSim", true);7 `6 W6 j5 C2 o
  216.         }9 T' k6 n% M+ M  g9 q$ D
  217.         else {
    9 N: l: [5 X: p- H( k9 D# L4 w# d3 F
  218.           smsJson.put("priority", msgSeg.getPriority());
    / v; E( W1 H% _) S5 U/ n$ O) O9 M9 ]
  219.         }% a  R. G+ F0 O. u5 l. G
  220.         smsJson.put("displayMode", msgSeg.getDisplayMode());
    ) @1 v3 C1 V1 r6 E
  221.         smsJson.put("privacyMode", msgSeg.getPrivacyMode()); break label257:
    ( A0 Z/ P9 j2 P$ [/ @  I* m
  222.       }
    + [0 ~1 c" I$ {, V0 z0 x- s
  223.   q" S  X7 l& l, a$ w" w
  224.       logger.severe("Did not find Message Segment to generate JSON string");1 G! G. \0 w7 u" l
  225.     }9 |0 y" z5 ?+ z
  226.     catch (ActiveRecordException e)- J; s! g! I6 L# Y
  227.     {
    2 |: y$ p$ Y6 L+ e# e2 {
  228.       logger.severe("Caught Exception", e);" G2 A# `( N. e4 o7 |2 N
  229.     }! Z3 F( A. l* T, ^' c' c$ o0 e
  230.     catch (JSONException e)
    , p# o7 C& W% C2 a' {; p1 S
  231.     {
    : }/ [0 x. b  a2 j1 s% _$ V% @6 u+ c, j
  232.       logger.severe("Caught Exception", e);! Q5 B5 s5 E) D9 C( j* {3 C
  233.     }
    ! F( a* Z! V* F( u6 A4 v' Q. o
  234.     label257: String jsonString = smsJson.toString();
    & l$ ^/ I5 f# A, J/ q3 |! i
  235.     logger.finer("toJSONString SMS Message: " + jsonString);6 r  D2 U9 p0 n' w( x$ b3 ?
  236.     return jsonString;
    # `. @+ d6 k  R* u
  237.   }
    - R, t3 C( c$ N! }+ q

  238. 6 ^# v" [6 y0 a# ^1 z
  239.   public String toJSONString()
    & J3 \; i# [- H( _# o1 @
  240.   {
    * |- G; x7 ^! e7 l$ u! ]
  241.     return convertToJson(false);
    5 A+ I' S& H" g$ V8 l% w" A# |
  242.   }
    8 Y0 ]# Q+ l. x3 ~4 V) _

  243. % ~' Y3 S, r  u
  244.   public String toDebugJSONString()% c. J8 h, \! j: I# `4 K
  245.   {
    * S# @/ \! I# z% l9 ]
  246.     return convertToJson(true);
    7 o) G8 ~( A" N0 f: i
  247.   }
    ' p, V1 e, `+ M6 D( V
  248. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2009-7-26 22:23 | 显示全部楼层

回复 楼主1# mfly 的帖子

我把palm的Jar也都加入Library了啊,咋回事呢?报了好多错哎
回复 支持 反对

使用道具 举报

发表于 2009-7-26 22:50 | 显示全部楼层

回复 楼主1# mfly 的帖子

是不是因为我加入的是1.1ROM里的jar的关系呢?跟1.0.4的参数对不上了
回复 支持 反对

使用道具 举报

发表于 2009-7-27 00:28 | 显示全部楼层

回复 楼主1# mfly 的帖子

我试了下,编译你的那个文件就ok,我编译的是SmsMessageSegmentContainer,不灵,估计是SmsMessageSegmentContainer里面的一些函数在library里找不到吧,如何才能编译这个文件成功呢?请指点一下,谢谢
回复 支持 反对

使用道具 举报

发表于 2009-7-27 21:24 | 显示全部楼层
eclipse啊~像我们这种穷人,只能用Emacs....
回复 支持 反对

使用道具 举报

发表于 2009-8-18 22:01 | 显示全部楼层
其它的代码有吗?我用jd-gui 0.2.7反编译出来好像有点问题啊。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

QQ|Archiver|手机版|小黑屋|吹友吧 ( 京ICP备05078561号 )

GMT+8, 2025-1-22 14:47 , Processed in 0.305509 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表