001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: InteractionUtils.java,v 1.2 2008/06/25 05:47:18 qcheng Exp $ 026 * 027 */ 028 029package com.sun.identity.liberty.ws.interaction; 030 031import com.sun.identity.liberty.ws.interaction.jaxb.InteractionResponseElement; 032import com.sun.identity.liberty.ws.interaction.jaxb.UserInteractionElement; 033import com.sun.identity.liberty.ws.interaction.jaxb.ParameterType; 034import com.sun.identity.liberty.ws.soapbinding.Message; 035import java.util.Collections; 036import java.util.HashMap; 037import java.util.Map; 038import java.util.List; 039import java.util.Iterator; 040 041/** 042 * Class that provides some utility methods that work with objects 043 * related to interaction 044 * 045 * @supported.all.api 046 */ 047public class InteractionUtils { 048 049 private InteractionUtils() {} 050 051 /** 052 * Returns user friendly <code>Map</code> representation of parameters 053 * in interaction response element 054 * 055 * @param interactionResponseElement obtained from 056 * <code>InteractionManager</code> 057 * @return a Map of parameters. Keys of the map are parameter 058 * name String objects. Values in the map are parameter value 059 * String objects 060 */ 061 public static Map getParameters( 062 InteractionResponseElement interactionResponseElement) { 063 List parameters = interactionResponseElement.getParameter(); 064 Map pm = new HashMap(); 065 Iterator iter = parameters.iterator(); 066 while (iter.hasNext()) { 067 ParameterType pt = (ParameterType) iter.next(); 068 pm.put(pt.getName(), pt.getValue()); 069 } 070 return pm; 071 } 072 073 /** 074 * Returns languages listed for the language attribute of the 075 * <code>UserInteraction</code> header in the message. Returns empty list 076 * if <code>UserInteraction</code> header is not included in the message 077 * 078 * @param message SOAP message from which to find out 079 * interaction languages 080 * 081 * @return languages listed for the language attribute of the 082 * <code>UserInteraction</code> header in the message. 083 * Returns empty list 084 * if <code>UserInteraction</code> header is not included 085 * in the message 086 */ 087 public static List getInteractionLangauge(Message message) { 088 List languages = null; 089 UserInteractionElement ue 090 = InteractionManager.getUserInteractionElement(message); 091 if (ue != null) { 092 languages = ue.getLanguage(); 093 } 094 if (languages == null) { 095 languages = Collections.EMPTY_LIST; 096 } 097 return languages; 098 } 099}