/*********************************************************************/
/* */
/* 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 primitive entities in an ontology.
///
public class PrimitiveSchema : TermSchema {
public static readonly new string base_name = "Primitive";
private static new PrimitiveSchema baseSchema = new PrimitiveSchema();
///
/// Constructs a primitive schema.
///
private PrimitiveSchema():base(base_name)
{
}
///
/// Constructs a primitive schema with a given name.
///
///
public PrimitiveSchema(string typeName):base(typeName)
{
}
///
/// Retrieves a generic baseschema for all primitives.
///
///
public static new ObjectSchema GetBaseSchema()
{
return baseSchema;
}
///
/// 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)
{
try
{
if (s != null)
{
if (s.Equals(GetBaseSchema()))
{
return true;
}
return base.DescendsFrom(s);
}
else
{
return false;
}
}
catch(Exception ex)
{
throw new OntologyException(ex.ToString());
}
}
///
/// Returns an abstract object that represents this primitive.
///
///
public override AbsObject NewInstance()
{
return new AbsPrimitive(GetTypeName());
}
///
/// Validates a given abstract object, using a given ontology.
///
/// The abstract object to Validate.
/// The ontology to use.
public override void Validate(AbsObject abs, Ontology onto)
{
try
{
if (!(abs is AbsPrimitive))
{
throw new ValidationException(abs+" is not an AbsPrimitive");
}
}
catch(Exception ex)
{
throw new ValidationException("Unable to Validate "+abs+": "+ex.ToString());
}
}
}
}