Add factory details in the webconsole plugin.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@963389 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/webconsole-plugin/src/main/java/org/apache/felix/ipojo/webconsole/IPOJOPlugin.java b/ipojo/webconsole-plugin/src/main/java/org/apache/felix/ipojo/webconsole/IPOJOPlugin.java
index 5053938..3151389 100644
--- a/ipojo/webconsole-plugin/src/main/java/org/apache/felix/ipojo/webconsole/IPOJOPlugin.java
+++ b/ipojo/webconsole-plugin/src/main/java/org/apache/felix/ipojo/webconsole/IPOJOPlugin.java
@@ -22,6 +22,7 @@
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;
import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.PropertyDescription;
import org.apache.felix.webconsole.AbstractWebConsolePlugin;
import org.apache.felix.webconsole.DefaultVariableResolver;
import org.apache.felix.webconsole.WebConsoleUtil;
@@ -277,6 +278,23 @@
data.put("services", services);
}
+ PropertyDescription[] props = factory.getComponentDescription().getProperties();
+ if (props != null && props.length != 0) {
+ JSONArray properties = new JSONArray();
+ for (int i = 0; i < props.length; i++) {
+ JSONObject prop = new JSONObject();
+ prop.put("name", props[i].getName());
+ prop.put("type", props[i].getType());
+ prop.put("mandatory", props[i].isMandatory());
+ prop.put("immutable", props[i].isImmutable());
+ if (props[i].getValue() != null) {
+ prop.put("value", props[i].getValue());
+ }
+ properties.put(prop);
+ }
+ data.put("properties", properties);
+ }
+
if (! factory.getRequiredHandlers().isEmpty()) {
JSONArray req = new JSONArray
(factory.getRequiredHandlers());
diff --git a/ipojo/webconsole-plugin/src/main/resources/res/ui/bundles.css b/ipojo/webconsole-plugin/src/main/resources/res/ui/bundles.css
new file mode 100644
index 0000000..a4f391b
--- /dev/null
+++ b/ipojo/webconsole-plugin/src/main/resources/res/ui/bundles.css
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+#optionalData {
+ margin: 0;
+ padding: 0;
+}
+
+th.col_Symbolic_Name { width: 9em }
+th.col_Version,
+th.col_Status { width: 7em }
+th.col_Actions { width: 121px }
+.filterBox { float: left; margin-left: 1em }
+.symName { font-style: italic }
+.symName:before { content: " (" }
+.symName:after { content: ")" }
+.filterClear { display: inline-block; vertical-align: middle }
+.bIcon, .bName { display: inline-block }
+.bIcon { float: left }
\ No newline at end of file
diff --git a/ipojo/webconsole-plugin/src/main/resources/res/ui/factory_detail.js b/ipojo/webconsole-plugin/src/main/resources/res/ui/factory_detail.js
new file mode 100644
index 0000000..8425d8c
--- /dev/null
+++ b/ipojo/webconsole-plugin/src/main/resources/res/ui/factory_detail.js
@@ -0,0 +1,160 @@
+/*
+ * 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.
+ */
+function renderFactoryDetails(data) {
+ $(".statline").html(getFactoriesStatLine(data));
+ createDetail( data.data );
+ //$("#plugin_table").trigger("update");
+}
+
+function getFactoriesStatLine(factories) {
+ return factories.count + " factories in total, "
+ + factories.valid_count + " valid factories, "
+ + factories.invalid_count + " invalid factories.";
+}
+
+function createDetail(factory) {
+ console.log("Create details");
+ var name = factory.name;
+ var state = factory.state;
+ var bundle = factory.bundle;
+ var service = "No provided services"
+
+ console.log("Create entry : " + factory);
+
+ var _ = tableBody;
+
+ // Set the name
+ _.find('td.Vname').html(factory.name);
+ // Set the bundle //TODO we can create a link here ?
+ _.find('td.Vbundle').text(factory.bundle);
+ // Set the state
+ _.find('td.Vstate').text(factory.state);
+
+ // Set the services
+ // If define, use a list
+ if (factory.services) {
+ var list = $('<ul>');
+ for (var s in factory.services) {
+ list.append($('<li>').append(factory.services[s]));
+ }
+ _.find('td.Vservices').html(list);
+ } else { // Undefined
+ _.find('td.Vservices').html('<i>No provided service specifications</i>');
+ }
+
+ // Set the properties
+ $(tablePropBody).empty();
+ if (factory.properties) {
+ for (var s in factory.properties) {
+ var prop = factory.properties[s];
+ // For each properties clone the template
+ var entry = propEntryTemplate.clone().appendTo(tablePropBody).attr('id', 'property-' + prop.name);
+ entry.find('td.name').text(prop.name);
+ entry.find('td.type').text(prop.type);
+ entry.find('td.mandatory').text(prop.mandatory);
+ entry.find('td.immutable').text(prop.immutable);
+ if (prop.value) {
+ entry.find('td.value').text(prop.value);
+ } else {
+ entry.find('td.value').html('<i>No default value</i>');
+ }
+ }
+ } else {
+ // Hide the table
+ $('table.properties').hide();
+ }
+
+ // Set the required handlers.
+ if (factory.requiredHandlers) {
+ var list = $('<ul>');
+ for (var s in factory.requiredHandlers) {
+ list.append($('<li>').append(factory.requiredHandlers[s]));
+ }
+ _.find('td.VrequiredHandlers').html(list);
+ } else { // Undefined
+ _.find('td.VrequiredHandlers').html('<i>No required handlers</i>');
+ }
+
+ // Set the missing handlers.
+ if (factory.missingHandlers) {
+ var list = $('<ul>');
+ for (var s in factory.missingHandlers) {
+ list.append($('<li>').append(factory.missingHandlers[s]));
+ }
+ _.find('td.VmissingHandlers').html(list);
+ } else { // Undefined
+ _.find('td.VmissingHandlers').html('<i>No missing handlers</i>');
+ }
+
+ // Set the created instances.
+ if (factory.instances) {
+ var list = $('<ul>');
+ for (var s in factory.instances) {
+ list.append($('<li>').append(factory.instances[s]));
+ }
+ _.find('td.VcreatedInstances').html(list);
+ } else { // Undefined
+ _.find('td.VcreatedInstances').html('<i>No created instances</i>');
+ }
+
+ _.find('pre.architecture_content').text(factory.architecture);
+}
+
+function retrieveDetails() {
+ $.get(pluginRoot + '/factories/' + factory_name + '.json', null, function(data) {
+ renderFactoryDetails(data);
+ }, "json");
+}
+
+function loadFactoriesData() {
+ window.location = factories_url;
+}
+
+function loadInstancesData() {
+ window.location = instances_url;
+}
+
+function loadHandlersData() {
+ window.location = handlers_url;
+}
+
+var tableBody = false;
+var tablePropBody = false;
+var propEntryTemplate = false;
+
+$(document).ready(function(){
+ tableBody = $('#plugin_table tbody');
+
+ tablePropBody = $('.properties tbody');
+ propEntryTemplate = tablePropBody.find('tr').clone();
+
+ retrieveDetails();
+
+ $(".instancesButton").click(loadInstancesData);
+ $(".factoriesButton").click(loadFactoriesData);
+ $(".handlersButton").click(loadHandlersData);
+
+ var extractMethod = function(node) {
+ var link = node.getElementsByTagName("a");
+ if ( link && link.length == 1 ) {
+ return link[0].innerHTML;
+ }
+ return node.innerHTML;
+ };
+
+});
+
diff --git a/ipojo/webconsole-plugin/src/main/resources/res/ui/ipojo.css b/ipojo/webconsole-plugin/src/main/resources/res/ui/ipojo.css
new file mode 100644
index 0000000..ff4b134
--- /dev/null
+++ b/ipojo/webconsole-plugin/src/main/resources/res/ui/ipojo.css
@@ -0,0 +1,17 @@
+td.lheader {
+ width: 20em;
+ font-weight: bold;
+}
+
+div.architecture {
+ border-color: #CCC;
+ border-width: 1px;
+ border-style: solid;
+ border-spacing: 5px;
+ font-family: Courier;
+ margin: 5px;
+ background: #CCC;
+ width: 80em;
+ overflow: auto;
+ padding: 8px;
+}