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 */
2ronwalfpackage impl.owls.grounding;
2ronwalf
2ronwalfimport impl.owl.WrappedIndividual;
2ronwalf
2ronwalfimport org.mindswap.owl.OWLIndividual;
2ronwalfimport org.mindswap.owl.OWLIndividualList;
2ronwalfimport org.mindswap.owls.OWLSFactory;
2ronwalfimport org.mindswap.owls.grounding.AtomicGrounding;
2ronwalfimport org.mindswap.owls.grounding.AtomicGroundingList;
2ronwalfimport org.mindswap.owls.grounding.Grounding;
2ronwalfimport org.mindswap.owls.process.AtomicProcess;
2ronwalfimport org.mindswap.owls.service.Service;
2ronwalfimport org.mindswap.owls.vocabulary.FLAServiceOnt;
2ronwalfimport org.mindswap.owls.vocabulary.OWLS;
2ronwalf
2ronwalf/**
2ronwalf * @author Evren Sirin
2ronwalf *
2ronwalf */
2ronwalfpublic class GroundingImpl extends WrappedIndividual implements Grounding {
2ronwalf public GroundingImpl(OWLIndividual ind) {
2ronwalf super(ind);
2ronwalf }
2ronwalf
2ronwalf /* (non-Javadoc)
2ronwalf * @see org.mindswap.owls.grounding.Grounding#getGrounding(org.mindswap.owls.process.AtomicProcess)
2ronwalf */
2ronwalf public AtomicGrounding getAtomicGrounding(AtomicProcess process) {
2ronwalf // TODO make this a RDQL query
2ronwalf OWLIndividualList list = getProperties(OWLS.Grounding.hasAtomicProcessGrounding);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual ind = list.individualAt(i);
2ronwalf if(ind.hasProperty(OWLS.Grounding.owlsProcess, process))
2ronwalf return (AtomicGrounding) ind.castTo(AtomicGrounding.class);
2ronwalf }
2ronwalf
2ronwalf return null;
2ronwalf }
2ronwalf
2ronwalf /* (non-Javadoc)
2ronwalf * @see org.mindswap.owls.grounding.Grounding#getGrounding(org.mindswap.owls.process.AtomicProcess)
2ronwalf */
2ronwalf public AtomicGroundingList getAtomicGroundings() {
2ronwalf OWLIndividualList list = getProperties(OWLS.Grounding.hasAtomicProcessGrounding);
2ronwalf list.addAll(getProperties(FLAServiceOnt.hasUPnPAtomicProcessGrounding));
2ronwalf// return OWLSFactory.createAtomicGroundingList(getProperties(OWLS.Grounding.hasAtomicProcessGrounding));
2ronwalf return OWLSFactory.createAtomicGroundingList(list);
2ronwalf }
2ronwalf
2ronwalf /* (non-Javadoc)
2ronwalf * @see org.mindswap.owls.grounding.Grounding#getGrounding(org.mindswap.owls.process.AtomicProcess)
2ronwalf */
2ronwalf public AtomicGroundingList getAtomicGroundings(AtomicProcess process) {
2ronwalf AtomicGroundingList result = OWLSFactory.createAtomicGroundingList();
2ronwalf OWLIndividualList list = getProperties(OWLS.Grounding.hasAtomicProcessGrounding);
2ronwalf for(int i = 0; i < list.size(); i++) {
2ronwalf OWLIndividual ind = list.individualAt(i);
2ronwalf if(ind.hasProperty(OWLS.Grounding.owlsProcess, process))
2ronwalf result.add(ind);
2ronwalf }
2ronwalf
2ronwalf return result;
2ronwalf }
2ronwalf
2ronwalf /* (non-Javadoc)
2ronwalf * @see org.mindswap.owls.grounding.Grounding#addGrounding(org.mindswap.owls.grounding.AtomicProcessGrounding)
2ronwalf */
2ronwalf public void addGrounding(AtomicGrounding apg) {
2ronwalf addProperty(OWLS.Grounding.hasAtomicProcessGrounding, apg);
2ronwalf }
2ronwalf /**
2ronwalf * @return Returns the service.
2ronwalf */
2ronwalf public Service getService() {
2ronwalf return (Service) getPropertyAs(OWLS.Service.supportedBy, Service.class);
2ronwalf }
2ronwalf
2ronwalf /**
2ronwalf * @param service The service to set.
2ronwalf */
2ronwalf public void setService(Service service) {
2ronwalf if(hasProperty(OWLS.Service.supportedBy, service))
2ronwalf return;
2ronwalf
2ronwalf setProperty(OWLS.Service.supportedBy, service);
2ronwalf service.setGrounding(this);
2ronwalf }
2ronwalf
10daenzerorama public void removeService() {
10daenzerorama if (hasProperty(OWLS.Service.supportedBy, getService()))
10daenzerorama removeProperty(OWLS.Service.supportedBy, getService());
10daenzerorama }
10daenzerorama
14daenzerorama public void deleteAtomicGroundings(AtomicProcess process) {
14daenzerorama AtomicGroundingList list = getAtomicGroundings();
14daenzerorama for (int index = 0; index < list.size(); index++) {
14daenzerorama if (list.groundingAt(index).hasProperty(OWLS.Grounding.owlsProcess, process))
14daenzerorama list.groundingAt(index).delete();
14daenzerorama }
14daenzerorama }
14daenzerorama
14daenzerorama public void removeAtomicGroundings(AtomicProcess process) {
14daenzerorama AtomicGroundingList list = getAtomicGroundings();
14daenzerorama for (int index = 0; index < list.size(); index++) {
14daenzerorama if (list.groundingAt(index).hasProperty(OWLS.Grounding.owlsProcess, process))
14daenzerorama removeProperty(OWLS.Grounding.hasAtomicProcessGrounding, list.groundingAt(index));
14daenzerorama }
14daenzerorama }
14daenzerorama
14daenzerorama public void deleteAtomicGroundings() {
14daenzerorama AtomicGroundingList list = getAtomicGroundings();
24daenzerorama removeAtomicGroundings();
14daenzerorama for (int index = 0; index < list.size(); index++)
14daenzerorama list.individualAt(index).delete();
14daenzerorama }
14daenzerorama
14daenzerorama public void removeAtomicGroundings() {
14daenzerorama if (hasProperty(OWLS.Grounding.hasAtomicProcessGrounding))
14daenzerorama removeProperties(OWLS.Grounding.hasAtomicProcessGrounding);
14daenzerorama }
24daenzerorama
24daenzerorama @Override
24daenzerorama public void delete() {
24daenzerorama deleteAtomicGroundings();
24daenzerorama super.delete();
24daenzerorama }
2ronwalf}