org.wso2.balana.utils.exception.PolicyBuilderException Java Examples

The following examples show how to use org.wso2.balana.utils.exception.PolicyBuilderException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PolicyUtils.java    From balana with Apache License 2.0 6 votes vote down vote up
public static Element createRequestElement(RequestElementDTO requestElementDTO, Document doc)
        throws PolicyBuilderException {

    Element requestElement = doc.createElement(PolicyConstants.Request.REQUEST_ELEMENT);
    requestElement.setAttribute("xmlns", PolicyConstants.Request.REQ_RES_CONTEXT_XACML3);
    requestElement.setAttribute(PolicyConstants.Request.RETURN_POLICY_LIST ,
            Boolean.toString(requestElementDTO.isReturnPolicyIdList()));
    requestElement.setAttribute(PolicyConstants.Request.COMBINED_DECISION ,
            Boolean.toString(requestElementDTO.isCombinedDecision()));
    
    List<AttributesElementDTO>  attributesElementDTOs = requestElementDTO.getAttributesElementDTOs();
    if(attributesElementDTOs != null && attributesElementDTOs.size() > 0){
        for(AttributesElementDTO dto : attributesElementDTOs){
            requestElement.appendChild(createAttributesElement(dto,doc));
        }
    }
    return requestElement;
}
 
Example #2
Source File: EntitlementPolicyCreator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Create XACML policy using the data received from basic policy wizard
 *
 * @param basicPolicyDTO BasicPolicyDTO
 * @return String object of the XACML policy
 * @throws PolicyEditorException throws
 */
public String createBasicPolicy(BasicPolicyDTO basicPolicyDTO) throws PolicyEditorException {

    if (basicPolicyDTO == null) {
        throw new PolicyEditorException("Policy object can not be null");
    }

    try {
        return PolicyBuilder.getInstance().build(basicPolicyDTO);
    } catch (PolicyBuilderException e) {
        log.error(e);
        throw new PolicyEditorException("Error while building policy");
    }
}
 
Example #3
Source File: EntitlementPolicyCreator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Create XACML policy using the data received from basic policy wizard
 *
 * @param policyDTO PolicyDTO
 * @return String object of the XACML policy
 * @throws PolicyEditorException throws
 */
public String createPolicy(PolicyDTO policyDTO) throws PolicyEditorException {

    if (policyDTO == null) {
        throw new PolicyEditorException("Policy object can not be null");
    }

    PolicyElementDTO policyElementDTO = new PolicyElementDTO();
    policyElementDTO.setPolicyName(policyDTO.getPolicyId());
    policyElementDTO.setRuleCombiningAlgorithms(policyDTO.getRuleAlgorithm());
    policyElementDTO.setPolicyDescription(policyDTO.getDescription());
    policyElementDTO.setVersion(policyDTO.getVersion());

    if (policyDTO.getTargetDTO() != null) {
        TargetElementDTO targetElementDTO = PolicyEditorUtil.
                createTargetElementDTO(policyDTO.getTargetDTO());
        policyElementDTO.setTargetElementDTO(targetElementDTO);
    }

    if (policyDTO.getRuleDTOs() != null) {
        for (RuleDTO ruleDTO : policyDTO.getRuleDTOs()) {
            RuleElementDTO ruleElementDTO = PolicyEditorUtil.createRuleElementDTO(ruleDTO);
            policyElementDTO.addRuleElementDTO(ruleElementDTO);
        }
    }

    if (policyDTO.getObligationDTOs() != null) {
        List<ObligationElementDTO> obligationElementDTOs = PolicyEditorUtil.
                createObligation(policyDTO.getObligationDTOs());
        policyElementDTO.setObligationElementDTOs(obligationElementDTOs);
    }

    try {
        return PolicyBuilder.getInstance().build(policyElementDTO);
    } catch (PolicyBuilderException e) {
        throw new PolicyEditorException("Error while building XACML Policy");
    }
}
 
Example #4
Source File: EntitlementPolicyCreator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Create basic XACML request
 *
 * @param requestDTO request element
 * @return String object of the XACML request
 * @throws EntitlementPolicyCreationException throws
 */
public String createBasicRequest(RequestDTO requestDTO)
        throws EntitlementPolicyCreationException, PolicyEditorException {
    try {

        RequestElementDTO requestElementDTO = PolicyCreatorUtil.createRequestElementDTO(requestDTO);
        return PolicyBuilder.getInstance().buildRequest(requestElementDTO);
    } catch (PolicyBuilderException e) {
        throw new PolicyEditorException("Error while building XACML Request");
    }

}
 
Example #5
Source File: EntitlementPolicyCreator.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Create XACML policy using the data received from basic policy wizard
 *
 * @param basicPolicyDTO BasicPolicyDTO
 * @return String object of the XACML policy
 * @throws PolicyEditorException throws
 */
public String createBasicPolicy(BasicPolicyDTO basicPolicyDTO) throws PolicyEditorException {

    if (basicPolicyDTO == null) {
        throw new PolicyEditorException("Policy object can not be null");
    }

    try {
        return PolicyBuilder.getInstance().build(basicPolicyDTO);
    } catch (PolicyBuilderException e) {
        log.error(e);
        throw new PolicyEditorException("Error while building policy");
    }
}
 
Example #6
Source File: EntitlementPolicyCreator.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Create XACML policy using the data received from basic policy wizard
 *
 * @param policyDTO PolicyDTO
 * @return String object of the XACML policy
 * @throws PolicyEditorException throws
 */
public String createPolicy(PolicyDTO policyDTO) throws PolicyEditorException {

    if (policyDTO == null) {
        throw new PolicyEditorException("Policy object can not be null");
    }

    PolicyElementDTO policyElementDTO = new PolicyElementDTO();
    policyElementDTO.setPolicyName(policyDTO.getPolicyId());
    policyElementDTO.setRuleCombiningAlgorithms(policyDTO.getRuleAlgorithm());
    policyElementDTO.setPolicyDescription(policyDTO.getDescription());
    policyElementDTO.setVersion(policyDTO.getVersion());

    if (policyDTO.getTargetDTO() != null) {
        TargetElementDTO targetElementDTO = PolicyEditorUtil.
                createTargetElementDTO(policyDTO.getTargetDTO());
        policyElementDTO.setTargetElementDTO(targetElementDTO);
    }

    if (policyDTO.getRuleDTOs() != null) {
        for (RuleDTO ruleDTO : policyDTO.getRuleDTOs()) {
            RuleElementDTO ruleElementDTO = PolicyEditorUtil.createRuleElementDTO(ruleDTO);
            policyElementDTO.addRuleElementDTO(ruleElementDTO);
        }
    }

    if (policyDTO.getObligationDTOs() != null) {
        List<ObligationElementDTO> obligationElementDTOs = PolicyEditorUtil.
                createObligation(policyDTO.getObligationDTOs());
        policyElementDTO.setObligationElementDTOs(obligationElementDTOs);
    }

    try {
        return PolicyBuilder.getInstance().build(policyElementDTO);
    } catch (PolicyBuilderException e) {
        throw new PolicyEditorException("Error while building XACML Policy");
    }
}
 
Example #7
Source File: EntitlementPolicyCreator.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Create basic XACML request
 *
 * @param requestDTO request element
 * @return String object of the XACML request
 * @throws EntitlementPolicyCreationException throws
 */
public String createBasicRequest(RequestDTO requestDTO)
        throws EntitlementPolicyCreationException, PolicyEditorException {
    try {

        RequestElementDTO requestElementDTO = PolicyCreatorUtil.createRequestElementDTO(requestDTO);
        return PolicyBuilder.getInstance().buildRequest(requestElementDTO);
    } catch (PolicyBuilderException e) {
        throw new PolicyEditorException("Error while building XACML Request");
    }

}
 
Example #8
Source File: PolicyUtils.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * This method creates a match elementof the XACML policy
 * @param matchElementDTO match element data object
 * @param doc XML document
 * @return match Element
 * @throws PolicyBuilderException throws
 */
public static Element createMatchElement(MatchElementDTO matchElementDTO,
                                         Document doc) throws PolicyBuilderException {

    Element matchElement = null;
    if(matchElementDTO.getMatchId() != null && matchElementDTO.getMatchId().trim().length() > 0) {

        matchElement = doc.createElement(PolicyConstants.MATCH_ELEMENT);

        matchElement.setAttribute(PolicyConstants.MATCH_ID,
                matchElementDTO.getMatchId());

        if(matchElementDTO.getAttributeValueElementDTO() != null) {
            Element attributeValueElement = createAttributeValueElement(matchElementDTO.
                    getAttributeValueElementDTO(), doc);
            matchElement.appendChild(attributeValueElement);
        }

        if(matchElementDTO.getAttributeDesignatorDTO() != null ) {
            Element attributeDesignatorElement = createAttributeDesignatorElement(matchElementDTO.
                    getAttributeDesignatorDTO(), doc);
            matchElement.appendChild(attributeDesignatorElement);
        }

        if(matchElementDTO.getAttributeSelectorDTO() != null ) {
            Element attributeSelectorElement = createAttributeSelectorElement(matchElementDTO.
                    getAttributeSelectorDTO(), doc);
            matchElement.appendChild(attributeSelectorElement);
        }
    }
    return matchElement;
}
 
Example #9
Source File: PolicyUtils.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of obligation Element  using List of ObligationElementDTO object
 *
 * @param obligationElementDTOs List of ObligationElementDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createObligationsElement(List<ObligationElementDTO> obligationElementDTOs,
                                               Document doc) throws PolicyBuilderException {


    Element obligationExpressions = null;

    if(obligationElementDTOs != null && obligationElementDTOs.size() > 0){

        for(ObligationElementDTO dto : obligationElementDTOs){
            String id = dto.getId();
            String effect = dto.getEffect();

            if(id != null && id.trim().length() > 0 && effect != null){
                if(obligationExpressions == null){
                    obligationExpressions = doc.
                            createElement(PolicyConstants.OBLIGATION_EXPRESSIONS);
                }
                Element obligationExpression = doc.
                        createElement(PolicyConstants.OBLIGATION_EXPRESSION);
                obligationExpression.setAttribute(PolicyConstants.OBLIGATION_ID, id);
                obligationExpression.setAttribute(PolicyConstants.OBLIGATION_EFFECT,
                        effect);
                List<AttributeAssignmentElementDTO> elementDTOs = dto.getAssignmentElementDTOs();
                if(elementDTOs != null){
                    for(AttributeAssignmentElementDTO elementDTO : elementDTOs){
                        Element element = createAttributeAssignmentElement(elementDTO, doc);
                        if(element != null){
                            obligationExpression.appendChild(element);
                        }
                    }
                }
                obligationExpressions.appendChild(obligationExpression);
            }
        }
    }

    return obligationExpressions;
}
 
Example #10
Source File: PolicyUtils.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of advice element using List of ObligationElementDTO object
 *
 * @param obligationElementDTOs List of ObligationElementDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createAdvicesElement(List<ObligationElementDTO> obligationElementDTOs,
                                               Document doc) throws PolicyBuilderException {

    Element adviceExpressions = null;

    if(obligationElementDTOs != null && obligationElementDTOs.size() > 0){

        for(ObligationElementDTO dto : obligationElementDTOs){
            String id = dto.getId();
            String effect = dto.getEffect();

            if(id != null && id.trim().length() > 0 && effect != null){
                if(adviceExpressions == null){
                    adviceExpressions = doc.
                            createElement(PolicyConstants.ADVICE_EXPRESSIONS);
                }

                Element adviceExpression = doc.
                        createElement(PolicyConstants.ADVICE_EXPRESSION);
                adviceExpression.setAttribute(PolicyConstants.ADVICE_ID, id);
                adviceExpression.setAttribute(PolicyConstants.ADVICE_EFFECT, effect);
                List<AttributeAssignmentElementDTO> elementDTOs = dto.getAssignmentElementDTOs();
                if(elementDTOs != null){
                    for(AttributeAssignmentElementDTO elementDTO : elementDTOs){
                        Element element = createAttributeAssignmentElement(elementDTO, doc);
                        if(element != null){
                            adviceExpression.appendChild(element);
                        }
                    }
                }
                adviceExpressions.appendChild(adviceExpression);
            }
        }
    }

    return adviceExpressions;
}
 
