⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 owlsfactory.java

📁 开发owl的API,提供了W3C规定标准接口,是目前比较少的API.
💻 JAVA
字号:
// The MIT License
//
// Copyright (c) 2004 Evren Sirin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

/*
 * Created on Dec 28, 2003
 *
 */
package org.mindswap.owls;

import java.util.Arrays;
import java.util.List;

import org.mindswap.owl.OWLConfig;
import org.mindswap.owl.OWLResource;
import org.mindswap.owl.OWLResourceWrapper;
import org.mindswap.owls.grounding.Grounding;
import org.mindswap.owls.grounding.MessageMap;
import org.mindswap.owls.grounding.MessageMapList;
import org.mindswap.owls.grounding.UPnPAtomicGrounding;
import org.mindswap.owls.grounding.WSDLAtomicGrounding;
import org.mindswap.owls.grounding.impl.GroundingImpl;
import org.mindswap.owls.grounding.impl.MessageMapImpl;
import org.mindswap.owls.grounding.impl.MessageMapListImpl;
import org.mindswap.owls.grounding.impl.UPnPAtomicGroundingImpl;
import org.mindswap.owls.grounding.impl.WSDLAtomicGroundingImpl;
import org.mindswap.owls.io.OWLSReader;
import org.mindswap.owls.io.OWLSWriter;
import org.mindswap.owls.io.impl.DAMLSReader_0_7;
import org.mindswap.owls.io.impl.GenericOWLSReader;
import org.mindswap.owls.io.impl.GenericOWLSWriter;
import org.mindswap.owls.io.impl.OWLSReader_0_9;
import org.mindswap.owls.io.impl.OWLSReader_1_0;
import org.mindswap.owls.io.impl.OWLSReader_1_0DL;
import org.mindswap.owls.io.impl.OWLSWriter_0_9;
import org.mindswap.owls.io.impl.OWLSWriter_1_0;
import org.mindswap.owls.process.AtomicProcess;
import org.mindswap.owls.process.Choice;
import org.mindswap.owls.process.CompositeProcess;
import org.mindswap.owls.process.Condition;
import org.mindswap.owls.process.ConditionList;
import org.mindswap.owls.process.DataFlow;
import org.mindswap.owls.process.DataFlowElement;
import org.mindswap.owls.process.Effect;
import org.mindswap.owls.process.EffectList;
import org.mindswap.owls.process.Input;
import org.mindswap.owls.process.InputList;
import org.mindswap.owls.process.Output;
import org.mindswap.owls.process.OutputList;
import org.mindswap.owls.process.ParameterList;
import org.mindswap.owls.process.ProcessComponentList;
import org.mindswap.owls.process.ProcessModel;
import org.mindswap.owls.process.Sequence;
import org.mindswap.owls.process.Split;
import org.mindswap.owls.process.SplitJoin;
import org.mindswap.owls.process.Unordered;
import org.mindswap.owls.process.ValueMap;
import org.mindswap.owls.process.execution.ProcessExecutionEngine;
import org.mindswap.owls.process.execution.impl.ProcessExecutionEngineImpl;
import org.mindswap.owls.process.impl.AtomicProcessImpl;
import org.mindswap.owls.process.impl.ChoiceImpl;
import org.mindswap.owls.process.impl.CompositeProcessImpl;
import org.mindswap.owls.process.impl.ConditionImpl;
import org.mindswap.owls.process.impl.ConditionListImpl;
import org.mindswap.owls.process.impl.DataFlowElementImpl;
import org.mindswap.owls.process.impl.DataFlowImpl;
import org.mindswap.owls.process.impl.EffectImpl;
import org.mindswap.owls.process.impl.EffectListImpl;
import org.mindswap.owls.process.impl.InputImpl;
import org.mindswap.owls.process.impl.InputListImpl;
import org.mindswap.owls.process.impl.OutputImpl;
import org.mindswap.owls.process.impl.OutputListImpl;
import org.mindswap.owls.process.impl.ParameterListImpl;
import org.mindswap.owls.process.impl.ProcessComponentListImpl;
import org.mindswap.owls.process.impl.ProcessModelImpl;
import org.mindswap.owls.process.impl.SequenceImpl;
import org.mindswap.owls.process.impl.SplitImpl;
import org.mindswap.owls.process.impl.SplitJoinImpl;
import org.mindswap.owls.process.impl.UnorderedImpl;
import org.mindswap.owls.process.impl.ValueMapImpl;
import org.mindswap.owls.profile.Profile;
import org.mindswap.owls.profile.impl.ProfileImpl;
import org.mindswap.owls.service.Service;
import org.mindswap.owls.service.impl.ServiceImpl;
import org.mindswap.owls.vocabulary.DAMLS_0_7;
import org.mindswap.owls.vocabulary.OWLS;
import org.mindswap.owls.vocabulary.OWLS_0_9;
import org.mindswap.owls.vocabulary.OWLS_1_0;
import org.mindswap.owls.vocabulary.OWLS_1_0DL;

