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

com.jdon.controller.service.WebServiceFactory Maven / Gradle / Ivy

Go to download

JdonFramework is a java framework that you can use to build your Domain Driven Design + CQRS + EventSource applications with asynchronous concurrency and higher throughput.

There is a newer version: 6.9
Show newest version
/**
 * Copyright 2003-2006 the original author or authors.
 * 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.
 */

package com.jdon.controller.service;

import com.jdon.bussinessproxy.TargetMetaDef;
import com.jdon.container.ContainerWrapper;
import com.jdon.container.access.UserTargetMetaDefFactory;
import com.jdon.container.finder.ContainerCallback;
import com.jdon.controller.context.AppContextWrapper;
import com.jdon.controller.context.ContextHolder;
import com.jdon.controller.context.RequestWrapper;
import com.jdon.util.Debug;

/**
 * the defualt concrete class of ServiceFactory by this class, we can get a
 * service instance; @ {@link com.jdon.controller.service.WebServiceDecorator}
 * @author banq
 * @see {@link ServiceFactory}
 */
public class WebServiceFactory implements ServiceFactory {

	private final static String module = WebServiceFactory.class.getName();

	private final ContainerCallback containerCallback;
	private final WebServiceAccessor webServiceAccessor;
	private final UserTargetMetaDefFactory userTargetMetaDefFactory;

	public WebServiceFactory(WebServiceAccessor webServiceAccessor, ContainerCallback containerCallback,
			UserTargetMetaDefFactory userTargetMetaDefFactory) {
		this.webServiceAccessor = webServiceAccessor;
		this.containerCallback = containerCallback;
		this.userTargetMetaDefFactory = userTargetMetaDefFactory;
	}

	public Object getService(String name, RequestWrapper request) {
		Debug.logVerbose("<==============================>start: JdonFramework core entrance", module);
		Debug.logVerbose("<===============>Looking up new service='" + name + "'", module);
		ContainerWrapper cw = containerCallback.getContainerWrapper();
		if (!cw.isStart()) {
			Debug.logError("JdonFramework not yet started, please try later ", module);
			return null;
		}
		TargetMetaDef targetMetaDef = userTargetMetaDefFactory.getTargetMetaDef(name, cw);
		if (targetMetaDef == null)
			return null;
		Debug.logVerbose("[JdonFramework] service=" + name + "  found, and now return the service instance", module);
		Object result = getService(targetMetaDef, request);
		Debug.logVerbose("<===============>found service='" + name + "'  instance and return  it successfully!", module);
		Debug.logVerbose("<==============================>over", module);
		return result;
	}

	/**
	 * get a service instance the service must have a interface and implements
	 * it.
	 * 
	 */
	public Object getService(TargetMetaDef targetMetaDef, RequestWrapper request) {
		userTargetMetaDefFactory.createTargetMetaRequest(targetMetaDef, request.getContextHolder());
		return webServiceAccessor.getService(request);
	}

	public Object getService(TargetMetaDef targetMetaDef, AppContextWrapper acw) {
		userTargetMetaDefFactory.createTargetMetaRequest(targetMetaDef, new ContextHolder(acw, null));
		return webServiceAccessor.getService();
	}

	public Object getService(String name, AppContextWrapper acw) {
		ContainerWrapper cw = containerCallback.getContainerWrapper();
		if (!cw.isStart()) {
			Debug.logError("JdonFramework not yet started, please try later ", module);
			return null;
		}
		TargetMetaDef targetMetaDef = userTargetMetaDefFactory.getTargetMetaDef(name, cw);
		if (targetMetaDef == null)
			return null;
		Debug.logVerbose("[JdonFramework] service=" + name + "  found, and now return the service instance", module);
		Object result = getService(targetMetaDef, acw);
		return result;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy