Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright: (c) 2004-2011 Mayo Foundation for Medical Education and 
   * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
   * triple-shield Mayo logo are trademarks and service marks of MFMER.
   *
   * Except as contained in the copyright notice above, or as used to identify 
   * MFMER as the author of this software, the trade names, trademarks, service
   * marks, or product names of the copyright holder shall not be used in
   * advertising, promotion or otherwise in connection with this software without
  * prior written authorization of the copyright holder.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.twinkql.result;
 
 import java.util.List;
 import java.util.Map;
 
 import  org.springframework.beans.factory.InitializingBean;
 import  org.springframework.beans.factory.annotation.Autowired;
 import  org.springframework.stereotype.Component;
 import  org.springframework.util.Assert;
 
 
The Class ResultBindingProcessor.

Author(s):
Kevin Peterson
 
 @Component
 public class ResultBindingProcessor implements InitializingBean {
 
 	@Autowired
 	
 	@Autowired
 	
 	@Autowired
 
 	@Autowired
 
 	private Map<Qname, ? extends ResultMapresultMaps = new HashMap<QnameResultMap>();
 	
 	private Map<ResultMap,Stringnamespaces = new HashMap<ResultMapString>();
 	
 
 	@Autowired
 	
 	@Autowired
Instantiates a new result binding processor.
 
 	public ResultBindingProcessor() {
 		super();
 	}

Instantiates a new result binding processor.

Parameters:
twinkqlContext the twinkql context
	public ResultBindingProcessor(TwinkqlContext twinkqlContext) {
		this. = twinkqlContext;
		this. = new BeanInstantiator(twinkqlContext);
	}
	/* (non-Javadoc)
	 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
	 */
	public void afterPropertiesSet() {
		Assert.notNull(this.);
		Assert.notNull(this.);
		this.initCaches();
	}

Inits the caches.
	protected void initCaches() {
		for (SparqlMap sparqlMap : this..getSparqlMaps()) {
			for (SparqlMapItem sparqlMapItem : sparqlMap.getSparqlMapItem()) {
				if (sparqlMapItem.getResultMap() != null) {
						sparqlMapItem.getResultMap());
					String namespace = sparqlMap.getNamespace();
					resultMaps.put(
						new Qname(namespaceresultMap.getId()),
						resultMap);
					this..put(resultMapnamespace);
				}
			}
			this. = this.processExtendableResultSet(resultMaps);
		}
	}

Bind.

Parameters:
<T> the generic type
resultSet the result set
resultMapQname the result map qname
Returns:
the list
	@SuppressWarnings("unchecked")
	public <T> List<T> bind(
			ResultSet resultSet,
			Qname resultMapQname) {
		List<T> returnList = new ArrayList<T>();
		//fail fast if its an invalid ResultMap Qname
		ResultMap resultMap = this..get(resultMapQname);
		if(resultMap == null){
			throw new ResultMapNotFoundException(resultMapQname);
		}
		List<QuerySolutionsolutions = this.resolveResultSet(resultSet);
		Collection<List<QuerySolution>> uniqueResults = 
				resultMap
				solutions);
		for(List<QuerySolutionuniqueSet : uniqueResults){
			returnList.add( (T) this.processUniqueSet(uniqueSetresultMap) );
		}
		return returnList;
	}

Resolve result set.

Parameters:
resultSet the result set
Returns:
the list
	private List<QuerySolutionresolveResultSet(ResultSet resultSet) {
		List<QuerySolutionreturnList = new ArrayList<QuerySolution>();
		while(resultSet.hasNext()){
			returnList.add(resultSet.next());
		}
		return returnList;
	}

Process extendable result set.

Parameters:
resultMaps the result maps
Returns:
the map
			Map<QnameExtendableResultMapresultMaps){
		for (Entry<QnameExtendableResultMapentry : resultMaps.entrySet()) {
			ExtendableResultMap map = entry.getValue();
			if (StringUtils.isNotBlank(map.getExtends())) {
				ExtendableResultMap extended = resultMaps.get(Qname
						.toQname(map.getExtends(), entry.getKey().getNamespace() ));
				map.setExtending(extended);
			}
		}
		return resultMaps;
	}

Process unique set.

