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

org.rapidoid.ioc.IoCContextWrapper Maven / Gradle / Ivy

There is a newer version: 5.5.5
Show newest version
package org.rapidoid.ioc;

import org.rapidoid.RapidoidThing;
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.lambda.Mapper;

import java.util.List;
import java.util.Map;

/*
 * #%L
 * rapidoid-inject
 * %%
 * Copyright (C) 2014 - 2016 Nikolche Mihajlovski and contributors
 * %%
 * 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%
 */

@Authors("Nikolche Mihajlovski")
@Since("5.1.0")
public class IoCContextWrapper extends RapidoidThing implements IoCContext {

	private final IoCContextImpl context;

	IoCContextWrapper(IoCContextImpl context) {
		this.context = context;
		context.wrapper(this);
	}

	@Override
	public IoCContext name(String name) {
		return context.name(name);
	}

	@Override
	public String name() {
		return context.name();
	}

	@Override
	public synchronized void reset() {
		IoCState backup = context.backup();

		try {
			context.reset();
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized void manage(Object... classesOrInstances) {
		IoCState backup = context.backup();

		try {
			context.manage(classesOrInstances);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized  T singleton(Class type) {
		IoCState backup = context.backup();

		try {
			return context.singleton(type);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized  T autowire(T target) {
		IoCState backup = context.backup();

		try {
			return context.autowire(target);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized  T autowire(T target, Mapper session, Mapper bindings) {
		IoCState backup = context.backup();

		try {
			return context.autowire(target, session, bindings);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized  T inject(T target) {
		IoCState backup = context.backup();

		try {
			return context.inject(target);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized  T inject(T target, Map properties) {
		IoCState backup = context.backup();

		try {
			return context.inject(target, properties);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized boolean remove(Object bean) {
		IoCState backup = context.backup();

		try {
			return context.remove(bean);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized  Map autoExpandingInjectingMap(Class clazz) {
		IoCState backup = context.backup();

		try {
			return context.autoExpandingInjectingMap(clazz);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized Object findInstanceOf(String className) {
		IoCState backup = context.backup();

		try {
			return context.findInstanceOf(className);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized IoCContextChanges reload(List> modified, List deleted) {
		IoCState backup = context.backup();

		try {
			return context.reload(modified, deleted);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized Map info() {
		IoCState backup = context.backup();

		try {
			return context.info();
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public synchronized void beanProvider(BeanProvider beanProvider) {
		IoCState backup = context.backup();

		try {
			context.beanProvider(beanProvider);
		} catch (RuntimeException e) {
			context.rollback(backup);
			throw e;
		}
	}

	@Override
	public String toString() {
		return context.toString();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy