@@ -24,47 +24,73 @@ public BSONObject create( boolean array , List<String> path ){
2424 }
2525
2626 public void objectStart (boolean array , String name ){
27- _lastName = name ;
2827 _lastArray = array ;
2928 super .objectStart ( array , name );
3029 }
3130
3231 public Object objectDone (){
32+ String name = curName ();
3333 Object o = super .objectDone ();
3434 BSONObject b = (BSONObject )o ;
3535
36+ // override the object if it's a special type
3637 if ( ! _lastArray ) {
3738 if ( b .containsField ( "$oid" ) ) {
3839 o = new ObjectId ((String )b .get ("$oid" ));
3940 if (!isStackEmpty ()) {
40- gotObjectId ( _lastName , (ObjectId )o );
41+ gotObjectId ( name , (ObjectId )o );
4142 } else {
4243 setRoot (o );
43- }
44+ }
4445 } else if ( b .containsField ( "$date" ) ) {
4546 SimpleDateFormat format =
4647 new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'" );
4748 format .setCalendar (new GregorianCalendar (new SimpleTimeZone (0 , "GMT" )));
4849 o = format .parse ((String )b .get ("$date" ), new ParsePosition (0 ));
4950 if (!isStackEmpty ()) {
50- cur ().put ( _lastName , o );
51+ cur ().put ( name , o );
5152 } else {
5253 setRoot (o );
5354 }
5455 } else if ( b .containsField ( "$regex" ) ) {
5556 o = Pattern .compile ( (String )b .get ( "$regex" ),
5657 BSON .regexFlags ( (String )b .get ( "$options" )) );
5758 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 );
5987 } else {
6088 setRoot (o );
6189 }
6290 }
6391 }
64-
6592 return o ;
6693 }
6794
68- private String _lastName ;
6995 private boolean _lastArray = false ;
7096}
0 commit comments