/* The base abstract class for an ontology adapter.
Copyright (c) 2007-2014 The Regents of the University of California.
All rights reserved.
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this
software and its documentation for any purpose, provided that the above
copyright notice and the following two paragraphs appear in all copies
of this software.
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
PT_COPYRIGHT_VERSION_2
COPYRIGHTENDKEY
*/
package ptolemy.data.ontologies;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import ptolemy.actor.IOPort;
import ptolemy.actor.lib.Expression;
import ptolemy.actor.parameters.PortParameter;
import ptolemy.data.expr.ASTPtRootNode;
import ptolemy.data.expr.Parameter;
import ptolemy.data.expr.Variable;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.Entity;
import ptolemy.kernel.util.Attribute;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NamedObj;
import ptolemy.kernel.util.Settable;
import ptolemy.kernel.util.StringAttribute;
///////////////////////////////////////////////////////////////////
//// OntologyAdapter
/**
Constraints for a component in the model.
The model component can be an object of any Ptolemy class
(e.g. ASTPtRootNode, Sink, Entity, and FSMActor). A model component,
in turn, may have one or multiple property-able objects. Each
constraint is relevant to a property-able object. For example,
the PropertyAdapter associated with an actor may have each of its
IOPorts as property-able.
A property-able object is an object that can be annotated with
a Property object. Users can define different Property classes as
part of their use-case definition.
Every PropertyAdapter is associated a property
solver. PropertyAdapters support hierarchical structuring. They may
have downward links to sub-adapters. This is helpful to construct
PropertyAdapter for hierarchical component in the model. For example, a
PropertyAdapter for the CompositeActor have all the contained actors'
adapters as its sub-adapters.
A PropertyAdapter supports manual annotation. Users can define their
own annotation evaluator to evaluate property expressions and/or
constraints.
@author Man-Kit Leung
@version $Id: OntologyAdapter.java 70402 2014-10-23 00:52:20Z cxh $
@since Ptolemy II 10.0
@Pt.ProposedRating Red (mankit)
@Pt.AcceptedRating Red (mankit)
*/
public abstract class OntologyAdapter {
///////////////////////////////////////////////////////////////////
//// public methods ////
/**
* Return the associated component object.
*
* @return The associated component.
* @see #setComponent
*/
public Object getComponent() {
return _component;
}
/**
* Return the container entity for the specified ASTPtRootNode.
*
* @param node The specified ASTPtRootNode.
*
* @return The container entity for the specified ASTPtRootNode.
*/
public Entity getContainerEntity(ASTPtRootNode node) {
Attribute attribute = _solver.getAttribute(node);
NamedObj container = attribute.getContainer();
while (!(container instanceof Entity)) {
container = container.getContainer();
}
return (Entity) container;
}
/**
* Return the name of the PropertyAdapter. In this base class,
* return the concatenation of the prefix "Adapter_" and the string
* representation of the component object. This method does not
* guarantee uniqueness.
*
* @return The name of the PropertyAdapter.
*/
public String getName() {
return "Adapter_" + _component.toString();
}
/**
* Return a list of property-able NamedObj contained by the component. All
* ports and parameters are considered property-able.
* @return The list of property-able named object.
*/
public List