incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1147909 - in /sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal: RepositoryPrinter.java SlingRepositoryProvider.java
Date Mon, 18 Jul 2011 14:53:38 GMT
Author: cziegeler
Date: Mon Jul 18 14:53:37 2011
New Revision: 1147909

URL: http://svn.apache.org/viewvc?rev=1147909&view=rev
Log:
SLING-2140 :  Add a ConfigurationPrinter to output the Repository Descriptors

Added:
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/RepositoryPrinter.java
  (with props)
Modified:
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/SlingRepositoryProvider.java

Added: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/RepositoryPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/RepositoryPrinter.java?rev=1147909&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/RepositoryPrinter.java
(added)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/RepositoryPrinter.java
Mon Jul 18 14:53:37 2011
@@ -0,0 +1,88 @@
+/*
+ * 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.sling.jcr.base.internal;
+
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.jcr.Repository;
+
+/**
+ * The Printer Plugin
+ */
+public class RepositoryPrinter {
+
+    private final Repository repository;
+
+    private final String name;
+
+    public RepositoryPrinter(final Repository repo, final Map<String, Object> props)
{
+        this.repository = repo;
+        if ( repo.getDescriptor(Repository.REP_NAME_DESC) != null ) {
+            name = "Repository " + repo.getDescriptor(Repository.REP_NAME_DESC);
+        } else  if ( props.get("name") != null ) {
+            name = "Repository " + props.get("name").toString();
+        } else {
+            this.name = "Repository @" + repo.hashCode();
+        }
+    }
+
+    public String getTitle() {
+        return this.name;
+    }
+
+    public Dictionary<String, Object> getProperties() {
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("felix.webconsole.label", this.name);
+        props.put("felix.webconsole.title", this.name);
+        props.put("felix.webconsole.configprinter.modes", "always");
+
+        return props;
+    }
+
+    public void printConfiguration(final PrintWriter pw) {
+        // try to get repository
+        final Repository repo = this.repository;
+        writeHeader(pw, "Repository Properties");
+        final String[] keys = repo.getDescriptorKeys();
+        Arrays.sort(keys);
+        for (final String key : keys) {
+            final String val = repo.getDescriptor(key);
+            writeEntry(pw, key, val);
+        }
+    }
+
+    private void writeHeader(final PrintWriter pw, final String value) {
+        pw.print(value);
+        pw.println(":");
+    }
+
+    private void writeEntry(final PrintWriter pw, final String key, final String value) {
+        pw.print(key);
+        pw.print(": ");
+        if ( value != null ) {
+            pw.println(value);
+        } else {
+            pw.println("-");
+        }
+    }
+}

Propchange: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/RepositoryPrinter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/RepositoryPrinter.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/RepositoryPrinter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/SlingRepositoryProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/SlingRepositoryProvider.java?rev=1147909&r1=1147908&r2=1147909&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/SlingRepositoryProvider.java
(original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/SlingRepositoryProvider.java
Mon Jul 18 14:53:37 2011
@@ -111,21 +111,42 @@ public class SlingRepositoryProvider {
         }
     }
 
+    private void registerPrinter(final BundleContext processContext,
+            final Repository repo,
+            final Map<String, Object> props) {
+        logger.info("Providing new configuration printer for {} : {}", repo, props);
+        final Long key = (Long)props.get(Constants.SERVICE_ID);
+        RepositoryRegistration reg;
+        synchronized ( this.registrations ) {
+            reg = this.registrations.get(key);
+        }
+        if ( reg == null ) {
+            reg = new RepositoryRegistration();
+            synchronized ( this.registrations ) {
+                this.registrations.put(key, reg);
+            }
+        }
+        final RepositoryPrinter printer = new RepositoryPrinter(repo, props);
+        reg.printer = processContext.registerService(RepositoryPrinter.class.getName(),
+                printer, printer.getProperties());
+    }
+
     /**
      * Bind a new repository.
      */
     protected void bindRepository(final Repository repo, final Map<String, Object>
props) {
-        if ( !isSlingRepository(props) ) {
-            final BundleContext processContext;
-            synchronized ( pendingServices ) {
-                processContext = this.bundleContext;
-                if ( processContext == null ) {
-                    this.pendingServices.add(new PendingService(repo, props));
-                }
+        final BundleContext processContext;
+        synchronized ( pendingServices ) {
+            processContext = this.bundleContext;
+            if ( processContext == null ) {
+                this.pendingServices.add(new PendingService(repo, props));
             }
-            if ( processContext != null ) {
+        }
+        if ( processContext != null ) {
+            if ( !isSlingRepository(props) ) {
                 this.registerRepository(processContext, repo, props);
             }
+            this.registerPrinter(processContext, repo, props);
         }
     }
 
@@ -133,20 +154,23 @@ public class SlingRepositoryProvider {
      * Unind a new repository.
      */
     protected void unbindRepository(final Repository repo, final Map<String, Object>
props) {
-        if ( !isSlingRepository(props) ) {
-            synchronized ( pendingServices ) {
-                this.pendingServices.remove(new PendingService(repo, props));
-            }
-            final Long key = (Long)props.get(Constants.SERVICE_ID);
-            final RepositoryRegistration slingRepo;
-            synchronized ( this.registrations ) {
-                slingRepo = this.registrations.remove(key);
-            }
-            if ( slingRepo != null ) {
+        synchronized ( pendingServices ) {
+            this.pendingServices.remove(new PendingService(repo, props));
+        }
+        final Long key = (Long)props.get(Constants.SERVICE_ID);
+        final RepositoryRegistration slingRepo;
+        synchronized ( this.registrations ) {
+            slingRepo = this.registrations.remove(key);
+        }
+        if ( slingRepo != null ) {
+            if ( slingRepo.wrapper != null ) {
                 logger.debug("Unregistering SlingRepository for {} : {}", repo, props);
                 slingRepo.wrapper.dispose();
                 slingRepo.registration.unregister();
             }
+            if ( slingRepo.printer != null ) {
+                slingRepo.printer.unregister();
+            }
         }
     }
 
@@ -187,6 +211,7 @@ public class SlingRepositoryProvider {
      */
     private static final class RepositoryRegistration {
         public ServiceRegistration registration;
+        public ServiceRegistration printer;
         public SlingRepositoryWrapper wrapper;
     }
 }



Mime
View raw message