package com.perforce.client.api; import java.io.*; import java.util.*; public class ClientUser { int instance; private boolean amFinished = false; private boolean releaseAfterFinished = true; /** * Makes a ClientUser object. By default this object cleans up the native * reference when the finished() method is called. * **/ public ClientUser() { this( true ); } /** * Makes a ClientUser object. * * @param releaseAfterFinished If you want the ClientUser to * clean up the native global reference * when the finished() method is called. * **/ public ClientUser( boolean releaseAfterFinished ) { this.instance = nNewInstance(); setReleaseAfterFinished( releaseAfterFinished ); } protected void finalize() { nDeleteInstance( this.instance ); this.instance = 0; } /** * A request from the server asking for input from the user. * * @param e . * @return the text that the user input. * * **/ public String inputData() throws P4ClientException { InputStreamReader isr = new InputStreamReader( System.in ); LineNumberReader lr = new LineNumberReader( isr ); try { return lr.readLine(); } catch ( IOException ioe ) { // e.setSomeError(); return null; } } public void handleError( P4ClientException err ) { // } public void outputError( String errBuf ) { System.err.print( errBuf ); } public void outputInfo( char level, String data ) { System.err.println( data ); } public void outputBinary( byte[] data ) { try { System.out.write( data ); } catch ( IOException e ) { e.printStackTrace(); } } public void outputText( char[] data ) { System.out.print( data ); } public void outputStat( Properties varList ) { StringBuffer msg = new StringBuffer(); // Dump out the variables, using the GetVar( x ) interface. // Don't display the function (duh), which is only relevant to rpc. Enumeration names = varList.propertyNames(); while ( names.hasMoreElements() ) { String currentName = (String)names.nextElement(); if ( currentName.equals( "func" ) ) continue; String val = varList.getProperty( currentName ); // otherAction and otherOpen go at level 2, as per 99.1 + earlier msg.append( currentName ); msg.append( " " ); msg.append( val ); char level = currentName.equals( "other" ) ? '1' : '2'; outputInfo( level, msg.toString() ); } // blank line outputInfo( '0', "" ); } public String prompt( final String msg, int noEcho ) throws P4ClientException { System.out.println( msg ); try { return new LineNumberReader( new InputStreamReader( System.in ) ).readLine(); } catch ( IOException ioe ) { // e.setSomeError(); return null; } } public void errorPause( String errBuf ) throws P4ClientException { outputError( errBuf ); prompt( "Hit enter/return to continue...", 0 ); } public void edit( FileSys f1 ) throws P4ClientException { P4Error err = new P4Error(); System.err.println( "Edit" ); nEdit( this.instance, f1.instance, err.instance ); err.checkException(); } public void diff( FileSys f1, FileSys f2, boolean doPage, String diffFlags ) throws P4ClientException { P4Error err = new P4Error(); nDiff( this.instance, f1.instance, f2.instance, doPage, diffFlags, err.instance ); err.checkException(); } public void merge( FileSys base, FileSys leg1, FileSys leg2, FileSys result ) throws P4ClientException { P4Error err = new P4Error(); nMerge( this.instance, base.instance, leg1.instance, leg2.instance, result.instance, err.instance ); err.checkException(); } public void help( String[] help ) { for ( int i = 0; i < help.length; i++ ) { System.out.println( help[i] ); } } public final void releaseNativeGlobalRef() { nReleaseNativeGlobalRef( this.instance ); } public final void setReleaseAfterFinished( boolean releaseAfterFinished ) { synchronized( this ) { releaseAfterFinished = true; } // // Maybe the finished method was already called by the time we get here. // if ( amFinished ) { releaseNativeGlobalRef(); } } public void finished() { } // // CALLBACKS FROM NATIVE CODE // private final String inputDataCALLBACK( int errorInstance ) { String result = null; P4Error catcher = P4Error.makeJavaPeer( errorInstance ); try { result = inputData(); } catch ( P4ClientException e ) { catcher.convertException( e ); } return result; } private final void handleErrorCALLBACK( int errorInstance ) { P4Error peer = P4Error.makeJavaPeer( errorInstance ); try { peer.checkException(); } catch ( P4ClientException err ) { handleError( err ); } } private final void outputErrorCALLBACK( String errBuf ) { outputError( errBuf ); } private final void outputInfoCALLBACK( char level, String data ) { outputInfo( level, data ); } private final void outputBinaryCALLBACK( byte[] data ) { outputBinary( data ); } private final void outputTextCALLBACK( char[] data ) { outputText( data ); } private final void outputStatCALLBACK( int strDictInstance ) { outputStat( new StrDict( strDictInstance ) ); } private final String promptCALLBACK( final String msg, int noEcho, int errInstance ) { String result = null; P4Error catcher = P4Error.makeJavaPeer( errInstance ); try { result = prompt( msg, noEcho ); } catch ( P4ClientException e ) { catcher.convertException( e ); } return result; } private final void errorPauseCALLBACK( String errBuf, int errInstance ) { P4Error catcher = P4Error.makeJavaPeer( errInstance ); try { errorPause( errBuf ); } catch ( P4ClientException e ) { catcher.convertException( e ); } } private final void editCALLBACK( int filesysInstance, int errInstance ) { P4Error catcher = P4Error.makeJavaPeer( errInstance ); try { edit( new FileSys( filesysInstance ) ); } catch ( P4ClientException e ) { catcher.convertException( e ); } } private final void diffCALLBACK( int fileSys1, int fileSys2, boolean doPage, String diffFlags, int errInstance ) { P4Error catcher = P4Error.makeJavaPeer( errInstance ); try { diff( new FileSys( fileSys1 ), new FileSys( fileSys2 ), doPage, diffFlags ); } catch ( P4ClientException e ) { catcher.convertException( e ); } } private final void mergeCALLBACK( int base, int leg1, int leg2, int result, int errInstance ) { P4Error catcher = P4Error.makeJavaPeer( errInstance ); try { merge( new FileSys( base ), new FileSys( leg1 ), new FileSys( leg2 ), new FileSys( result ) ); } catch ( P4ClientException e ) { catcher.convertException( e ); } } private final void helpCALLBACK( String[] helpText ) { help( helpText ); } private final void finishedCALLBACK() { synchronized( this ) { amFinished = true; } try { finished(); } finally { if ( releaseAfterFinished ) { releaseNativeGlobalRef(); } } } // // NATIVE METHODS // private native int nNewInstance(); private static native void nDeleteInstance( int instance ); private static native void nReleaseNativeGlobalRef( int instance ); private static native void nEdit( int instance, int fileSysInstance, int errInstance ); private static native void nDiff( int instance, int fileSysInstance1, int fileSysInstance2, boolean doPage, String diffFlags, int errInstance ); private static native void nMerge( int instance, int fileSysInstanceBase, int fileSysInstanceLeg1, int fileSysInstanceLeg2, int fileSysInstanceResult, int errInstance ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 783 | paul_hammant |
First cut of P4 Soap API. Uses Glue, can't work yet as DLLs missing. |
||
//guest/michael_bishop/P4APIForJava/java/com/perforce/client/api/ClientUser.java | |||||
#1 | 430 | Michael Bishop |
Initial checkin. Seems to work. Not very much testing. Not very much documentation. Some more commenting needs to take place. But, it's there to experiment with. |