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

jadex.bridge.nonfunctional.NFRootProperty Maven / Gradle / Ivy

Go to download

Jadex bridge is a base package for kernels and platforms, i.e. it is used by both and provides commonly used interfaces and classes for active components and their management.

The newest version!
package jadex.bridge.nonfunctional;

import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.search.SServiceProvider;
import jadex.bridge.service.types.cms.IComponentManagementService;
import jadex.commons.future.DefaultResultListener;
import jadex.commons.future.DelegationResultListener;
import jadex.commons.future.ExceptionDelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;

/**
 * 
 */
public abstract class NFRootProperty extends SimpleValueNFProperty
{
	/** The root access. */
	protected IExternalAccess root;
	
	/** The flag if the property has been injected to the root component. */
	protected boolean injected;
	
	/**
	 *  Create a new property.
	 */
	public NFRootProperty(final IInternalAccess comp, final NFPropertyMetaInfo mi)
	{
		this(comp, mi, true);
	}
	
	/**
	 *  Create a new property.
	 */
	public NFRootProperty(final IInternalAccess comp, final NFPropertyMetaInfo mi, boolean inject)
	{
		super(comp, mi);
		if(inject)
		{
			injectPropertyToRootComponent();
		}
	}
	
	/**
	 *  Inject the property to the root component.
	 */
	protected IFuture injectPropertyToRootComponent()
	{
		final Future ret = new Future();

		if(!injected)
		{
			this.injected = true;
			
			// Add property to root component
			SServiceProvider.getService(comp.getServiceContainer(), IComponentManagementService.class, RequiredServiceInfo.SCOPE_PLATFORM)
				.addResultListener(new ExceptionDelegationResultListener(ret)
			{
				public void customResultAvailable(IComponentManagementService cms)
				{
					cms.getExternalAccess(comp.getComponentIdentifier().getRoot()).addResultListener(new DefaultResultListener()
					{
						public void resultAvailable(IExternalAccess root)
						{
							NFRootProperty.this.root = root;
							INFPropertyMetaInfo mi = getMetaInfo();
							NFPropertyMetaInfo cmi = new NFPropertyMetaInfo(mi.getName(), mi.getType(), mi.getUnit(), mi.isDynamic(), mi.getUpdateRate(), mi.isRealtime(), Target.Root);
							root.addNFProperty(new NFPropertyRef(comp.getExternalAccess(), root, cmi)).addResultListener(new DelegationResultListener(ret));
						}
					});
				}
			});
		}
		else
		{
			ret.setResult(null);
		}
		
		return ret;
	}
	
	/**
	 *  Property was removed and should be disposed.
	 */
	public IFuture dispose()
	{
		if(root!=null && injected)
		{
			root.removeNFProperty(getName());//.addResultListener(new DelegationResultListener(ret));
		}
		return super.dispose();
	}

	/**
	 *  Get the injected.
	 *  @return The injected.
	 */
	public boolean isInjected()
	{
		return injected;
	}
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy