# Path: orangengine/models/base/baseservicegroup.py
# class BaseServiceGroup(BaseObject):
# 
#     def __init__(self, name):
#         """init a service group"""
# 
#         self.name = name
#         self.elements = list()
# 
#     def add(self, service):
#         """add a service"""
# 
#         self.elements.append(service)
# 
#     def __getattr__(self, item):
#         """
#         yield the values of the underlying objects
#         """
# 
#         if item == 'value':
#             return [s.value for s in self.elements]
#         else:
#             raise AttributeError
# 
#     def table_value(self, with_names):
#         value = "Group: " + self.name + "\n"
#         for s in self.elements:
#             value = value + "   " + s.table_value(with_names) + "\n"
#         return value.rstrip('\n')  # remove the last new line
# 
#     def serialize(self):
#         """Searialize self to a json acceptable data structure
#         """
# 
#         elements = []
#         for e in self.elements:
#             elements.append(e.serialize())
# 
#         return {
#             'name': self.name,
#             'elements': elements
#         }
# 
# Path: orangengine/utils.py
# def create_element(tag, text=None, parent=None):
#     # create an ambiguous xml element
#     if parent is not None:
#         e = letree.SubElement(parent, tag)
#     else:
#         e = letree.Element(tag)
#     if text:
#         e.text = text
#     return e


from orangengine.models.base import BaseServiceGroup
from orangengine.utils import create_element
# -*- coding: utf-8 -*-


class JuniperSRXServiceGroup(BaseServiceGroup):

    def __init__(self, name):

        super(JuniperSRXServiceGroup, self).__init__(name)

    def to_xml(self):
        """Map service group objects to juniper SRX config tree elements
        """

        servicegroup_element = create_element('application-set')
        create_element('name', text=self.name, parent=servicegroup_element)
        for service in self.elements:

# Path: orangengine/models/base/baseservicegroup.py
# class BaseServiceGroup(BaseObject):
# 
#     def __init__(self, name):
#         """init a service group"""
# 
#         self.name = name
#         self.elements = list()
# 
#     def add(self, service):
#         """add a service"""
# 
#         self.elements.append(service)
# 
#     def __getattr__(self, item):
#         """
#         yield the values of the underlying objects
#         """
# 
#         if item == 'value':
#             return [s.value for s in self.elements]
#         else:
#             raise AttributeError
# 
#     def table_value(self, with_names):
#         value = "Group: " + self.name + "\n"
#         for s in self.elements:
#             value = value + "   " + s.table_value(with_names) + "\n"
#         return value.rstrip('\n')  # remove the last new line
# 
#     def serialize(self):
#         """Searialize self to a json acceptable data structure
#         """
# 
#         elements = []
#         for e in self.elements:
#             elements.append(e.serialize())
# 
#         return {
#             'name': self.name,
#             'elements': elements
#         }
# 
# Path: orangengine/utils.py
# def create_element(tag, text=None, parent=None):
#     # create an ambiguous xml element
#     if parent is not None:
#         e = letree.SubElement(parent, tag)
#     else:
#         e = letree.Element(tag)
#     if text:
#         e.text = text
#     return e


# Path: orangengine/models/juniper/servicegroup.py
from orangengine.models.base import BaseServiceGroup
from orangengine.utils import create_element

# -*- coding: utf-8 -*-


class JuniperSRXServiceGroup(BaseServiceGroup):

    def __init__(self, name):

        super(JuniperSRXServiceGroup, self).__init__(name)

    def to_xml(self):
        """Map service group objects to juniper SRX config tree elements
        """

        servicegroup_element = create_element('application-set')
        create_element('name', text=self.name, parent=servicegroup_element)
        for service in self.elements:

            service_element = create_element('application', parent=servicegroup_element)