private Map < URI , MatchResult > findSome ( URI entityType , URI relationship , Set < URI > types , MatchType matchType ) { // Ensure that we have been given correct parameters if ( types == null || types . isEmpty ( ) || ( ! entityType . toASCIIString ( ) . equals ( MSM . Service . getURI ( ) ) && ! entityType . toASCIIString ( ) . equals ( MSM . Operation . getURI ( ) ) ) || ( ! relationship . toASCIIString ( ) . equals ( MSM . hasInput . getURI ( ) ) && ! relationship . toASCIIString ( ) . equals ( MSM . hasOutput . getURI ( ) ) && ! relationship . toASCIIString ( ) . equals ( SAWSDL . modelReference . getURI ( ) ) ) ) { return ImmutableMap . of ( ) ; } // Expand the input types to get all that match enough to be consumed // The structure is: <OriginalType, MatchingType, MatchResult> Table < URI , URI , MatchResult > expandedTypes ; if ( matchType . equals ( LogicConceptMatchType . Subsume ) ) { expandedTypes = HashBasedTable . create ( ) ; for ( URI type : types ) { expandedTypes . putAll ( this . conceptMatcher . listMatchesAtMostOfType ( ImmutableSet . of ( type ) , LogicConceptMatchType . Subsume ) ) ; expandedTypes . putAll ( this . conceptMatcher . listMatchesOfType ( ImmutableSet . of ( type ) , LogicConceptMatchType . Exact ) ) ; } } else if ( matchType . equals ( LogicConceptMatchType . Plugin ) ) { expandedTypes = this . conceptMatcher . listMatchesAtLeastOfType ( types , LogicConceptMatchType . Plugin ) ; } else { expandedTypes = HashBasedTable . create ( ) ; for ( URI type : types ) { expandedTypes . putAll ( this . conceptMatcher . listMatchesOfType ( ImmutableSet . of ( type ) , LogicConceptMatchType . Exact ) ) ; } } // Track all the results in a multimap to push the details up the stack Multimap < URI , MatchResult > result = ArrayListMultimap . create ( ) ; // Find all the entities with modelReferences to the expanded types // The column view is the one with all the possible matches since a class will always match itself Map < URI , Map < URI , MatchResult > > columnMap = expandedTypes . columnMap ( ) ; for ( URI type : columnMap . keySet ( ) ) { Set < URI > entities = ImmutableSet . of ( ) ; if ( relationship . toASCIIString ( ) . equals ( SAWSDL . modelReference . getURI ( ) ) ) { entities = listEntitesWithModelReference ( entityType , type ) ; } else if ( relationship . toASCIIString ( ) . equals ( MSM . hasInput . getURI ( ) ) || relationship . toASCIIString ( ) . equals ( MSM . hasOutput . getURI ( ) ) ) { entities = listEntitiesWithType ( entityType , relationship , type ) ; } for ( URI entity : entities ) { result . putAll ( entity , columnMap . get ( type ) . values ( ) ) ; } } // Merge the results into a single map using Union return Maps . transformValues ( result . asMap ( ) , MatchResultsMerger . UNION ) ; }
Generic implementation for finding all the Services or Operations that have SOME of the given types as inputs or outputs .