Project

General

Profile

« Previous | Next » 

Revision 5960

Added by Chris Jones over 13 years ago

Modified MetacatHandler and added two methods:
serializeSystemMetadata() - Serialize a SystemMetadata object to XML string
deserializeSystemMetadata() - Deserialize a SystemMetadata object from an XML string

View differences:

src/edu/ucsb/nceas/metacat/MetacatHandler.java
3252 3252
        _sitemapScheduled = sitemapScheduled;
3253 3253
    }
3254 3254

  
3255
    /**
3256
     * Serialize a system metadata doc. Note: This needs to refactored out
3257
     * of MetacatHandler and into a utitlity when stream i/o in Metacat is
3258
     * evaluated.
3259
     *
3260
     * @param sysmeta  The system metadata object to be serialized
3261
     * @return sysMetaOut  The system metadata XML document as a ByteArrayOutputStream
3262
     * @throws JiBXException
3263
     */
3264
    private static ByteArrayOutputStream serializeSystemMetadata(SystemMetadata sysmeta) 
3265
      throws JiBXException {
3266
      
3267
      IBindingFactory bfact;
3268
      ByteArrayOutputStream sysmetaOut = null;
3269
      
3270
      try {
3271
          bfact = BindingDirectory.getFactory(SystemMetadata.class);
3272
          IMarshallingContext mctx = bfact.createMarshallingContext();
3273
          sysmetaOut = new ByteArrayOutputStream();
3274
          mctx.marshalDocument(sysmeta, "UTF-8", null, sysmetaOut);
3275
      } catch (JiBXException jxe) {
3276
        throw jxe;
3277
        
3278
      }
3279
      
3280
      return sysmetaOut;
3281
    }
3282
    
3283
    /**
3284
     * deserialize a system metadata doc. Note: This needs to refactored out
3285
     * of MetacatHandler and into a utitlity when stream i/o in Metacat is
3286
     * evaluated.
3287
     * @param xml  The xml to be deserialized
3288
     * @return sysmeta  The SystemMetadata object to be returned
3289
     * @throws JiBXException
3290
     */
3291
    private static SystemMetadata deserializeSystemMetadata(InputStream xml) 
3292
      throws JiBXException {
3293
      
3294
      try {
3295
          IBindingFactory bfact = 
3296
            BindingDirectory.getFactory(SystemMetadata.class);
3297
          IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
3298
          SystemMetadata sysmeta = 
3299
            (SystemMetadata) uctx.unmarshalDocument(xml, null);
3300
          return sysmeta;
3301
          
3302
      } catch (JiBXException jxe) {
3303
        throw jxe;
3304
        
3305
      }
3306
       
3307
    }
3308
    
3255 3309
}

Also available in: Unified diff