All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.semanticweb.elk.owl.parsing.javacc.Owl2FunctionalStyleParserFactory Maven / Gradle / Ivy

The newest version!
/*
 * #%L
 * ELK OWL JavaCC Parser
 * 
 * $Id$
 * $HeadURL$
 * %%
 * Copyright (C) 2011 - 2012 Department of Computer Science, University of Oxford
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package org.semanticweb.elk.owl.parsing.javacc;

import java.io.InputStream;
import java.io.Reader;

import org.semanticweb.elk.owl.interfaces.ElkObject;
import org.semanticweb.elk.owl.iris.ElkPrefixDeclarations;
import org.semanticweb.elk.owl.iris.ElkPrefixDeclarationsImpl;
import org.semanticweb.elk.owl.managers.ElkObjectEntityRecyclingFactory;
import org.semanticweb.elk.owl.parsing.Owl2Parser;
import org.semanticweb.elk.owl.parsing.Owl2ParserFactory;

public class Owl2FunctionalStyleParserFactory implements Owl2ParserFactory {

	private final static JavaCCLexerFactory DEFAULT_LEXER_FACTORY = new ConcurrentJavaCCLexerFactory();

	/**
	 * the {@link ElkObject.Factory} used with this {@link Owl2ParserFactory}
	 */
	private final ElkObject.Factory objectFactory_;

	private final JavaCCLexerFactory lexerFactory_;

	public Owl2FunctionalStyleParserFactory(ElkObject.Factory objectFactory,
			JavaCCLexerFactory lexerFactory) {
		this.objectFactory_ = objectFactory;
		this.lexerFactory_ = lexerFactory;
	}

	public Owl2FunctionalStyleParserFactory(ElkObject.Factory objectFactory) {
		this(objectFactory, DEFAULT_LEXER_FACTORY);
	}

	public Owl2FunctionalStyleParserFactory() {
		this(new ElkObjectEntityRecyclingFactory(), DEFAULT_LEXER_FACTORY);
	}

	@Override
	public Owl2Parser getParser(InputStream stream) {
		return new Owl2FunctionalStyleParser(stream, objectFactory_,
				lexerFactory_);
	}

	@Override
	public Owl2Parser getParser(Reader reader) {
		return new Owl2FunctionalStyleParser(reader, objectFactory_,
				lexerFactory_);
	}

	
	/**
	 * 
	 * @author Pavel Klinov
	 *
	 * [email protected]
	 */
	private static class Owl2FunctionalStyleParser extends AbstractOwl2FunctionalStyleParser {

		private final ElkObject.Factory objectFactory_;

		private final ElkPrefixDeclarations prefixDeclarations_;

		private final JavaCCLexerFactory lexerFactory_;

		private Owl2FunctionalStyleParser(InputStream stream,
				ElkObject.Factory objectFactory,
				ElkPrefixDeclarations prefixDeclarations,
				JavaCCLexerFactory factory) {
			super(stream);
			this.objectFactory_ = objectFactory;
			this.prefixDeclarations_ = prefixDeclarations;
			this.lexerFactory_ = factory;

			wrapLexer();
		}

		Owl2FunctionalStyleParser(InputStream stream,
				ElkObject.Factory objectFactory, JavaCCLexerFactory lexerFactory) {
			this(stream, objectFactory, new ElkPrefixDeclarationsImpl(),
					lexerFactory);
		}

		Owl2FunctionalStyleParser(Reader reader,
				ElkObject.Factory objectFactory,
				ElkPrefixDeclarations prefixDeclarations,
				JavaCCLexerFactory factory) {
			super(reader);
			this.objectFactory_ = objectFactory;
			this.prefixDeclarations_ = prefixDeclarations;
			this.lexerFactory_ = factory;

			wrapLexer();
		}

		Owl2FunctionalStyleParser(Reader reader,
				ElkObject.Factory objectFactory, JavaCCLexerFactory lexerFactory) {
			this(reader, objectFactory, new ElkPrefixDeclarationsImpl(),
					lexerFactory);
		}

		@Override
		protected ElkPrefixDeclarations getElkPrefixDeclarations() {
			return prefixDeclarations_;
		}

		@Override
		protected ElkObject.Factory getElkObjectFactory() {
			return this.objectFactory_;
		}

		@Override
		public void ReInit(InputStream stream) {
			super.ReInit(stream);

			wrapLexer();
		}

		@Override
		public void ReInit(InputStream stream, String encoding) {
			super.ReInit(stream, encoding);

			wrapLexer();
		}

		@Override
		public void ReInit(Reader stream) {
			super.ReInit(stream);

			wrapLexer();
		}

		@Override
		public void ReInit(AbstractOwl2FunctionalStyleParserTokenManager tm) {
			super.ReInit(tm);

			wrapLexer();
		}

		private void wrapLexer() {
			token_source = lexerFactory_ != null ? lexerFactory_
					.createLexer(token_source) : token_source;
		}

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy