001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2013-2015 ForgeRock AS. 015 */ 016 017package org.forgerock.json.jose.jwe; 018 019import org.forgerock.json.jose.exceptions.JweException; 020import org.forgerock.json.jose.jwe.handlers.compression.CompressionHandler; 021import org.forgerock.json.jose.jwe.handlers.compression.DeflateCompressionHandler; 022import org.forgerock.json.jose.jwe.handlers.compression.NOPCompressionHandler; 023 024/** 025 * A service to get the appropriate CompressionHandler for a specified Compression algorithm. 026 * <p> 027 * For details of all supported algorithms see {@link CompressionAlgorithm}. 028 * 029 * @since 2.0.0 030 */ 031public class CompressionManager { 032 033 /** 034 * Gets the appropriate CompressionHandler that can perform the required compression using the given 035 * compression algorithm. 036 * 037 * @param algorithm The Compression algorithm. 038 * @return The CompressionHandler. 039 */ 040 public CompressionHandler getCompressionHandler(CompressionAlgorithm algorithm) { 041 042 switch (algorithm) { 043 case NONE: { 044 return new NOPCompressionHandler(); 045 } 046 case DEF: { 047 return new DeflateCompressionHandler(); 048 } 049 default: { 050 throw new JweException("No Compression Handler for unknown compression algorithm, " 051 + algorithm + "."); 052 } 053 } 054 } 055}