View Javadoc
1   /*
2    * RecordInserter.java
3    *
4    * Created on October 25, 2004, 11:22 AM
5    */
6   
7   package gov.noaa.gdsg.xmldbremote.manage;
8   import org.xmldb.api.base.Database;
9   import org.xmldb.api.base.Collection;
10  import org.xmldb.api.base.XMLDBException;
11  import org.xmldb.api.modules.XMLResource;
12  import org.w3c.dom.Node;
13  import org.apache.log4j.Logger;
14  
15  /***
16   *Provides a simple mechanism to create a new resource.
17   *
18   * @author  tns
19   * @version $Id: RecordInserter.java,v 1.1 2004/10/29 17:47:13 mrxtravis Exp $
20   */
21  public class RecordInserter extends BaseRecordAdmin{
22      
23      private static Logger log = Logger.getLogger(RecordInserter.class);
24  
25  
26      
27      /*** Creates a new instance of RecordInserter */
28      public RecordInserter() {
29      }
30  
31     
32      /*** Inserts the record into the database */
33      public void insertRecord(Node node) throws Exception {
34          if (collectionManager == null){
35              throw new NullPointerException("collectionManager property has not been set.");
36          }
37          
38          Collection collection = this.collectionManager.getCollection();
39           //now we insert the record
40          String newId = collection.createId();
41          XMLResource resource = (XMLResource) collection.createResource(newId,"XMLResource");
42          resource.setContentAsDOM(node);
43          collection.storeResource(resource);
44          log.info("Resource Stored Successfully.");
45          
46      }
47  
48   }