Example #11
Source File: PolicyUtils.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of target element using TargetElementDTO object
 *
 * @param targetElementDTO TargetElementDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createTargetElement(TargetElementDTO targetElementDTO,
                                                Document doc) throws PolicyBuilderException {

    Element targetElement = doc.createElement(PolicyConstants.TARGET_ELEMENT);
    List<AnyOfElementDTO> anyOfElementDTOs = targetElementDTO.getAnyOfElementDTOs();

    for(AnyOfElementDTO anyOfElementDTO : anyOfElementDTOs){
        Element anyOfElement = doc.createElement(PolicyConstants.ANY_OF_ELEMENT);
        List<AllOfElementDTO> allOfElementDTOs = anyOfElementDTO.getAllOfElementDTOs();

        for(AllOfElementDTO allOfElementDTO : allOfElementDTOs){
            Element allOfElement = doc.createElement(PolicyConstants.ALL_OF_ELEMENT);
            List<MatchElementDTO> matchElementDTOs =  allOfElementDTO.getMatchElementDTOs();

            for(MatchElementDTO matchElementDTO : matchElementDTOs){
                Element matchElement = createMatchElement(matchElementDTO, doc);

                allOfElement.appendChild(matchElement);
            }

            anyOfElement.appendChild(allOfElement);
        }

        targetElement.appendChild(anyOfElement);
    }

    return targetElement;

}
 
Example #12
Source File: PolicyUtils.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * This creates XML representation of condition element using ConditionElementDT0 object
 *
 * @param conditionElementDT0 ConditionElementDT0
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createConditionElement(ConditionElementDT0 conditionElementDT0,
                                             Document doc) throws PolicyBuilderException {

    Element conditionElement = doc.createElement(PolicyConstants.CONDITION_ELEMENT);

    if(conditionElementDT0.getApplyElement() != null){
        conditionElement.appendChild(createApplyElement(conditionElementDT0.getApplyElement(), doc));

    } else if(conditionElementDT0.getAttributeValueElementDTO() != null) {
        Element attributeValueElement = createAttributeValueElement(conditionElementDT0.
                getAttributeValueElementDTO(), doc);
        conditionElement.appendChild(attributeValueElement);

    } else if(conditionElementDT0.getAttributeDesignator() != null) {
        AttributeDesignatorDTO attributeDesignatorDTO = conditionElementDT0.getAttributeDesignator();
        conditionElement.appendChild(createAttributeDesignatorElement(attributeDesignatorDTO, doc));

    } else if(conditionElementDT0.getFunctionFunctionId() != null) {
        Element functionElement = doc.createElement(PolicyConstants.FUNCTION_ELEMENT);
        functionElement.setAttribute(PolicyConstants.FUNCTION_ID,
                conditionElementDT0.getFunctionFunctionId());
        conditionElement.appendChild(functionElement);
    } else if(conditionElementDT0.getVariableId() != null){
        Element variableReferenceElement = doc.createElement(PolicyConstants.
                VARIABLE_REFERENCE);
        variableReferenceElement.setAttribute(PolicyConstants.VARIABLE_ID,
                conditionElementDT0.getVariableId());
        conditionElement.appendChild(variableReferenceElement);
    }

    return conditionElement;

}
 
