code: public static boolean isForeignKey( NodeKey key,
                                          NodeKey rootKey ) {
          if (key == null) {
              return false;
          }
          String nodeWorkspaceKey = key.getWorkspaceKey();
  
          boolean sameWorkspace = rootKey.getWorkspaceKey().equals(nodeWorkspaceKey);
          boolean sameSource = rootKey.getSourceKey().equalsIgnoreCase(key.getSourceKey());
          return !sameWorkspace || !sameSource;
      }
docs: Checks if the node given key is foreign by comparing the source key & workspace key against the same keys from this
  session's root. This method is used for reference resolving.
  
  @param key the node key; may be null
  @param rootKey the key of the root node in the workspace; may not be null
  @return true if the node key is considered foreign, false otherwise.