/*
 * Copyright (C) 1999-2006 <a href="mailto:paschke@in.tum.de">Adrian Paschke</a>
 * 
 * The Regression Test is part of the Rule Based Service Level Agreement (RBSLA)
 * framework, available at 
 * <a href=" http://ibis.in.tum.de/staff/paschke/rbsla/index.htm">RBSLA</a>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package rbsla.rmltoprova;

import org.jdom.*;
/**
 * ServiceDefinition
 * 
 * Translates RBSLA 0.01 general service definition into Prova facts
 * 
 * Note: Since RBSLA 0.1 the general SLA information and Service Definitions are move to the RBSLA 0.1 Semantic Web ontology
 * and can be used as types and individuals for Prova facts which represent the general info.
 * 
 * @author <A HREF="mailto:adrian.paschke@gmx.de">Adrian Paschke</A>
 * @version 0.1 <1 Feb 2005>
 * @since 0.1
 * @deprecated Since RuleML 0.87 and RBSLA 0.1 XSLT Stylesheets are provided for translation
 */
public class ServiceDefinition
{
    String slaName;
    
    Element definitionElement;
    String definitionName;
    
    Element operationElement;
    String operationOwlRef;
    String operationName;
    
    Element scheduleElement;
    String scheduleRefName;
    
    Element slaParameterElement;
    String slaParameterName;
    String slaParameterType;
    String slaParameterUnit;
    
    Element metricElement;
    String metricName;
    
    private Namespace ns;
    
    public ServiceDefinition(Element _definition,String _slaName)
    {
        definitionElement = _definition;
        slaName = _slaName;
        definitionName = definitionElement.getAttributeValue("name");
        
        operationElement = definitionElement.getChild("Operation",ns);
        operationOwlRef = operationElement.getAttributeValue("owl-ref");
        operationName = operationElement.getAttributeValue("name");
        
        scheduleElement = operationElement.getChild("Schedule-ref",ns);
        scheduleRefName = scheduleElement.getText();
        
        slaParameterElement = operationElement.getChild("SLAParameter",ns);
        slaParameterName = slaParameterElement.getAttributeValue("name");
        slaParameterType = slaParameterElement.getAttributeValue("type");
        slaParameterUnit = slaParameterElement.getAttributeValue("unit");
        
        metricElement = slaParameterElement.getChild("Metric",ns);
        metricName = metricElement.getText();
    }

    public String toString()
    {
        StringBuffer definition = new StringBuffer("\n% Service definitions in " + slaName +"\r\n");
        definition.append("serviceDefinition(\"" + definitionName + " \",\"" + slaName + "\").");
        definition.append("\n");
        definition.append("serviceOperation(\"" + operationOwlRef + "\",\"" + definitionName + "\").");
        definition.append("\n");
        definition.append("serviceOperationName(\"" + operationOwlRef + "\",\"" + operationName + "\").");
        definition.append("\n");
        definition.append("serviceOperationSchedule(\"" + scheduleRefName +"\").");
        definition.append("\n");
        definition.append("slaParameter(\"" + slaParameterName + "\",\"" + operationName + "\").");
        definition.append("\n");
        definition.append("slaParameterType(\"" + slaParameterType + "\",\"" + slaParameterName + "\").");
        definition.append("\n");
        definition.append("slaParameterUnit(\"" + slaParameterUnit + "\",\"" + slaParameterName + "\").");
        definition.append("\n");
        definition.append("slaParameterMetric(\"" + metricName + "\",\"" + slaParameterName + "\").");
        
        return definition.toString();
    }
}
