idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
10,400
public boolean contains ( int ele ) { int idx ; idx = ele >> SHIFT ; if ( idx >= data . length ) { return false ; } return ( data [ idx ] & ( 1 << ele ) ) != 0 ; }
Lookup a specific element .
10,401
public void add ( int ele ) { int idx ; idx = ele >> SHIFT ; if ( idx >= data . length ) { resize ( idx + 1 + GROW ) ; } data [ ele >> SHIFT ] |= ( 1 << ele ) ; }
Add an element .
10,402
public void addRange ( int first , int last ) { int ele ; for ( ele = first ; ele <= last ; ele ++ ) { add ( ele ) ; } }
Add all elements in the indicated range . Nothing is set for first &gt ; last .
10,403
public void remove ( int ele ) { int idx ; idx = ele >> SHIFT ; if ( idx < data . length ) { data [ idx ] &= ~ ( 1 << ele ) ; } }
Remove an element from the set .
10,404
public void removeRange ( int first , int last ) { int ele ; for ( ele = first ; ele <= last ; ele ++ ) { remove ( ele ) ; } }
Remove all elements in the indicated range .
10,405
public boolean containsAll ( IntBitSet set ) { int i , end ; if ( data . length < set . data . length ) { end = data . length ; for ( i = end ; i < set . data . length ; i ++ ) { if ( set . data [ i ] != 0 ) { return false ; } } } else { end = set . data . length ; } for ( i = 0 ; i < end ; i ++ ) { if ( ( set . data [ i ] & ~ data [ i ] ) != 0 ) { return false ; } } return true ; }
The subset test .
10,406
public void retainAll ( IntBitSet set ) { int i ; if ( set . data . length > data . length ) { resize ( set . data . length ) ; } for ( i = 0 ; i < set . data . length ; i ++ ) { data [ i ] &= set . data [ i ] ; } for ( ; i < data . length ; i ++ ) { data [ i ] = 0 ; } }
Computes the intersection . The result is stored in this set .
10,407
public void removeAll ( IntBitSet set ) { int i , end ; end = ( set . data . length < data . length ) ? set . data . length : data . length ; for ( i = 0 ; i < end ; i ++ ) { data [ i ] &= ~ set . data [ i ] ; } }
Computes the set difference . The result is stored in this set .
10,408
public void addAll ( IntBitSet set ) { int i ; if ( set . data . length > data . length ) { resize ( set . data . length ) ; } for ( i = 0 ; i < set . data . length ; i ++ ) { data [ i ] |= set . data [ i ] ; } }
Computes the union . The result is stored in this set .
10,409
public int size ( ) { int ele , count ; count = 0 ; for ( ele = first ( ) ; ele != - 1 ; ele = next ( ele ) ) { count ++ ; } return count ; }
Counts the elements .
10,410
public int [ ] toArray ( ) { int i , ele ; int [ ] result ; result = new int [ size ( ) ] ; for ( ele = first ( ) , i = 0 ; ele != - 1 ; ele = next ( ele ) , i ++ ) { result [ i ] = ele ; } return result ; }
Creates an array with all elements of the set .
10,411
private void resize ( int s ) { int [ ] n ; int count ; n = new int [ s ] ; count = ( s < data . length ) ? s : data . length ; System . arraycopy ( data , 0 , n , 0 , count ) ; data = n ; }
Changes data to have data . length > = s components . All data components that fit into the new size are preserved .
10,412
public final synchronized void start ( ) throws IOException { LaunchingMessageKind . IJMX0001 . format ( this . host , this . port ) ; this . mbs = ManagementFactory . getPlatformMBeanServer ( ) ; final String oldRmiServerName = System . getProperty ( "java.rmi.server.hostname" ) ; System . setProperty ( "java.rmi.server.hostname" , this . host ) ; register = LocateRegistry . createRegistry ( this . port ) ; if ( oldRmiServerName == null ) { final Properties props = System . getProperties ( ) ; for ( Object key : props . keySet ( ) ) { if ( key . equals ( "java.rmi.server.hostname" ) ) { props . remove ( key ) ; break ; } } } else { System . setProperty ( "java.rmi.server.hostname" , oldRmiServerName ) ; } final String serviceURL = String . format ( serverUrlFormat , this . host , this . host , this . port ) ; LaunchingMessageKind . IJMX0002 . format ( serviceURL ) ; final JMXServiceURL url = new JMXServiceURL ( serviceURL ) ; this . jmxConnectorServer = JMXConnectorServerFactory . newJMXConnectorServer ( url , null , mbs ) ; this . jmxConnectorServer . start ( ) ; registerMBeans ( ) ; }
Start the JMX Server
10,413
public final synchronized void stop ( ) { LaunchingMessageKind . IJMX0003 . format ( ) ; unRegisterMBeans ( ) ; try { if ( this . jmxConnectorServer != null ) { this . jmxConnectorServer . stop ( ) ; } } catch ( IOException e1 ) { } try { UnicastRemoteObject . unexportObject ( register , true ) ; } catch ( NoSuchObjectException e ) { } }
Stop the JMX Server
10,414
public static Object getClassForName ( String className ) { Object object = null ; try { Class classDefinition = Class . forName ( className ) ; object = classDefinition . newInstance ( ) ; } catch ( ClassNotFoundException e ) { if ( log . isEnabledFor ( Level . ERROR ) ) { log . error ( "ClassNotFoundException" , e ) ; } } catch ( InstantiationException e ) { if ( log . isEnabledFor ( Level . ERROR ) ) { log . error ( "InstantiationException " + e . getMessage ( ) , e ) ; } } catch ( IllegalAccessException e ) { if ( log . isEnabledFor ( Level . ERROR ) ) { log . error ( "IllegalAccessException" , e ) ; } } return object ; }
Returns object instance from the string representing its class name .
10,415
@ SuppressWarnings ( "unchecked" ) public static Object getClassInstance ( String className , Class [ ] attrTypes , Object [ ] attrValues ) throws DISIException { Constructor constr ; try { Class cl = Class . forName ( className ) ; constr = cl . getConstructor ( attrTypes ) ; } catch ( ClassNotFoundException e ) { final String errMessage = e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) ; log . error ( errMessage , e ) ; throw new DISIException ( errMessage , e ) ; } catch ( NoSuchMethodException e ) { final String errMessage = e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) ; log . error ( errMessage , e ) ; throw new DISIException ( errMessage , e ) ; } Object classInst ; try { classInst = constr . newInstance ( attrValues ) ; } catch ( InstantiationException e ) { final String errMessage = e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) ; log . error ( errMessage , e ) ; throw new DISIException ( errMessage , e ) ; } catch ( IllegalAccessException e ) { final String errMessage = e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) ; log . error ( errMessage , e ) ; throw new DISIException ( errMessage , e ) ; } catch ( InvocationTargetException e ) { final String errMessage = e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) ; log . error ( errMessage , e ) ; throw new DISIException ( errMessage , e ) ; } return classInst ; }
Creates an instance of the class whose name is passed as the parameter .
10,416
public Set < String > getSupportedInputMediaTypes ( ) { ImmutableSet . Builder < String > result = ImmutableSet . builder ( ) ; result . addAll ( MediaType . NATIVE_MEDIATYPE_SYNTAX_MAP . keySet ( ) ) ; result . addAll ( this . serviceTransformationEngine . getSupportedMediaTypes ( ) ) ; return result . build ( ) ; }
Obtains the list of supported media types the engine can import
10,417
public boolean canImport ( String mediaType ) { return ( MediaType . NATIVE_MEDIATYPE_SYNTAX_MAP . containsKey ( mediaType ) || this . serviceTransformationEngine . canTransform ( mediaType ) ) ; }
Checks if the given media type can be imported
10,418
public FilenameFilter getFilenameFilter ( String mediaType ) { if ( mediaType == null ) { return null ; } if ( MediaType . NATIVE_MEDIATYPE_SYNTAX_MAP . containsKey ( mediaType ) ) { return new FilenameFilterBySyntax ( MediaType . NATIVE_MEDIATYPE_SYNTAX_MAP . get ( mediaType ) ) ; } else if ( this . getServiceTransformationEngine ( ) . canTransform ( mediaType ) ) { return this . getServiceTransformationEngine ( ) . getFilenameFilter ( mediaType ) ; } return null ; }
Gets the corresponding filename filter to a given media type by checking both native formats and those supported through transformation
10,419
public List < URI > importServices ( InputStream servicesContentStream , String mediaType ) throws SalException { boolean isNativeFormat = MediaType . NATIVE_MEDIATYPE_SYNTAX_MAP . containsKey ( mediaType ) ; if ( ! isNativeFormat && ! this . serviceTransformationEngine . canTransform ( mediaType ) ) { log . error ( "The media type {} is not natively supported and has no suitable transformer." , mediaType ) ; throw new ServiceException ( "Unable to import service. Format unsupported." ) ; } String fileExtension = findFileExtensionToUse ( mediaType , isNativeFormat ) ; List < Service > services = null ; List < URI > importedServices = new ArrayList < URI > ( ) ; URI sourceDocUri = null ; InputStream localStream = null ; try { sourceDocUri = this . docManager . createDocument ( servicesContentStream , fileExtension , mediaType ) ; if ( sourceDocUri == null ) { throw new ServiceException ( "Unable to save service document. Operation aborted." ) ; } localStream = this . docManager . getDocument ( sourceDocUri ) ; services = getServicesFromStream ( mediaType , isNativeFormat , localStream ) ; URI serviceUri = null ; if ( services != null && ! services . isEmpty ( ) ) { log . info ( "Importing {} services" , services . size ( ) ) ; for ( Service service : services ) { service . setSource ( sourceDocUri ) ; serviceUri = this . serviceManager . addService ( service ) ; if ( serviceUri != null ) { importedServices . add ( serviceUri ) ; } } } log . info ( "Source document imported: {}" , sourceDocUri . toASCIIString ( ) ) ; } finally { if ( ( services == null || ( services != null && services . size ( ) != importedServices . size ( ) ) ) && sourceDocUri != null ) { this . docManager . deleteDocument ( sourceDocUri ) ; for ( URI svcUri : importedServices ) { this . serviceManager . deleteService ( svcUri ) ; } log . warn ( "There were problems importing the service. Changes undone." ) ; } if ( localStream != null ) try { localStream . close ( ) ; } catch ( IOException e ) { log . error ( "Error closing the service content stream" , e ) ; } } return importedServices ; }
Imports a new service within iServe . The original document is stored in the server and the transformed version registered within iServe .
10,420
public boolean unregisterService ( URI serviceUri ) throws SalException { if ( serviceUri == null || ! UriUtil . isResourceLocalToServer ( serviceUri , this . getIserveUri ( ) ) ) { return false ; } if ( this . serviceManager . deleteService ( serviceUri ) ) { Set < URI > docs = this . serviceManager . listDocumentsForService ( serviceUri ) ; for ( URI doc : docs ) { this . docManager . deleteDocument ( doc ) ; } return true ; } return false ; }
Unregisters a service from the registry . Effectively this will delete the service description and remove any related documents on the server .
10,421
public void add ( final GeneratedMessage . GeneratedExtension < ? , ? > extension ) { if ( extension . getDescriptor ( ) . getJavaType ( ) == FieldDescriptor . JavaType . MESSAGE ) { if ( extension . getMessageDefaultInstance ( ) == null ) { throw new IllegalStateException ( "Registered message-type extension had null default instance: " + extension . getDescriptor ( ) . getFullName ( ) ) ; } add ( new ExtensionInfo ( extension . getDescriptor ( ) , extension . getMessageDefaultInstance ( ) ) ) ; } else { add ( new ExtensionInfo ( extension . getDescriptor ( ) , null ) ) ; } }
Add an extension from a generated file to the registry .
10,422
public void add ( final FieldDescriptor type ) { if ( type . getJavaType ( ) == FieldDescriptor . JavaType . MESSAGE ) { throw new IllegalArgumentException ( "ExtensionRegistry.add() must be provided a default instance when " + "adding an embedded message extension." ) ; } add ( new ExtensionInfo ( type , null ) ) ; }
Add a non - message - type extension to the registry by descriptor .
10,423
public void add ( final FieldDescriptor type , final Message defaultInstance ) { if ( type . getJavaType ( ) != FieldDescriptor . JavaType . MESSAGE ) { throw new IllegalArgumentException ( "ExtensionRegistry.add() provided a default instance for a " + "non-message extension." ) ; } add ( new ExtensionInfo ( type , defaultInstance ) ) ; }
Add a message - type extension to the registry by descriptor .
10,424
public String [ ] getMinors ( String major ) { prepareDetailedVersions ( ) ; if ( majors . containsKey ( major ) ) { return majors . get ( major ) . toArray ( new String [ ] { } ) ; } return null ; }
Returns all minor versions for the given major version or null if major version does not exist .
10,425
public String getRecentMinor ( String major ) { if ( major == null ) { return null ; } prepareDetailedVersions ( ) ; if ( majors . containsKey ( major ) && majors . get ( major ) . size ( ) > 0 ) { return majors . get ( major ) . get ( 0 ) ; } return null ; }
Returns the recent minor version for the given major version or null if neither major version or no minor version exists .
10,426
public Version getDetailedVersion ( String version ) { prepareDetailedVersions ( ) ; if ( detailedVersions . containsKey ( version ) ) { return detailedVersions . get ( version ) ; } return null ; }
Returns the detailed version for a given string version or null if the version doesn t exist in this version collection
10,427
@ SuppressWarnings ( "unchecked" ) public IType getMessageOrBuilder ( int index ) { if ( this . builders == null ) { return ( IType ) messages . get ( index ) ; } SingleFieldBuilder < MType , BType , IType > builder = builders . get ( index ) ; if ( builder == null ) { return ( IType ) messages . get ( index ) ; } else { return builder . getMessageOrBuilder ( ) ; } }
Gets the base class interface for the specified index . This may either be a builder or a message . It will return whatever is more efficient .
10,428
public RepeatedFieldBuilder < MType , BType , IType > setMessage ( int index , MType message ) { if ( message == null ) { throw new NullPointerException ( ) ; } ensureMutableMessageList ( ) ; messages . set ( index , message ) ; if ( builders != null ) { SingleFieldBuilder < MType , BType , IType > entry = builders . set ( index , null ) ; if ( entry != null ) { entry . dispose ( ) ; } } onChanged ( ) ; incrementModCounts ( ) ; return this ; }
Sets a message at the specified index replacing the existing item at that index .
10,429
public List < MType > build ( ) { isClean = true ; if ( ! isMessagesListMutable && builders == null ) { return messages ; } boolean allMessagesInSync = true ; if ( ! isMessagesListMutable ) { for ( int i = 0 ; i < messages . size ( ) ; i ++ ) { Message message = messages . get ( i ) ; SingleFieldBuilder < MType , BType , IType > builder = builders . get ( i ) ; if ( builder != null ) { if ( builder . build ( ) != message ) { allMessagesInSync = false ; break ; } } } if ( allMessagesInSync ) { return messages ; } } ensureMutableMessageList ( ) ; for ( int i = 0 ; i < messages . size ( ) ; i ++ ) { messages . set ( i , getMessage ( i , true ) ) ; } messages = Collections . unmodifiableList ( messages ) ; isMessagesListMutable = false ; return messages ; }
Builds the list of messages from the builder and returns them .
10,430
public Separator trim ( LineFormat . Trim trim ) { return new Separator ( separator , pattern , trim , skipEmpty , forNull , skipNull ) ; }
Trim elements before joining or after splitting
10,431
public Object getValue ( ) { Date d = Calendar . getInstance ( ) . getTime ( ) ; try { d = DEFAULT_DATE_FORMAT . parse ( ( ( JTextField ) editor ) . getText ( ) ) ; } catch ( ParseException ex ) { Logger . getLogger ( CalendarStringPropertyEditor . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } Calendar c = Calendar . getInstance ( ) ; c . setTime ( d ) ; return c ; }
Returns the Date of the Calendar .
10,432
public void setValue ( Object value ) { if ( value != null ) { Calendar c = ( Calendar ) value ; ( ( JTextField ) editor ) . setText ( DEFAULT_DATE_FORMAT . format ( c . getTime ( ) ) ) ; } }
Sets the Date of the Calendar .
10,433
public String getAsText ( ) { Calendar localDate = ( Calendar ) getValue ( ) ; String s = DEFAULT_DATE_FORMAT . format ( localDate . getTime ( ) ) ; LOGGER . log ( Level . WARNING , "getAsText(): {0}" , s ) ; return s ; }
Returns the Date formated with the locale and formatString set .
10,434
public static BooleanCliParam optional ( Identifier identifier , boolean defaultValue , boolean nullable ) { return new BooleanCliParam ( identifier , Opt . of ( MoreSuppliers . of ( defaultValue ) ) , nullable ) ; }
Construct an optional CLI boolean parameter with the given default value .
10,435
public FileNode locateClasspathEntry ( Class < ? > c ) { return locateEntry ( c , Reflect . resourceName ( c ) , false ) ; }
Returns the file or directory containing the specified class . Does not search modules
10,436
public FileNode locatePathEntry ( Class < ? > c ) { return locateEntry ( c , Reflect . resourceName ( c ) , true ) ; }
Returns the file or directory or module containing the specified class .
10,437
public long copyFileTo ( OutputStream dest , long skip ) throws FileNotFoundException , CopyFileToException { ChannelSftp sftp ; Progress monitor ; try { sftp = alloc ( ) ; monitor = new Progress ( ) ; try { sftp . get ( escape ( slashPath ) , dest , monitor , ChannelSftp . RESUME , skip ) ; } finally { free ( sftp ) ; } return Math . max ( 0 , monitor . sum - skip ) ; } catch ( SftpException e ) { if ( e . id == 2 || e . id == 4 ) { throw new FileNotFoundException ( this ) ; } throw new CopyFileToException ( this , e ) ; } catch ( JSchException e ) { throw new CopyFileToException ( this , e ) ; } }
This is the core function to read an ssh node . Does not close dest .
10,438
public void copyFileFrom ( InputStream src , boolean append ) throws CopyFileFromException { ChannelSftp sftp ; try { sftp = alloc ( ) ; try { sftp . put ( src , escape ( slashPath ) , append ? ChannelSftp . APPEND : ChannelSftp . OVERWRITE ) ; } finally { free ( sftp ) ; } } catch ( SftpException | JSchException e ) { throw new CopyFileFromException ( this , e ) ; } }
This is the core function to write an ssh node . Does not close src .
10,439
public void pushCommandLine ( String commandLine ) { history . add ( commandLine ) ; if ( history . size ( ) > maxHistory ) { history . remove ( 0 ) ; } resetCurrentIndex ( ) ; }
Adds a new command line to the history buffer . Resets the current history index .
10,440
public static String getDescription ( Change change ) { switch ( change . getType ( ) ) { case Change . TYPE_MASTER_VALUE_CHANGED : return "The master value has changed" ; case Change . TYPE_IMPORTED_STATUS_OLDER : return "The imported status is older than the database status" ; case Change . TYPE_IMPORTED_STATUS_NEWER : return "The imported status is newer than the database status" ; case Change . TYPE_LANGUAGE_ADDITION : return "The language \"" + change . getLanguage ( ) + "\" does not exist in the database" ; case Change . TYPE_MASTER_LANGUAGE_ADDITION : return "The master language \"" + change . getMasterLanguage ( ) + "\" does not exist in the database" ; case Change . TYPE_VALUE_CHANGED : if ( change . isConflicting ( ) ) { return "The value and the status are conflicting" ; } return "The value has changed" ; case Change . TYPE_VALUE_AND_STATUS_CHANGED : if ( change . isConflicting ( ) ) { return "The value and the status are conflicting" ; } return "The value and the status have changed" ; case Change . TYPE_KEY_ADDITION : return "The key does not exist in the database" ; default : return "Unknown change" ; } }
Gets a human readable description for a given change .
10,441
public boolean is ( String property , Type type ) { if ( super . has ( property ) ) { return get ( property ) . is ( type ) ; } return false ; }
Returns whether the property is instance of the given type .
10,442
public JsonArray getAsArray ( String property ) { if ( ! super . has ( property ) ) { super . set ( property , new JsonValue ( new JsonArray ( ) ) , false ) ; } return get ( property ) . getAsArray ( ) ; }
Returns the property value as array .
10,443
public JsonObject getAsObject ( String property ) { if ( ! super . has ( property ) ) { super . set ( property , new JsonValue ( new JsonObject ( ) ) , false ) ; } return get ( property ) . getAsObject ( ) ; }
Returns the property value as object .
10,444
public CpoOrderBy newOrderBy ( String attribute , boolean ascending ) throws CpoException { return new BindableCpoOrderBy ( attribute , ascending ) ; }
newOrderBy allows you to dynamically change the order of the objects in the resulting collection . This allows you to apply user input in determining the order of the collection
10,445
protected Session getReadSession ( ) throws CpoException { Session session ; try { if ( ! ( invalidReadSession ) ) { session = getReadDataSource ( ) . getSession ( ) ; } else { session = getWriteDataSource ( ) . getSession ( ) ; } } catch ( Exception e ) { invalidReadSession = true ; String msg = "getReadConnection(): failed" ; logger . error ( msg , e ) ; session = getWriteSession ( ) ; } return session ; }
getReadSession returns the read session for Cassandra
10,446
protected Session getWriteSession ( ) throws CpoException { Session session ; try { session = getWriteDataSource ( ) . getSession ( ) ; } catch ( Throwable t ) { String msg = "getWriteConnection(): failed" ; logger . error ( msg , t ) ; throw new CpoException ( msg , t ) ; } return session ; }
getWriteSession returns the write session for Cassandra
10,447
public List < CpoAttribute > getCpoAttributes ( String expression ) throws CpoException { List < CpoAttribute > attributes = new ArrayList < > ( ) ; if ( expression != null && ! expression . isEmpty ( ) ) { Session session ; ResultSet rs ; try { session = getWriteSession ( ) ; rs = session . execute ( expression ) ; ColumnDefinitions columnDefs = rs . getColumnDefinitions ( ) ; for ( int i = 0 ; i < columnDefs . size ( ) ; i ++ ) { CpoAttribute attribute = new CassandraCpoAttribute ( ) ; attribute . setDataName ( columnDefs . getName ( i ) ) ; DataTypeMapEntry < ? > dataTypeMapEntry = metaDescriptor . getDataTypeMapEntry ( columnDefs . getType ( i ) . getName ( ) . ordinal ( ) ) ; attribute . setDataType ( dataTypeMapEntry . getDataTypeName ( ) ) ; attribute . setDataTypeInt ( dataTypeMapEntry . getDataTypeInt ( ) ) ; attribute . setJavaType ( dataTypeMapEntry . getJavaClass ( ) . getName ( ) ) ; attribute . setJavaName ( dataTypeMapEntry . makeJavaName ( columnDefs . getName ( i ) ) ) ; attributes . add ( attribute ) ; } } catch ( Throwable t ) { logger . error ( ExceptionHelper . getLocalizedMessage ( t ) , t ) ; throw new CpoException ( "Error Generating Attributes" , t ) ; } } return attributes ; }
Get the cpo attributes for this expression
10,448
public static BeanInfo createBeanInfo ( Class < ? extends Object > c ) { BeanInfo bi = DefaultBeanInfoResolver . getBeanInfoHelper ( c ) ; if ( bi == null ) { bi = new ConfigBeanInfo ( c ) ; DefaultBeanInfoResolver . addBeanInfo ( c , bi ) ; } return bi ; }
Get the bean information of a type .
10,449
public void check ( BioCDocument document ) { String text = checkText ( document ) ; check ( document , 0 , text ) ; for ( BioCPassage passage : document . getPassages ( ) ) { check ( passage , 0 , text , document ) ; for ( BioCSentence sentence : passage . getSentences ( ) ) { check ( sentence , 0 , text , document , passage ) ; } } }
Checks text annotations and relations of the document .
10,450
public void check ( BioCPassage passage ) { String text = checkText ( passage ) ; check ( passage , passage . getOffset ( ) , text ) ; for ( BioCSentence sentence : passage . getSentences ( ) ) { check ( sentence , 0 , text , passage ) ; } }
Checks text annotations and relations of the passage .
10,451
public void check ( BioCSentence sentence ) { String text = checkText ( sentence ) ; check ( sentence , sentence . getOffset ( ) , text ) ; }
Checks text annotations and relations of the sentence .
10,452
public void check ( BioCStructure structure , int offset , String text , BioCStructure ... parents ) { BioCStructure [ ] path = new BioCStructure [ parents . length + 1 ] ; System . arraycopy ( parents , 0 , path , 0 , parents . length ) ; path [ path . length - 1 ] = structure ; String location = log ( path ) ; checkAnnotations ( structure , offset , text , location ) ; checkRelations ( structure , location ) ; }
Check the annotation and relation in the structure .
10,453
public static Method getReadMethod ( Class < ? > clazz , String propertyName ) { Method readMethod = null ; try { PropertyDescriptor [ ] thisProps = Introspector . getBeanInfo ( clazz ) . getPropertyDescriptors ( ) ; for ( PropertyDescriptor pd : thisProps ) { if ( pd . getName ( ) . equals ( propertyName ) && pd . getReadMethod ( ) != null ) { readMethod = pd . getReadMethod ( ) ; break ; } } } catch ( IntrospectionException ex ) { Logger . getLogger ( BeanUtils . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } return readMethod ; }
Helper method for getting a read method for a property .
10,454
public static JdbcCpoAdapter getInstance ( JdbcCpoMetaDescriptor metaDescriptor , DataSourceInfo < DataSource > jdsiWrite , DataSourceInfo < DataSource > jdsiRead ) throws CpoException { String adapterKey = metaDescriptor + ":" + jdsiWrite . getDataSourceName ( ) + ":" + jdsiRead . getDataSourceName ( ) ; JdbcCpoAdapter adapter = ( JdbcCpoAdapter ) findCpoAdapter ( adapterKey ) ; if ( adapter == null ) { adapter = new JdbcCpoAdapter ( metaDescriptor , jdsiWrite , jdsiRead ) ; addCpoAdapter ( adapterKey , adapter ) ; } return adapter ; }
Creates a JdbcCpoAdapter .
10,455
protected < T , C > T processExecuteGroup ( String name , C criteria , T result ) throws CpoException { Connection c = null ; T obj = null ; try { c = getWriteConnection ( ) ; obj = processExecuteGroup ( name , criteria , result , c ) ; commitLocalConnection ( c ) ; } catch ( Exception e ) { rollbackLocalConnection ( c ) ; ExceptionHelper . reThrowCpoException ( e , "processExecuteGroup(String name, Object criteria, Object result) failed" ) ; } finally { closeLocalConnection ( c ) ; } return obj ; }
Executes an Object whose MetaData contains a stored procedure . An assumption is that the object exists in the datasource .
10,456
public JsonArray getAsArray ( ) { if ( ! ( value instanceof JsonArray ) ) { JsonArray val = new JsonArray ( ) ; val . add ( value ) ; value = val ; } return ( JsonArray ) value ; }
Returns the value as array .
10,457
public Boolean getAsBoolean ( ) { if ( value instanceof String ) { return Boolean . parseBoolean ( ( String ) value ) ; } return ( Boolean ) value ; }
Returns the value as boolean .
10,458
public Integer getAsInteger ( ) { if ( value instanceof String ) { return Integer . valueOf ( ( String ) value ) ; } else if ( value instanceof Long ) { return ( ( Long ) value ) . intValue ( ) ; } return ( Integer ) value ; }
Returns the value as integer .
10,459
public char match ( String str1 , String str2 ) { if ( null == str1 || null == str2 || 0 == str1 . length ( ) || 0 == str2 . length ( ) ) { return IMappingElement . IDK ; } float sim = 1 - ( float ) getLevenshteinDistance ( str1 , str2 ) / java . lang . Math . max ( str1 . length ( ) , str2 . length ( ) ) ; if ( threshold <= sim ) { return IMappingElement . EQUIVALENCE ; } else { return IMappingElement . IDK ; } }
Computes the relation with optimized edit distance matcher .
10,460
void init ( KProcess process ) { process . markings = new Object [ this . elements . size ( ) ] ; for ( KElement element : this . elements ) { element . init ( process ) ; } }
Initialize a process .
10,461
void addElement ( KElement element ) { if ( ! this . elements . contains ( element ) ) { element . setIndex ( this . elements . size ( ) ) ; this . elements . add ( element ) ; } }
Add an element
10,462
private static String getStringValueFromRow ( QuerySolution resultRow , String variableName ) { if ( resultRow == null ) { return null ; } String result = null ; Resource res = resultRow . getResource ( variableName ) ; if ( res != null && res . isLiteral ( ) ) { result = res . asLiteral ( ) . getString ( ) ; } return result ; }
Given a query result from a SPARQL query obtain the given variable value as a String
10,463
private static URL getUrlValueFromRow ( QuerySolution resultRow , String variableName ) { if ( resultRow == null ) { return null ; } URL result = null ; Resource res = resultRow . getResource ( variableName ) ; if ( res . isAnon ( ) ) { log . warn ( "Blank node found and ignored " + res . toString ( ) ) ; } else if ( res . isURIResource ( ) ) { try { result = new URL ( res . getURI ( ) ) ; } catch ( MalformedURLException e ) { log . error ( "Malformed URL for node" , e ) ; } catch ( ClassCastException e ) { log . error ( "The node is not a URI" , e ) ; } } return result ; }
Given a query result from a SPARQL query obtain the given variable value as a URL
10,464
public static boolean isVariableSet ( QuerySolution resultRow , String variableName ) { if ( resultRow != null ) { return resultRow . contains ( variableName ) ; } return false ; }
Given a query result from a SPARQL query check if the given variable has a value or not
10,465
public static Integer getIntegerValue ( QuerySolution resultRow , String variableName ) { if ( resultRow != null ) { Resource res = resultRow . getResource ( variableName ) ; if ( res != null && res . isLiteral ( ) ) { Literal val = res . asLiteral ( ) ; if ( val != null ) { return Integer . valueOf ( val . getInt ( ) ) ; } } } return null ; }
Given a query result from a SPARQL query obtain the number value at the given variable
10,466
public static String generateLabelPattern ( String var , String labelVar ) { return new StringBuilder ( ) . append ( "?" ) . append ( var ) . append ( " " ) . append ( sparqlWrapUri ( RDFS . label . getURI ( ) ) ) . append ( " " ) . append ( "?" ) . append ( labelVar ) . append ( ". " ) . toString ( ) ; }
Generate a pattern for binding to a label
10,467
public static String generateSubclassPattern ( URI origin , URI destination ) { return new StringBuilder ( ) . append ( sparqlWrapUri ( destination ) ) . append ( " " ) . append ( sparqlWrapUri ( RDFS . subClassOf . getURI ( ) ) ) . append ( "+ " ) . append ( sparqlWrapUri ( origin ) ) . append ( " ." ) . toString ( ) ; }
Generate a pattern for checking if destination is a subclass of origin
10,468
public static String generateSuperclassPattern ( URI origin , String matchVariable ) { return new StringBuilder ( ) . append ( sparqlWrapUri ( origin ) ) . append ( " " ) . append ( sparqlWrapUri ( RDFS . subClassOf . getURI ( ) ) ) . append ( "+ " ) . append ( "?" ) . append ( matchVariable ) . append ( " ." ) . toString ( ) ; }
Generate a pattern for matching var to the superclasses of clazz
10,469
public static String generateUnionStatement ( List < String > patterns ) { if ( patterns == null || patterns . isEmpty ( ) ) { return "" ; } if ( patterns . size ( ) == 1 ) { return patterns . get ( 0 ) ; } StringBuffer query = new StringBuffer ( ) ; query . append ( " {" + NL ) ; query . append ( patterns . get ( 0 ) ) ; query . append ( " }" + NL ) ; for ( int i = 1 ; i < patterns . size ( ) ; i ++ ) { query . append ( " UNION {" + NL ) ; query . append ( patterns . get ( i ) ) ; query . append ( " }" + NL ) ; } return query . toString ( ) ; }
Generates a UNION SPARQL statement for the patterns passed in the input
10,470
public static String generateExactMatchPattern ( URI origin , URI destination , String bindingVar , boolean includeUrisBound ) { List < String > patterns = new ArrayList < String > ( ) ; StringBuffer query = new StringBuffer ( ) ; query . append ( Util . generateSubclassPattern ( origin , destination ) + NL ) ; query . append ( Util . generateSuperclassPattern ( origin , destination ) + NL ) ; patterns . add ( query . toString ( ) ) ; query = new StringBuffer ( ) ; query . append ( "FILTER (str(" ) . append ( sparqlWrapUri ( origin ) ) . append ( ") = str(" ) . append ( sparqlWrapUri ( destination ) ) . append ( ") ) . " + NL ) ; patterns . add ( query . toString ( ) ) ; StringBuffer result = new StringBuffer ( generateUnionStatement ( patterns ) ) ; result . append ( "BIND (true as ?" + bindingVar + ") ." + NL ) ; if ( includeUrisBound ) { result . append ( "BIND (" ) . append ( sparqlWrapUri ( origin ) ) . append ( " as ?origin) ." ) . append ( NL ) ; result . append ( "BIND (" ) . append ( sparqlWrapUri ( destination ) ) . append ( " as ?destination) ." ) . append ( NL ) ; } return result . toString ( ) ; }
Generate a pattern for check if two concepts have an exact match . Basically we look for either identical classes or equivalent ones Uses BIND which Requires SPARQL 1 . 1
10,471
public static String generateMatchStrictSubclassesPattern ( URI origin , String matchVariable , String flagVar , boolean includeUrisBound ) { StringBuffer query = new StringBuffer ( ) ; query . append ( Util . generateSubclassPattern ( origin , matchVariable ) + NL ) ; query . append ( "FILTER NOT EXISTS { " ) . append ( Util . generateSuperclassPattern ( origin , matchVariable ) ) . append ( "}" ) . append ( NL ) ; query . append ( "BIND (true as ?" ) . append ( flagVar ) . append ( ") ." ) . append ( NL ) ; if ( includeUrisBound ) { query . append ( "BIND (" ) . append ( sparqlWrapUri ( origin ) ) . append ( " as ?origin) ." ) . append ( NL ) ; query . append ( "BIND (?" ) . append ( matchVariable ) . append ( " as ?destination) ." ) . append ( NL ) ; } return query . toString ( ) ; }
Generate a pattern for obtaining the strict subclasses of a concept . Uses BIND which Requires SPARQL 1 . 1
10,472
public static String generateMatchStrictSuperclassesPattern ( URI origin , String matchVariable , String bindingVar , boolean includeUrisBound ) { StringBuffer query = new StringBuffer ( ) ; query . append ( Util . generateSuperclassPattern ( origin , matchVariable ) + NL ) ; query . append ( "FILTER NOT EXISTS { " + Util . generateSubclassPattern ( origin , matchVariable ) + "}" + NL ) ; query . append ( "BIND (true as ?" + bindingVar + ") ." + NL ) ; if ( includeUrisBound ) { query . append ( "BIND (" ) . append ( sparqlWrapUri ( origin ) ) . append ( " as ?origin) ." ) . append ( NL ) ; query . append ( "BIND (?" ) . append ( matchVariable ) . append ( " as ?destination) ." ) . append ( NL ) ; } return query . toString ( ) ; }
Generate a pattern for obtaining the strict superclasses of a concept . Uses BIND which Requires SPARQL 1 . 1
10,473
public static DiscoMatchType getMatchType ( boolean isSubsume , boolean isPlugin ) { if ( isSubsume ) { if ( isPlugin ) { return DiscoMatchType . Exact ; } return DiscoMatchType . Subsume ; } else { if ( isPlugin ) { return DiscoMatchType . Plugin ; } } return DiscoMatchType . Fail ; }
Given the match between concepts obtain the match type
10,474
public static DiscoMatchType calculateCompositeMatchType ( MatchType bestMatch , MatchType worstMatch ) { if ( bestMatch instanceof LogicConceptMatchType && worstMatch instanceof LogicConceptMatchType ) { return calculateCompositeMatchType ( ( LogicConceptMatchType ) bestMatch , ( LogicConceptMatchType ) worstMatch ) ; } return DiscoMatchType . Fail ; }
Given the best and worst match figure out the match type for the composite . The composite match type is determined by the worst case except when it is a FAIL . In this case if the best is EXACT or PLUGIN the composite match will be PARTIAL_PLUGIN . If the best is SUBSUMES it is PARTIAL_SUBSUMES .
10,475
public static URL getMatchUrl ( QuerySolution row , boolean operationDiscovery ) { if ( row == null ) { return null ; } URL matchUrl ; if ( operationDiscovery ) { matchUrl = Util . getOperationUrl ( row ) ; } else { matchUrl = Util . getServiceUrl ( row ) ; } return matchUrl ; }
Obtain the match url given the query row and the kind of discovery we are carrying out
10,476
public static String getOrGenerateMatchLabel ( QuerySolution row , boolean operationDiscovery ) { String label ; if ( operationDiscovery ) { label = getOrGenerateOperationLabel ( row ) ; } else { label = getOrGenerateServiceLabel ( row ) ; } return label ; }
Obtain or generate a label for the match result given a row resulting from a query .
10,477
private static String getOrGenerateOperationLabel ( QuerySolution row ) { String result ; String svcLabel = getOrGenerateServiceLabel ( row ) ; String opLabel = getOperationLabel ( row ) ; if ( opLabel == null ) { URL opUrl = getOperationUrl ( row ) ; result = URIUtil . generateItemLabel ( svcLabel , opUrl ) ; } else { result = svcLabel + "." + opLabel ; } return result ; }
Obtain or generate a label for an operation .
10,478
private static void showMapDetails ( Map < URL , MatchResult > map ) { for ( Entry < URL , MatchResult > entry : map . entrySet ( ) ) { log . info ( "Match " + entry . getKey ( ) . toString ( ) + NL ) ; } }
Expose the data within the map
10,479
public static CodedInputStream newInstance ( final byte [ ] buf , final int off , final int len ) { CodedInputStream result = new CodedInputStream ( buf , off , len ) ; try { result . pushLimit ( len ) ; } catch ( InvalidProtocolBufferException ex ) { throw new IllegalArgumentException ( ex ) ; } return result ; }
Create a new CodedInputStream wrapping the given byte array slice .
10,480
protected static String escapeXmlSpecialCharacters ( String aText ) { String result = aText ; result = result . replaceAll ( "&" , "&amp;" ) ; result = result . replaceAll ( "\'" , "\\\\&#039;" ) ; result = result . replaceAll ( "'" , "\\\\&#039;" ) ; return result ; }
Android specific escaping of characters . Note that since this is no real XML escaping the output string . xml file is potentially not valid XML . However this is explicitly allowed by Android .
10,481
protected String [ ] getRow ( String masterLanguage , ITextNode textNode , IValueNode valueNode ) { List < String > row = new ArrayList < > ( ) ; row . add ( textNode . getKey ( ) ) ; row . add ( valueNode . getStatus ( ) . getName ( ) ) ; if ( ! valueNode . getLanguage ( ) . equals ( masterLanguage ) ) { IValueNode masterValueNode = textNode . getValueNode ( masterLanguage ) ; if ( masterValueNode == null ) { row . add ( "" ) ; } else { row . add ( masterValueNode . getValue ( ) ) ; } } row . add ( valueNode . getValue ( ) ) ; row . add ( textNode . getContext ( ) ) ; return row . toArray ( new String [ row . size ( ) ] ) ; }
Constructs a row for a Trema CSV export file .
10,482
protected String [ ] [ ] getValues ( ITextNode [ ] textNodes , String masterLanguage , String language , Status [ ] status ) { int numberOfColumns = ( masterLanguage . equals ( language ) ) ? 4 : 5 ; List < String [ ] > rows = new ArrayList < > ( ) ; rows . add ( getHeaderRow ( masterLanguage , new String [ ] { language } ) ) ; for ( ITextNode textNode : textNodes ) { IValueNode valueNode = textNode . getValueNode ( language ) ; if ( valueNode != null ) { if ( status == null || TremaCoreUtil . containsStatus ( valueNode . getStatus ( ) , status ) ) { rows . add ( getRow ( masterLanguage , textNode , valueNode ) ) ; } } } return rows . toArray ( new String [ rows . size ( ) ] [ numberOfColumns ] ) ; }
Gets a 2 dimensional string array representation of the CSV export data ready to be written to a CSV file .
10,483
public void build ( Concept parent ) throws OntologyBuildException { if ( ! this . skipProviderHierarchy ) { try { root = this . metadata . getOrCreateHardCodedFolder ( "Provider" ) ; root . setFactTableColumn ( "provider_id" ) ; root . setTableName ( "provider_dimension" ) ; root . setColumnName ( "provider_path" ) ; if ( parent != null ) { root . setAlreadyLoaded ( parent . isAlreadyLoaded ( ) ) ; parent . add ( root ) ; } alpha = createAlphaCategoryConcepts ( ) ; } catch ( InvalidConceptCodeException ex ) { throw new OntologyBuildException ( "Could not build provider concept tree" , ex ) ; } } }
Create a hierarchy of providers organized by first letter of their full name .
10,484
private PropertyEditor loadPropertyEditor ( Class < ? > clz ) { PropertyEditor editor = null ; try { editor = ( PropertyEditor ) clz . newInstance ( ) ; } catch ( InstantiationException e ) { Logger . getLogger ( PropertyEditorRegistry . class . getName ( ) ) . log ( Level . SEVERE , null , e ) ; } catch ( IllegalAccessException e ) { Logger . getLogger ( PropertyEditorRegistry . class . getName ( ) ) . log ( Level . SEVERE , null , e ) ; } return editor ; }
Load PropertyEditor from clz through reflection .
10,485
IteratorInfo < R > setValues ( int previousIndex , int nextIndex , boolean hasPrevious , boolean hasNext , int currentIndex , int effectiveIndex , R res ) { this . previousIndex = previousIndex ; this . nextIndex = nextIndex ; this . hasPrevious = hasPrevious ; this . hasNext = hasNext ; return ( IteratorInfo < R > ) setValues ( currentIndex , effectiveIndex , res ) ; }
set all fields of the Iterator Info
10,486
public static LdapHelper getInstance ( String instance ) { if ( ! helpers . containsKey ( instance ) ) { helpers . put ( instance , new LdapHelper ( instance ) ) ; } LdapHelper helper = helpers . get ( instance ) ; if ( ! helper . online ) { helper . loadProperties ( ) ; } return helper ; }
Returns a new Instance of LdapHelper .
10,487
public boolean setUserAsUser ( Node node , String uid , String password ) throws Exception { boolean status = false ; StringBuilder sb = new StringBuilder ( userIdentifyer + "=" ) . append ( uid ) . append ( "," ) ; sb . append ( Configuration . getProperty ( instanceName + LdapKeys . ATTR_OU_PEOPLE ) ) . append ( "," ) ; sb . append ( baseDn ) ; if ( uid == null || uid . isEmpty ( ) || password == null || password . isEmpty ( ) ) { return false ; } try { Hashtable < String , String > environment = ( Hashtable < String , String > ) ctx . getEnvironment ( ) . clone ( ) ; environment . put ( Context . SECURITY_PRINCIPAL , sb . toString ( ) ) ; environment . put ( Context . SECURITY_CREDENTIALS , password ) ; DirContext dirContext = new InitialDirContext ( environment ) ; status = setUserInContext ( dirContext , node ) ; dirContext . close ( ) ; } catch ( NamingException ex ) { handleNamingException ( "NamingException " + ex . getLocalizedMessage ( ) , ex ) ; } return status ; }
Writes the modifications on an user object back to the LDAP using a specific context .
10,488
public boolean rmUser ( final Node node ) { LdapUser user = ( LdapUser ) node ; if ( node == null ) { return false ; } try { deletionCount ++ ; ctx . unbind ( getOuForNode ( user ) ) ; } catch ( NamingException ex ) { handleNamingException ( user , ex ) ; } Node ldapUser = getUser ( user . getUid ( ) ) ; return ldapUser . isEmpty ( ) ; }
Deletes an LDAP - User .
10,489
public boolean rmGroup ( Node node ) { LdapGroup group = ( LdapGroup ) node ; try { deletionCount ++ ; ctx . unbind ( getOuForNode ( group ) ) ; } catch ( NamingException ex ) { handleNamingException ( group , ex ) ; } Node ldapGroup = getGroup ( group . getCn ( ) ) ; return ldapGroup . isEmpty ( ) ; }
Deletes a LDAP - Group .
10,490
public boolean setGroup ( Node node ) throws Exception { LdapGroup newLdapGroup = ( LdapGroup ) node ; newLdapGroup = updateGroupMembers ( newLdapGroup ) ; LdapGroup oldLdapGroup = ( LdapGroup ) getGroup ( newLdapGroup . getCn ( ) ) ; if ( oldLdapGroup . isEmpty ( ) ) { creationCount ++ ; Logger . info ( LOG_BIND + getOuForNode ( newLdapGroup ) ) ; ctx . bind ( getOuForNode ( newLdapGroup ) , null , newLdapGroup . getAttributes ( ) ) ; return true ; } else { ModificationItem [ ] mods = buildModificationsForGroup ( newLdapGroup , oldLdapGroup ) ; if ( mods . length > 0 ) { modificationCount ++ ; Logger . info ( LOG_MODIFY_ATTRIBUTES + getOuForNode ( newLdapGroup ) ) ; ctx . modifyAttributes ( getOuForNode ( newLdapGroup ) , mods ) ; return true ; } } return false ; }
Adds or updates a LDAP - Group .
10,491
public Node getUser ( final String uid ) { try { String query = "(&(objectClass=" + userObjectClass + ")(" + userIdentifyer + "=" + uid + "))" ; SearchResult searchResult ; Attributes attributes ; SearchControls controls = new SearchControls ( ) ; controls . setReturningAttributes ( new String [ ] { LdapKeys . ASTERISK , LdapKeys . MODIFY_TIMESTAMP , LdapKeys . MODIFIERS_NAME , LdapKeys . ENTRY_UUID } ) ; controls . setSearchScope ( SearchControls . SUBTREE_SCOPE ) ; NamingEnumeration < SearchResult > results = ctx . search ( "" , query , controls ) ; queryCount ++ ; if ( results . hasMore ( ) ) { searchResult = results . next ( ) ; attributes = searchResult . getAttributes ( ) ; LdapUser user = new LdapUser ( uid , this ) ; user . setDn ( searchResult . getNameInNamespace ( ) ) ; user = fillAttributesInUser ( ( LdapUser ) user , attributes ) ; return user ; } } catch ( NamingException ex ) { handleNamingException ( instanceName + ":" + uid , ex ) ; } return new LdapUser ( ) ; }
Returns an LDAP - User .
10,492
public Set < Node > findUsers ( final String uid ) { QueryBuilder qb = new LdapQueryBuilder ( ) ; if ( "*" . equals ( uid ) ) { qb . append ( LdapKeys . OBJECT_CLASS , userObjectClass ) ; } else { qb . append ( LdapKeys . OBJECT_CLASS , userObjectClass ) ; qb . append ( userIdentifyer , uid + "*" ) ; } return findUsers ( qb ) ; }
Returns several LDAP - Users for a given search - String .
10,493
public Node getGroup ( final String cn ) { try { String query = "(&(objectClass=" + groupObjectClass + ")(" + groupIdentifyer + "=" + cn + "))" ; SearchResult searchResult ; Attributes attributes ; SearchControls controls = new SearchControls ( ) ; controls . setReturningAttributes ( new String [ ] { LdapKeys . ASTERISK , LdapKeys . MODIFY_TIMESTAMP , LdapKeys . MODIFIERS_NAME , LdapKeys . ENTRY_UUID } ) ; controls . setSearchScope ( SearchControls . SUBTREE_SCOPE ) ; NamingEnumeration < SearchResult > results = ctx . search ( "" , query , controls ) ; queryCount ++ ; if ( results . hasMore ( ) ) { LdapGroup group = new LdapGroup ( cn , this ) ; searchResult = results . next ( ) ; group . setDn ( searchResult . getNameInNamespace ( ) ) ; attributes = searchResult . getAttributes ( ) ; group = fillAttributesInGroup ( ( LdapGroup ) group , attributes ) ; return group ; } } catch ( NamingException ex ) { handleNamingException ( instanceName + ":" + cn , ex ) ; } return new LdapGroup ( ) ; }
Returns a LDAP - Group .
10,494
public Set < Node > findGroups ( final String cn ) { QueryBuilder qb = new LdapQueryBuilder ( ) ; if ( "*" . equals ( cn ) ) { qb . append ( LdapKeys . OBJECT_CLASS , groupObjectClass ) ; } else { qb . append ( LdapKeys . OBJECT_CLASS , groupObjectClass ) ; qb . append ( groupIdentifyer , cn + "*" ) ; } return findGroups ( qb ) ; }
Returns several LDAP - Groups for a given search - String .
10,495
public Node getPrincipal ( ) { if ( principal == null ) { principal = new LdapUser ( ) ; LdapUser p = ( LdapUser ) principal ; p . setDn ( Configuration . getProperty ( instanceName + ".principal" ) . trim ( ) ) ; p . setUid ( getUidForDN ( p . getDn ( ) ) ) ; } return principal ; }
Returns the LDAP - Principal as a LdapUser .
10,496
public String getDefault ( final String key ) { if ( defaultValues . containsKey ( key ) ) { return defaultValues . get ( key ) ; } return "" ; }
Returns a Value from the Default Collection .
10,497
public Set < Node > getGroupsForUser ( Node user ) { Set < Node > groups = new TreeSet < > ( ) ; try { String query = "(& (objectClass=" + groupObjectClass + ") (" + groupMemberAttribut + "=" + ( ( LdapUser ) user ) . getDn ( ) + "))" ; SearchResult searchResult ; Attributes attributes ; SearchControls controls = new SearchControls ( ) ; controls . setSearchScope ( SearchControls . SUBTREE_SCOPE ) ; NamingEnumeration < SearchResult > results = ctx . search ( "" , query , controls ) ; queryCount ++ ; Node group ; while ( results . hasMore ( ) ) { searchResult = results . next ( ) ; attributes = searchResult . getAttributes ( ) ; group = getGroup ( getAttributeOrNa ( attributes , groupIdentifyer ) ) ; group . setDn ( searchResult . getNameInNamespace ( ) ) ; groups . add ( group ) ; } } catch ( NamingException ex ) { handleNamingException ( user , ex ) ; } return groups ; }
Load all Groups for a given User .
10,498
public Set < Node > getUsersForGroup ( Node group ) { Set < Node > users = new TreeSet < > ( ) ; try { String query = "(" + groupIdentifyer + "=" + group . getName ( ) + ")" ; SearchResult searchResult ; Attributes attributes ; SearchControls controls = new SearchControls ( ) ; controls . setSearchScope ( SearchControls . SUBTREE_SCOPE ) ; NamingEnumeration < SearchResult > results = ctx . search ( "" , query , controls ) ; Node user ; while ( results . hasMore ( ) ) { searchResult = results . next ( ) ; attributes = searchResult . getAttributes ( ) ; NamingEnumeration < ? > members = attributes . get ( groupMemberAttribut ) . getAll ( ) ; while ( members . hasMoreElements ( ) ) { String memberDN = ( String ) members . nextElement ( ) ; String uid = getIdentifyerValueFromDN ( memberDN ) ; user = getUser ( uid ) ; user . setDn ( memberDN ) ; users . add ( user ) ; } } } catch ( NamingException ex ) { handleNamingException ( group , ex ) ; } return users ; }
Load all Users for a given Group .
10,499
public LdapUser getUserTemplate ( String uid ) { LdapUser user = new LdapUser ( uid , this ) ; user . set ( "dn" , getDNForNode ( user ) ) ; for ( String oc : userObjectClasses ) { user . addObjectClass ( oc . trim ( ) ) ; } user = ( LdapUser ) updateObjectClasses ( user ) ; if ( user . getObjectClasses ( ) . contains ( "inetOrgPerson" ) || user . getObjectClasses ( ) . contains ( "person" ) ) { user . set ( "sn" , uid ) ; } if ( user . getObjectClasses ( ) . contains ( "JabberAccount" ) ) { user . set ( "jabberID" , uid + "@" + defaultValues . get ( "jabberServer" ) ) ; user . set ( "jabberAccess" , "TRUE" ) ; } if ( user . getObjectClasses ( ) . contains ( "posixAccount" ) ) { user . set ( "uidNumber" , "99999" ) ; user . set ( "gidNumber" , "99999" ) ; user . set ( "cn" , uid ) ; user . set ( "homeDirectory" , "/dev/null" ) ; } if ( user . getObjectClasses ( ) . contains ( "ldapPublicKey" ) ) { user . set ( "sshPublicKey" , defaultValues . get ( "sshKey" ) ) ; } return user ; }
Returns a basic LDAP - User - Template for a new LDAP - User .