/* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.security.mapping; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * Generic Context used by the Mapping Framework * @author Anil Saldhana * @version $Revision$ * @param * @since Aug 24, 2006 */ public class MappingContext { private List> modules = new ArrayList>(); private MappingResult result; public MappingContext(List> mod) { this.modules = mod; } /** * Get the set of mapping modules * @return */ public List> getModules() { return this.modules; } /** * Apply mapping semantics on the passed object * @param contextMap Read-only Contextual Map * @param mappedObject an object on which mapping will be applied */ public void performMapping(Map contextMap, T mappedObject) { int len = modules.size(); result = new MappingResult(); for(int i = 0 ; i < len; i++) { MappingProvider mp = (MappingProvider)modules.get(i); mp.setMappingResult(result); mp.performMapping(contextMap, mappedObject); } } /** * * @return Result of previous mapping operation */ public MappingResult getMappingResult() { return result; } /** * Optimization Step to determine if we have configured mapping modules * to avoid unnecessary mapping step * @return true - at least one mapping provider is configured */ public boolean hasModules() { return this.modules.size() > 0; } }