idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
23,300 | private void scanComment ( ) { final char input = mQuery . charAt ( mPos + 1 ) ; if ( mInput == ':' ) { if ( input == ')' ) { mCommentCount -- ; if ( mCommentCount == 0 ) { mState = State . START ; mPos ++ ; } } } else if ( mInput == '(' ) { if ( input == ':' ) { mCommentCount ++ ; } } mPos ++ ; } | Scans comments . |
23,301 | private boolean isLetter ( final char paramInput ) { return ( paramInput >= '0' && paramInput <= '9' ) || ( paramInput >= 'a' && paramInput <= 'z' ) || ( paramInput >= 'A' && paramInput <= 'Z' ) || ( paramInput == '_' ) || ( paramInput == '-' ) || ( paramInput == '.' ) ; } | Checks if the given character is a letter . |
23,302 | public StreamingOutput getResource ( final String resourceName , final long nodeId , final Map < QueryParameter , String > queryParams ) throws JaxRxException { final StreamingOutput sOutput = new StreamingOutput ( ) { public void write ( final OutputStream output ) throws IOException , JaxRxException { final String revision = queryParams . get ( QueryParameter . REVISION ) ; final String wrap = queryParams . get ( QueryParameter . WRAP ) ; final String doNodeId = queryParams . get ( QueryParameter . OUTPUT ) ; final boolean wrapResult = ( wrap == null ) ? false : wrap . equalsIgnoreCase ( YESSTRING ) ; final boolean nodeid = ( doNodeId == null ) ? false : doNodeId . equalsIgnoreCase ( YESSTRING ) ; final Long rev = revision == null ? null : Long . valueOf ( revision ) ; serialize ( resourceName , nodeId , rev , nodeid , output , wrapResult ) ; } } ; return sOutput ; } | This method is responsible to deliver the whole XML resource addressed by a unique node id . |
23,303 | public StreamingOutput performQueryOnResource ( final String resourceName , final long nodeId , final String query , final Map < QueryParameter , String > queryParams ) { final StreamingOutput sOutput = new StreamingOutput ( ) { public void write ( final OutputStream output ) throws IOException , JaxRxException { final String revision = queryParams . get ( QueryParameter . REVISION ) ; final String wrap = queryParams . get ( QueryParameter . WRAP ) ; final String doNodeId = queryParams . get ( QueryParameter . OUTPUT ) ; final boolean wrapResult = ( wrap == null ) ? true : wrap . equalsIgnoreCase ( YESSTRING ) ; final boolean nodeid = ( doNodeId == null ) ? false : doNodeId . equalsIgnoreCase ( YESSTRING ) ; final Long rev = revision == null ? null : Long . valueOf ( revision ) ; final RestXPathProcessor xpathProcessor = new RestXPathProcessor ( mDatabase ) ; try { xpathProcessor . getXpathResource ( resourceName , nodeId , query , nodeid , rev , output , wrapResult ) ; } catch ( final TTException exce ) { throw new JaxRxException ( exce ) ; } } } ; return sOutput ; } | This method is responsible to perform a XPath query expression on the XML resource which is addressed through a unique node id . |
23,304 | public void modifyResource ( final String resourceName , final long nodeId , final InputStream newValue ) throws JaxRxException { synchronized ( resourceName ) { ISession session = null ; INodeWriteTrx wtx = null ; boolean abort = false ; if ( mDatabase . existsResource ( resourceName ) ) { try { session = mDatabase . getSession ( new SessionConfiguration ( resourceName , StandardSettings . KEY ) ) ; wtx = new NodeWriteTrx ( session , session . beginBucketWtx ( ) , HashKind . Rolling ) ; if ( wtx . moveTo ( nodeId ) ) { final long parentKey = wtx . getNode ( ) . getParentKey ( ) ; wtx . remove ( ) ; wtx . moveTo ( parentKey ) ; WorkerHelper . shredInputStream ( wtx , newValue , EShredderInsert . ADDASFIRSTCHILD ) ; } else { throw new JaxRxException ( 404 , NOTFOUND ) ; } } catch ( final TTException exc ) { abort = true ; throw new JaxRxException ( exc ) ; } finally { try { WorkerHelper . closeWTX ( abort , wtx , session ) ; } catch ( final TTException exce ) { throw new JaxRxException ( exce ) ; } } } else { throw new JaxRxException ( 404 , "Requested resource not found" ) ; } } } | This method is responsible to modify the XML resource which is addressed through a unique node id . |
23,305 | 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 { session = mDatabase . getSession ( new SessionConfiguration ( resourceName , StandardSettings . KEY ) ) ; 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 . |
23,306 | private void serialize ( final String resource , final long nodeId , final Long revision , final boolean doNodeId , final OutputStream output , final boolean wrapResult ) { if ( mDatabase . existsResource ( resource ) ) { ISession session = null ; try { session = mDatabase . getSession ( new SessionConfiguration ( resource , StandardSettings . KEY ) ) ; if ( wrapResult ) { output . write ( BEGINRESULT ) ; final XMLSerializerProperties props = new XMLSerializerProperties ( ) ; final XMLSerializerBuilder builder = new XMLSerializerBuilder ( session , nodeId , output , props ) ; builder . setREST ( doNodeId ) ; builder . setID ( doNodeId ) ; builder . setDeclaration ( false ) ; final XMLSerializer serializer = builder . build ( ) ; serializer . call ( ) ; output . write ( ENDRESULT ) ; } else { final XMLSerializerProperties props = new XMLSerializerProperties ( ) ; final XMLSerializerBuilder builder = new XMLSerializerBuilder ( session , nodeId , output , props ) ; builder . setREST ( doNodeId ) ; builder . setID ( doNodeId ) ; builder . setDeclaration ( false ) ; final XMLSerializer serializer = builder . build ( ) ; serializer . call ( ) ; } } catch ( final TTException ttExcep ) { throw new JaxRxException ( ttExcep ) ; } catch ( final IOException ioExcep ) { throw new JaxRxException ( ioExcep ) ; } catch ( final Exception globExcep ) { if ( globExcep instanceof JaxRxException ) { throw ( JaxRxException ) globExcep ; } else { throw new JaxRxException ( globExcep ) ; } } finally { try { WorkerHelper . closeRTX ( null , session ) ; } catch ( final TTException exce ) { throw new JaxRxException ( exce ) ; } } } else { throw new JaxRxException ( 404 , "Resource does not exist" ) ; } } | This method serializes requested resource |
23,307 | public static final AbsComparator getComparator ( final INodeReadTrx paramRtx , final AbsAxis paramOperandOne , final AbsAxis paramOperandTwo , final CompKind paramKind , final String paramVal ) { if ( "eq" . equals ( paramVal ) || "lt" . equals ( paramVal ) || "le" . equals ( paramVal ) || "gt" . equals ( paramVal ) || "ge" . equals ( paramVal ) ) { return new ValueComp ( paramRtx , paramOperandOne , paramOperandTwo , paramKind ) ; } else if ( "=" . equals ( paramVal ) || "!=" . equals ( paramVal ) || "<" . equals ( paramVal ) || "<=" . equals ( paramVal ) || ">" . equals ( paramVal ) || ">=" . equals ( paramVal ) ) { return new GeneralComp ( paramRtx , paramOperandOne , paramOperandTwo , paramKind ) ; } else if ( "is" . equals ( paramVal ) || "<<" . equals ( paramVal ) || ">>" . equals ( paramVal ) ) { return new NodeComp ( paramRtx , paramOperandOne , paramOperandTwo , paramKind ) ; } throw new IllegalStateException ( paramVal + " is not a valid comparison." ) ; } | Factory method to implement the comparator . |
23,308 | public Integer getIntReqPar ( final String name , final String errProp ) throws Throwable { try { return super . getIntReqPar ( name ) ; } catch ( final Throwable t ) { getErr ( ) . emit ( errProp , getReqPar ( name ) ) ; return null ; } } | Get an Integer request parameter or null . Emit error for non - null and non integer |
23,309 | public static String retrieveData ( String sUrl , int timeout ) throws IOException { return retrieveData ( sUrl , null , timeout ) ; } | Download data from an URL . |
23,310 | public static String retrieveData ( String sUrl , String encoding , int timeout , SSLSocketFactory sslFactory ) throws IOException { byte [ ] rawData = retrieveRawData ( sUrl , timeout , sslFactory ) ; if ( encoding == null ) { return new String ( rawData ) ; } return new String ( rawData , encoding ) ; } | Download data from an URL if necessary converting from a character encoding . |
23,311 | public static byte [ ] retrieveRawData ( String sUrl , int timeout , SSLSocketFactory sslFactory ) throws IOException { URL url = new URL ( sUrl ) ; LOGGER . fine ( "Using the following URL for retrieving the data: " + url . toString ( ) ) ; HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ( ) ; if ( timeout != 0 ) { conn . setConnectTimeout ( timeout ) ; conn . setReadTimeout ( timeout ) ; } try { conn . setDoOutput ( false ) ; conn . setDoInput ( true ) ; if ( conn instanceof HttpsURLConnection && sslFactory != null ) { ( ( HttpsURLConnection ) conn ) . setSSLSocketFactory ( sslFactory ) ; } conn . connect ( ) ; int code = conn . getResponseCode ( ) ; if ( code != HttpURLConnection . HTTP_OK && code != HttpURLConnection . HTTP_CREATED && code != HttpURLConnection . HTTP_ACCEPTED ) { String msg = "Error " + code + " returned while retrieving response for url '" + url + "' message from client: " + conn . getResponseMessage ( ) ; LOGGER . warning ( msg ) ; throw new IOException ( msg ) ; } try ( InputStream strm = conn . getInputStream ( ) ) { return IOUtils . toByteArray ( strm ) ; } } finally { conn . disconnect ( ) ; } } | Download data from an URL and return the raw bytes . |
23,312 | private AtomicValue atomize ( final AbsAxis mOperand ) { int type = getNode ( ) . getTypeKey ( ) ; AtomicValue atom ; if ( XPATH_10_COMP ) { atom = new AtomicValue ( ( ( ITreeValData ) getNode ( ) ) . getRawValue ( ) , getNode ( ) . getTypeKey ( ) ) ; } else { if ( type == NamePageHash . generateHashForString ( "xs:untypedAtomic" ) ) { type = NamePageHash . generateHashForString ( "xs:double" ) ; } atom = new AtomicValue ( ( ( ITreeValData ) getNode ( ) ) . getRawValue ( ) , getNode ( ) . getTypeKey ( ) ) ; } return atom ; } | Atomizes an operand according to the rules specified in the XPath specification . |
23,313 | public String checkProp ( final Properties pr , final String name , final String defaultVal ) { String val = pr . getProperty ( name ) ; if ( val == null ) { pr . put ( name , defaultVal ) ; val = defaultVal ; } return val ; } | If the named property is present and has a value use that . Otherwise set the value to the given default and use that . |
23,314 | public void finishExpr ( final INodeReadTrx mTransaction , final int mNum ) { if ( getPipeStack ( ) . size ( ) != mNum ) { throw new IllegalStateException ( "The query has not been processed correctly" ) ; } int no = mNum ; AbsAxis [ ] axis ; if ( no > 1 ) { axis = new AbsAxis [ no ] ; while ( no -- > 0 ) { axis [ no ] = getPipeStack ( ) . pop ( ) . getExpr ( ) ; } if ( mExprStack . size ( ) > 1 ) { assert mExprStack . peek ( ) . empty ( ) ; mExprStack . pop ( ) ; } if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( new SequenceAxis ( mTransaction , axis ) ) ; } else if ( no == 1 ) { axis = new AbsAxis [ 1 ] ; axis [ 0 ] = getPipeStack ( ) . pop ( ) . getExpr ( ) ; if ( mExprStack . size ( ) > 1 ) { assert mExprStack . peek ( ) . empty ( ) ; mExprStack . pop ( ) ; } if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } final AbsAxis iAxis ; if ( mExprStack . size ( ) == 1 && getPipeStack ( ) . size ( ) == 1 && getExpression ( ) . getSize ( ) == 0 ) { iAxis = new SequenceAxis ( mTransaction , axis ) ; } else { iAxis = axis [ 0 ] ; } getExpression ( ) . add ( iAxis ) ; } else { mExprStack . pop ( ) ; } } | Ends an expression . This means that the currently used pipeline stack will be emptied and the singleExpressions that were on the stack are combined by a sequence expression which is lated added to the next pipeline stack . |
23,315 | public void addIfExpression ( final INodeReadTrx mTransaction ) { assert getPipeStack ( ) . size ( ) >= 3 ; final INodeReadTrx rtx = mTransaction ; final AbsAxis elseExpr = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis thenExpr = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis ifExpr = getPipeStack ( ) . pop ( ) . getExpr ( ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( new IfAxis ( rtx , ifExpr , thenExpr , elseExpr ) ) ; } | Adds a if expression to the pipeline . |
23,316 | public void addCompExpression ( final INodeReadTrx mTransaction , final String mComp ) { assert getPipeStack ( ) . size ( ) >= 2 ; final INodeReadTrx rtx = mTransaction ; final AbsAxis paramOperandTwo = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis paramOperandOne = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final CompKind kind = CompKind . fromString ( mComp ) ; final AbsAxis axis = AbsComparator . getComparator ( rtx , paramOperandOne , paramOperandTwo , kind , mComp ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( axis ) ; } | Adds a comparison expression to the pipeline . |
23,317 | public void addOperatorExpression ( final INodeReadTrx mTransaction , final String mOperator ) { assert getPipeStack ( ) . size ( ) >= 1 ; final INodeReadTrx rtx = mTransaction ; final AbsAxis mOperand2 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis mOperand1 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } final AbsAxis axis ; if ( mOperator . equals ( "+" ) ) { axis = new AddOpAxis ( rtx , mOperand1 , mOperand2 ) ; } else if ( mOperator . equals ( "-" ) ) { axis = new SubOpAxis ( rtx , mOperand1 , mOperand2 ) ; } else if ( mOperator . equals ( "*" ) ) { axis = new MulOpAxis ( rtx , mOperand1 , mOperand2 ) ; } else if ( mOperator . equals ( "div" ) ) { axis = new DivOpAxis ( rtx , mOperand1 , mOperand2 ) ; } else if ( mOperator . equals ( "idiv" ) ) { axis = new IDivOpAxis ( rtx , mOperand1 , mOperand2 ) ; } else if ( mOperator . equals ( "mod" ) ) { axis = new ModOpAxis ( rtx , mOperand1 , mOperand2 ) ; } else { throw new IllegalStateException ( mOperator + " is not a valid operator." ) ; } getExpression ( ) . add ( axis ) ; } | Adds an operator expression to the pipeline . |
23,318 | public void addUnionExpression ( final INodeReadTrx mTransaction ) { assert getPipeStack ( ) . size ( ) >= 2 ; final AbsAxis mOperand2 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis mOperand1 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( new DupFilterAxis ( mTransaction , new UnionAxis ( mTransaction , mOperand1 , mOperand2 ) ) ) ; } | Adds a union expression to the pipeline . |
23,319 | public void addAndExpression ( final INodeReadTrx mTransaction ) { assert getPipeStack ( ) . size ( ) >= 2 ; final AbsAxis mOperand2 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis operand1 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( new AndExpr ( mTransaction , operand1 , mOperand2 ) ) ; } | Adds a and expression to the pipeline . |
23,320 | public void addOrExpression ( final INodeReadTrx mTransaction ) { assert getPipeStack ( ) . size ( ) >= 2 ; final AbsAxis mOperand2 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis mOperand1 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( new OrExpr ( mTransaction , mOperand1 , mOperand2 ) ) ; } | Adds a or expression to the pipeline . |
23,321 | public void addIntExcExpression ( final INodeReadTrx mTransaction , final boolean mIsIntersect ) { assert getPipeStack ( ) . size ( ) >= 2 ; final INodeReadTrx rtx = mTransaction ; final AbsAxis mOperand2 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis mOperand1 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis axis = mIsIntersect ? new IntersectAxis ( rtx , mOperand1 , mOperand2 ) : new ExceptAxis ( rtx , mOperand1 , mOperand2 ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( axis ) ; } | Adds a intersect or a exception expression to the pipeline . |
23,322 | public void addLiteral ( final INodeReadTrx pTrans , final AtomicValue pVal ) { getExpression ( ) . add ( new LiteralExpr ( pTrans , AbsAxis . addAtomicToItemList ( pTrans , pVal ) ) ) ; } | Adds a literal expression to the pipeline . |
23,323 | public void addStep ( final AbsAxis axis , final AbsFilter mFilter ) { getExpression ( ) . add ( new FilterAxis ( axis , mRtx , mFilter ) ) ; } | Adds a step to the pipeline . |
23,324 | public AbsAxis getPipeline ( ) { assert getPipeStack ( ) . size ( ) <= 1 ; if ( getPipeStack ( ) . size ( ) == 1 && mExprStack . size ( ) == 1 ) { return getPipeStack ( ) . pop ( ) . getExpr ( ) ; } else { throw new IllegalStateException ( "Query was not build correctly." ) ; } } | Returns a queue of all pipelines build so far and empties the pipeline stack . |
23,325 | public void addPredicate ( final INodeReadTrx mTransaction ) { assert getPipeStack ( ) . size ( ) >= 2 ; final AbsAxis mPredicate = getPipeStack ( ) . pop ( ) . getExpr ( ) ; if ( mPredicate instanceof LiteralExpr ) { mPredicate . hasNext ( ) ; final int type = mTransaction . getNode ( ) . getTypeKey ( ) ; if ( type == NamePageHash . generateHashForString ( "xs:integer" ) || type == NamePageHash . generateHashForString ( "xs:double" ) || type == NamePageHash . generateHashForString ( "xs:float" ) || type == NamePageHash . generateHashForString ( "xs:decimal" ) ) { throw new IllegalStateException ( "function fn:position() is not implemented yet." ) ; } } getExpression ( ) . add ( new PredicateFilterAxis ( mTransaction , mPredicate ) ) ; } | Adds a predicate to the pipeline . |
23,326 | public void addQuantifierExpr ( final INodeReadTrx mTransaction , final boolean mIsSome , final int mVarNum ) { assert getPipeStack ( ) . size ( ) >= ( mVarNum + 1 ) ; final AbsAxis satisfy = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final List < AbsAxis > vars = new ArrayList < AbsAxis > ( ) ; int num = mVarNum ; while ( num -- > 0 ) { vars . add ( num , getPipeStack ( ) . pop ( ) . getExpr ( ) ) ; } final AbsAxis mAxis = mIsSome ? new SomeExpr ( mTransaction , vars , satisfy ) : new EveryExpr ( mTransaction , vars , satisfy ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( mAxis ) ; } | Adds a SomeExpression or an EveryExpression to the pipeline depending on the parameter isSome . |
23,327 | public void addCastableExpr ( final INodeReadTrx mTransaction , final SingleType mSingleType ) { assert getPipeStack ( ) . size ( ) >= 1 ; final AbsAxis candidate = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis axis = new CastableExpr ( mTransaction , candidate , mSingleType ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( axis ) ; } | Adds a castable expression to the pipeline . |
23,328 | public void addRangeExpr ( final INodeReadTrx mTransaction ) { assert getPipeStack ( ) . size ( ) >= 2 ; final AbsAxis mOperand2 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis mOperand1 = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis axis = new RangeAxis ( mTransaction , mOperand1 , mOperand2 ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( axis ) ; } | Adds a range expression to the pipeline . |
23,329 | public void addInstanceOfExpr ( final INodeReadTrx mTransaction , final SequenceType mSequenceType ) { assert getPipeStack ( ) . size ( ) >= 1 ; final AbsAxis candidate = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis axis = new InstanceOfExpr ( mTransaction , candidate , mSequenceType ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( axis ) ; } | Adds a instance of expression to the pipeline . |
23,330 | public void addVariableExpr ( final INodeReadTrx mTransaction , final String mVarName ) { assert getPipeStack ( ) . size ( ) >= 1 ; final AbsAxis bindingSeq = getPipeStack ( ) . pop ( ) . getExpr ( ) ; final AbsAxis axis = new VariableAxis ( mTransaction , bindingSeq ) ; mVarRefMap . put ( mVarName , axis ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( axis ) ; } | Adds a variable expression to the pipeline . Adds the expression that will evaluate the results the variable holds . |
23,331 | public void addFunction ( final INodeReadTrx mTransaction , final String mFuncName , final int mNum ) throws TTXPathException { assert getPipeStack ( ) . size ( ) >= mNum ; final List < AbsAxis > args = new ArrayList < AbsAxis > ( mNum ) ; for ( int i = 0 ; i < mNum ; i ++ ) { args . add ( getPipeStack ( ) . pop ( ) . getExpr ( ) ) ; } final FuncDef func ; try { func = FuncDef . fromString ( mFuncName ) ; } catch ( final NullPointerException e ) { throw EXPathError . XPST0017 . getEncapsulatedException ( ) ; } final Class < ? extends AbsFunction > function = func . getFunc ( ) ; final Integer min = func . getMin ( ) ; final Integer max = func . getMax ( ) ; final Integer returnType = NamePageHash . generateHashForString ( func . getReturnType ( ) ) ; final Class < ? > [ ] paramTypes = { INodeReadTrx . class , List . class , Integer . TYPE , Integer . TYPE , Integer . TYPE } ; try { final Constructor < ? > cons = function . getConstructor ( paramTypes ) ; final AbsAxis axis = ( AbsAxis ) cons . newInstance ( mTransaction , args , min , max , returnType ) ; if ( getPipeStack ( ) . empty ( ) || getExpression ( ) . getSize ( ) != 0 ) { addExpressionSingle ( ) ; } getExpression ( ) . add ( axis ) ; } catch ( final NoSuchMethodException e ) { throw EXPathError . XPST0017 . getEncapsulatedException ( ) ; } catch ( final IllegalArgumentException e ) { throw EXPathError . XPST0017 . getEncapsulatedException ( ) ; } catch ( final InstantiationException e ) { throw new IllegalStateException ( "Function not implemented yet." ) ; } catch ( final IllegalAccessException e ) { throw EXPathError . XPST0017 . getEncapsulatedException ( ) ; } catch ( final InvocationTargetException e ) { throw EXPathError . XPST0017 . getEncapsulatedException ( ) ; } } | Adds a function to the pipeline . |
23,332 | public void addVarRefExpr ( final INodeReadTrx mTransaction , final String mVarName ) { final VariableAxis axis = ( VariableAxis ) mVarRefMap . get ( mVarName ) ; if ( axis != null ) { getExpression ( ) . add ( new VarRefExpr ( mTransaction , axis ) ) ; } else { throw new IllegalStateException ( "Variable " + mVarName + " unkown." ) ; } } | Adds a VarRefExpr to the pipeline . This Expression holds a reference to the current context item of the specified variable . |
23,333 | public static boolean stopProcess ( final AbstractProcessorThread proc ) { proc . info ( "************************************************************" ) ; proc . info ( " * Stopping " + proc . getName ( ) ) ; proc . info ( "************************************************************" ) ; proc . setRunning ( false ) ; proc . interrupt ( ) ; boolean ok = true ; try { proc . join ( 20 * 1000 ) ; } catch ( final InterruptedException ignored ) { } catch ( final Throwable t ) { proc . error ( "Error waiting for processor termination" ) ; proc . error ( t ) ; ok = false ; } proc . info ( "************************************************************" ) ; proc . info ( " * " + proc . getName ( ) + " terminated" ) ; proc . info ( "************************************************************" ) ; return ok ; } | Shut down a running process . |
23,334 | public void reset ( final long paramNodeKey ) { mStartKey = paramNodeKey ; mKey = paramNodeKey ; mNext = false ; lastPointer . remove ( mRTX ) ; } | Resetting the nodekey of this axis to a given nodekey . |
23,335 | public boolean moveTo ( final long pKey ) { try { if ( pKey < 0 || mRTX . moveTo ( pKey ) ) { lastPointer . put ( mRTX , pKey ) ; return true ; } else { return false ; } } catch ( TTIOException exc ) { throw new RuntimeException ( exc ) ; } } | Move cursor to a node by its node key . |
23,336 | public void close ( ) throws TTException { atomics . remove ( mRTX ) ; lastPointer . remove ( mRTX ) ; mRTX . close ( ) ; } | Closing the Transaction |
23,337 | public ItemList getItemList ( ) { if ( ! atomics . containsKey ( mRTX ) ) { atomics . put ( mRTX , new ItemList ( ) ) ; } return atomics . get ( mRTX ) ; } | Getting the ItemList . |
23,338 | public static int addAtomicToItemList ( final INodeReadTrx pRtx , final AtomicValue pVal ) { if ( ! atomics . containsKey ( pRtx ) ) { atomics . put ( pRtx , new ItemList ( ) ) ; } return atomics . get ( pRtx ) . addItem ( pVal ) ; } | Adding any AtomicVal to any ItemList staticly . |
23,339 | public DirRecord nextRecord ( ) throws NamingException { if ( inp == null ) { if ( in == null ) { throw new NamingException ( "No ldif input stream" ) ; } inp = new LdifRecord . Input ( ) ; inp . init ( new InputStreamReader ( in ) ) ; } else if ( inp . eof ) { return null ; } LdifRecord ldr = new LdifRecord ( ) ; if ( ! ldr . read ( inp ) ) { return null ; } return ldr ; } | Return the next record in the input stream . |
23,340 | public static void dumpLdif ( LdifOut lo , DirRecord rec ) throws NamingException { if ( rec == null ) { throw new NamingException ( "dumpLdif: No record supplied" ) ; } String dn = rec . getDn ( ) ; if ( dn == null ) { throw new NamingException ( "Unable to get dn" ) ; } lo . out ( "dn: " + dn ) ; int ctype = rec . getChangeType ( ) ; if ( ! rec . getIsContent ( ) ) { lo . out ( "changeType: " + LdifRecord . changeTypes [ ctype ] ) ; } if ( ( rec . getIsContent ( ) ) || ( ctype == DirRecord . changeTypeAdd ) ) { Attributes as = rec . getAttributes ( ) ; if ( as == null ) throw new NamingException ( "No attributes" ) ; Enumeration e = as . getAll ( ) ; while ( e . hasMoreElements ( ) ) { dumpAttr ( lo , ( Attribute ) e . nextElement ( ) ) ; } } else if ( ctype == DirRecord . changeTypeDelete ) { lo . out ( "changetype: delete" ) ; } else { lo . out ( "changetype: modify" ) ; ModificationItem [ ] mods = rec . getMods ( ) ; if ( mods == null ) { lo . out ( "# Invalid record - no mods" ) ; } else { for ( int i = 0 ; i < mods . length ; i ++ ) { ModificationItem m = mods [ i ] ; int op = m . getModificationOp ( ) ; Attribute a = m . getAttribute ( ) ; String aid = a . getID ( ) ; if ( op == DirContext . ADD_ATTRIBUTE ) { lo . out ( "add: " + aid ) ; } else if ( op == DirContext . REPLACE_ATTRIBUTE ) { lo . out ( "replace: " + aid ) ; } else if ( op == DirContext . REMOVE_ATTRIBUTE ) { lo . out ( "delete: " + aid ) ; } else { lo . out ( "# Invalid record - bad mod op " + op ) ; } dumpAttr ( lo , a ) ; } } lo . out ( "-" ) ; } lo . out ( "" ) ; } | dumpLdif write the entire record as ldif . |
23,341 | public static String makeLocale ( String lang , String country ) { if ( ( lang == null ) || ( lang . length ( ) == 0 ) ) { return localeInfoDefaultDefault ; } if ( ( country == null ) || ( country . length ( ) == 0 ) ) { return localeInfoDefaultDefault ; } return lang + "_" + country ; } | If either the lang or country is null we provide a default value for the whole locale . Otherwise we construct one . |
23,342 | private StreamingOutput createOutput ( final JaxRx impl , final ResourcePath path ) { String qu = path . getValue ( QueryParameter . COMMAND ) ; if ( qu != null ) { return impl . command ( qu , path ) ; } qu = path . getValue ( QueryParameter . RUN ) ; if ( qu != null ) { return impl . run ( qu , path ) ; } qu = path . getValue ( QueryParameter . QUERY ) ; if ( qu != null ) { return impl . query ( qu , path ) ; } return impl . get ( path ) ; } | Returns a stream output depending on the query parameters . |
23,343 | Response createResponse ( final JaxRx impl , final ResourcePath path ) { final StreamingOutput out = createOutput ( impl , path ) ; final boolean wrap = path . getValue ( QueryParameter . WRAP ) == null || path . getValue ( QueryParameter . WRAP ) . equals ( "yes" ) ; String type = wrap ? MediaType . APPLICATION_XML : MediaType . TEXT_PLAIN ; final String op = path . getValue ( QueryParameter . OUTPUT ) ; if ( op != null ) { final Scanner sc = new Scanner ( op ) ; sc . useDelimiter ( "," ) ; while ( sc . hasNext ( ) ) { final String [ ] sp = sc . next ( ) . split ( "=" , 2 ) ; if ( sp . length == 1 ) continue ; if ( sp [ 0 ] . equals ( METHOD ) ) { for ( final String [ ] m : METHODS ) if ( sp [ 1 ] . equals ( m [ 0 ] ) ) type = m [ 1 ] ; } else if ( sp [ 0 ] . equals ( MEDIATYPE ) ) { type = sp [ 1 ] ; } } } MediaType mt = null ; try { mt = MediaType . valueOf ( type ) ; } catch ( final IllegalArgumentException ex ) { throw new JaxRxException ( 400 , ex . getMessage ( ) ) ; } return Response . ok ( out , mt ) . build ( ) ; } | Returns a result depending on the query parameters . |
23,344 | protected Map < QueryParameter , String > getParameters ( final UriInfo uri , final JaxRx jaxrx ) { final MultivaluedMap < String , String > params = uri . getQueryParameters ( ) ; final Map < QueryParameter , String > newParam = createMap ( ) ; final Set < QueryParameter > impl = jaxrx . getParameters ( ) ; for ( final String key : params . keySet ( ) ) { for ( final String s : params . get ( key ) ) { addParameter ( key , s , newParam , impl ) ; } } return newParam ; } | Extracts and returns query parameters from the specified map . If a parameter is specified multiple times its values will be separated with tab characters . |
23,345 | private Map < QueryParameter , String > createMap ( ) { final Map < QueryParameter , String > params = new HashMap < QueryParameter , String > ( ) ; final Properties props = System . getProperties ( ) ; for ( final Map . Entry < Object , Object > set : props . entrySet ( ) ) { final String key = set . getKey ( ) . toString ( ) ; final String up = key . replace ( "org.jaxrx.parameter." , "" ) ; if ( key . equals ( up ) ) continue ; try { params . put ( QueryParameter . valueOf ( up . toUpperCase ( ) ) , set . getValue ( ) . toString ( ) ) ; } catch ( final IllegalArgumentException ex ) { } } return params ; } | Returns a fresh parameter map . This map contains all parameters as defaults which have been specified by the user via system properties with the pattern org . jaxrx . parameter . KEY as key . |
23,346 | private void prefetch ( long storageIndex ) { long startIndex = storageIndex / BYTES_IN_DATA ; startIndex += 128 ; if ( mPrefetchedBuckets . contains ( startIndex ) ) { mPrefetchedBuckets . remove ( startIndex ) ; return ; } for ( int i = 0 ; i < BUCKETS_TO_PREFETCH ; i ++ ) { if ( ( startIndex + i ) > ( mNodeNumbers / 128 ) ) { return ; } mRtx . moveTo ( startIndex ) ; startIndex += 128 ; } } | Prefetch buckets if necessary |
23,347 | public Document check ( final InputStream input ) { Document document ; try { final DocumentBuilder docBuilder = DocumentBuilderFactory . newInstance ( ) . newDocumentBuilder ( ) ; document = docBuilder . parse ( input ) ; final InputStream is = getClass ( ) . getResourceAsStream ( xslSchema ) ; final Source source = new SAXSource ( new InputSource ( is ) ) ; checkIsValid ( document , source ) ; } catch ( final SAXException exce ) { throw new JaxRxException ( 400 , exce . getMessage ( ) ) ; } catch ( final ParserConfigurationException exce ) { throw new JaxRxException ( exce ) ; } catch ( final IOException exce ) { throw new JaxRxException ( exce ) ; } return document ; } | This method parses an XML input with a W3C DOM implementation and validates it then with the available XML schema . |
23,348 | private void checkIsValid ( final Document document , final Source source ) throws SAXException , IOException { final SchemaFactory schemaFactory = SchemaFactory . newInstance ( XMLConstants . W3C_XML_SCHEMA_NS_URI ) ; final Schema schema = schemaFactory . newSchema ( source ) ; final Validator validator = schema . newValidator ( ) ; validator . validate ( new DOMSource ( document ) ) ; } | This method checks the parsed document if it is valid to a given XML schema . If not an exception is thrown |
23,349 | public static String getUid ( ) { short hiTime = ( short ) ( System . currentTimeMillis ( ) >>> 32 ) ; int loTime = ( int ) System . currentTimeMillis ( ) ; int ct ; synchronized ( Uid . class ) { if ( counter < 0 ) { counter = 0 ; } ct = counter ++ ; } return new StringBuilder ( 36 ) . append ( format ( IP ) ) . append ( sep ) . append ( format ( JVM ) ) . append ( sep ) . append ( format ( hiTime ) ) . append ( sep ) . append ( format ( loTime ) ) . append ( sep ) . append ( format ( ct ) ) . toString ( ) ; } | Code copied and modified from hibernate UUIDHexGenerator . Generates a unique 36 character key of hex + separators . |
23,350 | public static int toInt ( byte [ ] bytes ) { int result = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { result = ( result << 8 ) - Byte . MIN_VALUE + ( int ) bytes [ i ] ; } return result ; } | From hibernate . util |
23,351 | public boolean search ( String base , String filter ) throws NamingException { return search ( base , filter , scopeSub ) ; } | Carry out a subtree search |
23,352 | public boolean searchBase ( String base , String filter ) throws NamingException { return search ( base , filter , scopeBase ) ; } | Carry out a base level search . This should be the default if the scope is not specified . |
23,353 | public boolean searchOne ( String base , String filter ) throws NamingException { return search ( base , filter , scopeOne ) ; } | Carry out a one level search |
23,354 | public DirRecord newRecord ( String entryDn ) throws NamingException { DirRecord rec = new BasicDirRecord ( ) ; rec . setDn ( entryDn ) ; return rec ; } | newRecord - Return a record which can have attribute values added . create should be called to create the directory entry . |
23,355 | public LogIterator getIterator ( ) { Set < Entry < LogKey , LogValue > > entries = mCache . asMap ( ) . entrySet ( ) ; for ( Entry < LogKey , LogValue > entry : entries ) { insertIntoBDB ( entry . getKey ( ) , entry . getValue ( ) ) ; } return new LogIterator ( ) ; } | Returning all elements as Iterator . |
23,356 | public boolean read ( Input in ) throws NamingException { clear ( ) ; this . in = in ; haveControls = false ; crec = null ; for ( ; ; ) { int alen = - 1 ; try { crec = in . readFullLine ( ) ; } catch ( Exception e ) { throwmsg ( e . getMessage ( ) ) ; } int inLen = 0 ; if ( crec != null ) { inLen = crec . length ( ) ; } if ( crec != null ) { ldifData . addElement ( crec ) ; alen = crec . indexOf ( ':' ) ; } if ( inLen == 0 ) { if ( state == stateModSpec ) { invalid ( ) ; } break ; } if ( ( inLen > 0 ) && ( crec . startsWith ( "#" ) ) ) { } else if ( alen > 0 ) { String attr = null ; StringBuffer val = null ; boolean encoded = false ; boolean url = false ; int valStart ; valStart = alen + 1 ; if ( valStart == inLen ) { throw new NamingException ( "Bad input value \"" + crec + "\"" ) ; } else if ( ( alen < inLen ) && ( crec . charAt ( valStart ) == ':' ) ) { valStart ++ ; encoded = true ; } else if ( ( alen < inLen ) && ( crec . charAt ( valStart ) == '<' ) ) { valStart ++ ; url = true ; } while ( ( valStart < inLen ) && ( crec . charAt ( valStart ) == ' ' ) ) { valStart ++ ; } attr = crec . substring ( 0 , alen ) . toLowerCase ( ) ; val = new StringBuffer ( crec . substring ( valStart ) ) ; addAttrVal ( attr , val . toString ( ) , encoded , url ) ; } else if ( ( state == stateModSpec ) && ( inLen == 1 ) && ( crec . equals ( "-" ) ) ) { if ( changes == null ) { changes = new Vector ( ) ; } changes . addElement ( curChange ) ; curChange = null ; state = stateModify ; } else if ( inLen > 0 ) { invalid ( ) ; } } return somedata ; } | Read an entire ldif record from an input stream |
23,357 | public boolean writeInputData ( Writer wtr ) throws Throwable { if ( ( ldifData == null ) || ( ldifData . size ( ) == 0 ) ) { return false ; } synchronized ( wtr ) { for ( int i = 0 ; i < ldifData . size ( ) ; i ++ ) { String str = ( String ) ldifData . elementAt ( i ) ; wtr . write ( str ) ; wtr . write ( '\n' ) ; } wtr . write ( '\n' ) ; wtr . flush ( ) ; } return true ; } | Write the data we built this from |
23,358 | public void write ( Writer wtr ) throws Throwable { wtr . write ( getDn ( ) ) ; wtr . write ( '\n' ) ; throw new Exception ( "Incomplete" ) ; } | Write an ldif record representing this object |
23,359 | private void addAttrVal ( String attr , String val , boolean encoded , boolean url ) throws NamingException { if ( state == stateNeedDn ) { if ( attr . equals ( "version" ) ) { if ( version != null ) throwmsg ( "Repeated version record" ) ; if ( ! ( val . equals ( "1" ) ) ) throwmsg ( "Invalid LDIF version " + val . toString ( ) ) ; version = val ; } else if ( attr . equals ( "dn" ) ) { setDn ( makeVal ( val , encoded , url ) ) ; state = stateHadDn ; } else { invalid ( ) ; } } else if ( state == stateHadDn ) { if ( attr . equals ( "control" ) ) { setIsContent ( false ) ; throwmsg ( "controls unimplemented" ) ; } else if ( attr . equals ( "changetype" ) ) { setIsContent ( false ) ; doChangeType ( val ) ; } else { if ( haveControls ) throwmsg ( "Missing changetype" ) ; state = stateNotModRec ; addAttrVal ( attr , val , encoded , url ) ; } } else if ( state == stateDeleteRec ) { throwmsg ( "Should have no values for delete" ) ; } else if ( state == stateNotModRec ) { addAttr ( attr , makeVal ( val , encoded , url ) ) ; } else if ( state == stateModrdn ) { throwmsg ( "changetype: mod(r)dn unimplemented" ) ; } else if ( state == stateModify ) { if ( encoded || url ) { throwmsg ( "Invalid LDIF mod-spec" ) ; } curChange = new Change ( ) ; if ( attr . equals ( "add" ) ) { curChange . changeType = DirContext . ADD_ATTRIBUTE ; } else if ( attr . equals ( "replace" ) ) { curChange . changeType = DirContext . REPLACE_ATTRIBUTE ; } else if ( attr . equals ( "delete" ) ) { curChange . changeType = DirContext . REMOVE_ATTRIBUTE ; } else { throwmsg ( "Invalid LDIF mod-spec changetype" ) ; } curChange . name = val ; state = stateModSpec ; } else if ( state == stateModSpec ) { if ( ( curChange == null ) || ( curChange . name == null ) ) { throwmsg ( "LDIF software error: No current change" ) ; } if ( ! curChange . name . equalsIgnoreCase ( attr ) ) { throwmsg ( "Invalid LDIF mod-spec: attribute name mismatch" ) ; } if ( curChange . vals == null ) { curChange . vals = new Vector ( ) ; } curChange . vals . addElement ( makeVal ( val , encoded , url ) ) ; } else { throwmsg ( "LDIF software error: invalid state " + state ) ; } somedata = true ; } | For all record types we expect an optional version spec first . After that comes the dn . After that for content records we expect attrval - spec . for change record we have optional controls followed by changes . |
23,360 | public void add ( final AbsAxis mAx ) { AbsAxis axis = mAx ; if ( isDupOrd ( axis ) ) { axis = new DupFilterAxis ( mRtx , axis ) ; DupState . nodup = true ; } switch ( mNumber ) { case 0 : mFirstAxis = axis ; mNumber ++ ; break ; case 1 : mExpr = new NestedAxis ( mFirstAxis , axis , mRtx ) ; mNumber ++ ; break ; default : final AbsAxis cache = mExpr ; mExpr = new NestedAxis ( cache , axis , mRtx ) ; } } | Adds a new Axis to the expression chain . The first axis that is added has to be stored till a second axis is added . When the second axis is added it is nested with the first one and builds the execution chain . |
23,361 | private static int decodePercent ( final CharSequence s , final int length , final int i ) { if ( i + 2 >= length ) { return INVALID ; } final char n1 = s . charAt ( i + 1 ) ; final char n2 = s . charAt ( i + 2 ) ; return decodeNibbles ( n1 , n2 ) ; } | Decode a percent encoded byte . E . g . %3F - > 63 . |
23,362 | private static int decodeNibbles ( final char c1 , final char c2 ) { final int n1 = decodeHex ( c1 ) ; if ( n1 == INVALID ) { return INVALID ; } final int n2 = decodeHex ( c2 ) ; if ( n2 == INVALID ) { return INVALID ; } return ( ( ( n1 & 0xf ) << 4 ) | ( n2 & 0xf ) ) ; } | Decode two hex nibbles to a byte . E . g . 3 and F - > 63 . |
23,363 | private static int decodeHex ( final char c ) { if ( c < '0' ) { return INVALID ; } if ( c <= '9' ) { return c - '0' ; } if ( c < 'A' ) { return INVALID ; } if ( c <= 'F' ) { return c - 'A' + 10 ; } if ( c < 'a' ) { return INVALID ; } if ( c <= 'f' ) { return c - 'a' + 10 ; } return INVALID ; } | Decode a hex nibble . E . g . 3 - > 3 and F - > 15 . |
23,364 | private static int utf8Read3 ( int cu1 , int cu2 , int cu3 ) { if ( ( cu2 & 0xC0 ) != 0x80 ) { return INVALID ; } if ( cu1 == 0xE0 && cu2 < 0xA0 ) { return INVALID ; } if ( ( cu3 & 0xC0 ) != 0x80 ) { return INVALID ; } return ( cu1 << 12 ) + ( cu2 << 6 ) + cu3 - 0xE2080 ; } | Read a 3 byte UTF8 sequence . |
23,365 | private static int utf8Read4 ( int cu1 , int cu2 , int cu3 , int cu4 ) { if ( ( cu2 & 0xC0 ) != 0x80 ) { return INVALID ; } if ( cu1 == 0xF0 && cu2 < 0x90 ) { return INVALID ; } if ( cu1 == 0xF4 && cu2 >= 0x90 ) { return INVALID ; } if ( ( cu3 & 0xC0 ) != 0x80 ) { return INVALID ; } if ( ( cu4 & 0xC0 ) != 0x80 ) { return INVALID ; } return ( cu1 << 18 ) + ( cu2 << 12 ) + ( cu3 << 6 ) + cu4 - 0x3C82080 ; } | Read a 4 byte UTF8 sequence . |
23,366 | public void close ( ) { if ( consumer != null ) { try { consumer . close ( ) ; } catch ( Throwable t ) { warn ( t . getMessage ( ) ) ; } } conn . close ( ) ; } | Close and release resources . |
23,367 | public void process ( final boolean asynch ) throws NotificationException { if ( asynch ) { try { consumer . setMessageListener ( this ) ; return ; } catch ( final JMSException je ) { throw new NotificationException ( je ) ; } } while ( running ) { final Message m = conn . receive ( ) ; if ( m == null ) { running = false ; return ; } onMessage ( m ) ; } } | For asynch we do the onMessage listener style . Otherwise we wait synchronously for incoming messages . |
23,368 | public static boolean getURL ( final String sUrl , final AtomicInteger gCount , long start ) { int count = gCount . incrementAndGet ( ) ; if ( count % 100 == 0 ) { long diff = ( System . currentTimeMillis ( ) - start ) / 1000 ; logger . info ( "Count: " + count + " IPS: " + count / diff ) ; } final URL url ; try { url = new URL ( sUrl ) ; } catch ( MalformedURLException e ) { logger . info ( "URL-Failed(" + count + "): " + e . toString ( ) ) ; return false ; } logger . log ( Level . FINE , "Testing(" + count + "): " + url ) ; final URLConnection con ; try { con = url . openConnection ( ) ; con . setConnectTimeout ( 10000 ) ; con . setReadTimeout ( 10000 ) ; if ( - 1 == con . getInputStream ( ) . read ( ) ) { return false ; } } catch ( IOException e ) { if ( Utils . isIgnorableException ( e ) ) { return false ; } logger . log ( Level . WARNING , "Failed (" + url + ")(" + count + ")" , e ) ; return false ; } logger . info ( "Last Modified (" + url + ")(" + count + "): " + new Date ( con . getLastModified ( ) ) ) ; return true ; } | Test URL and report if it can be read . |
23,369 | private void fillDataStructures ( ) { final ITreeData treeData = mRtx . getNode ( ) ; mInOrder . put ( treeData , true ) ; mDescendants . put ( treeData , 1L ) ; } | Fill data structures . |
23,370 | @ SuppressForbidden ( reason = "We want to bind to any address here when checking for free ports" ) public static int getNextFreePort ( int portRangeStart , int portRangeEnd ) throws IOException { for ( int port = portRangeStart ; port <= portRangeEnd ; port ++ ) { try ( ServerSocket sock = new ServerSocket ( ) ) { sock . setReuseAddress ( true ) ; sock . bind ( new InetSocketAddress ( port ) ) ; return port ; } catch ( IOException e ) { log . warning ( "Port " + port + " seems to be used already, trying next one..." ) ; } } throw new IOException ( "No free port found in the range of [" + portRangeStart + " - " + portRangeEnd + "]" ) ; } | Method that is used to find the next available port . It used the two constants PORT_RANGE_START and PORT_RANGE_END defined above to limit the range of ports that are tried . |
23,371 | protected TimeZone fetchTimeZone ( final String id ) throws TimezonesException { final TaggedTimeZone ttz = fetchTimeZone ( id , null ) ; if ( ttz == null ) { return null ; } register ( id , ttz . tz ) ; return ttz . tz ; } | Fetch a timezone object from the server given the id . |
23,372 | void diffMovement ( ) throws TTException { assert mHashKind != null ; assert mNewRtx != null ; assert mOldRtx != null ; assert mDiff != null ; assert mDiffKind != null ; if ( mNewRtx . getNode ( ) . getKind ( ) != ROOT ) { if ( mHashKind == HashKind . None || mDiffKind == EDiffOptimized . NO ) { mDiff = diff ( mNewRtx , mOldRtx , mDepth , EFireDiff . TRUE ) ; } else { mDiff = optimizedDiff ( mNewRtx , mOldRtx , mDepth , EFireDiff . TRUE ) ; } } while ( ( mOldRtx . getNode ( ) . getKind ( ) != ROOT && mDiff == EDiff . DELETED ) || moveCursor ( mNewRtx , ERevision . NEW ) ) { if ( mDiff != EDiff . INSERTED ) { moveCursor ( mOldRtx , ERevision . OLD ) ; } if ( mNewRtx . getNode ( ) . getKind ( ) != ROOT || mOldRtx . getNode ( ) . getKind ( ) != ROOT ) { if ( mHashKind == HashKind . None || mDiffKind == EDiffOptimized . NO ) { mDiff = diff ( mNewRtx , mOldRtx , mDepth , EFireDiff . TRUE ) ; } else { mDiff = optimizedDiff ( mNewRtx , mOldRtx , mDepth , EFireDiff . TRUE ) ; } } } if ( mOldRtx . getNode ( ) . getKind ( ) != ROOT ) { while ( mDiff == EDiff . INSERTED || moveCursor ( mOldRtx , ERevision . OLD ) ) { if ( mHashKind == HashKind . None || mDiffKind == EDiffOptimized . NO ) { mDiff = diff ( mNewRtx , mOldRtx , mDepth , EFireDiff . TRUE ) ; } else { mDiff = optimizedDiff ( mNewRtx , mOldRtx , mDepth , EFireDiff . TRUE ) ; } } } done ( ) ; } | Do the diff . |
23,373 | boolean moveCursor ( final INodeReadTrx paramRtx , final ERevision paramRevision ) throws TTIOException { assert paramRtx != null ; boolean moved = false ; final ITreeStructData node = ( ( ITreeStructData ) paramRtx . getNode ( ) ) ; if ( node . hasFirstChild ( ) ) { if ( node . getKind ( ) != ROOT && mDiffKind == EDiffOptimized . HASHED && mHashKind != HashKind . None && ( mDiff == EDiff . SAMEHASH || mDiff == EDiff . DELETED ) ) { moved = paramRtx . moveTo ( ( ( ITreeStructData ) paramRtx . getNode ( ) ) . getRightSiblingKey ( ) ) ; if ( ! moved ) { moved = moveToFollowingNode ( paramRtx , paramRevision ) ; } } else { moved = paramRtx . moveTo ( ( ( ITreeStructData ) paramRtx . getNode ( ) ) . getFirstChildKey ( ) ) ; if ( moved ) { switch ( paramRevision ) { case NEW : mDepth . incrementNewDepth ( ) ; break ; case OLD : mDepth . incrementOldDepth ( ) ; break ; } } } } else if ( node . hasRightSibling ( ) ) { if ( paramRtx . getNode ( ) . getDataKey ( ) == mRootKey ) { paramRtx . moveTo ( ROOT_NODE ) ; } else { moved = paramRtx . moveTo ( ( ( ITreeStructData ) paramRtx . getNode ( ) ) . getRightSiblingKey ( ) ) ; } } else { moved = moveToFollowingNode ( paramRtx , paramRevision ) ; } return moved ; } | Move cursor one node forward in pre order . |
23,374 | private boolean moveToFollowingNode ( final INodeReadTrx paramRtx , final ERevision paramRevision ) throws TTIOException { boolean moved = false ; while ( ! ( ( ITreeStructData ) paramRtx . getNode ( ) ) . hasRightSibling ( ) && ( ( ITreeStructData ) paramRtx . getNode ( ) ) . hasParent ( ) && paramRtx . getNode ( ) . getDataKey ( ) != mRootKey ) { moved = paramRtx . moveTo ( paramRtx . getNode ( ) . getParentKey ( ) ) ; if ( moved ) { switch ( paramRevision ) { case NEW : mDepth . decrementNewDepth ( ) ; break ; case OLD : mDepth . decrementOldDepth ( ) ; break ; } } } if ( paramRtx . getNode ( ) . getDataKey ( ) == mRootKey ) { paramRtx . moveTo ( ROOT_NODE ) ; } moved = paramRtx . moveTo ( ( ( ITreeStructData ) paramRtx . getNode ( ) ) . getRightSiblingKey ( ) ) ; return moved ; } | Move to next following node . |
23,375 | EDiff diff ( final INodeReadTrx paramNewRtx , final INodeReadTrx paramOldRtx , final DepthCounter paramDepth , final EFireDiff paramFireDiff ) throws TTIOException { assert paramNewRtx != null ; assert paramOldRtx != null ; assert paramDepth != null ; EDiff diff = EDiff . SAME ; switch ( paramNewRtx . getNode ( ) . getKind ( ) ) { case ROOT : case TEXT : case ELEMENT : if ( ! checkNodes ( paramNewRtx , paramOldRtx ) ) { diff = diffAlgorithm ( paramNewRtx , paramOldRtx , paramDepth ) ; } break ; default : } if ( paramFireDiff == EFireDiff . TRUE ) { fireDiff ( diff , ( ( ITreeStructData ) paramNewRtx . getNode ( ) ) , ( ( ITreeStructData ) paramOldRtx . getNode ( ) ) , new DiffDepth ( paramDepth . getNewDepth ( ) , paramDepth . getOldDepth ( ) ) ) ; } return diff ; } | Diff of nodes . |
23,376 | EDiff optimizedDiff ( final INodeReadTrx paramNewRtx , final INodeReadTrx paramOldRtx , final DepthCounter paramDepth , final EFireDiff paramFireDiff ) throws TTIOException { assert paramNewRtx != null ; assert paramOldRtx != null ; assert paramDepth != null ; EDiff diff = EDiff . SAMEHASH ; switch ( paramNewRtx . getNode ( ) . getKind ( ) ) { case ROOT : case TEXT : case ELEMENT : if ( paramNewRtx . getNode ( ) . getDataKey ( ) != paramOldRtx . getNode ( ) . getDataKey ( ) || paramNewRtx . getNode ( ) . getHash ( ) != paramOldRtx . getNode ( ) . getHash ( ) ) { if ( checkNodes ( paramNewRtx , paramOldRtx ) ) { diff = EDiff . SAME ; } else { diff = diffAlgorithm ( paramNewRtx , paramOldRtx , paramDepth ) ; } } break ; default : } if ( paramFireDiff == EFireDiff . TRUE ) { if ( diff == EDiff . SAMEHASH ) { fireDiff ( EDiff . SAME , ( ( ITreeStructData ) paramNewRtx . getNode ( ) ) , ( ( ITreeStructData ) paramOldRtx . getNode ( ) ) , new DiffDepth ( paramDepth . getNewDepth ( ) , paramDepth . getOldDepth ( ) ) ) ; } else { fireDiff ( diff , ( ( ITreeStructData ) paramNewRtx . getNode ( ) ) , ( ( ITreeStructData ) paramOldRtx . getNode ( ) ) , new DiffDepth ( paramDepth . getNewDepth ( ) , paramDepth . getOldDepth ( ) ) ) ; } } return diff ; } | Optimized diff which skips unnecessary comparsions . |
23,377 | private EDiff diffAlgorithm ( final INodeReadTrx paramNewRtx , final INodeReadTrx paramOldRtx , final DepthCounter paramDepth ) throws TTIOException { EDiff diff = null ; if ( paramDepth . getOldDepth ( ) > paramDepth . getNewDepth ( ) ) { diff = EDiff . DELETED ; } else if ( checkUpdate ( paramNewRtx , paramOldRtx ) ) { diff = EDiff . UPDATED ; } else { EFoundEqualNode found = EFoundEqualNode . FALSE ; final long key = paramOldRtx . getNode ( ) . getDataKey ( ) ; while ( ( ( ITreeStructData ) paramOldRtx . getNode ( ) ) . hasRightSibling ( ) && paramOldRtx . moveTo ( ( ( ITreeStructData ) paramOldRtx . getNode ( ) ) . getRightSiblingKey ( ) ) && found == EFoundEqualNode . FALSE ) { if ( checkNodes ( paramNewRtx , paramOldRtx ) ) { found = EFoundEqualNode . TRUE ; } } paramOldRtx . moveTo ( key ) ; diff = found . kindOfDiff ( ) ; } assert diff != null ; return diff ; } | Main algorithm to compute diffs between two nodes . |
23,378 | boolean checkUpdate ( final INodeReadTrx paramNewRtx , final INodeReadTrx paramOldRtx ) throws TTIOException { assert paramNewRtx != null ; assert paramOldRtx != null ; boolean updated = false ; final long newKey = paramNewRtx . getNode ( ) . getDataKey ( ) ; boolean movedNewRtx = paramNewRtx . moveTo ( ( ( ITreeStructData ) paramNewRtx . getNode ( ) ) . getRightSiblingKey ( ) ) ; final long oldKey = paramOldRtx . getNode ( ) . getDataKey ( ) ; boolean movedOldRtx = paramOldRtx . moveTo ( ( ( ITreeStructData ) paramOldRtx . getNode ( ) ) . getRightSiblingKey ( ) ) ; if ( movedNewRtx && movedOldRtx && checkNodes ( paramNewRtx , paramOldRtx ) ) { updated = true ; } else if ( ! movedNewRtx && ! movedOldRtx ) { movedNewRtx = paramNewRtx . moveTo ( paramNewRtx . getNode ( ) . getParentKey ( ) ) ; movedOldRtx = paramOldRtx . moveTo ( paramOldRtx . getNode ( ) . getParentKey ( ) ) ; if ( movedNewRtx && movedOldRtx && checkNodes ( paramNewRtx , paramOldRtx ) ) { updated = true ; } } paramNewRtx . moveTo ( newKey ) ; paramOldRtx . moveTo ( oldKey ) ; if ( ! updated ) { updated = paramNewRtx . getNode ( ) . getDataKey ( ) == paramOldRtx . getNode ( ) . getDataKey ( ) ; } return updated ; } | Check for an update of a node . |
23,379 | private void checkArgument ( boolean argument , String msg , Object ... args ) { if ( ! argument ) { throw new IllegalArgumentException ( String . format ( msg , args ) ) ; } } | copy of Guava to avoid including Guava in this core library |
23,380 | public void open ( final String queueName ) throws NotificationException { try { final ConnectionFactory connFactory ; final Context ctx = new InitialContext ( pr ) ; try { connFactory = ( ConnectionFactory ) ctx . lookup ( pr . getProperty ( "org.bedework.connection.factory.name" ) ) ; connection = connFactory . createConnection ( ) ; } catch ( final Throwable t ) { if ( debug ( ) ) { error ( t ) ; } throw new NotificationException ( t ) ; } try { session = connection . createSession ( useTransactions , ackMode ) ; if ( session == null ) { throw new NotificationException ( "No session created" ) ; } final String qn = pr . getProperty ( "org.bedework.jms.queue.prefix" ) + queueName ; try { ourQueue = ( Queue ) new InitialContext ( ) . lookup ( qn ) ; } catch ( final NamingException ne ) { ourQueue = ( Queue ) ctx . lookup ( qn ) ; } } catch ( final Throwable t ) { if ( debug ( ) ) { error ( t ) ; } throw new NotificationException ( t ) ; } } catch ( final NotificationException ne ) { throw ne ; } catch ( final Throwable t ) { if ( debug ( ) ) { error ( t ) ; } throw new NotificationException ( t ) ; } } | Open a connection to the named queue ready to create a producer or consumer . |
23,381 | public static void writeln ( final Writer writer , final String string , int indentLevel ) throws IOException { writer . write ( StringUtils . repeat ( "\t" , indentLevel ) + string ) ; writer . write ( "\n" ) ; } | Write out the string and a newline appending a number of tabs to properly indent the resulting text - file . |
23,382 | public static void writeHeader ( Writer writer , int dpi , String rankDir , String id , List < String > attribLines ) throws IOException { if ( attribLines == null ) { attribLines = new ArrayList < > ( ) ; } else { attribLines = new ArrayList < > ( attribLines ) ; } attribLines . add ( "node [shape=box];" ) ; StringBuilder header = new StringBuilder ( "digraph " + id + " {\n" ) ; if ( dpi > 0 ) { header . append ( "dpi=" ) . append ( dpi ) . append ( ";\n" ) ; } header . append ( "rankdir=" ) . append ( StringUtils . isNotBlank ( rankDir ) ? rankDir : "LR" ) . append ( ";\n" ) ; for ( String line : attribLines ) { line = line . trim ( ) ; header . append ( line ) . append ( line . endsWith ( ";" ) ? "\n" : ";\n" ) ; } DotUtils . writeln ( writer , header . toString ( ) ) ; } | Write the header structure . |
23,383 | public static void renderGraph ( File dotfile , File resultfile ) throws IOException { CommandLine cmdLine = new CommandLine ( DOT_EXE ) ; cmdLine . addArgument ( "-T" + StringUtils . substringAfterLast ( resultfile . getAbsolutePath ( ) , "." ) ) ; cmdLine . addArgument ( dotfile . getAbsolutePath ( ) ) ; DefaultExecutor executor = new DefaultExecutor ( ) ; executor . setExitValue ( 0 ) ; ExecuteWatchdog watchdog = new ExecuteWatchdog ( 60000 ) ; executor . setWatchdog ( watchdog ) ; try { try ( FileOutputStream out2 = new FileOutputStream ( resultfile ) ) { executor . setStreamHandler ( new PumpStreamHandler ( out2 , System . err ) ) ; int exitValue = executor . execute ( cmdLine ) ; if ( exitValue != 0 ) { throw new IOException ( "Could not convert graph to dot, had exit value: " + exitValue + "!" ) ; } } } catch ( IOException e ) { if ( ! resultfile . delete ( ) ) { System . out . println ( "Could not delete file " + resultfile ) ; } throw e ; } } | Call graphviz - dot to convert the . dot - file to a rendered graph . |
23,384 | public static boolean checkDot ( ) throws IOException { CommandLine cmdLine = new CommandLine ( DOT_EXE ) ; cmdLine . addArgument ( "-V" ) ; DefaultExecutor executor = new DefaultExecutor ( ) ; executor . setExitValue ( 0 ) ; ExecuteWatchdog watchdog = new ExecuteWatchdog ( 60000 ) ; executor . setWatchdog ( watchdog ) ; executor . setStreamHandler ( new PumpStreamHandler ( System . out , System . err ) ) ; int exitValue = executor . execute ( cmdLine ) ; if ( exitValue != 0 ) { System . err . println ( "Could not run '" + DOT_EXE + "', had exit value: " + exitValue + "!" ) ; return false ; } return true ; } | Verify if dot can be started and print out the version to stdout . |
23,385 | public static void shredInputStream ( final INodeWriteTrx wtx , final InputStream value , final EShredderInsert child ) { final XMLInputFactory factory = XMLInputFactory . newInstance ( ) ; factory . setProperty ( XMLInputFactory . SUPPORT_DTD , false ) ; XMLEventReader parser ; try { parser = factory . createXMLEventReader ( value ) ; } catch ( final XMLStreamException xmlse ) { throw new WebApplicationException ( xmlse ) ; } try { final XMLShredder shredder = new XMLShredder ( wtx , parser , child ) ; shredder . call ( ) ; } catch ( final Exception exce ) { throw new WebApplicationException ( exce ) ; } } | Shreds a given InputStream |
23,386 | public static void closeWTX ( final boolean abortTransaction , final INodeWriteTrx wtx , final ISession ses ) throws TTException { synchronized ( ses ) { if ( abortTransaction ) { wtx . abort ( ) ; } ses . close ( ) ; } } | This method closes all open treetank connections concerning a NodeWriteTrx . |
23,387 | public String getContentName ( final Request req ) throws Throwable { UtilActionForm form = req . getForm ( ) ; PresentationState ps = getPresentationState ( req ) ; String contentName = ps . getContentName ( ) ; form . setContentName ( contentName ) ; return contentName ; } | Override this to get the contentName from different sources |
23,388 | protected String checkLogOut ( final HttpServletRequest request , final UtilActionForm form ) throws Throwable { final String reqUser = request . getRemoteUser ( ) ; final boolean forceLogout = ! Util . equalsString ( reqUser , form . getCurrentUser ( ) ) ; final String temp = request . getParameter ( requestLogout ) ; if ( forceLogout || ( temp != null ) ) { final HttpSession sess = request . getSession ( false ) ; if ( ( sess != null ) && logOutCleanup ( request , form ) ) { sess . invalidate ( ) ; } return forwardLoggedOut ; } return null ; } | Check for logout request . |
23,389 | public void setRefreshInterval ( final HttpServletRequest request , final HttpServletResponse response , final int refreshInterval , final String refreshAction , final UtilActionForm form ) { if ( refreshInterval != 0 ) { StringBuilder sb = new StringBuilder ( 250 ) ; sb . append ( refreshInterval ) ; sb . append ( "; URL=" ) ; sb . append ( form . getUrlPrefix ( ) ) ; if ( ! refreshAction . startsWith ( "/" ) ) { sb . append ( "/" ) ; } sb . append ( refreshAction ) ; response . setHeader ( "Refresh" , sb . toString ( ) ) ; } } | Check request for refresh interval |
23,390 | public boolean setAppVar ( final String name , final String val , final HashMap < String , String > appVars ) { if ( val == null ) { appVars . remove ( name ) ; return true ; } if ( appVars . size ( ) > maxAppVars ) { return false ; } appVars . put ( name , val ) ; return true ; } | Called to set an application variable to a value |
23,391 | protected String checkConfirmationId ( final HttpServletRequest request , final UtilActionForm form ) throws Throwable { String reqpar = request . getParameter ( "confirmationid" ) ; if ( reqpar == null ) { return null ; } if ( ! reqpar . equals ( form . getConfirmationId ( ) ) ) { return "badConformationId" ; } return null ; } | Check for a confirmation id . This is a random string embedded in some requests to confirm that the incoming request came from a page we generated . Not all pages will have such an id but if we do it must match . |
23,392 | protected String getReqPar ( final HttpServletRequest req , final String name ) throws Throwable { return Util . checkNull ( req . getParameter ( name ) ) ; } | Get a request parameter stripped of white space . Return null for zero length . |
23,393 | public Status route ( final CharSequence method , final CharSequence path , final Result < T > result ) { result . captor . optionalTrailingSlash ( optionalTrailingSlash ) ; final RouteTarget < T > route = trie . lookup ( path , result . captor ) ; if ( route == null ) { return result . notFound ( ) . status ( ) ; } final Target < T > target = route . lookup ( method ) ; if ( target == null ) { return result . notAllowed ( route ) . status ( ) ; } return result . success ( path , route , target ) . status ( ) ; } | Route a request . |
23,394 | private int insertName ( final String pName ) throws TTException { final String string = ( pName == null ? "" : pName ) ; final int nameKey = NamePageHash . generateHashForString ( string ) ; NodeMetaPageFactory . MetaKey key = new NodeMetaPageFactory . MetaKey ( nameKey ) ; NodeMetaPageFactory . MetaValue value = new NodeMetaPageFactory . MetaValue ( string ) ; getPageWtx ( ) . getMetaBucket ( ) . put ( key , value ) ; return nameKey ; } | Setting a new name in the metapage . |
23,395 | private void adaptForInsert ( final ITreeData paramNewNode , final boolean addAsFirstChild ) throws TTException { assert paramNewNode != null ; if ( paramNewNode instanceof ITreeStructData ) { final ITreeStructData strucNode = ( ITreeStructData ) paramNewNode ; final ITreeStructData parent = ( ITreeStructData ) getPtx ( ) . getData ( paramNewNode . getParentKey ( ) ) ; parent . incrementChildCount ( ) ; if ( addAsFirstChild ) { parent . setFirstChildKey ( paramNewNode . getDataKey ( ) ) ; } getPtx ( ) . setData ( parent ) ; if ( strucNode . hasRightSibling ( ) ) { final ITreeStructData rightSiblingNode = ( ITreeStructData ) getPtx ( ) . getData ( strucNode . getRightSiblingKey ( ) ) ; rightSiblingNode . setLeftSiblingKey ( paramNewNode . getDataKey ( ) ) ; getPtx ( ) . setData ( rightSiblingNode ) ; } if ( strucNode . hasLeftSibling ( ) ) { final ITreeStructData leftSiblingNode = ( ITreeStructData ) getPtx ( ) . getData ( strucNode . getLeftSiblingKey ( ) ) ; leftSiblingNode . setRightSiblingKey ( paramNewNode . getDataKey ( ) ) ; getPtx ( ) . setData ( leftSiblingNode ) ; } } } | Adapting everything for insert operations . |
23,396 | private void adaptForRemove ( final ITreeStructData pOldNode ) throws TTException { assert pOldNode != null ; if ( pOldNode . hasLeftSibling ( ) ) { final ITreeStructData leftSibling = ( ITreeStructData ) getPtx ( ) . getData ( pOldNode . getLeftSiblingKey ( ) ) ; leftSibling . setRightSiblingKey ( pOldNode . getRightSiblingKey ( ) ) ; getPtx ( ) . setData ( leftSibling ) ; } if ( pOldNode . hasRightSibling ( ) ) { final ITreeStructData rightSibling = ( ITreeStructData ) getPtx ( ) . getData ( pOldNode . getRightSiblingKey ( ) ) ; rightSibling . setLeftSiblingKey ( pOldNode . getLeftSiblingKey ( ) ) ; getPtx ( ) . setData ( rightSibling ) ; } final ITreeStructData parent = ( ITreeStructData ) getPtx ( ) . getData ( pOldNode . getParentKey ( ) ) ; if ( ! pOldNode . hasLeftSibling ( ) ) { parent . setFirstChildKey ( pOldNode . getRightSiblingKey ( ) ) ; } parent . decrementChildCount ( ) ; getPtx ( ) . setData ( parent ) ; if ( pOldNode . getKind ( ) == IConstants . ELEMENT ) { for ( int i = 0 ; i < ( ( ElementNode ) pOldNode ) . getAttributeCount ( ) ; i ++ ) { moveTo ( ( ( ElementNode ) pOldNode ) . getAttributeKey ( i ) ) ; getPtx ( ) . removeData ( mDelegate . getCurrentNode ( ) ) ; } moveTo ( pOldNode . getDataKey ( ) ) ; for ( int i = 0 ; i < ( ( ElementNode ) pOldNode ) . getNamespaceCount ( ) ; i ++ ) { moveTo ( ( ( ElementNode ) pOldNode ) . getNamespaceKey ( i ) ) ; getPtx ( ) . removeData ( mDelegate . getCurrentNode ( ) ) ; } } getPtx ( ) . removeData ( pOldNode ) ; } | Adapting everything for remove operations . |
23,397 | private void rollingUpdate ( final long paramOldHash ) throws TTException { final ITreeData newNode = mDelegate . getCurrentNode ( ) ; final long newNodeHash = newNode . hashCode ( ) ; long resultNew = newNode . hashCode ( ) ; do { synchronized ( mDelegate . getCurrentNode ( ) ) { getPtx ( ) . getData ( mDelegate . getCurrentNode ( ) . getDataKey ( ) ) ; if ( mDelegate . getCurrentNode ( ) . getDataKey ( ) == newNode . getDataKey ( ) ) { resultNew = mDelegate . getCurrentNode ( ) . getHash ( ) - paramOldHash ; resultNew = resultNew + newNodeHash ; } else { resultNew = mDelegate . getCurrentNode ( ) . getHash ( ) - ( paramOldHash * PRIME ) ; resultNew = resultNew + newNodeHash * PRIME ; } mDelegate . getCurrentNode ( ) . setHash ( resultNew ) ; getPtx ( ) . setData ( mDelegate . getCurrentNode ( ) ) ; } } while ( moveTo ( mDelegate . getCurrentNode ( ) . getParentKey ( ) ) ) ; mDelegate . setCurrentNode ( newNode ) ; } | Adapting the structure with a rolling hash for all ancestors only with update . |
23,398 | private void rollingRemove ( ) throws TTException { final ITreeData startNode = mDelegate . getCurrentNode ( ) ; long hashToRemove = startNode . getHash ( ) ; long hashToAdd = 0 ; long newHash = 0 ; do { synchronized ( mDelegate . getCurrentNode ( ) ) { getPtx ( ) . getData ( mDelegate . getCurrentNode ( ) . getDataKey ( ) ) ; if ( mDelegate . getCurrentNode ( ) . getDataKey ( ) == startNode . getDataKey ( ) ) { newHash = 0 ; } else if ( mDelegate . getCurrentNode ( ) . getDataKey ( ) == startNode . getParentKey ( ) ) { newHash = mDelegate . getCurrentNode ( ) . getHash ( ) - ( hashToRemove * PRIME ) ; hashToRemove = mDelegate . getCurrentNode ( ) . getHash ( ) ; } else { newHash = mDelegate . getCurrentNode ( ) . getHash ( ) - ( hashToRemove * PRIME ) ; newHash = newHash + hashToAdd * PRIME ; hashToRemove = mDelegate . getCurrentNode ( ) . getHash ( ) ; } mDelegate . getCurrentNode ( ) . setHash ( newHash ) ; hashToAdd = newHash ; getPtx ( ) . setData ( mDelegate . getCurrentNode ( ) ) ; } } while ( moveTo ( mDelegate . getCurrentNode ( ) . getParentKey ( ) ) ) ; mDelegate . setCurrentNode ( startNode ) ; } | Adapting the structure with a rolling hash for all ancestors only with remove . |
23,399 | public static String buildName ( final QName pQName ) { if ( pQName == null ) { throw new NullPointerException ( "mQName must not be null!" ) ; } String name ; if ( pQName . getPrefix ( ) . isEmpty ( ) ) { name = pQName . getLocalPart ( ) ; } else { name = new StringBuilder ( pQName . getPrefix ( ) ) . append ( ":" ) . append ( pQName . getLocalPart ( ) ) . toString ( ) ; } return name ; } | Building name consisting out of prefix and name . NamespaceUri is not used over here . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.