/*********************************************************************/
/* */
/* 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 System;
using AgentService.Ontology;
using AgentService.Ontology.Validation;
namespace AgentService.Ontology.Schema.Abstract
{
///
/// It's a base class that permforms the setting of attributes of primitive type, without the need of wrapping the new value in an abstract primitive.
///
public class AbsPrimitiveSlotsHolder: AbsObjectImpl
{
///
/// Constructs an abstract descriptor of the proper type.
///
/// The name of the abstract descriptor.
protected AbsPrimitiveSlotsHolder(string typeName):base(typeName)
{
}
///
/// Sets the given attribute with a string value.
///
/// The name of the attribute.
/// The new value.
public void SetAttribute(string name, string val)
{
try
{
base.SetAttribute(name, AbsPrimitive.Wrap(val));
}
catch(Exception e)
{
throw new ValidationException(e.ToString());
}
}
///
/// Sets the given attribute with a bool value.
///
/// The name of the attribute.
/// The new value.
public void SetAttribute(string name, bool val)
{
try
{
SetAttribute(name, AbsPrimitive.Wrap(val));
}
catch(Exception e)
{
throw new ValidationException(e.ToString());
}
}
///
/// Sets the given attribute with a int value.
///
/// The name of the attribute.
/// The new value.
public void SetAttribute(string name, int val)
{
try
{
SetAttribute(name, AbsPrimitive.Wrap(val));
}
catch(Exception e)
{
throw new ValidationException(e.ToString());
}
}
///
/// Sets the given attribute with a long value.
///
/// The name of the attribute.
/// The new value.
public void SetAttribute(string name, long val)
{
try
{
SetAttribute(name, AbsPrimitive.Wrap(val));
}
catch(Exception e)
{
throw new ValidationException(e.ToString());
}
}
///
/// Sets the given attribute with a float value.
///
/// The name of the attribute.
/// The new value.
public void SetAttribute(string name, float val)
{
try
{
SetAttribute(name, AbsPrimitive.Wrap(val));
}
catch(Exception e)
{
throw new ValidationException(e.ToString());
}
}
///
/// Sets the given attribute with a double value.
///
/// The name of the attribute.
/// The new value.
public void SetAttribute(string name, double val)
{
try
{
SetAttribute(name, AbsPrimitive.Wrap(val));
}
catch(Exception e)
{
throw new ValidationException(e.ToString());
}
}
///
/// Sets the given attribute with a DateTime value.
///
/// The name of the attribute.
/// The new value.
public void SetAttribute(string name, DateTime val)
{
SetAttribute(name, AbsPrimitive.Wrap(val));
}
///
/// Sets the given attribute with a byte[] value.
///
/// The name of the attribute.
/// The new value.
public void SetAttribute(string name, byte[] val)
{
SetAttribute(name, AbsPrimitive.Wrap(val));
}
///
/// Returns the string value of a given attribute.
///
/// The name of the attribute.
///
public string GetString(string name)
{
AbsPrimitive p = (AbsPrimitive) GetAbsObject(name);
if (p != null)
{
return p.GetString();
}
else
{
return null;
}
}
///
/// Returns the boolean value of a given attribute.
///
/// The name of the attribute.
///
public bool GetBoolean(string name)
{
return ((AbsPrimitive) GetAbsObject(name)).GetBoolean();
}
///
/// Returns the integer value of a given attribute.
///
/// The name of the attribute.
///
public int GetInteger(string name)
{
return ((AbsPrimitive) GetAbsObject(name)).GetInteger();
}
///
/// Returns the long value of a given attribute.
///
/// The name of the attribute.
///
public long GetLong(string name)
{
return ((AbsPrimitive) GetAbsObject(name)).GetLong();
}
///
/// Returns the float value of a given attribute.
///
/// The name of the attribute.
///
public float GetFloat(string name)
{
return ((AbsPrimitive) GetAbsObject(name)).GetFloat();
}
///
/// Returns the double value of a given attribute.
///
/// The name of the attribute.
///
public double GetDouble(string name)
{
return ((AbsPrimitive) GetAbsObject(name)).GetDouble();
}
///
/// Returns the DateTime value of a given attribute.
///
/// The name of the attribute.
///
public DateTime GetDate(string name)
{
AbsPrimitive p = (AbsPrimitive) GetAbsObject(name);
return p.GetDate();
}
///
/// Returns the byte[] value of a given attribute.
///
/// The name of the attribute.
///
public byte[] GetByteSequence(string name)
{
AbsPrimitive p = (AbsPrimitive) GetAbsObject(name);
if (p != null)
{
return p.GetByteSequence();
}
else
{
return null;
}
}
}
}