Permalink
Browse files

KARAF-1785 Provide additional actions for SCR plugin

Signed-off-by: Lukasz Dywicki <luke@code-house.org>

git-svn-id: https://svn.apache.org/repos/asf/karaf/webconsole/trunk@1379106 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent f44b86f commit 4d802b702ae13137483af470b9034847eb7eb403 @splatch splatch committed Aug 30, 2012
View
@@ -61,7 +61,7 @@
</Import-Package>
<Export-Package></Export-Package>
<Private-Package>org.apache.karaf.webconsole.osgi.scr*,</Private-Package>
- <Service-Component>OSGI-INF/column.xml,OSGI-INF/decoration.xml,OSGI-INF/component.xml</Service-Component>
+ <Service-Component>OSGI-INF/column.xml,OSGI-INF/decoration.xml,OSGI-INF/action.xml,OSGI-INF/component.xml</Service-Component>
</instructions>
</configuration>
</plugin>
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.karaf.webconsole.osgi.scr;
+
+import org.apache.felix.scr.Component;
+import org.apache.karaf.webconsole.osgi.scr.link.DisableLink;
+import org.apache.karaf.webconsole.osgi.scr.link.EnableLink;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.markup.repeater.RepeatingView;
+import org.apache.wicket.model.IModel;
+import org.osgi.framework.Bundle;
+
+public class ScrActionPanel extends Panel {
+
+ private static final long serialVersionUID = 1L;
+ private RepeatingView view;
+ private int childCount = 0;
+
+ public ScrActionPanel(String componentId, IModel<Bundle> model, Component[] components) {
+ super(componentId, model);
+
+ view = new RepeatingView("components");
+ for (Component component : components) {
+ switch (component.getState()) {
+ case Component.STATE_ACTIVE:
+ view.add(createDisableLink(component, view.newChildId()));
+ childCount++;
+ break;
+ case Component.STATE_DISABLED:
+ view.add(createEnableLink(component, view.newChildId()));
+ childCount++;
+ break;
+ }
+ }
+
+ add(view);
+ }
+
+ private WebMarkupContainer createDisableLink(Component component, String childId) {
+ WebMarkupContainer container = new WebMarkupContainer(childId);
+ Link<Bundle> link = new DisableLink("link", getModel(), component.getName());
+ link.add(new Label("label", "Disable " + component.getName()));
+ container.add(link);
+ return container;
+ }
+
+ private WebMarkupContainer createEnableLink(Component component, String childId) {
+ WebMarkupContainer container = new WebMarkupContainer(childId);
+ Link<Bundle> link = new EnableLink("link", getModel(), component.getName());
+ link.add(new Label("label", "Enable " + component.getName()));
+ container.add(link);
+ return container;
+ }
+
+ @SuppressWarnings("unchecked")
+ public IModel<Bundle> getModel() {
+ return (IModel<Bundle>) getDefaultModel();
+ }
+
+ @Override
+ public boolean isVisible() {
+ return childCount > 0;
+ }
+
+}
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.karaf.webconsole.osgi.scr;
+
+import org.apache.felix.scr.Component;
+import org.apache.felix.scr.ScrService;
+import org.apache.karaf.webconsole.osgi.core.shared.BundleModel;
+import org.apache.karaf.webconsole.osgi.core.spi.IActionProvider;
+import org.apache.wicket.markup.html.panel.EmptyPanel;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.osgi.framework.Bundle;
+
+public class ScrActionProvider implements IActionProvider {
+
+ public Panel create(String componentId, Bundle object) {
+ ScrService scr = ScrComponent.getScrService();
+ if (scr == null) {
+ return null;
+ }
+
+ Component[] components = scr.getComponents(object);
+ if (components != null) {
+ return new ScrActionPanel(componentId, new BundleModel(object), components);
+ }
+
+ EmptyPanel panel = new EmptyPanel(componentId);
+ panel.setVisible(false);
+ return panel;
+ }
+
+}
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.karaf.webconsole.osgi.scr.link;
+
+import org.apache.felix.scr.Component;
+import org.apache.wicket.Session;
+import org.apache.wicket.model.IModel;
+import org.osgi.framework.Bundle;
+
+public class DisableLink extends ScrLink {
+
+ private static final long serialVersionUID = 1L;
+
+ public DisableLink(String id, IModel<Bundle> model, String componentName) {
+ super(id, model, componentName);
+ }
+
+ @Override
+ public void onClick(Component component) {
+ component.disable();
+ Session.get().info("Component disabled successfully");
+ }
+
+}
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.karaf.webconsole.osgi.scr.link;
+
+import org.apache.felix.scr.Component;
+import org.apache.wicket.Session;
+import org.apache.wicket.model.IModel;
+import org.osgi.framework.Bundle;
+
+public class EnableLink extends ScrLink {
+
+ private static final long serialVersionUID = 1L;
+
+ public EnableLink(String id, IModel<Bundle> model, String componentName) {
+ super(id, model, componentName);
+ }
+
+ @Override
+ public void onClick(Component component) {
+ component.enable();
+ Session.get().info("Component enabled successfully");
+ }
+
+}
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.karaf.webconsole.osgi.scr.link;
+
+import org.apache.felix.scr.Component;
+import org.apache.felix.scr.ScrService;
+import org.apache.karaf.webconsole.osgi.scr.ScrComponent;
+import org.apache.wicket.Session;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.model.IModel;
+import org.osgi.framework.Bundle;
+
+public abstract class ScrLink extends Link<Bundle> {
+
+ private static final long serialVersionUID = 1L;
+
+ private String component;
+
+ public ScrLink(String id, IModel<Bundle> model, String componentName) {
+ super(id, model);
+
+ this.component = componentName;
+ }
+
+ @Override
+ public void onClick() {
+ ScrService scr = ScrComponent.getScrService();
+ if (scr == null) {
+ Session.get().warn("SCR service not found");
+ return;
+ }
+
+ Component[] components = scr.getComponents(getModelObject());
+ if (components == null) {
+ Session.get().warn("SCR components for bundle " + getModelObject().getSymbolicName() + " not found");
+ return;
+ }
+
+ for (Component component : components) {
+ if (this.component == component.getName()) {
+ onClick(component);
+ return;
+ }
+ }
+ Session.get().warn("SCR component named " + component + " not found in bundle " + getModelObject().getSymbolicName());
+ }
+
+ protected abstract void onClick(Component component);
+
+}
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="scr-action-plugin">
+ <implementation class="org.apache.karaf.webconsole.osgi.scr.ScrActionProvider"/>
+
+ <service>
+ <provide interface="org.apache.karaf.webconsole.osgi.core.spi.IActionProvider"/>
+ </service>
+
+</scr:component>
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<wicket:panel xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
+
+ <ul class="unstyled">
+ <li>
+ <span><a>SCR components</a></span>
+ </li>
+ <li class="divider"></li>
+ <li wicket:id="components">
+ <a wicket:id="link">
+ <span wicket:id="label">[component]</span>
+ </a>
+ </li>
+ </ul>
+
+</wicket:panel>

0 comments on commit 4d802b7

Please sign in to comment.