001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2005 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: ClientsManager.java,v 1.5 2008/06/25 05:41:32 qcheng Exp $ 026 * 027 */ 028 029package com.iplanet.services.cdm; 030 031import java.util.Iterator; 032import java.util.Map; 033 034import com.iplanet.am.util.AMClientDetector; 035 036/** 037 * Provides common access to client data. 038 * <p> 039 * <p> 040 * Client data is accessed for a particular client type. The underlying client 041 * data is stored in the profile service, but this interface should always used 042 * for accessing it (not by accessing the profile directly). 043 * 044 * <p> 045 * Client does not allow clients to modify the Client Data unless they have a 046 * valid user sso token. clients trying to modify Client Data should explicitly 047 * call store() to save changes into SMS. versions of the getInstance methods 048 * that accept a SSO token should be used if the client code wishes to set 049 * client data. 050 * @supported.api 051 */ 052public class ClientsManager { 053 054 protected static ClientTypesManager clientTypesManager = AMClientDetector 055 .getClientTypesManagerInstance(); 056 057 /** 058 * Constructor 059 */ 060 public ClientsManager() { 061 } 062 063 /** 064 * Returns Client instance for a specific client type. 065 * 066 * @param clientType 067 * Client Type. 068 * @return Requested Client instance. 069 * @throws ClientException 070 * if specified client type is null or not defined. 071 * @supported.api 072 */ 073 public static Client getInstance(String clientType) throws ClientException { 074 if (clientType == null) { 075 throw new ClientException(CDMBundle.getString("null_clientType")); 076 } 077 Client client = (clientTypesManager != null) ? 078 clientTypesManager.getClientInstance(clientType) : null; 079 080 if (client == null) { 081 throw new ClientException( 082 CDMBundle.getString("unknown_clientType") + ", " + clientType); 083 } 084 085 return client; 086 } 087 088 /** 089 * Returns a Client instance for the default client type 090 * @return The Client instance corresponding to the default client type 091 * 092 * iPlanet-PUBLIC-METHOD 093 */ 094 public static Client getDefaultInstance() { 095 String def = (clientTypesManager != null) ? 096 clientTypesManager.getDefaultClientType() : "genericHTML"; 097 Client client = (clientTypesManager != null) ? 098 clientTypesManager.getClientInstance(def) : null; 099 100 return client; 101 } 102 103 /** 104 * Returns an iterator of Client objects for all known client types. 105 * @return Iterator of Client objects 106 * 107 * iPlanet-PUBLIC-METHOD 108 */ 109 public static Iterator getAllInstances() { 110 Map allInstances = (clientTypesManager != null) ? 111 clientTypesManager.getAllClientInstances() : null; 112 if (allInstances != null) { 113 return allInstances.values().iterator(); 114 } else { 115 return null; 116 } 117 } 118}