Parameters:
uniqueSet the unique set
resultMap the result map
Returns:
the object
	private Object processUniqueSet(List<QuerySolutionuniqueSetResultMap resultMap){
		Object returnResult = this.createNewResult(resultMap);
		ResultMapChoice resultMapChoice = resultMap.getResultMapChoice();
		for(QuerySolution solution : uniqueSet){
			for(ResultMapChoiceItem resultMapItem : resultMapChoice.getResultMapChoiceItem()){
				RowMap rowMap = resultMapItem.getRowMap();
				if(rowMap != null){
							returnResult
							rowMap,
							solution);
				}
				Conditional conditional = resultMapItem.getIf();
				if(conditional != null){
							returnResult
							solution
							conditional
							null);
				}
				Association association = resultMapItem.getAssociation();
				if(association != null){
					Object associatedObject = 
						this.processAssociation(associationuniqueSetthis..get(resultMap));
						setProperty(returnResultassociatedObjectassociationnull);
				}
			}
		}
				resultMap.getAfterMap(), 
				returnResult
				null);
		return returnResult;
	}

Process row map.

Parameters:
target the target
rowMap the row map
solution the solution
	private void processRowMap(Object targetRowMap rowMapQuerySolution solution) {
		if(this.isMatch(rowMapsolution)){
			String result = 
							solution.get(rowMap.getVar()), 
							rowMap);
					target
					result
					rowMap,
					null);
		}
	}

Process association.

Parameters:
association the association
uniqueSet the unique set
Returns:
the object
	private Object processAssociation(Association associationList<QuerySolutionuniqueSetString defaultNamespace) {
		Object returnObject;
		ResultMap resultMap = this.getResultMapFromAssociation(associationdefaultNamespace);
		if(association.isIsCollection()){
			List<ObjectreturnList = new ArrayList<Object>();
			Collection<List<QuerySolution>> innerUniqueSets = 
				this..separateByUniqueIds(resultMapuniqueSet);
			for(List<QuerySolutioninnerUniqueSet : innerUniqueSets){
				Object result = this.processUniqueSet(innerUniqueSetresultMap);
				returnList.add(result);
			}
			returnObject = returnList;
else {
			returnObject = this.processUniqueSet(uniqueSetresultMap);
		}
		return returnObject;
	}
	private ResultMap getResultMapFromAssociation(Association associationString defaultNamespace) {
		ResultMap resultMap;
		if(StringUtils.isNotBlank(association.getResultMap())) {
			if(association.getResultMapChoice() != null){
				throw new MappingException(
					"Association cannot declare a 'resultMap' attribute and contain content.");
			}
			resultMap = this..get(
				Qname.toQname(association.getResultMap(), defaultNamespace));	
else {
			resultMap = association;
		}
		return resultMap;
	}



Creates the new result.

Parameters:
resultMap the result map
Returns:
the object
	private Object createNewResult(ResultMap resultMap) {
		String resultAliasOrClass = resultMap.getResultClass();
		return this..instantiate(resultAliasOrClasstrue);
	}

Checks if is match.

Parameters:
rowMap the row map
solution the solution
Returns:
true, if is match
	private boolean isMatch(RowMap rowMapQuerySolution solution){
		if(StringUtils.isBlank(rowMap.getMatch())){
			return true;
else {
			MatchExpression matchExpression = 
			return matchExpression.isMatch(solution);
		}
	}



Handle conditional.

Parameters:
targetObj the target obj
solution the solution
conditional the conditional
tracker the tracker
	private void handleConditional(
			Object targetObj
			QuerySolution solution,
			Conditional conditional
			CompositeTracker tracker) {
		@SuppressWarnings("unchecked")
						conditional.getFunction(),
						false);
		String parameter = conditional.getParam();
		if (test.test(solution.get(parameter))) {
			for (ConditionalItem conditionalItem : 
				conditional.getConditionalItem()){
				if (conditionalItem.getRowMap() != null) {
					RowMap rowMap = conditionalItem.getRowMap();
					this.processRowMap(targetObjrowMapsolution);
				}
			}
		}
	}

Gets the twinkql context.

Returns:
the twinkql context
	}

Sets the twinkql context.

Parameters:
twinkqlContext the new twinkql context
	public void setTwinkqlContext(TwinkqlContext twinkqlContext) {
		this. = twinkqlContext;
	}
New to GrepCode? Check out our FAQ X