public void addSubResource ( final String resourceName , final long nodeId , final InputStream input , final EIdAccessType type ) throws JaxRxException { ISession session = null ; INodeWriteTrx wtx = null ; synchronized ( resourceName ) { boolean abort ; if ( mDatabase . existsResource ( resourceName ) ) { abort = false ; try { // Creating a new session session = mDatabase . getSession ( new SessionConfiguration ( resourceName , StandardSettings . KEY ) ) ; // Creating a write transaction wtx = new NodeWriteTrx ( session , session . beginBucketWtx ( ) , HashKind . Rolling ) ; final boolean exist = wtx . moveTo ( nodeId ) ; if ( exist ) { if ( type == EIdAccessType . FIRSTCHILD ) { WorkerHelper . shredInputStream ( wtx , input , EShredderInsert . ADDASFIRSTCHILD ) ; } else if ( type == EIdAccessType . RIGHTSIBLING ) { WorkerHelper . shredInputStream ( wtx , input , EShredderInsert . ADDASRIGHTSIBLING ) ; } else if ( type == EIdAccessType . LASTCHILD ) { if ( wtx . moveTo ( ( ( ITreeStructData ) wtx . getNode ( ) ) . getFirstChildKey ( ) ) ) { long last = wtx . getNode ( ) . getDataKey ( ) ; while ( wtx . moveTo ( ( ( ITreeStructData ) wtx . getNode ( ) ) . getRightSiblingKey ( ) ) ) { last = wtx . getNode ( ) . getDataKey ( ) ; } wtx . moveTo ( last ) ; WorkerHelper . shredInputStream ( wtx , input , EShredderInsert . ADDASRIGHTSIBLING ) ; } else { throw new JaxRxException ( 404 , NOTFOUND ) ; } } else if ( type == EIdAccessType . LEFTSIBLING && wtx . moveTo ( ( ( ITreeStructData ) wtx . getNode ( ) ) . getLeftSiblingKey ( ) ) ) { WorkerHelper . shredInputStream ( wtx , input , EShredderInsert . ADDASRIGHTSIBLING ) ; } } else { throw new JaxRxException ( 404 , NOTFOUND ) ; } } catch ( final JaxRxException exce ) { abort = true ; throw exce ; } catch ( final Exception exce ) { abort = true ; throw new JaxRxException ( exce ) ; } finally { try { WorkerHelper . closeWTX ( abort , wtx , session ) ; } catch ( final TTException exce ) { throw new JaxRxException ( exce ) ; } } } } }
This method is responsible to perform a POST request to a node id . This method adds a new XML subtree as first child or as right sibling to the node which is addressed through a node id .