Scr plugin for webconsole, decorates bundle list
Signed-off-by: Lukasz Dywicki <luke@code-house.org>
git-svn-id: https://svn.apache.org/repos/asf/karaf/webconsole/trunk@1225174 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/osgi/scr/pom.xml b/osgi/scr/pom.xml
new file mode 100644
index 0000000..c5a84ce
--- /dev/null
+++ b/osgi/scr/pom.xml
@@ -0,0 +1,73 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf.webconsole</groupId>
+ <artifactId>osgi</artifactId>
+ <version>0.3.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.karaf.webconsole.osgi</groupId>
+ <artifactId>org.apache.karaf.webconsole.osgi.scr</artifactId>
+ <name>Apache Karaf :: WebConsole :: OSGi :: Scr</name>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.karaf.webconsole.osgi</groupId>
+ <artifactId>org.apache.karaf.webconsole.osgi.bundle</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr</artifactId>
+ <version>1.6.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.3.5</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Import-Package>
+ !org.apache.karaf.webconsole.osgi.blueprint*,
+ *,
+ <!-- transient dependencies -->
+ org.ops4j.pax.wicket.api,
+ org.ops4j.pax.wicket.util,
+ org.ops4j.pax.wicket.util.proxy
+ </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</Service-Component>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrColumn.java b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrColumn.java
new file mode 100644
index 0000000..fe72357
--- /dev/null
+++ b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrColumn.java
@@ -0,0 +1,55 @@
+/*
+ * 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 static org.apache.wicket.model.Model.of;
+
+import org.apache.felix.scr.Component;
+import org.apache.felix.scr.ScrService;
+import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.model.IModel;
+import org.osgi.framework.Bundle;
+
+/**
+ * A dedicated column to display scr component states.
+ */
+public class ScrColumn extends AbstractColumn<Bundle> {
+
+ private ScrService scr;
+
+ public ScrColumn(ScrService scr, String title) {
+ super(of(title));
+ this.scr = scr;
+ }
+
+ public void populateItem(Item<ICellPopulator<Bundle>> cellItem, String componentId, IModel<Bundle> rowModel) {
+ if (scr == null) {
+ return;
+ }
+
+ Component[] components = scr.getComponents(rowModel.getObject());
+ if (components != null) {
+ cellItem.add(new ScrColumnPanel(componentId, components));
+ } else {
+ // no scr for this bundle
+ cellItem.add(new Label(componentId));
+ }
+ }
+}
\ No newline at end of file
diff --git a/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrColumnPanel.java b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrColumnPanel.java
new file mode 100644
index 0000000..2ec80e0
--- /dev/null
+++ b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrColumnPanel.java
@@ -0,0 +1,50 @@
+/*
+ * 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 static org.apache.wicket.model.Model.of;
+
+import org.apache.felix.scr.Component;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.markup.repeater.RepeatingView;
+
+/**
+ * Panel to list components and it's states.
+ */
+public class ScrColumnPanel extends Panel {
+
+ public ScrColumnPanel(String id, Component[] components) {
+ super(id);
+
+ RepeatingView view = new RepeatingView("components", of(components));
+
+ for (Component component : components) {
+ MarkupContainer container = new WebMarkupContainer(view.newChildId());
+
+ container.add(new Label("name", component.getName()));
+ container.add(new Label("state", ScrUtils.getState(component)));
+
+ view.add(container);
+ }
+
+ add(view);
+ }
+
+}
diff --git a/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrColumnProvider.java b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrColumnProvider.java
new file mode 100644
index 0000000..366202c
--- /dev/null
+++ b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrColumnProvider.java
@@ -0,0 +1,32 @@
+/*
+ * 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.karaf.webconsole.osgi.bundle.IColumnProvider;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
+import org.osgi.framework.Bundle;
+
+/**
+ * Scr column provider, creates a dedicated column.
+ */
+public class ScrColumnProvider extends ScrComponent implements IColumnProvider {
+
+ public IColumn<Bundle> getColumn() {
+ return new ScrColumn(scr, "SCR");
+ }
+
+}
diff --git a/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrComponent.java b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrComponent.java
new file mode 100644
index 0000000..3dd735f
--- /dev/null
+++ b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrComponent.java
@@ -0,0 +1,37 @@
+/*
+ * 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.ScrService;
+
+/**
+ * Base class for scr-dependand extensions.
+ */
+public class ScrComponent {
+
+ protected ScrService scr;
+
+ public void bind(ScrService service) {
+ this.scr = service;
+ }
+
+ public void unbind(ScrService service) {
+ this.scr = null;
+ }
+
+}
\ No newline at end of file
diff --git a/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrDecorationProvider.java b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrDecorationProvider.java
new file mode 100644
index 0000000..7b1b28d
--- /dev/null
+++ b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrDecorationProvider.java
@@ -0,0 +1,46 @@
+/*
+ * 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 static org.apache.wicket.markup.html.CSSPackageResource.getHeaderContribution;
+
+import org.apache.karaf.webconsole.core.panel.CssImagePanel;
+import org.apache.karaf.webconsole.osgi.bundle.IDecorationProvider;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
+import org.osgi.framework.Bundle;
+
+/**
+ * A decoration provider which add scr icon in first column of bundles.
+ */
+public class ScrDecorationProvider extends ScrComponent implements IDecorationProvider {
+
+ public Panel getDecoration(String componentId, IModel<Bundle> model) {
+ Bundle bundle = model.getObject();
+
+ if (scr == null || scr.getComponents(bundle) == null) {
+ return null;
+ }
+
+ // if scr is present and components are not null - then we have a scr components
+ CssImagePanel imagePanel = new CssImagePanel(componentId, "scr");
+ imagePanel.add(getHeaderContribution(getClass(), "decorator.css"));
+ return imagePanel;
+ }
+
+}
diff --git a/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrUtils.java b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrUtils.java
new file mode 100644
index 0000000..b491d52
--- /dev/null
+++ b/osgi/scr/src/main/java/org/apache/karaf/webconsole/osgi/scr/ScrUtils.java
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+/**
+ * Utility class to extract component state from int mask.
+ */
+public class ScrUtils {
+
+ @SuppressWarnings("deprecation")
+ public static String getState(Component component) {
+ switch (component.getState()) {
+ case Component.STATE_DISABLED:
+ return "disabled";
+ case Component.STATE_ENABLING:
+ return "enabling";
+ case Component.STATE_ENABLED:
+ return "enabled";
+ case Component.STATE_UNSATISFIED:
+ return "unsatisfied";
+ case Component.STATE_ACTIVATING:
+ return "activating";
+ case Component.STATE_ACTIVE:
+ return "active";
+ case Component.STATE_REGISTERED:
+ return "registered";
+ case Component.STATE_FACTORY:
+ return "factory";
+ case Component.STATE_DEACTIVATING:
+ return "deactivating";
+ case Component.STATE_DISABLING:
+ return "disabling";
+ case Component.STATE_DISPOSING:
+ return "disposing";
+ case Component.STATE_DISPOSED:
+ return "disposed";
+ default:
+ return "" + component.getState();
+ }
+ }
+
+}
diff --git a/osgi/scr/src/main/resources/OSGI-INF/column.xml b/osgi/scr/src/main/resources/OSGI-INF/column.xml
new file mode 100644
index 0000000..1a57cbf
--- /dev/null
+++ b/osgi/scr/src/main/resources/OSGI-INF/column.xml
@@ -0,0 +1,26 @@
+<?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-column-plugin">
+ <implementation class="org.apache.karaf.webconsole.osgi.scr.ScrColumnProvider"/>
+
+ <service>
+ <provide interface="org.apache.karaf.webconsole.osgi.bundle.IColumnProvider"/>
+ </service>
+
+ <reference name="ScrService" cardinality="1..1" interface="org.apache.felix.scr.ScrService" policy="static" bind="bind" unbind="unbind" />
+</scr:component>
diff --git a/osgi/scr/src/main/resources/OSGI-INF/decoration.xml b/osgi/scr/src/main/resources/OSGI-INF/decoration.xml
new file mode 100644
index 0000000..9655adb
--- /dev/null
+++ b/osgi/scr/src/main/resources/OSGI-INF/decoration.xml
@@ -0,0 +1,26 @@
+<?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-decoration-plugin">
+ <implementation class="org.apache.karaf.webconsole.osgi.scr.ScrDecorationProvider" />
+
+ <service>
+ <provide interface="org.apache.karaf.webconsole.osgi.bundle.IDecorationProvider"/>
+ </service>
+
+ <reference name="ScrService" cardinality="1..1" interface="org.apache.felix.scr.ScrService" policy="static" bind="bind" unbind="unbind" />
+</scr:component>
diff --git a/osgi/scr/src/main/resources/org/apache/karaf/webconsole/osgi/scr/ScrColumnPanel.html b/osgi/scr/src/main/resources/org/apache/karaf/webconsole/osgi/scr/ScrColumnPanel.html
new file mode 100644
index 0000000..c407880
--- /dev/null
+++ b/osgi/scr/src/main/resources/org/apache/karaf/webconsole/osgi/scr/ScrColumnPanel.html
@@ -0,0 +1,35 @@
+<?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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <title>Karaf WebConsole</title>
+</head>
+<body>
+
+ <wicket:panel>
+ <ul>
+ <li wicket:id="components">
+ <span wicket:id="name">component-name</span>
+ <span wicket:id="state">ACTIVE</span>
+ </li>
+ </ul>
+ </wicket:panel>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/osgi/scr/src/main/resources/org/apache/karaf/webconsole/osgi/scr/decorator.css b/osgi/scr/src/main/resources/org/apache/karaf/webconsole/osgi/scr/decorator.css
new file mode 100644
index 0000000..6b48c3c
--- /dev/null
+++ b/osgi/scr/src/main/resources/org/apache/karaf/webconsole/osgi/scr/decorator.css
@@ -0,0 +1,6 @@
+.scr {
+ background: url("scr.gif");
+ width: 16px;
+ height: 16px;
+ display: block;
+}
\ No newline at end of file
diff --git a/osgi/scr/src/main/resources/org/apache/karaf/webconsole/osgi/scr/scr.gif b/osgi/scr/src/main/resources/org/apache/karaf/webconsole/osgi/scr/scr.gif
new file mode 100644
index 0000000..cc9cbea
--- /dev/null
+++ b/osgi/scr/src/main/resources/org/apache/karaf/webconsole/osgi/scr/scr.gif
Binary files differ