/*********************************************************************/
/* */
/* AgentService Framework */
/* www.agentservice.it */
/* */
/* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */
/* GNU Lesser General Public License */
/* */
/* 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, */
/* version 2.1 of the License. */
/* */
/* 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. */
/* */
/*********************************************************************/
using AgentService.Ontology;
using AgentService.Ontology.Schema.Abstract;
using System;
using AgentService.Ontology.Validation;
namespace AgentService.Ontology.Schema
{
///
/// This class represents the schema of a variable.
///
public class VariableSchema : TermSchema
{
public static readonly new string base_name = "Variable";
private static new VariableSchema baseSchema = new VariableSchema();
public static readonly string name = "Name";
public static readonly string value_type = "Value_type";
///
/// Constructs a generic schema.
///
public VariableSchema():base(base_name)
{
try
{
Add("Name", BasicOntology.singletonBasicOntology.GetSchema(BasicOntology.BO_string));
Add("Value_type", BasicOntology.singletonBasicOntology.GetSchema(BasicOntology.BO_string), ObjectSchema.optional);
}
catch(Exception ex)
{
throw new OntologyException(ex.ToString());
}
}
///
/// Retrieves a generic baseschema for all variables.
///
///
public static new ObjectSchema GetBaseSchema()
{
return baseSchema;
}
///
/// A variable can be put whereever a term of whatever type is required.
///
///
///
public new bool IsCompatibleWith(ObjectSchema s)
{
try
{
if (s != null)
{
return s.DescendsFrom(TermSchema.GetBaseSchema());
}
else
{
return false;
}
}
catch(Exception ex)
{
throw new ValidationException(ex.ToString());
}
}
///
/// Returns true if
///- s is the base schema for the XXXSchema class and this schema is
/// an instance of (e.g. s is ConceptSchema.GetBaseSchema() and this
/// schema is an instance of ConceptSchema)
/// - s is the base schema for a super-class of the XXXSchema class and
/// this schema is an instance of (e.g. s is TermSchema.GetBaseSchema()
/// and this schema is an instance of ConceptSchema.
///
/// Object schema
/// Returns true if s is a base schema for this schema.
public override bool DescendsFrom(ObjectSchema s) //override?
{
try
{
if (s != null)
{
if (s.Equals(GetBaseSchema()))
{
return true;
}
return base.DescendsFrom(s);
}
else
{
return false;
}
}
catch(Exception ex)
{
throw new ValidationException(ex.ToString());
}
}
///
/// Returns an abstract object that represents this variable.
///
///
public override AbsObject NewInstance()
{
return new AbsVariable("Name","Value_type");
}
}
}