Author: bdelacretaz
Date: Thu May 14 12:28:42 2009
New Revision: 774747

URL: http://svn.apache.org/viewvc?rev=774747&view=rev
Log:
SLING-904 - move ConfigInstallableData to osgiworker as 
DictionaryInstallableData, it's of general use

Added:
    
incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/DictionaryInstallableData.java
   (with props)
    
incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/DigestTest.java
      - copied, changed from r774735, 
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/DigestTest.java
Removed:
    
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ConfigInstallableData.java
    
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/DigestTest.java
Modified:
    
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ConfigNodeConverter.java

Added: 
incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/DictionaryInstallableData.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/DictionaryInstallableData.java?rev=774747&view=auto
==============================================================================
--- 
incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/DictionaryInstallableData.java
 (added)
+++ 
incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/DictionaryInstallableData.java
 Thu May 14 12:28:42 2009
@@ -0,0 +1,75 @@
+/*
+ * 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.jcrinstall.osgiworker;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.util.Dictionary;
+
+/** InstallableData that provides a Dictionary, used for
+ *     OSGi Configurations.
+ */
+public class DictionaryInstallableData implements InstallableData {
+       private final Dictionary<String, Object> data;
+       private final String digest;
+       
+       public DictionaryInstallableData(Dictionary<String, Object> data) 
throws Exception {
+               this.data = data;
+               digest = computeDigest(data);
+       }
+       
+       @Override
+       public String toString() {
+               return getClass().getSimpleName() + ", digest=" + digest;
+       }
+       
+       @SuppressWarnings("unchecked")
+       public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+               if(type.equals(Dictionary.class)) {
+                       return (AdapterType)data;
+               }
+               return null;
+       }
+
+       public String getDigest() {
+               return digest;
+       }
+       
+       /** Digest is needed to detect changes in data */
+       static String computeDigest(Dictionary<String, Object> data) throws 
Exception {
+               final String digestType = "MD5";
+               final MessageDigest d = MessageDigest.getInstance(digestType);
+               final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+               final ObjectOutputStream oos = new ObjectOutputStream(bos);
+               oos.writeObject(data);
+               bos.flush();
+               d.update(bos.toByteArray());
+               // convert to readable string 
(http://www.javalobby.org/java/forums/t84420.html)
+               final BigInteger bigInt = new BigInteger(1, d.digest());
+               return new String(bigInt.toString(16));
+       }
+
+       /** Not applicable for config nodes, return 0 */
+       public int getBundleStartLevel() {
+           return 0;
+       }
+
+}

Propchange: 
incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/DictionaryInstallableData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/DictionaryInstallableData.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: 
incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/DigestTest.java
 (from r774735, 
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/DigestTest.java)
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/DigestTest.java?p2=incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/DigestTest.java&p1=incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/DigestTest.java&r1=774735&r2=774747&rev=774747&view=diff
==============================================================================
--- 
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/DigestTest.java
 (original)
+++ 
incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/DigestTest.java
 Thu May 14 12:28:42 2009
@@ -1,4 +1,22 @@
-package org.apache.sling.jcr.jcrinstall.jcr.impl;
+/*
+ * 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.jcrinstall.osgiworker;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -15,7 +33,7 @@
        
        private String testDigestChanged(Dictionary<String, Object> d, 
                        String oldDigest, int step, boolean shouldChange) 
throws Exception {
-               final String newDigest = ConfigInstallableData.computeDigest(d);
+               final String newDigest = 
DictionaryInstallableData.computeDigest(d);
                if(shouldChange) {
                        assertTrue("Digest (" + newDigest + ") should have 
changed at step " + step, !newDigest.equals(oldDigest));
                } else {
@@ -33,8 +51,8 @@
                
                assertEquals(
                                "Two dictionary with same values have the same 
key", 
-                               ConfigInstallableData.computeDigest(d1),
-                               ConfigInstallableData.computeDigest(d2)
+                               DictionaryInstallableData.computeDigest(d1),
+                               DictionaryInstallableData.computeDigest(d2)
                );
        }
        

Modified: 
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ConfigNodeConverter.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ConfigNodeConverter.java?rev=774747&r1=774746&r2=774747&view=diff
==============================================================================
--- 
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ConfigNodeConverter.java
 (original)
+++ 
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ConfigNodeConverter.java
 Thu May 14 12:28:42 2009
@@ -32,6 +32,7 @@
 import javax.jcr.Value;
 
 import org.apache.sling.jcr.jcrinstall.jcr.NodeConverter;
+import org.apache.sling.jcr.jcrinstall.osgiworker.DictionaryInstallableData;
 import org.apache.sling.jcr.jcrinstall.osgiworker.InstallableData;
 import org.apache.sling.runmode.RunMode;
 import org.slf4j.Logger;
@@ -61,7 +62,7 @@
                // We only consider CONFIG_NODE_TYPE nodes
                if(n.isNodeType(CONFIG_NODE_TYPE)) {
                        final Dictionary<String, Object> config = load(n);
-                       result = new ConfigInstallableData(config);
+                       result = new DictionaryInstallableData(config);
                        log.debug("Converted node {} to {}", n.getPath(), 
result);
                } else {
                        log.debug("Node is not a {} node, ignored:{}", 
CONFIG_NODE_TYPE, n.getPath());


Reply via email to