Example #13
Source File: PolicyUtils.java    From balana with Apache License 2.0 4 votes vote down vote up
/**
 * This creates XML representation of attribute designator Element using AttributeDesignatorDTO object
 *
 * @param attributeDesignatorDTO  AttributeDesignatorDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createAttributeDesignatorElement(AttributeDesignatorDTO
                           attributeDesignatorDTO, Document doc) throws PolicyBuilderException {

    String attributeDesignatorElementName = PolicyConstants.ATTRIBUTE_DESIGNATOR;

    Element attributeDesignatorElement = doc.createElement(attributeDesignatorElementName);

    String attributeId = attributeDesignatorDTO.getAttributeId();
    String category = attributeDesignatorDTO.getCategory();

    if(attributeId != null && attributeId.trim().length() > 0 && category != null &&
            category.trim().length() > 0){

        attributeDesignatorElement.setAttribute(PolicyConstants.ATTRIBUTE_ID,
                attributeDesignatorDTO.getAttributeId());

        attributeDesignatorElement.setAttribute(PolicyConstants.CATEGORY,
                attributeDesignatorDTO.getCategory());

        if(attributeDesignatorDTO.getDataType() != null && attributeDesignatorDTO.
                getDataType().trim().length() > 0) {
            attributeDesignatorElement.setAttribute(PolicyConstants.DATA_TYPE,
                    attributeDesignatorDTO.getDataType());
        } else {
            attributeDesignatorElement.setAttribute(PolicyConstants.DATA_TYPE,
                    PolicyConstants.STRING_DATA_TYPE);
        }

        if(attributeDesignatorDTO.getIssuer() != null && attributeDesignatorDTO.getIssuer().
                trim().length() > 0) {
            attributeDesignatorElement.setAttribute(PolicyConstants.ISSUER,
                    attributeDesignatorDTO.getIssuer());
        }

        if(attributeDesignatorDTO.getMustBePresent() != null && attributeDesignatorDTO.
                getMustBePresent().trim().length() > 0){
            attributeDesignatorElement.setAttribute(PolicyConstants.MUST_BE_PRESENT,
                    attributeDesignatorDTO.getMustBePresent());
        } else {
            attributeDesignatorElement.setAttribute(PolicyConstants.MUST_BE_PRESENT,
                    "true");
        }
    } else {
        throw new PolicyBuilderException("Category  name can not be null");  // TODO
    }

    return attributeDesignatorElement;
}
 
Example #14
Source File: PolicyUtils.java    From balana with Apache License 2.0 4 votes vote down vote up
/**
 * This creates XML representation of assignment element using AttributeAssignmentElementDTO object
 *
 * @param assignmentElementDTO AttributeAssignmentElementDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createAttributeAssignmentElement(AttributeAssignmentElementDTO assignmentElementDTO,
                                                       Document doc) throws PolicyBuilderException {

    String attributeId = assignmentElementDTO.getAttributeId();

    if(attributeId != null && attributeId.trim().length() > 0){

        String category = assignmentElementDTO.getCategory();
        String issuer = assignmentElementDTO.getIssuer();
        ApplyElementDTO applyElementDTO = assignmentElementDTO.getApplyElementDTO();
        AttributeDesignatorDTO designatorDTO = assignmentElementDTO.getDesignatorDTO();
        AttributeValueElementDTO valueElementDTO = assignmentElementDTO.getValueElementDTO();

        Element attributeAssignment = doc.
                createElement(PolicyConstants.ATTRIBUTE_ASSIGNMENT);
        attributeAssignment.setAttribute(PolicyConstants.ATTRIBUTE_ID,
                attributeId);
        if(category != null && category.trim().length() > 0){
            attributeAssignment.setAttribute(PolicyConstants.CATEGORY, category);
        }

        if(issuer != null && issuer.trim().length() > 0){
            attributeAssignment.setAttribute(PolicyConstants.ISSUER, issuer);
        }

        if(applyElementDTO != null){
            attributeAssignment.appendChild(createApplyElement(applyElementDTO, doc));
        }

        if(designatorDTO != null){
            attributeAssignment.appendChild(createAttributeDesignatorElement(designatorDTO, doc));
        }

        if(valueElementDTO != null){
            attributeAssignment.appendChild(createAttributeValueElement(valueElementDTO, doc));
        }

        return attributeAssignment;
    }

    return null;
}
 
Example #15
Source File: PolicyUtils.java    From balana with Apache License 2.0 4 votes vote down vote up
/**
 * This creates XML representation of rule element using RuleElementDTO object
 *
 * @param ruleElementDTO RuleElementDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createRuleElement(RuleElementDTO ruleElementDTO, Document doc) throws PolicyBuilderException {

    TargetElementDTO targetElementDTO = ruleElementDTO.getTargetElementDTO();
    ConditionElementDT0 conditionElementDT0 = ruleElementDTO.getConditionElementDT0();
    List<ObligationElementDTO> obligationElementDTOs = ruleElementDTO.getObligationElementDTOs();

    Element ruleElement = doc.createElement(PolicyConstants.RULE_ELEMENT);

    if(ruleElementDTO.getRuleId() != null && ruleElementDTO.getRuleId().trim().length() > 0){
        ruleElement.setAttribute(PolicyConstants.RULE_ID, ruleElementDTO.getRuleId());
    }

    if(ruleElementDTO.getRuleEffect() != null && ruleElementDTO.getRuleEffect().trim().length() > 0){
        ruleElement.setAttribute(PolicyConstants.RULE_EFFECT,
                ruleElementDTO.getRuleEffect());
    }

    if(ruleElementDTO.getRuleDescription() != null && ruleElementDTO.getRuleDescription().
            trim().length() > 0){
        Element descriptionElement = doc.createElement(PolicyConstants.
                DESCRIPTION_ELEMENT);
        descriptionElement.setTextContent(ruleElementDTO.getRuleDescription());
        ruleElement.appendChild(descriptionElement);
    }

    if(targetElementDTO != null ){
        Element targetElement = createTargetElement(targetElementDTO, doc);
        ruleElement.appendChild(targetElement);
    }

    if(conditionElementDT0 != null){
        ruleElement.appendChild(createConditionElement(conditionElementDT0, doc));
    }

    if(obligationElementDTOs != null && obligationElementDTOs.size() > 0){
        List<ObligationElementDTO> obligations = new ArrayList<ObligationElementDTO>();
        List<ObligationElementDTO> advices = new ArrayList<ObligationElementDTO>();
        for(ObligationElementDTO obligationElementDTO : obligationElementDTOs){
            if(obligationElementDTO.getType() == ObligationElementDTO.ADVICE){
                advices.add(obligationElementDTO);
            } else {
                obligations.add(obligationElementDTO);
            }
        }
        Element obligation = createObligationsElement(obligations, doc);
        Element advice = createAdvicesElement(advices, doc);
        if(obligation != null){
            ruleElement.appendChild(obligation);
        }
        if(advice != null){
            ruleElement.appendChild(advice);
        }
    }

    return ruleElement;
}
 
Example #16
Source File: PolicyUtils.java    From balana with Apache License 2.0 4 votes vote down vote up
/**
 * This creates XML representation of apply element using ApplyElementDTO object
 *
 * @param applyElementDTO ApplyElementDTO
 * @param doc Document
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createApplyElement(ApplyElementDTO applyElementDTO,
                                                Document doc) throws PolicyBuilderException {

    Element applyElement = doc.createElement(PolicyConstants.APPLY_ELEMENT);

    if(applyElementDTO.getFunctionId() != null && applyElementDTO.getFunctionId().trim().length() > 0){
        applyElement.setAttribute(PolicyConstants.FUNCTION_ID,
                applyElementDTO.getFunctionId());
    }

    if(applyElementDTO.getFunctionFunctionId() != null && applyElementDTO.
            getFunctionFunctionId().trim().length() > 0){
        FunctionElementDTO functionElementDTO = new FunctionElementDTO();
        functionElementDTO.setFunctionId(applyElementDTO.getFunctionFunctionId());
        Element functionElement = createFunctionElement(functionElementDTO, doc);
        applyElement.appendChild(functionElement);
    }

    List<ApplyElementDTO> applyElementDTOs = applyElementDTO.getApplyElements();

    if(applyElementDTOs != null && applyElementDTOs.size() > 0) {

        for(ApplyElementDTO elementDTO : applyElementDTOs) {
            Element subApplyElement = createApplyElement(elementDTO, doc);
            applyElement.appendChild(subApplyElement);
        }
    }

    List<AttributeValueElementDTO> attributeValueElementDTOs = applyElementDTO.
            getAttributeValueElementDTOs();
    if(attributeValueElementDTOs != null && attributeValueElementDTOs.size() > 0) {

        for(AttributeValueElementDTO attributeValueElementDTO : attributeValueElementDTOs) {
            Element attributeValueElement = createAttributeValueElement(attributeValueElementDTO,
                    doc);

            applyElement.appendChild(attributeValueElement);
        }
    }

    List<AttributeDesignatorDTO> attributeDesignatorDTOs = applyElementDTO.getAttributeDesignators();
    if(attributeDesignatorDTOs != null && attributeDesignatorDTOs.size() > 0) {

        for(AttributeDesignatorDTO attributeDesignatorDTO : attributeDesignatorDTOs) {
            Element attributeDesignatorElement =
                    createAttributeDesignatorElement(attributeDesignatorDTO, doc);
            applyElement.appendChild(attributeDesignatorElement);
        }
    }

    List<AttributeSelectorDTO> attributeSelectorDTOs = applyElementDTO.getAttributeSelectors();
    if(attributeSelectorDTOs != null && attributeSelectorDTOs.size() > 0) {

        for(AttributeSelectorDTO attributeSelectorDTO : attributeSelectorDTOs) {
            Element attributeSelectorElement = createAttributeSelectorElement(attributeSelectorDTO,
                    doc);
            applyElement.appendChild(attributeSelectorElement);
        }
    }
    return applyElement;
}