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 SupplementProfile
s 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 VerifyTransformsInfoProfile
s 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;
}
}