String groupContext, String shortCanonicalName, String expectedGroupContext)
throws TeiidComponentException, QueryResolverException {
boolean isExternal = false;
boolean groupMatched = false;
GroupContext root = null;
if (groups != null || externalContext != null) {
if (groups != null) {
root = new GroupContext(externalContext, groups);
}
if (root == null) {
isExternal = true;
root = externalContext;
}
} else {
try {
LinkedList<GroupSymbol> matchedGroups = new LinkedList<GroupSymbol>();
if (groupContext != null) {
//assume that this is fully qualified
Object groupID = this.metadata.getGroupID(groupContext);
// No groups specified, so any group is valid
GroupSymbol groupSymbol = new GroupSymbol(groupContext);
groupSymbol.setMetadataID(groupID);
matchedGroups.add(groupSymbol);
}
root = new GroupContext(null, matchedGroups);
} catch(QueryMetadataException e) {
// ignore
}
}
LinkedList<ElementMatch> matches = new LinkedList<ElementMatch>();
while (root != null) {
Collection<GroupSymbol> matchedGroups = ResolverUtil.findMatchingGroups(groupContext, root.getGroups(), metadata);
if (matchedGroups != null && !matchedGroups.isEmpty()) {
groupMatched = true;
resolveAgainstGroups(shortCanonicalName, matchedGroups, matches);
if (matches.size() > 1) {
if (isExternal && matches.size() == 2) {
if ((isScalar(matches.get(0).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(1).element, ProcedureReservedWords.INPUT))) {
matches.removeLast();
break;
} else if (isScalar(matches.get(1).element, ProcedureReservedWords.INPUTS) && isScalar(matches.get(0).element, ProcedureReservedWords.INPUT)) {
matches.removeFirst();
break;
}
}
throw handleUnresolvedElement(elementSymbol, QueryPlugin.Util.getString("ERR.015.008.0053", elementSymbol)); //$NON-NLS-1$
}
if (matches.size() == 1) {
break;
}
}
root = root.getParent();
isExternal = true;
}
if (matches.isEmpty()) {
if (groupMatched) {