/* * Copyright 2003 Federal Chancellery Austria * MOA-SPSS has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egovernment.moa.spss.server.invoke; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.w3c.dom.Element; import at.gv.egovernment.moa.spss.MOAApplicationException; import at.gv.egovernment.moa.spss.api.xmlbind.ProfileParser; import at.gv.egovernment.moa.spss.api.xmlsign.CreateSignatureEnvironmentProfile; import at.gv.egovernment.moa.spss.api.xmlsign.CreateSignatureEnvironmentProfileExplicit; import at.gv.egovernment.moa.spss.api.xmlsign.CreateSignatureEnvironmentProfileID; import at.gv.egovernment.moa.spss.api.xmlsign.CreateTransformsInfoProfile; import at.gv.egovernment.moa.spss.api.xmlsign.CreateTransformsInfoProfileExplicit; import at.gv.egovernment.moa.spss.api.xmlsign.CreateTransformsInfoProfileID; import at.gv.egovernment.moa.spss.api.xmlverify.SupplementProfile; import at.gv.egovernment.moa.spss.api.xmlverify.SupplementProfileExplicit; import at.gv.egovernment.moa.spss.api.xmlverify.SupplementProfileID; import at.gv.egovernment.moa.spss.api.xmlverify.VerifyTransformsInfoProfile; import at.gv.egovernment.moa.spss.api.xmlverify.VerifyTransformsInfoProfileExplicit; import at.gv.egovernment.moa.spss.api.xmlverify.VerifyTransformsInfoProfileID; import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; /** * Map ProfileID objects to their explicit represantation. * * @author Patrick Peck * @version $Id$ */ public class ProfileMapper { /** The parser to parse the profiles. */ private static ProfileParser profileParser = new ProfileParser(); /** * Map a CreateTransformsInfoProfile to a * CreateTransformsInfoProfileExplicit. * * @param profile The profile object to map. * @param config The MOA configuration to use for looking up the profile. * @return profile, if the given profile is of type * EXPLICIT_CREATETRANSFORMSINFOPROFILE, otherwise the profile * that is looked up and parsed from the configuration. * @throws MOAApplicationException An error occurred parsing the profile. */ public static CreateTransformsInfoProfileExplicit mapCreateTransformsInfoProfile( CreateTransformsInfoProfile profile, ConfigurationProvider config) throws MOAApplicationException { switch (profile.getCreateTransformsInfoProfileType()) { case CreateTransformsInfoProfile.EXPLICIT_CREATETRANSFORMSINFOPROFILE : return (CreateTransformsInfoProfileExplicit) profile; case CreateTransformsInfoProfile.ID_CREATETRANSFORMSINFOPROFILE : CreateTransformsInfoProfileID profileIdObj = (CreateTransformsInfoProfileID) profile; String profileID = profileIdObj.getCreateTransformsInfoProfileID(); Element profileElem = config.getCreateTransformsInfoProfile(profileID); if (profileElem == null) { throw new MOAApplicationException("2234", new Object[] { profileID }); } return ( CreateTransformsInfoProfileExplicit) profileParser .parseCreateTransformsInfoProfile( profileElem); } return null; // this will not happen } /** * Map a CreateSignatureEnvironmentProfile to a * CreateSignatureEnvironmentProfileExplicit. * * @param profile The profile object to map. * @param config The MOA configuration to use for looking up the profile. * @return profile, if the given profile is of type * EXPLICIT_CREATESIGNATUREENVIRONMENTPROFILE, otherwise the * profile that is looked up and parsed from the configuration. * @throws MOAApplicationException An error occurred parsing the profile. */ public static CreateSignatureEnvironmentProfileExplicit mapCreateSignatureEnvironmentProfile( CreateSignatureEnvironmentProfile profile, ConfigurationProvider config) throws MOAApplicationException { switch (profile.getCreateSignatureEnvironmentProfileType()) { case CreateSignatureEnvironmentProfile .EXPLICIT_CREATESIGNATUREENVIRONMENTPROFILE : return (CreateSignatureEnvironmentProfileExplicit) profile; case CreateSignatureEnvironmentProfile .ID_CREATESIGNATUREENVIRONMENTPROFILE : CreateSignatureEnvironmentProfileID profileIdObj = (CreateSignatureEnvironmentProfileID) profile; String profileID = profileIdObj.getCreateSignatureEnvironmentProfileID(); Element profileElem = config.getCreateSignatureEnvironmentProfile(profileID); if (profileElem == null) { throw new MOAApplicationException("2236", new Object[] { profileID }); } return ( CreateSignatureEnvironmentProfileExplicit) profileParser .parseCreateSignatureEnvironmentProfile( profileElem); } return null; } /** * Map a List of SupplementProfiles to their * explicit representation. * * @param profiles The profiles to map. * @param config The MOA configuration to use for looking up profiles. * @return The mapped profiles. * @throws MOAApplicationException An error occurred mapping one of the * profiles. */ public static List mapSupplementProfiles( List profiles, ConfigurationProvider config) throws MOAApplicationException { List mappedProfiles = new ArrayList(); Iterator iter; for (iter = profiles.iterator(); iter.hasNext();) { SupplementProfile profile = (SupplementProfile) iter.next(); mappedProfiles.add(mapSupplementProfile(profile, config)); } return mappedProfiles; } /** * Map a SupplementProfile to a * SupplementProfileExplicit. * * @param profile The profile object to map. * @param config The MOA configuration to use for looking up the profile. * @return profile, if the given profile is of type * EXPLICIT_SUPPLEMENTPROFILE, otherwise the * profile that is looked up and parsed from the configuration. * @throws MOAApplicationException An error occurred parsing the profile. */ public static SupplementProfileExplicit mapSupplementProfile( SupplementProfile profile, ConfigurationProvider config) throws MOAApplicationException { switch (profile.getSupplementProfileType()) { case SupplementProfile.EXPLICIT_SUPPLEMENTPROFILE : return (SupplementProfileExplicit) profile; case SupplementProfile.ID_SUPPLEMENTPROFILE : SupplementProfileID profileIdObj = (SupplementProfileID) profile; String profileID = profileIdObj.getSupplementProfileID(); Element profileElem = config.getSupplementProfile(profileID); if (profileElem == null) { throw new MOAApplicationException("2267", new Object[] { profileID }); } return ( SupplementProfileExplicit) profileParser.parseSupplementProfile( profileElem); } return null; } /** * Map a List of VerifyTransformsInfoProfiles to * their explicit representation. * * @param profiles The profiles to map. * @param config The MOA configuration to use for looking up profiles. * @return The mapped profiles. * @throws MOAApplicationException An error occurred mapping one of the * profiles. */ public static List mapVerifyTransformsInfoProfiles( List profiles, ConfigurationProvider config) throws MOAApplicationException { List mappedProfiles = new ArrayList(); Iterator iter; for (iter = profiles.iterator(); iter.hasNext();) { VerifyTransformsInfoProfile profile = (VerifyTransformsInfoProfile) iter.next(); mappedProfiles.add(mapVerifyTransformsInfoProfile(profile, config)); } return mappedProfiles; } /** * Map a VerifyTransformsInfoProfile to a * VerifyTransformsInfoProfileExplicit. * * @param profile The profile object to map. * @param config The MOA configuration to use for looking up the profile. * @return profile, if the given profile is of type * EXPLICIT_VERIFYTRANSFORMSINFOPROFILE, otherwise the * profile that is looked up and parsed from the configuration. * @throws MOAApplicationException An error occurred parsing the profile. */ public static VerifyTransformsInfoProfileExplicit mapVerifyTransformsInfoProfile( VerifyTransformsInfoProfile profile, ConfigurationProvider config) throws MOAApplicationException { switch (profile.getVerifyTransformsInfoProfileType()) { case VerifyTransformsInfoProfile.EXPLICIT_VERIFYTRANSFORMSINFOPROFILE : return (VerifyTransformsInfoProfileExplicit) profile; case VerifyTransformsInfoProfile.ID_VERIFYTRANSFORMSINFOPROFILE : VerifyTransformsInfoProfileID profileIdObj = (VerifyTransformsInfoProfileID) profile; String profileID = profileIdObj.getVerifyTransformsInfoProfileID(); Element profileElem = config.getVerifyTransformsInfoProfile(profileID); if (profileElem == null) { throw new MOAApplicationException("2268", new Object[] { profileID }); } return ( VerifyTransformsInfoProfileExplicit) profileParser .parseVerifyTransformsInfoProfile( profileElem); } return null; } }