package org.opennaas.extensions.sampleresource.capability.example; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.opennaas.core.resources.ActivatorException; import org.opennaas.core.resources.action.IAction; import org.opennaas.core.resources.action.IActionSet; import org.opennaas.core.resources.capability.AbstractCapability; import org.opennaas.core.resources.capability.CapabilityException; import org.opennaas.core.resources.descriptor.CapabilityDescriptor; import org.opennaas.core.resources.descriptor.ResourceDescriptorConstants; import org.opennaas.extensions.queuemanager.IQueueManagerCapability; /** * * @author Elisabeth Rigol * */ public class ExampleCapability extends AbstractCapability implements IExampleCapability { public static String CAPABILITY_TYPE = "example"; Log log = LogFactory.getLog(ExampleCapability.class); private String resourceId = ""; public ExampleCapability(CapabilityDescriptor descriptor, String resourceId) { super(descriptor); this.resourceId = resourceId; log.debug("Built new Example Capability"); } @Override public void activate() throws CapabilityException { registerService(Activator.getContext(), CAPABILITY_TYPE, getResourceType(), getResourceName(), IExampleCapability.class.getName()); super.activate(); } @Override public void deactivate() throws CapabilityException { unregisterService(); super.deactivate(); } @Override public String getCapabilityName() { return CAPABILITY_TYPE; } @Override public IActionSet getActionSet() throws CapabilityException { String name = this.descriptor.getPropertyValue(ResourceDescriptorConstants.ACTION_NAME); String version = this.descriptor.getPropertyValue(ResourceDescriptorConstants.ACTION_VERSION); try { return Activator.getExampleActionSetService(name, version); } catch (ActivatorException e) { throw new CapabilityException(e); } } @Override public void queueAction(IAction action) throws CapabilityException { getQueueManager(resourceId).queueAction(action); } /** * * @return QueuemanagerService this capability is associated to. * @throws CapabilityException * if desired queueManagerService could not be retrieved. */ private IQueueManagerCapability getQueueManager(String resourceId) throws CapabilityException { try { return Activator.getQueueManagerService(resourceId); } catch (ActivatorException e) { throw new CapabilityException("Failed to get QueueManagerService for resource " + resourceId, e); } } /** * @param the * user name * @return the greeting message * */ @Override public String sayHello(String userName) throws CapabilityException { return "Hello " + userName; } }