import com.hp.hpl.jena.rdf.model.Resource;

/**
 * @author Evren Sirin
 *
 */
public class OWLSFactory {	
	static {
		OWLConfig.addWrapper(Process.class, new OWLSFactory.ProcessWrapper());
		OWLConfig.addWrapper(AtomicProcess.class, new OWLSFactory.AtomicProcessWrapper());
	}
	
	private static OWLSFactory factory = new OWLSFactory();
	
	public final static String[] supportedVersions = new String[] {"0.7", "0.9", "1.0", "1.0DL" };
	
	/**
	 * @return
	 */
	static public OWLSFactory getFactory() {
		return factory;
	}

	public static List getSupportedVersions() {
		return Arrays.asList(supportedVersions);
	}

	public static String getLatestVersion() {
		return supportedVersions[supportedVersions.length - 1];
	}
	
	static public OWLS getVocabulary() {
		return getVocabulary(getLatestVersion());			
	}
	
	static public OWLS getVocabulary(String version) {
		if(version.equals("0.7")) return DAMLS_0_7.instance;
		if(version.equals("0.9")) return OWLS_0_9.instance;
		if(version.equals("1.0")) return OWLS_1_0.instance;
		if(version.equals("1.0DL")) return OWLS_1_0DL.instance;
		
		throw new IllegalArgumentException("There is no vocabulary for OWL-S version " + version);		
	}
	
	public static ProcessExecutionEngine createExecutionEngine() {
		return new ProcessExecutionEngineImpl();
	}
	

	/**
	 * @return
	 */
	public static OWLSReader createOWLSReader() { return new GenericOWLSReader(); }
	
	/**
	 * @param version
	 * @return
	 */
	public static OWLSReader createOWLSReader(String version) {
		if(version.equals("0.7")) return new DAMLSReader_0_7();
		if(version.equals("0.9")) return new OWLSReader_0_9();
		if(version.equals("1.0")) return new OWLSReader_1_0();		
		if(version.equals("1.0DL")) return new OWLSReader_1_0DL();
		
		throw new IllegalArgumentException("There is no reader for OWLS version " + version);
	}

	/**
	 * @return
	 */
	public static OWLSWriter createOWLSWriter() { return new GenericOWLSWriter(); }
	
	/**
	 * @param version
	 * @return
	 */
	public static OWLSWriter createOWLSWriter(String version) {
		if(version.equals("0.9")) return new OWLSWriter_0_9();
		if(version.equals("1.0")) return new OWLSWriter_1_0();
		
		throw new IllegalArgumentException("There is no writer for OWLS version " + version);
	}
	
	/**
	 * @return
	 */
	static public Service createService() { return createService(null); }	
	/**
	 * @param resource
	 * @return
	 */
	static public Service createService(Resource resource) {
		return new ServiceImpl(resource);
	}

