You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/04/10 17:56:15 UTC
svn commit: r1466532 - in /karaf/trunk/scr:
command/src/main/java/org/apache/karaf/scr/command/
command/src/main/java/org/apache/karaf/scr/command/action/
command/src/main/java/org/apache/karaf/scr/command/completer/
management/src/main/java/org/apache...
Author: jbonofre
Date: Wed Apr 10 15:56:14 2013
New Revision: 1466532
URL: http://svn.apache.org/r1466532
Log:
[KARAF-2257] Add SCR hidden component support
Modified:
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ActivateCommandComponent.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DeactivateCommandComponent.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DetailsCommandComponent.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ListCommandComponent.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandConstants.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandSupport.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java
karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java
karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java
karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ActivateCommandComponent.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ActivateCommandComponent.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ActivateCommandComponent.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ActivateCommandComponent.java Wed Apr 10 15:56:14 2013
@@ -34,8 +34,16 @@ import aQute.bnd.annotation.component.Re
/**
* Shell Command used to activate a Declarative Service Component.
*/
-@Component(provide=CompletableFunction.class, name = ActivateCommandComponent.COMPONENT_NAME, enabled = true, immediate = true,
- properties={ ScrCommandConstants.OSGI_COMMAND_SCOPE_KEY+"="+ScrCommandConstants.SCR_COMMAND, ScrCommandConstants.OSGI_COMMAND_FUNCTION_KEY+"="+ScrCommandConstants.ACTIVATE_FUNCTION})
+@Component(
+ provide=CompletableFunction.class,
+ name = ActivateCommandComponent.COMPONENT_NAME,
+ enabled = true,
+ immediate = true,
+ properties={
+ ScrCommandConstants.OSGI_COMMAND_SCOPE_KEY + "=" + ScrCommandConstants.SCR_COMMAND,
+ ScrCommandConstants.OSGI_COMMAND_FUNCTION_KEY + "=" + ScrCommandConstants.ACTIVATE_FUNCTION,
+ ScrCommandConstants.HIDDEN_COMPONENT_KEY + "=true"
+ })
public class ActivateCommandComponent extends ScrCommandSupport {
public static final String COMPONENT_NAME = "ActivateCommand";
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DeactivateCommandComponent.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DeactivateCommandComponent.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DeactivateCommandComponent.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DeactivateCommandComponent.java Wed Apr 10 15:56:14 2013
@@ -34,8 +34,16 @@ import aQute.bnd.annotation.component.Re
/**
* Shell Command used to deactivate a Declarative Service Component.
*/
-@Component(provide=CompletableFunction.class, name = DeactivateCommandComponent.COMPONENT_NAME, enabled = true, immediate = true,
- properties={ ScrCommandConstants.OSGI_COMMAND_SCOPE_KEY+"="+ScrCommandConstants.SCR_COMMAND, ScrCommandConstants.OSGI_COMMAND_FUNCTION_KEY+"="+ScrCommandConstants.DEACTIVATE_FUNCTION})
+@Component(
+ provide=CompletableFunction.class,
+ name = DeactivateCommandComponent.COMPONENT_NAME,
+ enabled = true,
+ immediate = true,
+ properties={
+ ScrCommandConstants.OSGI_COMMAND_SCOPE_KEY + "=" + ScrCommandConstants.SCR_COMMAND,
+ ScrCommandConstants.OSGI_COMMAND_FUNCTION_KEY + "=" + ScrCommandConstants.DEACTIVATE_FUNCTION,
+ ScrCommandConstants.HIDDEN_COMPONENT_KEY + "=true"
+ })
public class DeactivateCommandComponent extends ScrCommandSupport {
public static final String COMPONENT_NAME = "DeactivateCommand";
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DetailsCommandComponent.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DetailsCommandComponent.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DetailsCommandComponent.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/DetailsCommandComponent.java Wed Apr 10 15:56:14 2013
@@ -35,8 +35,16 @@ import aQute.bnd.annotation.component.Re
* Shell Command that prints the current state details of a given
* Declarative Service Component.
*/
-@Component(provide=CompletableFunction.class, name = DetailsCommandComponent.COMPONENT_NAME, enabled = true, immediate = true,
- properties={ ScrCommandConstants.OSGI_COMMAND_SCOPE_KEY+"="+ScrCommandConstants.SCR_COMMAND, ScrCommandConstants.OSGI_COMMAND_FUNCTION_KEY+"="+ScrCommandConstants.DETAILS_FUNCTION})
+@Component(
+ provide=CompletableFunction.class,
+ name = DetailsCommandComponent.COMPONENT_NAME,
+ enabled = true,
+ immediate = true,
+ properties={
+ ScrCommandConstants.OSGI_COMMAND_SCOPE_KEY + "=" + ScrCommandConstants.SCR_COMMAND,
+ ScrCommandConstants.OSGI_COMMAND_FUNCTION_KEY + "=" + ScrCommandConstants.DETAILS_FUNCTION,
+ ScrCommandConstants.HIDDEN_COMPONENT_KEY + "=true"
+ })
public class DetailsCommandComponent extends ScrCommandSupport {
public static final String COMPONENT_NAME = "DetailsCommand";
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ListCommandComponent.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ListCommandComponent.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ListCommandComponent.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ListCommandComponent.java Wed Apr 10 15:56:14 2013
@@ -32,8 +32,16 @@ import aQute.bnd.annotation.component.Re
/**
* Shell Command that lists the available Declarative Service Components.
*/
-@Component(provide=CompletableFunction.class, name = ListCommandComponent.COMPONENT_NAME, enabled = true, immediate = true,
- properties={ ScrCommandConstants.OSGI_COMMAND_SCOPE_KEY+"="+ScrCommandConstants.SCR_COMMAND, ScrCommandConstants.OSGI_COMMAND_FUNCTION_KEY+"="+ScrCommandConstants.LIST_FUNCTION})
+@Component(
+ provide=CompletableFunction.class,
+ name = ListCommandComponent.COMPONENT_NAME,
+ enabled = true,
+ immediate = true,
+ properties={
+ ScrCommandConstants.OSGI_COMMAND_SCOPE_KEY + "=" + ScrCommandConstants.SCR_COMMAND,
+ ScrCommandConstants.OSGI_COMMAND_FUNCTION_KEY + "=" + ScrCommandConstants.LIST_FUNCTION,
+ ScrCommandConstants.HIDDEN_COMPONENT_KEY + "=true"
+ })
public class ListCommandComponent extends ScrCommandSupport {
public static final String COMPONENT_NAME = "ListCommand";
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandConstants.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandConstants.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandConstants.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandConstants.java Wed Apr 10 15:56:14 2013
@@ -22,6 +22,8 @@ public class ScrCommandConstants {
public static final String OSGI_COMMAND_FUNCTION_KEY = "osgi.command.function";
+ public static final String HIDDEN_COMPONENT_KEY = "hidden.component";
+
public static final String SCR_COMMAND = "scr";
public static final String LIST_FUNCTION = "list";
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandSupport.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandSupport.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/ScrCommandSupport.java Wed Apr 10 15:56:14 2013
@@ -48,8 +48,7 @@ public abstract class ScrCommandSupport
public Action createNewAction() {
try {
lock.readLock().lock();
- ScrActionSupport action = (ScrActionSupport) getActionClass()
- .newInstance();
+ ScrActionSupport action = (ScrActionSupport) getActionClass().newInstance();
action.setScrService(getScrService());
return action;
} catch (InstantiationException e) {
@@ -69,8 +68,7 @@ public abstract class ScrCommandSupport
lock.readLock().lock();
completers = new ArrayList<Completer>();
for (Class<? extends Completer> completerClass : getCompleterClasses()) {
- ScrCompleterSupport ccs = (ScrCompleterSupport) completerClass
- .newInstance();
+ ScrCompleterSupport ccs = (ScrCompleterSupport) completerClass.newInstance();
ccs.setScrService(scrService);
completers.add(ccs);
}
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java Wed Apr 10 15:56:14 2013
@@ -25,7 +25,6 @@ import org.apache.karaf.scr.command.ScrU
/**
* Activates the given component by supplying its component name.
- *
*/
@Command(scope = ScrCommandConstants.SCR_COMMAND, name = ScrCommandConstants.ACTIVATE_FUNCTION, description = "Activates a Component for the given name")
public class ActivateAction extends ScrActionSupport {
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java Wed Apr 10 15:56:14 2013
@@ -24,7 +24,6 @@ import org.apache.karaf.scr.command.ScrC
/**
* Deactivates the given component by supplying its component name.
- *
*/
@Command(scope = ScrCommandConstants.SCR_COMMAND, name = ScrCommandConstants.DEACTIVATE_FUNCTION, description = "Deactivates a Component for the given name")
public class DeactivateAction extends ScrActionSupport {
@@ -34,7 +33,7 @@ public class DeactivateAction extends Sc
@Override
protected Object doScrAction(ScrService scrService) throws Exception {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("Deactivate Action");
logger.debug(" Deactivating the Component: " + name);
}
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java Wed Apr 10 15:56:14 2013
@@ -27,6 +27,8 @@ import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentConstants;
+import java.util.Hashtable;
+
/**
* Displays the details associated with a given component by supplying its component name.
*/
@@ -39,7 +41,7 @@ public class DetailsAction extends ScrAc
@SuppressWarnings("rawtypes")
@Override
protected Object doScrAction(ScrService scrService) throws Exception {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("Executing the Details Action");
}
System.out.println(getBoldString("Component Details"));
@@ -47,43 +49,48 @@ public class DetailsAction extends ScrAc
for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
printDetail(" Name : ", component.getName());
printDetail(" State : ", ScrUtils.getState(component.getState()));
+
+ Hashtable props = (Hashtable)component.getProperties();
+ if (!props.isEmpty()) {
+ System.out.println(getBoldString(" Properties : "));
+ for (Object key : props.keySet()) {
+ Object value = props.get(key);
+ printDetail(" ", key + "=" + value);
+ }
+ }
Reference[] references = component.getReferences();
System.out.println(getBoldString("References"));
- for (Reference reference : ScrUtils.emptyIfNull(Reference.class,references)) {
+ for (Reference reference : ScrUtils.emptyIfNull(Reference.class, references)) {
printDetail(" Reference : ", reference.getName());
- printDetail(" State : ", (reference.isSatisfied())?"satisfied":"unsatisfied");
+ printDetail(" State : ", (reference.isSatisfied()) ? "satisfied" : "unsatisfied");
printDetail(" Multiple : ", (reference.isMultiple() ? "multiple" : "single" ));
printDetail(" Optional : ", (reference.isOptional() ? "optional" : "mandatory" ));
- printDetail(" Policy : ", (reference.isStatic() ? "static" : "dynamic" ));
+ printDetail(" Policy : ", (reference.isStatic() ? "static" : "dynamic" ));
// list bound services
ServiceReference[] boundRefs = reference.getServiceReferences();
for (ServiceReference serviceReference : ScrUtils.emptyIfNull(ServiceReference.class, boundRefs)) {
final StringBuffer b = new StringBuffer();
- b.append( "Bound Service ID " );
- b.append( serviceReference.getProperty( Constants.SERVICE_ID ) );
+ b.append("Bound Service ID ");
+ b.append(serviceReference.getProperty(Constants.SERVICE_ID));
- String componentName = ( String ) serviceReference.getProperty( ComponentConstants.COMPONENT_NAME );
- if ( componentName == null )
- {
- componentName = ( String ) serviceReference.getProperty( Constants.SERVICE_PID );
- if ( componentName == null )
- {
- componentName = ( String ) serviceReference.getProperty( Constants.SERVICE_DESCRIPTION );
+ String componentName = (String) serviceReference.getProperty(ComponentConstants.COMPONENT_NAME);
+ if (componentName == null) {
+ componentName = (String) serviceReference.getProperty(Constants.SERVICE_PID);
+ if (componentName == null) {
+ componentName = (String) serviceReference.getProperty(Constants.SERVICE_DESCRIPTION);
}
}
- if ( componentName != null )
- {
- b.append( " (" );
- b.append( componentName );
- b.append( ")" );
+ if (componentName != null) {
+ b.append(" (");
+ b.append(componentName);
+ b.append(")");
}
printDetail(" Service Reference : ", b.toString());
}
- if(ScrUtils.emptyIfNull(ServiceReference.class, boundRefs).length == 0)
- {
+ if(ScrUtils.emptyIfNull(ServiceReference.class, boundRefs).length == 0) {
printDetail(" Service Reference : ", "No Services bound");
}
}
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java Wed Apr 10 15:56:14 2013
@@ -30,21 +30,32 @@ public class ListAction extends ScrActio
@Override
protected Object doScrAction(ScrService scrService) throws Exception {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("Executing the List Action");
}
- System.out.println(getBoldString(
- " ID State Component Name"));
+ System.out.println(getBoldString(" ID State Component Name"));
Component[] components = scrService.getComponents();
for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
- String name = component.getName();
- String id = buildLeftPadBracketDisplay(component.getId() + "", 4);
- String state = buildRightPadBracketDisplay(
- ScrUtils.getState(component.getState()), 16);
- System.out.println(
- "[" + id + "] [" + state + "] " + name);
+ if (showHidden) {
+ // we display all because we are overridden
+ printComponent(component);
+ } else {
+ if (ScrActionSupport.isHiddenComponent(component)) {
+ // do nothing
+ } else {
+ // we aren't hidden so print it
+ printComponent(component);
+ }
+ }
}
return null;
}
+ private void printComponent(Component component) {
+ String name = component.getName();
+ String id = buildLeftPadBracketDisplay(component.getId() + "", 4);
+ String state = buildRightPadBracketDisplay(ScrUtils.getState(component.getState()), 16);
+ System.out.println("[" + id + "] [" + state + "] " + name);
+ }
+
}
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java Wed Apr 10 15:56:14 2013
@@ -16,22 +16,39 @@
*/
package org.apache.karaf.scr.command.action;
+import org.apache.felix.scr.Component;
import org.apache.felix.scr.ScrService;
+import org.apache.felix.service.command.CommandSession;
+import org.apache.karaf.scr.command.ScrCommandConstants;
+import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.AbstractAction;
+import org.apache.karaf.shell.console.CommandSessionHolder;
+import org.apache.karaf.shell.console.SubShellAction;
+import org.apache.karaf.shell.console.completer.ArgumentCompleter;
import org.fusesource.jansi.Ansi;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class ScrActionSupport extends AbstractAction {
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+
+public abstract class ScrActionSupport extends SubShellAction {
+
+ @Option(name = ScrActionSupport.SHOW_ALL_OPTION, aliases = {ScrActionSupport.SHOW_ALL_ALIAS}, description = "Show all Components including the System Components (hidden by default)", required = false, multiValued = false)
+ boolean showHidden = false;
+
+ public static final String SHOW_ALL_OPTION = "-s";
+ public static final String SHOW_ALL_ALIAS = "--show-hidden";
protected final Logger logger = LoggerFactory.getLogger(getClass().getName());
private ScrService scrService;
@Override
- protected Object doExecute() throws Exception {
+ public Object doExecute() throws Exception {
if (scrService == null) {
String msg = "ScrService is unavailable";
System.out.println(msg);
@@ -42,12 +59,46 @@ public abstract class ScrActionSupport e
return null;
}
- protected abstract Object doScrAction(ScrService scrService)
- throws Exception;
+ protected abstract Object doScrAction(ScrService scrService) throws Exception;
+
+ protected boolean isActionable(Component component) {
+ boolean answer = true;
+ return answer;
+ }
+
+ public static boolean showHiddenComponent(Component component) {
+ boolean answer = false;
+ // first look to see if the show all option is there
+ // if it is we set showAllFlag to true so the next section will be skipped
+ CommandSession commandSession = CommandSessionHolder.getSession();
+ ArgumentCompleter.ArgumentList list = (ArgumentCompleter.ArgumentList) commandSession.get(ArgumentCompleter.ARGUMENTS_LIST);
+ if (list != null && list.getArguments() != null && list.getArguments().length > 0) {
+ List<String> arguments = Arrays.asList(list.getArguments());
+ if (arguments.contains(ScrActionSupport.SHOW_ALL_OPTION) || arguments.contains(ScrActionSupport.SHOW_ALL_ALIAS)) {
+ answer = true;
+ }
+ }
+
+ return answer;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public static boolean isHiddenComponent(Component component) {
+ boolean answer = false;
+ Hashtable properties = (Hashtable) component.getProperties();
+ if (properties != null && properties.containsKey(ScrCommandConstants.HIDDEN_COMPONENT_KEY)) {
+ String value = (String) properties.get(ScrCommandConstants.HIDDEN_COMPONENT_KEY);
+ // if the value is false, show the hidden
+ // then someone wants us to display the name of a hidden component
+ if (value != null && value.equals("true")) {
+ answer = true;
+ }
+ }
+ return answer;
+ }
public String getBoldString(String value) {
- return Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(value)
- .a(Ansi.Attribute.INTENSITY_BOLD_OFF).toString();
+ return Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(value).a(Ansi.Attribute.INTENSITY_BOLD_OFF).toString();
}
public String buildRightPadBracketDisplay(String s, int max) {
@@ -81,8 +132,7 @@ public abstract class ScrActionSupport e
/**
* Sets the scrService Object for this ScrActionSupport instance.
*
- * @param scrService
- * the scrService to set
+ * @param scrService the scrService to set
*/
public void setScrService(ScrService scrService) {
this.scrService = scrService;
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java Wed Apr 10 15:56:14 2013
@@ -28,8 +28,7 @@ public class ActivateCompleter extends S
*/
@Override
public boolean availableComponent(Component component) throws Exception {
- return (component != null
- && component.getState() == Component.STATE_DISABLED);
+ return (component != null && component.getState() == Component.STATE_DISABLED);
}
}
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java Wed Apr 10 15:56:14 2013
@@ -28,11 +28,7 @@ public class DeactivateCompleter extends
*/
@Override
public boolean availableComponent(Component component) throws Exception {
- return (component != null
- && (
- component.getState() == Component.STATE_ACTIVE ||
- component.getState() == Component.STATE_REGISTERED ||
- component.getState() == Component.STATE_UNSATISFIED));
+ return (component != null && (component.getState() == Component.STATE_ACTIVE));
}
}
Modified: karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java (original)
+++ karaf/trunk/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java Wed Apr 10 15:56:14 2013
@@ -20,11 +20,16 @@ import java.util.List;
import org.apache.felix.scr.Component;
import org.apache.felix.scr.ScrService;
+import org.apache.karaf.scr.command.action.ScrActionSupport;
import org.apache.karaf.shell.console.Completer;
import org.apache.karaf.shell.console.completer.StringsCompleter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public abstract class ScrCompleterSupport implements Completer {
+ protected final transient Logger logger = LoggerFactory.getLogger(ScrCompleterSupport.class);
+
private ScrService scrService;
/**
@@ -38,18 +43,32 @@ public abstract class ScrCompleterSuppor
StringsCompleter delegate = new StringsCompleter();
try {
for (Component component : scrService.getComponents()) {
- if (availableComponent(component)) {
- delegate.getStrings().add(component.getName());
+ if (logger.isDebugEnabled()) {
+ logger.debug("Component Name to work on: " + component.getName());
+ }
+ if (ScrActionSupport.showHiddenComponent(component)) {
+ // we display all because we are overridden
+ if (availableComponent(component)) {
+ delegate.getStrings().add(component.getName());
+ }
+ } else {
+ if (ScrActionSupport.isHiddenComponent(component)) {
+ // do nothing
+ } else {
+ // we aren't hidden so print it
+ if (availableComponent(component)) {
+ delegate.getStrings().add(component.getName());
+ }
+ }
}
}
} catch (Exception e) {
- // Ignore
+ logger.warn("Exception completing the command request: " + e.getLocalizedMessage());
}
return delegate.complete(buffer, cursor, candidates);
}
- public abstract boolean availableComponent(Component component)
- throws Exception;
+ public abstract boolean availableComponent(Component component) throws Exception;
/**
* Get the scrService Object associated with this instance of
Modified: karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java (original)
+++ karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java Wed Apr 10 15:56:14 2013
@@ -16,14 +16,51 @@
*/
package org.apache.karaf.scr.management;
+/**
+ * The management interface for SCR Components.
+ */
public interface ScrServiceMBean {
+
+ /**
+ * Presents a {@String} array of components currently registered with the SCR.
+ *
+ * @return String[]
+ * @throws Exception
+ */
String[] listComponents() throws Exception;
+ /**
+ * Verifies if the named component is currently in an ACTIVE state.
+ *
+ * @param componentName the components name
+ * @return true if ACTIVE, otherwise false
+ * @throws Exception
+ */
boolean isComponentActive(String componentName) throws Exception;
-
+
+ /**
+ * Returns the named components state
+ *
+ * @param componentName the components name
+ * @return
+ * @throws Exception
+ */
int componentState(String componentName) throws Exception;
+ /**
+ * Activates a component that is currently in a DISABLED state.
+ *
+ * @param componentName the components name
+ * @throws Exception
+ */
void activateComponent(String componentName) throws Exception;
- void deactiveateComponent(String componentName) throws Exception;
+ /**
+ * Disables a component that is not in an ACTIVE state.
+ *
+ * @param componentName the components name
+ * @throws Exception
+ */
+ void deactivateComponent(String componentName) throws Exception;
+
}
Modified: karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java?rev=1466532&r1=1466531&r2=1466532&view=diff
==============================================================================
--- karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java (original)
+++ karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java Wed Apr 10 15:56:14 2013
@@ -40,7 +40,8 @@ import org.slf4j.LoggerFactory;
@aQute.bnd.annotation.component.Component(
name = ScrServiceMBeanImpl.COMPONENT_NAME,
enabled = true,
- immediate = true)
+ immediate = true,
+ properties = { "hidden.component=true" })
public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBean {
public static final String OBJECT_NAME = "org.apache.karaf:type=scr,name=" + System.getProperty("karaf.name", "root");
@@ -107,6 +108,12 @@ public class ScrServiceMBeanImpl extends
}
}
+ /*
+ * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#listComponents()
+ *
+ * @return
+ * @throws Exception
+ */
public String[] listComponents() throws Exception {
Component[] components = safe(scrService.getComponents());
String[] componentNames = new String[components.length];
@@ -116,10 +123,24 @@ public class ScrServiceMBeanImpl extends
return componentNames;
}
+ /*
+ * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#isComponentActive(java.lang.String)
+ *
+ * @param componentName
+ * @return
+ * @throws Exception
+ */
public boolean isComponentActive(String componentName) throws Exception {
return (componentState(componentName) == Component.STATE_ACTIVE)?true:false;
}
-
+
+ /*
+ * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#componentState(java.lang.String)
+ *
+ * @param componentName
+ * @return
+ * @throws Exception
+ */
public int componentState(String componentName) throws Exception {
int state = -1;
final Component component = findComponent(componentName);
@@ -130,6 +151,12 @@ public class ScrServiceMBeanImpl extends
return state;
}
+ /*
+ * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#activateComponent(java.lang.String)
+ *
+ * @param componentName
+ * @throws Exception
+ */
public void activateComponent(String componentName) throws Exception {
final Component component = findComponent(componentName);
if(component != null)
@@ -138,7 +165,13 @@ public class ScrServiceMBeanImpl extends
LOGGER.warn("No component found for name: " + componentName);
}
- public void deactiveateComponent(String componentName) throws Exception {
+ /*
+ * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#deactiveateComponent(java.lang.String)
+ *
+ * @param componentName
+ * @throws Exception
+ */
+ public void deactivateComponent(String componentName) throws Exception {
final Component component = findComponent(componentName);
if(component != null)
component.disable();