2ronwalf// The MIT License
2ronwalf//
2ronwalf// Copyright (c) 2004 Evren Sirin
2ronwalf//
2ronwalf// Permission is hereby granted, free of charge, to any person obtaining a copy
2ronwalf// of this software and associated documentation files (the "Software"), to
2ronwalf// deal in the Software without restriction, including without limitation the
2ronwalf// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2ronwalf// sell copies of the Software, and to permit persons to whom the Software is
2ronwalf// furnished to do so, subject to the following conditions:
2ronwalf//
2ronwalf// The above copyright notice and this permission notice shall be included in
2ronwalf// all copies or substantial portions of the Software.
2ronwalf//
2ronwalf// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2ronwalf// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2ronwalf// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2ronwalf// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2ronwalf// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2ronwalf// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2ronwalf// IN THE SOFTWARE.
2ronwalf
2ronwalf/*
2ronwalf * Created on Dec 27, 2003
2ronwalf *
2ronwalf */
23daenzeroramapackage impl.owls.process;
2ronwalf
2ronwalfimport impl.owl.WrappedIndividual;
2ronwalf
2ronwalfimport java.net.URI;
2ronwalf
2ronwalfimport org.mindswap.owl.OWLDataValueList;
2ronwalfimport org.mindswap.owl.OWLIndividual;
2ronwalfimport org.mindswap.owl.OWLType;
2ronwalfimport org.mindswap.owls.OWLSFactory;
2ronwalfimport org.mindswap.owls.process.Condition;
2ronwalfimport org.mindswap.owls.process.ConditionList;
2ronwalfimport org.mindswap.owls.process.Input;
2ronwalfimport org.mindswap.owls.process.InputList;
2ronwalfimport org.mindswap.owls.process.Local;
2ronwalfimport org.mindswap.owls.process.Output;
2ronwalfimport org.mindswap.owls.process.OutputList;
2ronwalfimport org.mindswap.owls.process.Parameter;
2ronwalfimport org.mindswap.owls.process.ParameterList;
7daenzeroramaimport org.mindswap.owls.process.Perform;
2ronwalfimport org.mindswap.owls.process.Process;
2ronwalfimport org.mindswap.owls.process.Result;
2ronwalfimport org.mindswap.owls.process.ResultList;
2ronwalfimport org.mindswap.owls.profile.Profile;
2ronwalfimport org.mindswap.owls.service.Service;
2ronwalfimport org.mindswap.owls.vocabulary.OWLS;
7daenzeroramaimport org.mindswap.owls.vocabulary.OWLS_Extensions;
2ronwalf
2ronwalf/**
2ronwalf * @author Evren Sirin
2ronwalf *
2ronwalf */
2ronwalfpublic abstract class ProcessImpl extends WrappedIndividual implements Process {
7daenzerorama
2ronwalf public ProcessImpl(OWLIndividual ind) {
2ronwalf super(ind);
2ronwalf }
2ronwalf
2ronwalf /* (non-Javadoc)
2ronwalf * @see org.mindswap.owls.process.Process#getService()
2ronwalf */
2ronwalf public Service getService() {
2ronwalf return (Service) getPropertyAs(OWLS.Service.describes, Service.class);
2ronwalf }
2ronwalf
2ronwalf public void setService(Service service) {
2ronwalf if(hasProperty(OWLS.Service.describes, service))
2ronwalf return;
2ronwalf
2ronwalf setProperty(OWLS.Service.describes, service);
2ronwalf service.setProcess(this);
2ronwalf }
14daenzerorama
14daenzerorama public void removeService() {
14daenzerorama if(hasProperty(OWLS.Service.describes, getService()))
14daenzerorama removeProperty(OWLS.Service.describes, getService());
14daenzerorama }
2ronwalf
2ronwalf public Profile getProfile() {
2ronwalf return getService().getProfile();
2ronwalf }
2ronwalf
2ronwalf public void addInput(Input input) {
2ronwalf addProperty(OWLS.Process.hasInput, input);
2ronwalf }
2ronwalf
2ronwalf public Input createInput(URI uri, OWLType paramType) {
2ronwalf Input in = getOntology().createInput( uri );
2ronwalf
2ronwalf if( paramType != null )
2ronwalf in.setParamType( paramType );
2ronwalf
2ronwalf addInput( in );
2ronwalf
2ronwalf return in;
2ronwalf }
2ronwalf
24daenzerorama public void addInputs(InputList inputs) {
24daenzerorama for (int i = 0; i < inputs.size(); i++)
24daenzerorama addInput(inputs.inputAt(i));
24daenzerorama }
24daenzerorama
2ronwalf public void addOutput(Output output) {
2ronwalf addProperty(OWLS.Process.hasOutput, output);
2ronwalf }
2ronwalf
2ronwalf public Output createOutput(URI uri, OWLType paramType) {
2ronwalf Output out = getOntology().createOutput( uri );
2ronwalf
2ronwalf if( paramType != null )
2ronwalf out.setParamType( paramType );
2ronwalf
2ronwalf addOutput( out );
2ronwalf
2ronwalf return out;
2ronwalf
2ronwalf }
2ronwalf
24daenzerorama public void addOutputs(OutputList outputs) {
24daenzerorama for (int i = 0; i < outputs.size(); i++)
24daenzerorama addOutput(outputs.outputAt(i));
24daenzerorama }
24daenzerorama
2ronwalf public void addLocal(Local local) {
2ronwalf addProperty(OWLS.Process.hasLocal, local);
2ronwalf }
2ronwalf
2ronwalf public Local createLocal(URI uri, OWLType paramType) {
2ronwalf Local local = getOntology().createLocal( uri );
2ronwalf
2ronwalf if( paramType != null )
2ronwalf local.setParamType( paramType );
2ronwalf
2ronwalf addLocal( local );
2ronwalf
2ronwalf return local;
2ronwalf
2ronwalf }
2ronwalf
2ronwalf public void addParameter(Parameter param) {
2ronwalf if(param instanceof Input)
2ronwalf addInput((Input) param);
2ronwalf else if(param instanceof Output)
2ronwalf addOutput((Output) param);
2ronwalf else if(param instanceof Local)
2ronwalf addLocal((Local) param);
2ronwalf else
2ronwalf addProperty(OWLS.Process.hasParameter, param);
2ronwalf }
2ronwalf
2ronwalf public void addResult(Result result) {
2ronwalf addProperty(OWLS.Process.hasResult, result);
2ronwalf }
2ronwalf
2ronwalf public void setResult(Result result) {
2ronwalf setProperty(OWLS.Process.hasResult, result);
2ronwalf }
2ronwalf
2ronwalf public Result createResult() {
2ronwalf Result result = getOntology().createResult();
2ronwalf
2ronwalf addResult( result );
2ronwalf
2ronwalf return result;
2ronwalf }
2ronwalf
2ronwalf public Result createResult( URI uri ) {
2ronwalf Result result = getOntology().createResult( uri );
2ronwalf
2ronwalf addResult( result );
2ronwalf
2ronwalf return result;
2ronwalf }
2ronwalf
10daenzerorama public void removeResult(Result result) {
10daenzerorama if (hasProperty(OWLS.Process.hasResult, result))
10daenzerorama removeProperty(OWLS.Process.hasResult, result);
10daenzerorama }
10daenzerorama
10daenzerorama public void removeResults() {
10daenzerorama ResultList list = getResults();
10daenzerorama for (int i = 0; i < list.size(); i++)
10daenzerorama removeResult((Result) list.get(i));
10daenzerorama }
10daenzerorama
2ronwalf public InputList getInputs() {
2ronwalf return OWLSFactory.createInputList(getProperties(OWLS.Process.hasInput));
2ronwalf }
2ronwalf
2ronwalf public Input getInput() {
2ronwalf InputList inputs = getInputs();
2ronwalf return inputs.isEmpty() ? null : inputs.inputAt(0);
2ronwalf }
2ronwalf
2ronwalf public Input getInput(int i) {
2ronwalf InputList inputs = getInputs();
2ronwalf return inputs.inputAt(i);
2ronwalf }
2ronwalf
2ronwalf public Input getInput(String localName) {
2ronwalf InputList inputs = getInputs();
2ronwalf return (Input) inputs.getParameter(localName);
2ronwalf }
2ronwalf
2ronwalf public OutputList getOutputs() {
2ronwalf return OWLSFactory.createOutputList(getProperties(OWLS.Process.hasOutput));
2ronwalf }
2ronwalf
2ronwalf public Output getOutput() {
2ronwalf OutputList outputs = getOutputs();
2ronwalf return outputs.isEmpty() ? null : outputs.outputAt(0);
2ronwalf }
2ronwalf
2ronwalf public Output getOutput(int i) {
2ronwalf OutputList outputs = getOutputs();
2ronwalf return outputs.outputAt(i);
2ronwalf }
2ronwalf
2ronwalf public Output getOutput(String localName) {
2ronwalf OutputList outputs = getOutputs();
2ronwalf return (Output) outputs.getParameter(localName);
2ronwalf }
2ronwalf
2ronwalf public ParameterList getLocals() {
2ronwalf return OWLSFactory.createParameterList(getProperties(OWLS.Process.hasLocal));
2ronwalf }
2ronwalf
2ronwalf public ParameterList getParameters() {
2ronwalf ParameterList parameters = OWLSFactory.createParameterList(getInputs());
2ronwalf parameters.addAll(getOutputs());
2ronwalf parameters.addAll(getLocals());
2ronwalf
2ronwalf return parameters;
2ronwalf }
2ronwalf
2ronwalf /* (non-Javadoc)
2ronwalf * @see org.mindswap.owls.process.Process#getParameter(java.net.URI)
2ronwalf */
2ronwalf public Parameter getParameter(URI parameterURI) {
2ronwalf return getParameters().getParameter(parameterURI);
2ronwalf }
2ronwalf
2ronwalf /* (non-Javadoc)
2ronwalf * @see org.mindswap.owls.process.Conditional#getCondition()
2ronwalf */
2ronwalf public Condition getCondition() {
2ronwalf return (Condition) getPropertyAs(OWLS.Process.hasPrecondition, Condition.class);
2ronwalf }
2ronwalf
2ronwalf public ConditionList getConditions() {
2ronwalf return OWLSFactory.createConditionList(getProperties(OWLS.Process.hasPrecondition));
2ronwalf }
2ronwalf
2ronwalf public void setCondition(Condition condition) {
2ronwalf setProperty(OWLS.Process.hasPrecondition, condition);
2ronwalf }
2ronwalf
2ronwalf public void addCondition(Condition condition) {
2ronwalf addProperty(OWLS.Process.hasPrecondition, condition);
2ronwalf }
2ronwalf
2ronwalf public ResultList getResults() {
2ronwalf return OWLSFactory.createResultList(getProperties(OWLS.Process.hasResult));
2ronwalf }
2ronwalf
2ronwalf public Result getResult() {
2ronwalf return (Result) getPropertyAs(OWLS.Process.hasResult, Result.class);
2ronwalf }
2ronwalf
2ronwalf
2ronwalf public String getName() {
2ronwalf return getPropertyAsString(OWLS.Process.name);
2ronwalf }
2ronwalf
2ronwalf public String getName(String lang) {
2ronwalf return getPropertyAsString(OWLS.Process.name, lang);
2ronwalf }
2ronwalf
2ronwalf public OWLDataValueList getNames() {
2ronwalf return getProperties(OWLS.Process.name);
2ronwalf }
2ronwalf
2ronwalf public String debugString() {
2ronwalf InputList inputs = getInputs();
2ronwalf OutputList outputs = getOutputs();
2ronwalf String str = getLabel() + " " + getURI() + "\n";
2ronwalf for(int i = 0; i < inputs.size(); i++)
2ronwalf str += inputs.inputAt(i).debugString() + "\n";
2ronwalf for(int i = 0; i < outputs.size(); i++)
2ronwalf str += outputs.outputAt(i).debugString() + "\n";
2ronwalf
2ronwalf return str;
2ronwalf }
7daenzerorama
7daenzerorama public Perform getPerform() {
7daenzerorama return (Perform) getPropertyAs(OWLS_Extensions.Process.hasPerform, Perform.class);
7daenzerorama }
7daenzerorama
7daenzerorama public void setPerform(Perform perform) {
7daenzerorama if(hasProperty(OWLS_Extensions.Process.hasPerform, perform))
7daenzerorama return;
7daenzerorama
7daenzerorama setProperty(OWLS_Extensions.Process.hasPerform, perform);
8daenzerorama if (perform != null)
8daenzerorama perform.setProcess(this);
7daenzerorama }
10daenzerorama
14daenzerorama public void removeInput(Input input) {
14daenzerorama if (hasProperty(OWLS.Process.hasInput, input))
14daenzerorama removeProperty(OWLS.Process.hasInput, input);
10daenzerorama }
14daenzerorama
14daenzerorama public void removeInputs() {
14daenzerorama InputList list = getInputs();
14daenzerorama for (int i = 0; i < list.size(); i++)
14daenzerorama removeInput((Input) list.individualAt(i));
14daenzerorama }
14daenzerorama
14daenzerorama public void removeLocal(Local local) {
14daenzerorama if (hasProperty(OWLS.Process.hasLocal, local))
14daenzerorama removeProperty(OWLS.Process.hasLocal, local);
14daenzerorama }
14daenzerorama
14daenzerorama public void removeLocals() {
14daenzerorama ParameterList list = getLocals();
14daenzerorama for (int i = 0; i < list.size(); i++)
14daenzerorama removeLocal((Local) list.individualAt(i));
14daenzerorama
14daenzerorama }
14daenzerorama
14daenzerorama public void removeOutput(Output output) {
14daenzerorama if (hasProperty(OWLS.Process.hasOutput, output))
14daenzerorama removeProperty(OWLS.Process.hasOutput, output);
14daenzerorama }
14daenzerorama
14daenzerorama public void removeOutputs() {
14daenzerorama OutputList list = getOutputs();
14daenzerorama for (int i = 0; i < list.size(); i++)
14daenzerorama removeOutput((Output) list.individualAt(i));
14daenzerorama }
14daenzerorama
14daenzerorama public void deleteInput(Input input) {
18daenzerorama removeInput(input);
14daenzerorama input.delete();
14daenzerorama }
14daenzerorama
18daenzerorama public void deleteInputs() {
14daenzerorama InputList inputs = getInputs();
18daenzerorama removeInputs();
14daenzerorama for (int index = 0; index < inputs.size(); index++)
14daenzerorama inputs.individualAt(index).delete();
14daenzerorama }
14daenzerorama
14daenzerorama public void deleteLocal(Local local) {
18daenzerorama removeLocal(local);
14daenzerorama local.delete();
14daenzerorama }
14daenzerorama
14daenzerorama public void deleteLocals() {
14daenzerorama ParameterList locals = getLocals();
18daenzerorama removeLocals();
18daenzerorama for (int index = 0; index < locals.size(); index++)
14daenzerorama locals.individualAt(index).delete();
14daenzerorama }
14daenzerorama
14daenzerorama public void deleteOutput(Output output) {
18daenzerorama removeOutput(output);
14daenzerorama output.delete();
14daenzerorama }
14daenzerorama
14daenzerorama public void deleteOutputs() {
18daenzerorama OutputList outputs = getOutputs();
18daenzerorama removeOutputs();
14daenzerorama for (int index = 0; index < outputs.size(); index++)
14daenzerorama outputs.individualAt(index).delete();
14daenzerorama }
14daenzerorama
14daenzerorama public void deleteResult(Result result) {
18daenzerorama removeResult(result);
14daenzerorama result.delete();
14daenzerorama }
14daenzerorama
18daenzerorama public void deleteResults() {
14daenzerorama ResultList results = getResults();
18daenzerorama removeResults();
14daenzerorama for (int index = 0; index < results.size(); index++)
14daenzerorama results.individualAt(index).delete();
14daenzerorama }
18daenzerorama
18daenzerorama public void deleteAllParameters() {
18daenzerorama deleteInputs();
18daenzerorama deleteOutputs();
18daenzerorama deleteLocals();
18daenzerorama deleteResults();
18daenzerorama }
18daenzerorama
18daenzerorama @Override
18daenzerorama public void delete() {
18daenzerorama deleteAllParameters();
18daenzerorama }
2ronwalf}