private void populateRelation ( TaskField field , Task sourceTask , String relationship ) throws MPXJException { int index = 0 ; int length = relationship . length ( ) ; // // Extract the identifier // while ( ( index < length ) && ( Character . isDigit ( relationship . charAt ( index ) ) == true ) ) { ++ index ; } Integer taskID ; try { taskID = Integer . valueOf ( relationship . substring ( 0 , index ) ) ; } catch ( NumberFormatException ex ) { throw new MPXJException ( MPXJException . INVALID_FORMAT + " '" + relationship + "'" ) ; } // // Now find the task, so we can extract the unique ID // Task targetTask ; if ( field == TaskField . PREDECESSORS ) { targetTask = m_projectFile . getTaskByID ( taskID ) ; } else { targetTask = m_projectFile . getTaskByUniqueID ( taskID ) ; } // // If we haven't reached the end, we next expect to find // SF, SS, FS, FF // RelationType type = null ; Duration lag = null ; if ( index == length ) { type = RelationType . FINISH_START ; lag = Duration . getInstance ( 0 , TimeUnit . DAYS ) ; } else { if ( ( index + 1 ) == length ) { throw new MPXJException ( MPXJException . INVALID_FORMAT + " '" + relationship + "'" ) ; } type = RelationTypeUtility . getInstance ( m_locale , relationship . substring ( index , index + 2 ) ) ; index += 2 ; if ( index == length ) { lag = Duration . getInstance ( 0 , TimeUnit . DAYS ) ; } else { if ( relationship . charAt ( index ) == ' ' ) { ++ index ; } lag = DurationUtility . getInstance ( relationship . substring ( index ) , m_formats . getDurationDecimalFormat ( ) , m_locale ) ; } } if ( type == null ) { throw new MPXJException ( MPXJException . INVALID_FORMAT + " '" + relationship + "'" ) ; } // We have seen at least one example MPX file where an invalid task ID // is present. We'll ignore this as the schedule is otherwise valid. if ( targetTask != null ) { Relation relation = sourceTask . addPredecessor ( targetTask , type , lag ) ; m_eventManager . fireRelationReadEvent ( relation ) ; } }
Creates and populates a new task relationship .