	/**
	 * @return
	 */
	static public Profile createProfile() { return createProfile(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public Profile createProfile(Resource resource) {
		return new ProfileImpl(resource);
	}
	
	/**
	 * @return
	 */
	static public Grounding createGrounding() { return createGrounding(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public Grounding createGrounding(Resource resource) {
		return new GroundingImpl(resource);
	}
	
	/**
	 * @return
	 */
	static public ProcessModel createProcessModel() { return createProcessModel(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public ProcessModel createProcessModel(Resource resource) {
		return new ProcessModelImpl(resource);
	}
	
	/**
	 * @return
	 */
	static public AtomicProcess createAtomicProcess() { return createAtomicProcess(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public AtomicProcess createAtomicProcess(Resource resource) {
		return new AtomicProcessImpl(resource);
	}

	/**
	 * @return
	 */
	static public CompositeProcess createCompositeProcess() { return createCompositeProcess(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public CompositeProcess createCompositeProcess(Resource resource) {
		return new CompositeProcessImpl(resource);
	}

	/**
	 * @return
	 */
	static public Sequence createSequence() { return createSequence(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public Sequence createSequence(Resource resource) {
		return new SequenceImpl(resource);
	}

	/**
	 * @return
	 */
	static public Split createSplit() { return createSplit(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public Split createSplit(Resource resource) {
		return new SplitImpl(resource);
	}

	/**
	 * @return
	 */
	static public SplitJoin createSplitJoin() { return createSplitJoin(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public SplitJoin createSplitJoin(Resource resource) {
		return new SplitJoinImpl(resource);
	}

	/**
	 * @return
	 */
	static public Choice createChoice() { return createChoice(null); }
	
	/**
	 * @param resource
	 * @return
	 */
	static public Choice createChoice(Resource resource) {
		return new ChoiceImpl(resource);
	}
	
	/**
	 * @return
	 */
	static public Unordered createUnordered() { return createUnordered(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public Unordered createUnordered(Resource resource) {
		return new UnorderedImpl(resource);
	}
	
	
	/**
	 * @param resource
	 * @return
	 */
	static public Input createInput(Resource resource) {
		return new InputImpl(resource);
	}
	
	/**
	 * @param resource
	 * @return
	 */
	static public Output createOutput(Resource resource) {
		return new OutputImpl(resource);
	}

	/**
	 * @return
	 */
	static public Condition createCondition(Resource r) { return new ConditionImpl(r);	}
	
	/**
	 * @return
	 */
	static public Effect createEffect(Resource r) { return new EffectImpl(r);	}
	
	
	
	/**
	 * @return
	 */
	static public WSDLAtomicGrounding createWSDLAtomicGrounding() { 
		return createWSDLAtomicGrounding(null); 
	}
	/**
	 * @param resource
	 * @return
	 */
	static public WSDLAtomicGrounding createWSDLAtomicGrounding(Resource resource) {
		return new WSDLAtomicGroundingImpl(resource);
	}

	/**
	 * @return
	 */
	static public UPnPAtomicGrounding createUPnPAtomicGrounding() { 
		return createUPnPAtomicGrounding(null); 
	}
	/**
	 * @param resource
	 * @return
	 */
	static public UPnPAtomicGrounding createUPnPAtomicGrounding(Resource resource) {
		return new UPnPAtomicGroundingImpl(resource);
	}
	
	/**
	 * @return
	 */
	static public DataFlow createDataFlow() { return new DataFlowImpl(); }
	/**
	 * @return
	 */
	static public DataFlowElement createDataFlowElement() { return new DataFlowElementImpl(); }

	/**
	 * @return
	 */
	static public MessageMap createMessageMap() { return createMessageMap(null); }
	/**
	 * @param resource
	 * @return
	 */
	static public MessageMap createMessageMap(Resource resource) {
		return new MessageMapImpl(resource);
	}

	/**
	 * @return
	 */
	static public ParameterList createParameterList() { return new ParameterListImpl();	}
	/**
	 * @return
	 */
	static public InputList createInputList() { return new InputListImpl();	}
	/**
	 * @return
	 */
	static public OutputList createOutputList() { return new OutputListImpl();	}
	/**
	 * @return
	 */
	static public EffectList createEffectList() { return new EffectListImpl();	}
	/**
	 * @return
	 */
	static public ConditionList createConditionList() { return new ConditionListImpl();	}
	/**
	 * @return
	 */
	static public MessageMapList createMessageMapList() { return new MessageMapListImpl();	}
	/**
	 * @return
	 */
	static public ValueMap createValueMap() { return new ValueMapImpl();	}

	/**
	 * createProcessComponentList
	 * 
	 * @return
	 */
	public static ProcessComponentList createProcessComponentList() {
		return new ProcessComponentListImpl();
	}

	
	public static class ProcessWrapper implements OWLResourceWrapper {
		public boolean canWrap(OWLResource resource) {
			return true;
		}
		
		public OWLResource wrap(OWLResource resource) {
			return createOWLSReader().createProcess(null, resource.getJenaResource());
		}
	}

	public static class AtomicProcessWrapper implements OWLResourceWrapper {
		public boolean canWrap(OWLResource resource) {
			return true;
		}
		
		public OWLResource wrap(OWLResource resource) {
			return (AtomicProcess) createOWLSReader().createProcess(null, resource.getJenaResource());
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -