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

📄 springremotingdestinationbootstrapservice.java

📁 快速FLEX+J2EE开发工具。具体自动生成功能代码功能。
💻 JAVA
字号:
package cn.org.pomer.flex.remoting.services;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import cn.org.pomer.flex.remoting.annotation.BeanType;
import cn.org.pomer.flex.remoting.annotation.RemoteObject;

import flex.messaging.config.ConfigMap;
import flex.messaging.services.AbstractBootstrapService;
import flex.messaging.services.Service;

/**
 * 动态产生flex远程对象,不需要在配置件里配置
 * 
 * @author linlinyu badqiu
 * 
 */
public class SpringRemotingDestinationBootstrapService extends
		AbstractBootstrapService {

	public static final String DEFAULT_INCLUDE_END_WITHS = "FlexService";

	private String channel;
	private String securityConstraint;
	private String scope;
	private String adapter;
	private String factory;
	private String serviceId;
	private String includeEndsWith;

	/**
	 * 被MessageBroker调用
	 * 
	 * @param id
	 *            Id of the <code>AbstractBootstrapService</code>.
	 * @param properties
	 *            Properties for the <code>AbstractBootstrapService</code>.
	 */
	public void initialize(String id, ConfigMap properties) {
		serviceId = properties.getPropertyAsString("service-id",
				"remoting-service");
		factory = properties.getPropertyAsString("factory", "spring");
		adapter = properties.getProperty("adapter");
		scope = properties.getProperty("scope");
		securityConstraint = properties.getProperty("security-constraint");
		channel = properties.getProperty("channel");

		includeEndsWith = properties.getPropertyAsString("includeEndsWith",
				DEFAULT_INCLUDE_END_WITHS);

		Service remotingService = broker.getService(serviceId);
		if (remotingService == null) {
			throw new RuntimeException("not found Service with serviceId:"
					+ serviceId);
		}

		createSpringDestinations(remotingService);
	}

	private void createSpringDestinations(Service remotingService) {
		WebApplicationContext wac = WebApplicationContextUtils
				.getWebApplicationContext(broker.getInitServletContext());
		List<String> addedBeanNames = new ArrayList();
		for (String beanName : wac.getBeanDefinitionNames()) {
			Class type = wac.getType(beanName);
			boolean isCreateSpringDestination = isAnnotationSpringBean(type)
					|| beanName.endsWith(includeEndsWith)
					|| isCreateDestination(beanName, type);

			if (isCreateSpringDestination) {
				createSpringDestination(remotingService, beanName);
				addedBeanNames.add(beanName);
			}
		}
		System.out
				.println("======[Auto Export Spring to RemotingDestination],beans="
						+ addedBeanNames);
	}

	private boolean isAnnotationSpringBean(Class clazz) {
		if (clazz.isAnnotationPresent(RemoteObject.class)) {
			RemoteObject ro = (RemoteObject) clazz
					.getAnnotation(RemoteObject.class);
			BeanType value = ro.value();
			if (value == BeanType.SpringBean) {
				return true;
			}
		}
		return false;
	}

	protected boolean isCreateDestination(String beanName, Class bean) {
		return false;
	}

	protected void createSpringDestination(Service service, String destinationId) {
		flex.messaging.services.remoting.RemotingDestination destination = (flex.messaging.services.remoting.RemotingDestination) service
				.createDestination(destinationId);

		destination.setSource(destinationId);
		destination.setFactory(factory);

		if (adapter != null)
			destination.createAdapter(adapter);
		if (scope != null)
			destination.setScope(scope);
		if (securityConstraint != null)
			destination.setSecurityConstraint(securityConstraint);
		destination.addChannel("my-amf");

		service.addDestination(destination);
	}

	public void start() {
		// No-op
	}

	public void stop() {
		// No-op
	}

}

⌨️ 快捷键说明

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