idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
28,700
public ByteBuffer sliceAsByteBuffer ( int index , int length ) { if ( hasArray ( ) ) { return ByteBuffer . wrap ( ( byte [ ] ) base , ( int ) ( ( address - ARRAY_BYTE_BASE_OFFSET ) + index ) , length ) ; } else { assert ( ! isUniversalBuffer ) ; return DirectBufferAccess . newByteBuffer ( address , index , length , ref...
Create a ByteBuffer view of the range [ index index + length ) of this memory
28,701
public byte [ ] toByteArray ( ) { byte [ ] b = new byte [ size ( ) ] ; unsafe . copyMemory ( base , address , b , ARRAY_BYTE_BASE_OFFSET , size ( ) ) ; return b ; }
Get a copy of this buffer
28,702
public void copyTo ( int index , MessageBuffer dst , int offset , int length ) { unsafe . copyMemory ( base , address + index , dst . base , dst . address + offset , length ) ; }
Copy this buffer contents to another MessageBuffer
28,703
public JsonFormat . Value findFormat ( Annotated ann ) { JsonFormat . Value precedenceFormat = super . findFormat ( ann ) ; if ( precedenceFormat != null ) { return precedenceFormat ; } return ARRAY_FORMAT ; }
Defines array format for serialized entities with ObjectMapper without actually including the schema
28,704
public Boolean findIgnoreUnknownProperties ( AnnotatedClass ac ) { final Boolean precedenceIgnoreUnknownProperties = super . findIgnoreUnknownProperties ( ac ) ; if ( precedenceIgnoreUnknownProperties != null ) { return precedenceIgnoreUnknownProperties ; } return true ; }
Defines that unknown properties will be ignored and won t fail the un - marshalling process . Happens in case of de - serialization of a payload that contains more properties than the actual value type
28,705
public OutputStream reset ( OutputStream out ) throws IOException { OutputStream old = this . out ; this . out = out ; return old ; }
Reset Stream . This method doesn t close the old stream .
28,706
public InputStream reset ( InputStream in ) throws IOException { InputStream old = this . in ; this . in = in ; return old ; }
Reset Stream . This method doesn t close the old resource .
28,707
public WritableByteChannel reset ( WritableByteChannel channel ) throws IOException { WritableByteChannel old = this . channel ; this . channel = channel ; return old ; }
Reset channel . This method doesn t close the old channel .
28,708
public ReadableByteChannel reset ( ReadableByteChannel channel ) throws IOException { ReadableByteChannel old = this . channel ; this . channel = channel ; return old ; }
Reset channel . This method doesn t close the old resource .
28,709
private MessageBuffer getNextBuffer ( ) throws IOException { MessageBuffer next = in . next ( ) ; if ( next == null ) { throw new MessageInsufficientBufferException ( ) ; } assert ( buffer != null ) ; totalReadBytes += buffer . size ( ) ; return next ; }
Get the next buffer without changing the position
28,710
public MessageFormat getNextFormat ( ) throws IOException { if ( ! ensureBuffer ( ) ) { throw new MessageInsufficientBufferException ( ) ; } byte b = buffer . getByte ( position ) ; return MessageFormat . valueOf ( b ) ; }
Returns format of the next value .
28,711
private byte readByte ( ) throws IOException { if ( buffer . size ( ) > position ) { byte b = buffer . getByte ( position ) ; position ++ ; return b ; } else { nextBuffer ( ) ; if ( buffer . size ( ) > 0 ) { byte b = buffer . getByte ( 0 ) ; position = 1 ; return b ; } return readByte ( ) ; } }
Read a byte value at the cursor and proceed the cursor .
28,712
public void skipValue ( int count ) throws IOException { while ( count > 0 ) { byte b = readByte ( ) ; MessageFormat f = MessageFormat . valueOf ( b ) ; switch ( f ) { case POSFIXINT : case NEGFIXINT : case BOOLEAN : case NIL : break ; case FIXMAP : { int mapLen = b & 0x0f ; count += mapLen * 2 ; break ; } case FIXARRA...
Skip next values then move the cursor at the end of the value
28,713
private static MessagePackException unexpected ( String expected , byte b ) { MessageFormat format = MessageFormat . valueOf ( b ) ; if ( format == MessageFormat . NEVER_USED ) { return new MessageNeverUsedFormatException ( String . format ( "Expected %s, but encountered 0xC1 \"NEVER_USED\" byte" , expected ) ) ; } els...
Create an exception for the case when an unexpected byte value is read
28,714
public boolean tryUnpackNil ( ) throws IOException { if ( ! ensureBuffer ( ) ) { throw new MessageInsufficientBufferException ( ) ; } byte b = buffer . getByte ( position ) ; if ( b == Code . NIL ) { readByte ( ) ; return true ; } return false ; }
Peeks a Nil byte and reads it if next byte is a nil value .
28,715
public boolean unpackBoolean ( ) throws IOException { byte b = readByte ( ) ; if ( b == Code . FALSE ) { return false ; } else if ( b == Code . TRUE ) { return true ; } throw unexpected ( "boolean" , b ) ; }
Reads true or false .
28,716
public short unpackShort ( ) throws IOException { byte b = readByte ( ) ; if ( Code . isFixInt ( b ) ) { return ( short ) b ; } switch ( b ) { case Code . UINT8 : byte u8 = readByte ( ) ; return ( short ) ( u8 & 0xff ) ; case Code . UINT16 : short u16 = readShort ( ) ; if ( u16 < ( short ) 0 ) { throw overflowU16 ( u16...
Reads a short .
28,717
public long unpackLong ( ) throws IOException { byte b = readByte ( ) ; if ( Code . isFixInt ( b ) ) { return ( long ) b ; } switch ( b ) { case Code . UINT8 : byte u8 = readByte ( ) ; return ( long ) ( u8 & 0xff ) ; case Code . UINT16 : short u16 = readShort ( ) ; return ( long ) ( u16 & 0xffff ) ; case Code . UINT32 ...
Reads a long .
28,718
public BigInteger unpackBigInteger ( ) throws IOException { byte b = readByte ( ) ; if ( Code . isFixInt ( b ) ) { return BigInteger . valueOf ( ( long ) b ) ; } switch ( b ) { case Code . UINT8 : byte u8 = readByte ( ) ; return BigInteger . valueOf ( ( long ) ( u8 & 0xff ) ) ; case Code . UINT16 : short u16 = readShor...
Reads a BigInteger .
28,719
public float unpackFloat ( ) throws IOException { byte b = readByte ( ) ; switch ( b ) { case Code . FLOAT32 : float fv = readFloat ( ) ; return fv ; case Code . FLOAT64 : double dv = readDouble ( ) ; return ( float ) dv ; } throw unexpected ( "Float" , b ) ; }
Reads a float .
28,720
public int unpackArrayHeader ( ) throws IOException { byte b = readByte ( ) ; if ( Code . isFixedArray ( b ) ) { return b & 0x0f ; } switch ( b ) { case Code . ARRAY16 : { int len = readNextLength16 ( ) ; return len ; } case Code . ARRAY32 : { int len = readNextLength32 ( ) ; return len ; } } throw unexpected ( "Array"...
Reads header of an array .
28,721
public int unpackMapHeader ( ) throws IOException { byte b = readByte ( ) ; if ( Code . isFixedMap ( b ) ) { return b & 0x0f ; } switch ( b ) { case Code . MAP16 : { int len = readNextLength16 ( ) ; return len ; } case Code . MAP32 : { int len = readNextLength32 ( ) ; return len ; } } throw unexpected ( "Map" , b ) ; }
Reads header of a map .
28,722
public int unpackBinaryHeader ( ) throws IOException { byte b = readByte ( ) ; if ( Code . isFixedRaw ( b ) ) { return b & 0x1f ; } int len = tryReadBinaryHeader ( b ) ; if ( len >= 0 ) { return len ; } if ( allowReadingStringAsBinary ) { len = tryReadStringHeader ( b ) ; if ( len >= 0 ) { return len ; } } throw unexpe...
Reads header of a binary .
28,723
public MessageBuffer readPayloadAsReference ( int length ) throws IOException { int bufferRemaining = buffer . size ( ) - position ; if ( bufferRemaining >= length ) { MessageBuffer slice = buffer . slice ( position , length ) ; position += length ; return slice ; } MessageBuffer dst = MessageBuffer . allocate ( length...
Reads payload bytes of binary extension or raw string types as a reference to internal buffer .
28,724
public MessageBuffer reset ( MessageBuffer buf ) { MessageBuffer old = this . buffer ; this . buffer = buf ; if ( buf == null ) { isEmpty = true ; } else { isEmpty = false ; } return old ; }
Reset buffer . This method returns the old buffer .
28,725
public ModbusRequest buildDiagnostics ( DiagnosticsSubFunctionCode subFunctionCode , int serverAddress , int data ) throws ModbusNumberException { DiagnosticsRequest request = new DiagnosticsRequest ( ) ; request . setServerAddress ( serverAddress ) ; request . setSubFunctionCode ( subFunctionCode ) ; request . setSubF...
The function uses a sub - function code field in the query to define the type of test to be performed . The server echoes both the function code and sub - function code in a normal response . Some of the diagnostics cause data to be returned from the remote device in the data field of a normal response .
28,726
synchronized public ModbusResponse processRequest ( ModbusRequest request ) throws ModbusProtocolException , ModbusIOException { try { sendRequest ( request ) ; if ( request . getServerAddress ( ) != Modbus . BROADCAST_ID ) { do { try { ModbusResponse msg = ( ModbusResponse ) readResponse ( request ) ; request . valida...
this function allows you to process your own ModbusRequest . Each request class has a compliant response class for instance ReadHoldingRegistersRequest and ReadHoldingRegistersResponse . If you process an instance of ReadHoldingRegistersRequest this function exactly either returns a ReadHoldingRegistersResponse instanc...
28,727
public void setResponseTimeout ( int timeout ) { try { getConnection ( ) . setReadTimeout ( timeout ) ; } catch ( Exception e ) { Modbus . log ( ) . warning ( e . getLocalizedMessage ( ) ) ; } }
ModbusMaster will block for only this amount of time . If the timeout expires a ModbusTransportException is raised though the ModbusMaster is still valid .
28,728
final public int [ ] readHoldingRegisters ( int serverAddress , int startAddress , int quantity ) throws ModbusProtocolException , ModbusNumberException , ModbusIOException { ModbusRequest request = ModbusRequestBuilder . getInstance ( ) . buildReadHoldingRegisters ( serverAddress , startAddress , quantity ) ; ReadHold...
This function code is used to read the contents of a contiguous block of holding registers in a remote device . The Request PDU specifies the starting register address and the number of registers . In the PDU Registers are addressed starting at zero . Therefore registers numbered 1 - 16 are addressed as 0 - 15 .
28,729
final public int [ ] readInputRegisters ( int serverAddress , int startAddress , int quantity ) throws ModbusProtocolException , ModbusNumberException , ModbusIOException { ModbusRequest request = ModbusRequestBuilder . getInstance ( ) . buildReadInputRegisters ( serverAddress , startAddress , quantity ) ; ReadHoldingR...
This function code is used to read from 1 to 125 contiguous input registers in a remote device . The Request PDU specifies the starting register address and the number of registers . In the PDU Registers are addressed starting at zero . Therefore input registers numbered 1 - 16 are addressed as 0 - 15 .
28,730
final synchronized public boolean [ ] readCoils ( int serverAddress , int startAddress , int quantity ) throws ModbusProtocolException , ModbusNumberException , ModbusIOException { ModbusRequest request = ModbusRequestBuilder . getInstance ( ) . buildReadCoils ( serverAddress , startAddress , quantity ) ; ReadCoilsResp...
This function code is used to read from 1 to 2000 contiguous status of coils in a remote device . The Request PDU specifies the starting address i . e . the address of the first coil specified and the number of coils . In the PDU Coils are addressed starting at zero . Therefore coils numbered 1 - 16 are addressed as 0 ...
28,731
final public boolean [ ] readDiscreteInputs ( int serverAddress , int startAddress , int quantity ) throws ModbusProtocolException , ModbusNumberException , ModbusIOException { ModbusRequest request = ModbusRequestBuilder . getInstance ( ) . buildReadDiscreteInputs ( serverAddress , startAddress , quantity ) ; ReadDisc...
This function code is used to read from 1 to 2000 contiguous status of discrete inputs in a remote device . The Request PDU specifies the starting address i . e . the address of the first input specified and the number of inputs . In the PDU Discrete Inputs are addressed starting at zero . Therefore Discrete inputs num...
28,732
final public void writeSingleRegister ( int serverAddress , int startAddress , int register ) throws ModbusProtocolException , ModbusNumberException , ModbusIOException { processRequest ( ModbusRequestBuilder . getInstance ( ) . buildWriteSingleRegister ( serverAddress , startAddress , register ) ) ; }
This function code is used to write a single holding register in a remote device . The Request PDU specifies the address of the register to be written . Registers are addressed starting at zero . Therefore register numbered 1 is addressed as 0 .
28,733
final public int [ ] readWriteMultipleRegisters ( int serverAddress , int readAddress , int readQuantity , int writeAddress , int [ ] registers ) throws ModbusProtocolException , ModbusNumberException , ModbusIOException { ModbusRequest request = ModbusRequestBuilder . getInstance ( ) . buildReadWriteMultipleRegisters ...
This function code performs a combination of one read operation and one write operation in a single MODBUS transaction . The write operation is performed before the read . Holding registers are addressed starting at zero . Therefore holding registers 1 - 16 are addressed in the PDU as 0 - 15 . The request specifies the...
28,734
final public ModbusFileRecord [ ] readFileRecord ( int serverAddress , ModbusFileRecord [ ] records ) throws ModbusProtocolException , ModbusNumberException , ModbusIOException { ModbusRequest request = ModbusRequestBuilder . getInstance ( ) . buildReadFileRecord ( serverAddress , records ) ; ReadFileRecordResponse res...
This function code is used to perform a file record read . A file is an organization of records . Each file contains 10000 records addressed 0000 to 9999 decimal or 0X0000 to 0X270F . For example record 12 is addressed as 12 . The function can read multiple groups of references .
28,735
final public void writeFileRecord ( int serverAddress , ModbusFileRecord record ) throws ModbusProtocolException , ModbusNumberException , ModbusIOException { processRequest ( ModbusRequestBuilder . getInstance ( ) . buildWriteFileRecord ( serverAddress , record ) ) ; }
This function code is used to perform a file record write . All Request Data Lengths are provided in terms of number of bytes and all Record Lengths are provided in terms of the number of 16 - bit words . A file is an organization of records . Each file contains 10000 records addressed 0000 to 9999 decimal or 0X0000 to...
28,736
static public void setLogLevel ( LogLevel level ) { logLevel = level ; log . setLevel ( level . value ( ) ) ; for ( Handler handler : log . getHandlers ( ) ) { handler . setLevel ( level . value ( ) ) ; } }
changes the log level for all loggers used
28,737
static public boolean checkServerAddress ( int serverAddress ) { switch ( serverAddress ) { case 0x00 : return true ; case 0xFF : return true ; default : return ! ( serverAddress < Modbus . MIN_SERVER_ADDRESS || serverAddress > Modbus . MAX_SERVER_ADDRESS ) ; } }
validates address of server
28,738
public int readShortBE ( ) throws IOException { int h = read ( ) ; int l = read ( ) ; if ( - 1 == h || - 1 == l ) return - 1 ; return DataUtils . toShort ( h , l ) ; }
read two bytes in Big Endian Byte Order
28,739
public int readShortLE ( ) throws IOException { int l = read ( ) ; int h = read ( ) ; if ( - 1 == h || - 1 == l ) return - 1 ; return DataUtils . toShort ( h , l ) ; }
read two bytes in Little Endian Byte Order
28,740
public Future < AuthenticationResult > acquireToken ( final String resource , final UserAssertion userAssertion , final ClientCredential credential , final AuthenticationCallback callback ) { this . validateOnBehalfOfRequestInput ( resource , userAssertion , credential , true ) ; final ClientAuthentication clientAuth =...
Acquires an access token from the authority on behalf of a user . It requires using a user token previously received .
28,741
public Future < AuthenticationResult > acquireToken ( final String resource , final UserAssertion userAssertion , final AsymmetricKeyCredential credential , final AuthenticationCallback callback ) { this . validateOnBehalfOfRequestInput ( resource , userAssertion , credential , true ) ; ClientAssertion clientAssertion ...
Acquires an access token from the authority on behalf of a user . It requires using a user token previously received . Uses certificate to authenticate client .
28,742
public Future < DeviceCode > acquireDeviceCode ( final String clientId , final String resource , final AuthenticationCallback < DeviceCode > callback ) { validateDeviceCodeRequestInput ( clientId , resource ) ; return service . submit ( new AcquireDeviceCodeCallable ( this , clientId , resource , callback ) ) ; }
Acquires a device code from the authority
28,743
public Future < AuthenticationResult > acquireTokenByDeviceCode ( final DeviceCode deviceCode , final AuthenticationCallback callback ) throws AuthenticationException { final ClientAuthentication clientAuth = new ClientAuthenticationPost ( ClientAuthenticationMethod . NONE , new ClientID ( deviceCode . getClientId ( ) ...
Acquires security token from the authority using an device code previously received .
28,744
public Future < AuthenticationResult > acquireTokenByRefreshToken ( final String refreshToken , final String clientId , final String resource , final AuthenticationCallback callback ) { final ClientAuthentication clientAuth = new ClientAuthenticationPost ( ClientAuthenticationMethod . NONE , new ClientID ( clientId ) )...
Acquires a security token from the authority using a Refresh Token previously received . This method is suitable for the daemon OAuth2 flow when a client secret is not possible .
28,745
public Map < String , List < String > > toParameters ( ) { final Map < String , List < String > > outParams = new LinkedHashMap < > ( ) ; outParams . put ( "resource" , Collections . singletonList ( resource ) ) ; outParams . put ( "grant_type" , Collections . singletonList ( GRANT_TYPE ) ) ; outParams . put ( "code" ,...
Converts the device code grant to a map of HTTP paramters .
28,746
public static JSONObject processBadRespStr ( int responseCode , String responseMsg ) throws JSONException { JSONObject response = new JSONObject ( ) ; response . put ( "responseCode" , responseCode ) ; if ( responseMsg . equalsIgnoreCase ( "" ) ) { response . put ( "responseMsg" , "" ) ; } else { JSONObject errorObject...
for good response
28,747
static ClientAssertion buildJwt ( final AsymmetricKeyCredential credential , final String jwtAudience ) throws AuthenticationException { if ( credential == null ) { throw new IllegalArgumentException ( "credential is null" ) ; } final long time = System . currentTimeMillis ( ) ; final JWTClaimsSet claimsSet = new JWTCl...
Builds JWT object .
28,748
public static JSONArray fetchDirectoryObjectJSONArray ( JSONObject jsonObject ) throws Exception { JSONArray jsonArray = new JSONArray ( ) ; jsonArray = jsonObject . optJSONObject ( "responseMsg" ) . optJSONArray ( "value" ) ; return jsonArray ; }
This method parses an JSON Array out of a collection of JSON Objects within a string .
28,749
public static JSONObject fetchDirectoryObjectJSONObject ( JSONObject jsonObject ) throws Exception { JSONObject jObj = new JSONObject ( ) ; jObj = jsonObject . optJSONObject ( "responseMsg" ) ; return jObj ; }
This method parses an JSON Object out of a collection of JSON Objects within a string
28,750
public static String fetchNextSkiptoken ( JSONObject jsonObject ) throws Exception { String skipToken = "" ; skipToken = jsonObject . optJSONObject ( "responseMsg" ) . optString ( "odata.nextLink" ) ; if ( ! skipToken . equalsIgnoreCase ( "" ) ) { int index = skipToken . indexOf ( "$skiptoken=" ) + ( new String ( "$ski...
This method parses the skip token from a json formatted string .
28,751
public static String createJSONString ( HttpServletRequest request , String controller ) throws Exception { JSONObject obj = new JSONObject ( ) ; try { Field [ ] allFields = Class . forName ( "com.microsoft.windowsazure.activedirectory.sdk.graph.models." + controller ) . getDeclaredFields ( ) ; String [ ] allFieldStr =...
This method would create a string consisting of a JSON document with all the necessary elements set from the HttpServletRequest request .
28,752
public static < T > void convertJSONObjectToDirectoryObject ( JSONObject jsonObject , T destObject ) throws Exception { Field [ ] fieldList = destObject . getClass ( ) . getDeclaredFields ( ) ; for ( int i = 0 ; i < fieldList . length ; i ++ ) { if ( fieldList [ i ] . getType ( ) . equals ( String . class ) ) { destObj...
This is a generic method that copies the simple attribute values from an argument jsonObject to an argument generic object .
28,753
public String getPublicCertificateHash ( ) throws CertificateEncodingException , NoSuchAlgorithmException { return Base64 . encodeBase64String ( AsymmetricKeyCredential . getHash ( this . publicCertificate . getEncoded ( ) ) ) ; }
Base64 encoded hash of the the public certificate .
28,754
public boolean isDeviceCodeError ( ) { ErrorObject errorObject = getErrorObject ( ) ; if ( errorObject == null ) { return false ; } String code = errorObject . getCode ( ) ; if ( code == null ) { return false ; } switch ( code ) { case "authorization_pending" : case "slow_down" : case "access_denied" : case "code_expir...
Checks if is a device code error .
28,755
private StateData validateState ( HttpSession session , String state ) throws Exception { if ( StringUtils . isNotEmpty ( state ) ) { StateData stateDataInSession = removeStateFromSession ( session , state ) ; if ( stateDataInSession != null ) { return stateDataInSession ; } } throw new Exception ( FAILED_TO_VALIDATE_M...
make sure that state is stored in the session delete it from session - should be used only once
28,756
public String getLdapEncoded ( ) { if ( components . size ( ) == 0 ) { throw new IndexOutOfBoundsException ( "No components in Rdn." ) ; } StringBuffer sb = new StringBuffer ( DEFAULT_BUFFER_SIZE ) ; for ( Iterator iter = components . values ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { LdapRdnComponent component = ( L...
Get a properly rfc2253 - encoded String representation of this LdapRdn .
28,757
public String encodeUrl ( ) { StringBuffer sb = new StringBuffer ( DEFAULT_BUFFER_SIZE ) ; for ( Iterator iter = components . values ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { LdapRdnComponent component = ( LdapRdnComponent ) iter . next ( ) ; sb . append ( component . encodeUrl ( ) ) ; if ( iter . hasNext ( ) ) { s...
Get a String representation of this LdapRdn for use in urls .
28,758
public int compareTo ( Object obj ) { LdapRdn that = ( LdapRdn ) obj ; if ( this . components . size ( ) != that . components . size ( ) ) { return this . components . size ( ) - that . components . size ( ) ; } Set < Map . Entry < String , LdapRdnComponent > > theseEntries = this . components . entrySet ( ) ; for ( Ma...
Compare this LdapRdn to another object .
28,759
public LdapRdn immutableLdapRdn ( ) { Map < String , LdapRdnComponent > mapWithImmutableRdns = new LinkedHashMap < String , LdapRdnComponent > ( components . size ( ) ) ; for ( Iterator iterator = components . values ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { LdapRdnComponent rdnComponent = ( LdapRdnComponent ) ...
Create an immutable copy of this instance . It will not be possible to add or remove components or modify the keys and values of these components .
28,760
void doCloseConnection ( DirContext context , ContextSource contextSource ) throws javax . naming . NamingException { DirContextHolder transactionContextHolder = ( DirContextHolder ) TransactionSynchronizationManager . getResource ( contextSource ) ; if ( transactionContextHolder == null || transactionContextHolder . g...
Close the supplied context but only if it is not associated with the current transaction .
28,761
protected String encodeLdap ( ) { StringBuffer buff = new StringBuffer ( key . length ( ) + value . length ( ) * 2 ) ; buff . append ( key ) ; buff . append ( '=' ) ; buff . append ( LdapEncoder . nameEncode ( value ) ) ; return buff . toString ( ) ; }
Encode key and value to ldap .
28,762
public String encodeUrl ( ) { try { URI valueUri = new URI ( null , null , value , null ) ; return key + "=" + valueUri . toString ( ) ; } catch ( URISyntaxException e ) { return key + "=" + "value" ; } }
Get a String representation of this instance for use in URLs .
28,763
public int compareTo ( Object obj ) { LdapRdnComponent that = ( LdapRdnComponent ) obj ; int keyCompare = this . key . toLowerCase ( ) . compareTo ( that . key . toLowerCase ( ) ) ; if ( keyCompare == 0 ) { return this . value . toLowerCase ( ) . compareTo ( that . value . toLowerCase ( ) ) ; } else { return keyCompare...
Compare this instance to the supplied object .
28,764
public static void collectAttributeValues ( Attributes attributes , String name , Collection < Object > collection ) { collectAttributeValues ( attributes , name , collection , Object . class ) ; }
Collect all the values of a the specified attribute from the supplied Attributes .
28,765
public static < T > void collectAttributeValues ( Attributes attributes , String name , Collection < T > collection , Class < T > clazz ) { Assert . notNull ( attributes , "Attributes must not be null" ) ; Assert . hasText ( name , "Name must not be empty" ) ; Assert . notNull ( collection , "Collection must not be nul...
Collect all the values of a the specified attribute from the supplied Attributes as the specified class .
28,766
public static void iterateAttributeValues ( Attribute attribute , AttributeValueCallbackHandler callbackHandler ) { Assert . notNull ( attribute , "Attribute must not be null" ) ; Assert . notNull ( callbackHandler , "callbackHandler must not be null" ) ; if ( attribute instanceof Iterable ) { int i = 0 ; for ( Object ...
Iterate through all the values of the specified Attribute calling back to the specified callbackHandler .
28,767
public static LdapName newLdapName ( String distinguishedName ) { Assert . notNull ( distinguishedName , "distinguishedName must not be null" ) ; try { return new LdapName ( distinguishedName ) ; } catch ( InvalidNameException e ) { throw convertLdapException ( e ) ; } }
Construct a new LdapName instance from the supplied distinguished name string .
28,768
public static Rdn getRdn ( Name name , String key ) { Assert . notNull ( name , "name must not be null" ) ; Assert . hasText ( key , "key must not be blank" ) ; LdapName ldapName = returnOrConstructLdapNameFromName ( name ) ; List < Rdn > rdns = ldapName . getRdns ( ) ; for ( Rdn rdn : rdns ) { NamingEnumeration < Stri...
Find the Rdn with the requested key in the supplied Name .
28,769
public static Object getValue ( Name name , String key ) { NamingEnumeration < ? extends Attribute > allAttributes = getRdn ( name , key ) . toAttributes ( ) . getAll ( ) ; while ( allAttributes . hasMoreElements ( ) ) { Attribute oneAttribute = allAttributes . nextElement ( ) ; if ( key . equalsIgnoreCase ( oneAttribu...
Get the value of the Rdn with the requested key in the supplied Name .
28,770
public static Object getValue ( Name name , int index ) { Assert . notNull ( name , "name must not be null" ) ; LdapName ldapName = returnOrConstructLdapNameFromName ( name ) ; Rdn rdn = ldapName . getRdn ( index ) ; if ( rdn . size ( ) > 1 ) { LOGGER . warn ( "Rdn at position " + index + " of dn '" + name + "' is mult...
Get the value of the Rdn at the requested index in the supplied Name .
28,771
public static String getStringValue ( Name name , String key ) { return ( String ) getValue ( name , key ) ; }
Get the value of the Rdn with the requested key in the supplied Name as a String .
28,772
static byte [ ] numberToBytes ( String number , int length , boolean bigEndian ) { BigInteger bi = new BigInteger ( number ) ; byte [ ] bytes = bi . toByteArray ( ) ; int remaining = length - bytes . length ; if ( remaining < 0 ) { bytes = Arrays . copyOfRange ( bytes , - remaining , bytes . length ) ; } else { byte [ ...
Converts the given number to a binary representation of the specified length and endian - ness .
28,773
static String toHexString ( final byte b ) { String hexString = Integer . toHexString ( b & 0xFF ) ; if ( hexString . length ( ) % 2 != 0 ) { hexString = "0" + hexString ; } return hexString ; }
Converts a byte into its hexadecimal representation padding with a leading zero to get an even number of characters .
28,774
static String toHexString ( final byte [ ] b ) { StringBuffer sb = new StringBuffer ( "{" ) ; for ( int i = 0 ; i < b . length ; i ++ ) { sb . append ( toHexString ( b [ i ] ) ) ; if ( i < b . length - 1 ) { sb . append ( "," ) ; } } sb . append ( "}" ) ; return sb . toString ( ) ; }
Converts a byte array into its hexadecimal representation padding each with a leading zero to get an even number of characters .
28,775
public Context getInnermostDelegateContext ( ) { final Context delegateContext = this . getDelegateContext ( ) ; if ( delegateContext instanceof DelegatingContext ) { return ( ( DelegatingContext ) delegateContext ) . getInnermostDelegateContext ( ) ; } return delegateContext ; }
Recursivley inspect delegates until a non - delegating context is found .
28,776
public boolean isSatisfiedBy ( LdapAttributes record ) throws NamingException { if ( record != null ) { LdapName dn = record . getName ( ) ; if ( dn != null ) { if ( record . get ( "objectClass" ) != null ) { Rdn rdn = dn . getRdn ( dn . size ( ) - 1 ) ; if ( record . get ( rdn . getType ( ) ) != null ) { Object object...
Determines if the policy is satisfied by the supplied LdapAttributes object .
28,777
public void destroy ( ) { try { ctx . close ( ) ; } catch ( javax . naming . NamingException e ) { LOG . warn ( "Error when closing" , e ) ; } }
Destroy method that allows the target DirContext to be cleaned up when the SingleContextSource is not going to be used any more .
28,778
protected final void parse ( String path ) { DnParser parser = DefaultDnParserFactory . createDnParser ( unmangleCompositeName ( path ) ) ; DistinguishedName dn ; try { dn = parser . dn ( ) ; } catch ( ParseException e ) { throw new BadLdapGrammarException ( "Failed to parse DN" , e ) ; } catch ( TokenMgrError e ) { th...
Parse the supplied String and make this instance represent the corresponding distinguished name .
28,779
public String toUrl ( ) { StringBuffer buffer = new StringBuffer ( DEFAULT_BUFFER_SIZE ) ; for ( int i = names . size ( ) - 1 ; i >= 0 ; i -- ) { LdapRdn n = ( LdapRdn ) names . get ( i ) ; buffer . append ( n . encodeUrl ( ) ) ; if ( i > 0 ) { buffer . append ( "," ) ; } } return buffer . toString ( ) ; }
Builds a complete LDAP path ldap and url encoded . Separates only with .
28,780
public int compareTo ( Object obj ) { DistinguishedName that = ( DistinguishedName ) obj ; ListComparator comparator = new ListComparator ( ) ; return comparator . compare ( this . names , that . names ) ; }
Compare this instance to another object . Note that the comparison is done in order of significance so the most significant Rdn is compared first then the second and so on .
28,781
public DistinguishedName immutableDistinguishedName ( ) { List listWithImmutableRdns = new ArrayList ( names . size ( ) ) ; for ( Iterator iterator = names . iterator ( ) ; iterator . hasNext ( ) ; ) { LdapRdn rdn = ( LdapRdn ) iterator . next ( ) ; listWithImmutableRdns . add ( rdn . immutableLdapRdn ( ) ) ; } return ...
Return an immutable copy of this instance . It will not be possible to add or remove any Rdns to or from the returned instance and the respective Rdns will also be immutable in turn .
28,782
private boolean processAttributeAnnotation ( Field field ) { syntax = "" ; isBinary = false ; name = new CaseIgnoreString ( field . getName ( ) ) ; boolean foundAnnotation = false ; Attribute attribute = field . getAnnotation ( Attribute . class ) ; List < String > attrList = new ArrayList < String > ( ) ; if ( attribu...
syntax isBinary isObjectClass and name .
28,783
private static Map < String , String > readSyntaxMap ( File syntaxMapFile ) throws IOException { Map < String , String > result = new HashMap < String , String > ( ) ; BufferedReader reader = null ; try { reader = new BufferedReader ( new FileReader ( syntaxMapFile ) ) ; String line ; while ( ( line = reader . readLine...
Read mappings of LDAP syntaxes to Java classes .
28,784
private static ObjectSchema readSchema ( String url , String user , String pass , SyntaxToJavaClass syntaxToJavaClass , Set < String > binarySet , Set < String > objectClasses ) throws NamingException , ClassNotFoundException { Hashtable < String , String > env = new Hashtable < String , String > ( ) ; env . put ( Cont...
Bind to the directory read and process the schema
28,785
private static void createCode ( String packageName , String className , ObjectSchema schema , Set < SyntaxToJavaClass . ClassInfo > imports , File outputFile ) throws IOException , TemplateException { Configuration freeMarkerConfiguration = new Configuration ( ) ; freeMarkerConfiguration . setClassForTemplateLoading (...
Create the Java
28,786
private static File makeOutputFile ( String outputDir , String packageName , String className ) throws IOException { Pattern pattern = Pattern . compile ( "\\." ) ; Matcher matcher = pattern . matcher ( packageName ) ; String sepToUse = File . separator ; if ( sepToUse . equals ( "\\" ) ) { sepToUse = "\\\\" ; } String...
Create the output file for the generated code along with all intervening directories
28,787
public ObjectSchema getObjectSchema ( Set < String > objectClasses ) throws NamingException , ClassNotFoundException { ObjectSchema result = new ObjectSchema ( ) ; createObjectClass ( objectClasses , schemaContext , result ) ; return result ; }
Get the object schema for the given object classes
28,788
private void createObjectClass ( Set < String > objectClasses , DirContext schemaContext , ObjectSchema schema ) throws NamingException , ClassNotFoundException { Set < String > supList = new HashSet < String > ( ) ; for ( String objectClass : objectClasses ) { schema . addObjectClass ( objectClass ) ; Attributes attri...
Recursively extract schema from the directory and process it
28,789
private void closeContext ( DirContext ctx ) { if ( ctx != null ) { try { ctx . close ( ) ; } catch ( Exception e ) { LOG . debug ( "Exception closing context" , e ) ; } } }
Close the context and swallow any exceptions .
28,790
protected DirContext createContext ( Hashtable < String , Object > environment ) { DirContext ctx = null ; try { ctx = getDirContextInstance ( environment ) ; if ( LOG . isInfoEnabled ( ) ) { Hashtable < ? , ? > ctxEnv = ctx . getEnvironment ( ) ; String ldapUrl = ( String ) ctxEnv . get ( Context . PROVIDER_URL ) ; LO...
Create a DirContext using the supplied environment .
28,791
public void afterPropertiesSet ( ) { if ( ObjectUtils . isEmpty ( urls ) ) { throw new IllegalArgumentException ( "At least one server url must be set" ) ; } if ( authenticationSource == null ) { LOG . debug ( "AuthenticationSource not set - " + "using default implementation" ) ; if ( ! StringUtils . hasText ( userDn )...
Checks that all necessary data is set and that there is no compatibility issues after which the instance is initialized . Note that you need to call this method explicitly after setting all desired properties if using the class outside of a Spring Context .
28,792
public void setBaseEnvironmentProperties ( Map < String , Object > baseEnvironmentProperties ) { this . baseEnv = new Hashtable < String , Object > ( baseEnvironmentProperties ) ; }
If any custom environment properties are needed these can be set using this method .
28,793
public LdapNameBuilder add ( Name name ) { Assert . notNull ( name , "name must not be null" ) ; try { ldapName . addAll ( ldapName . size ( ) , name ) ; return this ; } catch ( InvalidNameException e ) { throw new org . springframework . ldap . InvalidNameException ( e ) ; } }
Append the specified name to the currently built LdapName .
28,794
public LdapNameBuilder add ( String name ) { Assert . notNull ( name , "name must not be null" ) ; return add ( LdapUtils . newLdapName ( name ) ) ; }
Append the LdapName represented by the specified string to the currently built LdapName .
28,795
protected void deleteRecursively ( DirContext ctx , Name name ) { NamingEnumeration enumeration = null ; try { enumeration = ctx . listBindings ( name ) ; while ( enumeration . hasMore ( ) ) { Binding binding = ( Binding ) enumeration . next ( ) ; LdapName childName = LdapUtils . newLdapName ( binding . getName ( ) ) ;...
Delete all subcontexts including the current one recursively .
28,796
private void assureReturnObjFlagSet ( SearchControls controls ) { Assert . notNull ( controls , "controls must not be null" ) ; if ( ! controls . getReturningObjFlag ( ) ) { LOG . debug ( "The returnObjFlag of supplied SearchControls is not set" + " but a ContextMapper is used - setting flag to true" ) ; controls . set...
Make sure the returnObjFlag is set in the supplied SearchControls . Set it and log if it s not set .
28,797
public DirContext getInnermostDelegateDirContext ( ) { final DirContext delegateDirContext = this . getDelegateDirContext ( ) ; if ( delegateDirContext instanceof DelegatingDirContext ) { return ( ( DelegatingDirContext ) delegateDirContext ) . getInnermostDelegateDirContext ( ) ; } return delegateDirContext ; }
Recursivley inspect delegates until a non - delegating dir context is found .
28,798
public static Name getFirstArgumentAsName ( Object [ ] args ) { Assert . notEmpty ( args ) ; Object firstArg = args [ 0 ] ; return getArgumentAsName ( firstArg ) ; }
Get the first parameter in the argument list as a Name .
28,799
public static Name getArgumentAsName ( Object arg ) { if ( arg instanceof String ) { return LdapUtils . newLdapName ( ( String ) arg ) ; } else if ( arg instanceof Name ) { return ( Name ) arg ; } else { throw new IllegalArgumentException ( "First argument needs to be a Name or a String representation thereof" ) ; } }
Get the argument as a Name .