@@ -24,47 +24,73 @@ public BSONObject create( boolean array , List<String> path ){
24
24
}
25
25
26
26
public void objectStart (boolean array , String name ){
27
- _lastName = name ;
28
27
_lastArray = array ;
29
28
super .objectStart ( array , name );
30
29
}
31
30
32
31
public Object objectDone (){
32
+ String name = curName ();
33
33
Object o = super .objectDone ();
34
34
BSONObject b = (BSONObject )o ;
35
35
36
+ // override the object if it's a special type
36
37
if ( ! _lastArray ) {
37
38
if ( b .containsField ( "$oid" ) ) {
38
39
o = new ObjectId ((String )b .get ("$oid" ));
39
40
if (!isStackEmpty ()) {
40
- gotObjectId ( _lastName , (ObjectId )o );
41
+ gotObjectId ( name , (ObjectId )o );
41
42
} else {
42
43
setRoot (o );
43
- }
44
+ }
44
45
} else if ( b .containsField ( "$date" ) ) {
45
46
SimpleDateFormat format =
46
47
new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'" );
47
48
format .setCalendar (new GregorianCalendar (new SimpleTimeZone (0 , "GMT" )));
48
49
o = format .parse ((String )b .get ("$date" ), new ParsePosition (0 ));
49
50
if (!isStackEmpty ()) {
50
- cur ().put ( _lastName , o );
51
+ cur ().put ( name , o );
51
52
} else {
52
53
setRoot (o );
53
54
}
54
55
} else if ( b .containsField ( "$regex" ) ) {
55
56
o = Pattern .compile ( (String )b .get ( "$regex" ),
56
57
BSON .regexFlags ( (String )b .get ( "$options" )) );
57
58
if (!isStackEmpty ()) {
58
- cur ().put ( _lastName , o );
59
+ cur ().put ( name , o );
60
+ } else {
61
+ setRoot (o );
62
+ }
63
+ } else if ( b .containsField ( "$ts" ) ) {
64
+ Long ts = (Long ) b .get ("$ts" );
65
+ Long inc = (Long ) b .get ("$ts" );
66
+ o = new BSONTimestamp (ts .intValue (), inc .intValue ());
67
+ if (!isStackEmpty ()) {
68
+ cur ().put ( name , o );
69
+ } else {
70
+ setRoot (o );
71
+ }
72
+ } else if ( b .containsField ( "$code" ) ) {
73
+ if (b .containsField ("$scope" )) {
74
+ o = new CodeWScope ((String )b .get ("$code" ), (DBObject )b .get ("$scope" ));
75
+ } else {
76
+ o = new Code ((String )b .get ("$code" ));
77
+ }
78
+ if (!isStackEmpty ()) {
79
+ cur ().put ( name , o );
80
+ } else {
81
+ setRoot (o );
82
+ }
83
+ } else if ( b .containsField ( "$ref" ) ) {
84
+ o = new DBRefBase (null , (String )b .get ("$ref" ), b .get ("$id" ));
85
+ if (!isStackEmpty ()) {
86
+ cur ().put ( name , o );
59
87
} else {
60
88
setRoot (o );
61
89
}
62
90
}
63
91
}
64
-
65
92
return o ;
66
93
}
67
94
68
- private String _lastName ;
69
95
private boolean _lastArray = false ;
70
96
}
0 commit comments