static ImmutableAttributes loadAttributes ( String line , ImmutableAttributes cachedAttributes ) { // Builder pattern for Immutable attributes // This parses a cache line that looks like this: // repoType|symbolicName=Lots;of;attribtues int index = line . indexOf ( ' ' ) ; String key = line . substring ( 0 , index ) ; String repoType = FeatureDefinitionUtils . EMPTY ; String symbolicName = key ; // Do we have a prefix repoType? If so, split the key. int pfxIndex = key . indexOf ( ' ' ) ; if ( pfxIndex > - 1 ) { repoType = key . substring ( 0 , pfxIndex ) ; symbolicName = key . substring ( pfxIndex + 1 ) ; } // Now let's work on the value half... String [ ] parts = splitPattern . split ( line . substring ( index + 1 ) ) ; // Old or mismatched cache if ( parts . length < 9 ) return null ; String path = parts [ 0 ] ; // Make sure file information from cache line is still accurate // i.e. the file exists, and the modification time and size have not changed. File featureFile = new File ( path ) ; if ( featureFile . exists ( ) ) { // Did we have a previous entry in the cache already? // This will happen on a subsequent feature update operation (post-initial provisioning) if ( cachedAttributes != null ) { return cachedAttributes ; } // Assuming we're still good, but didn't have a cache entry, we should read the rest // of the attributes.. long lastModified = getLongValue ( parts [ 1 ] , - 1 ) ; long fileSize = getLongValue ( parts [ 2 ] , - 1 ) ; String shortName = parts [ 3 ] ; int featureVersion = getIntegerValue ( parts [ 4 ] , 2 ) ; Visibility visibility = Visibility . fromString ( parts [ 5 ] ) ; AppForceRestart appRestart = AppForceRestart . fromString ( parts [ 6 ] ) ; Version version = VersionUtility . stringToVersion ( parts [ 7 ] ) ; String flags = parts [ 8 ] ; boolean isAutoFeature = toBoolean ( flags . charAt ( 0 ) ) ; boolean hasApiServices = toBoolean ( flags . charAt ( 1 ) ) ; boolean hasApiPackages = toBoolean ( flags . charAt ( 2 ) ) ; boolean hasSpiPackages = toBoolean ( flags . charAt ( 3 ) ) ; boolean isSingleton = flags . length ( ) > 4 ? toBoolean ( flags . charAt ( 4 ) ) : false ; EnumSet < ProcessType > processTypes = ProcessType . fromString ( parts . length > 9 ? parts [ 9 ] : null ) ; // Everything is ok with the cache contents, // make a new subsystem definition from the cached information return new ImmutableAttributes ( emptyIfNull ( repoType ) , symbolicName , nullIfEmpty ( shortName ) , featureVersion , visibility , appRestart , version , featureFile , lastModified , fileSize , isAutoFeature , hasApiServices , hasApiPackages , hasSpiPackages , isSingleton , processTypes ) ; } // The definition in the filesystem has been deleted: return null to remove it from the cache return null ; }
Create the ImmutableAttributes based on an line in a cache file . There is no validation or warnings in this load path as it is assumed the definition would not have been added to the cache if it were invalid .