Author: gnodet
Date: Thu Nov 10 09:41:48 2011
New Revision: 1200241

URL: http://svn.apache.org/viewvc?rev=1200241&view=rev
Log:
[KARAF-988][KARAF-993][KARAF-995] Upgrade to Aries blueprint / util / proxy 0.4

Added:
    
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/AbstractPropertyPlaceholder.java
    
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/PlaceholdersUtils.java
Modified:
    karaf/trunk/jaas/jasypt/pom.xml
    
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
    
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
    karaf/trunk/jaas/modules/pom.xml
    karaf/trunk/pom.xml

Modified: karaf/trunk/jaas/jasypt/pom.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/jasypt/pom.xml?rev=1200241&r1=1200240&r2=1200241&view=diff
==============================================================================
--- karaf/trunk/jaas/jasypt/pom.xml (original)
+++ karaf/trunk/jaas/jasypt/pom.xml Thu Nov 10 09:41:48 2011
@@ -50,6 +50,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.aries.blueprint</groupId>
             <artifactId>org.apache.aries.blueprint</artifactId>
             <scope>provided</scope>

Added: 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/AbstractPropertyPlaceholder.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/AbstractPropertyPlaceholder.java?rev=1200241&view=auto
==============================================================================
--- 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/AbstractPropertyPlaceholder.java
 (added)
+++ 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/AbstractPropertyPlaceholder.java
 Thu Nov 10 09:41:48 2011
@@ -0,0 +1,256 @@
+/**
+ * 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.jaas.jasypt.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.aries.blueprint.ComponentDefinitionRegistry;
+import org.apache.aries.blueprint.ComponentDefinitionRegistryProcessor;
+import org.apache.aries.blueprint.mutable.MutableBeanArgument;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutableBeanProperty;
+import org.apache.aries.blueprint.mutable.MutableCollectionMetadata;
+import org.apache.aries.blueprint.mutable.MutableMapEntry;
+import org.apache.aries.blueprint.mutable.MutableMapMetadata;
+import org.apache.aries.blueprint.mutable.MutablePropsMetadata;
+import org.apache.aries.blueprint.mutable.MutableReferenceListener;
+import org.apache.aries.blueprint.mutable.MutableRegistrationListener;
+import org.apache.aries.blueprint.mutable.MutableServiceMetadata;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.BeanArgument;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.service.blueprint.reflect.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.MapEntry;
+import org.osgi.service.blueprint.reflect.MapMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.NonNullMetadata;
+import org.osgi.service.blueprint.reflect.PropsMetadata;
+import org.osgi.service.blueprint.reflect.ReferenceListMetadata;
+import org.osgi.service.blueprint.reflect.ReferenceListener;
+import org.osgi.service.blueprint.reflect.ReferenceMetadata;
+import org.osgi.service.blueprint.reflect.RegistrationListener;
+import org.osgi.service.blueprint.reflect.ServiceMetadata;
+import org.osgi.service.blueprint.reflect.Target;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract class for property placeholders.
+ *
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractPropertyPlaceholder implements 
ComponentDefinitionRegistryProcessor {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(AbstractPropertyPlaceholder.class);
+
+    private String placeholderPrefix = "${";
+    private String placeholderSuffix = "}";
+    private Pattern pattern;
+
+    public String getPlaceholderPrefix() {
+        return placeholderPrefix;
+    }
+
+    public void setPlaceholderPrefix(String placeholderPrefix) {
+        this.placeholderPrefix = placeholderPrefix;
+    }
+
+    public String getPlaceholderSuffix() {
+        return placeholderSuffix;
+    }
+
+    public void setPlaceholderSuffix(String placeholderSuffix) {
+        this.placeholderSuffix = placeholderSuffix;
+    }
+
+    public void process(ComponentDefinitionRegistry registry) throws 
ComponentDefinitionException {
+        for (String name : registry.getComponentDefinitionNames()) {
+            processMetadata(registry.getComponentDefinition(name));
+        }
+    }
+
+    protected Metadata processMetadata(Metadata metadata) {
+        if (metadata instanceof BeanMetadata) {
+            return processBeanMetadata((BeanMetadata) metadata);
+        } else if (metadata instanceof ReferenceListMetadata) {
+            return processRefCollectionMetadata((ReferenceListMetadata) 
metadata);
+        } else if (metadata instanceof ReferenceMetadata) {
+            return processReferenceMetadata((ReferenceMetadata) metadata);
+        } else if (metadata instanceof ServiceMetadata) {
+            return processServiceMetadata((ServiceMetadata) metadata);
+        } else if (metadata instanceof CollectionMetadata) {
+            return processCollectionMetadata((CollectionMetadata) metadata);
+        } else if (metadata instanceof MapMetadata) {
+            return processMapMetadata((MapMetadata) metadata);
+        } else if (metadata instanceof PropsMetadata) {
+            return processPropsMetadata((PropsMetadata) metadata);
+        } else if (metadata instanceof ValueMetadata) {
+            return processValueMetadata((ValueMetadata) metadata);
+        } else {
+            return metadata;
+        }
+    }
+
+    protected Metadata processBeanMetadata(BeanMetadata component) {
+        for (BeanArgument arg :  component.getArguments()) {
+            ((MutableBeanArgument) 
arg).setValue(processMetadata(arg.getValue()));
+        }
+        for (BeanProperty prop : component.getProperties()) {
+            ((MutableBeanProperty) 
prop).setValue(processMetadata(prop.getValue()));
+        }
+        ((MutableBeanMetadata) component).setFactoryComponent((Target) 
processMetadata(component.getFactoryComponent()));
+        return component;
+    }
+
+    protected Metadata processServiceMetadata(ServiceMetadata component) {
+        ((MutableServiceMetadata) component).setServiceComponent((Target) 
processMetadata(component.getServiceComponent()));
+        List<MapEntry> entries = new 
ArrayList<MapEntry>(component.getServiceProperties());
+        for (MapEntry entry : entries) {
+            ((MutableServiceMetadata) component).removeServiceProperty(entry);
+        }
+        for (MapEntry entry : processMapEntries(entries)) {
+            ((MutableServiceMetadata) component).addServiceProperty(entry);
+        }
+        for (RegistrationListener listener : 
component.getRegistrationListeners()) {
+            ((MutableRegistrationListener) 
listener).setListenerComponent((Target) 
processMetadata(listener.getListenerComponent()));
+        }
+        return component;
+    }
+
+    protected Metadata processReferenceMetadata(ReferenceMetadata component) {
+        for (ReferenceListener listener : component.getReferenceListeners()) {
+            ((MutableReferenceListener) 
listener).setListenerComponent((Target) 
processMetadata(listener.getListenerComponent()));
+        }
+        return component;
+    }
+
+    protected Metadata processRefCollectionMetadata(ReferenceListMetadata 
component) {
+        for (ReferenceListener listener : component.getReferenceListeners()) {
+            ((MutableReferenceListener) 
listener).setListenerComponent((Target) 
processMetadata(listener.getListenerComponent()));
+        }
+        return component;
+    }
+
+    protected Metadata processPropsMetadata(PropsMetadata metadata) {
+        List<MapEntry> entries = new 
ArrayList<MapEntry>(metadata.getEntries());
+        for (MapEntry entry : entries) {
+            ((MutablePropsMetadata) metadata).removeEntry(entry);
+        }
+        for (MapEntry entry : processMapEntries(entries)) {
+            ((MutablePropsMetadata) metadata).addEntry(entry);
+        }
+        return metadata;
+    }
+
+    protected Metadata processMapMetadata(MapMetadata metadata) {
+        List<MapEntry> entries = new 
ArrayList<MapEntry>(metadata.getEntries());
+        for (MapEntry entry : entries) {
+            ((MutableMapMetadata) metadata).removeEntry(entry);
+        }
+        for (MapEntry entry : processMapEntries(entries)) {
+            ((MutableMapMetadata) metadata).addEntry(entry);
+        }
+        return metadata;
+    }
+
+    protected List<MapEntry> processMapEntries(List<MapEntry> entries) {
+        for (MapEntry entry : entries) {
+            ((MutableMapEntry) entry).setKey((NonNullMetadata) 
processMetadata(entry.getKey()));
+            ((MutableMapEntry) 
entry).setValue(processMetadata(entry.getValue()));
+        }
+        return entries;
+    }
+
+    protected Metadata processCollectionMetadata(CollectionMetadata metadata) {
+        List<Metadata> values = new ArrayList<Metadata>(metadata.getValues());
+        for (Metadata value : values) {
+            ((MutableCollectionMetadata) metadata).removeValue(value);
+        }
+        for (Metadata value : values) {
+            ((MutableCollectionMetadata) 
metadata).addValue(processMetadata(value));
+        }
+        return metadata;
+    }
+
+    protected Metadata processValueMetadata(ValueMetadata metadata) {
+        return new LateBindingValueMetadata(metadata);
+    }
+
+    protected String retrieveValue(String expression) {
+        return getProperty(expression);
+    }
+    
+    protected String processString(String str) {
+        // TODO: we need to handle escapes on the prefix / suffix
+        Matcher matcher = getPattern().matcher(str);
+        while (matcher.find()) {
+            String rep = retrieveValue(matcher.group(1));
+            if (rep != null) {
+                str = str.replace(matcher.group(0), rep);
+                matcher.reset(str);
+            }
+        }
+        return str;
+    }
+
+    protected String getProperty(String val) {
+        return null;
+    }
+
+    protected Pattern getPattern() {
+        if (pattern == null) {
+            pattern = Pattern.compile("\\Q" + placeholderPrefix + 
"\\E(.+?)\\Q" + placeholderSuffix + "\\E");
+        }
+        return pattern;
+    }
+
+    public class LateBindingValueMetadata implements ValueMetadata {
+
+        private final ValueMetadata metadata;
+        private boolean retrieved;
+        private String retrievedValue;
+
+        public LateBindingValueMetadata(ValueMetadata metadata) {
+            this.metadata = metadata;
+        }
+
+        public String getStringValue() {
+            if (!retrieved) {
+                String v = metadata.getStringValue();
+                LOGGER.debug("Before process: {}", v);
+                retrievedValue = processString(v);
+                LOGGER.debug("After process: {}", retrievedValue);
+                
+                retrieved = true;
+            }
+            return retrievedValue;
+        }
+
+        public String getType() {
+            return metadata.getType();
+        }
+
+    }
+
+}
\ No newline at end of file

Modified: 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java?rev=1200241&r1=1200240&r2=1200241&view=diff
==============================================================================
--- 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
 (original)
+++ 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/EncryptablePropertyPlaceholder.java
 Thu Nov 10 09:41:48 2011
@@ -14,7 +14,6 @@
  */
 package org.apache.karaf.jaas.jasypt.handler;
 
-import org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder;
 import org.jasypt.encryption.StringEncryptor;
 
 public class EncryptablePropertyPlaceholder extends 
AbstractPropertyPlaceholder {

Modified: 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java?rev=1200241&r1=1200240&r2=1200241&view=diff
==============================================================================
--- 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
 (original)
+++ 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/NamespaceHandler.java
 Thu Nov 10 09:41:48 2011
@@ -21,7 +21,6 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.aries.blueprint.ParserContext;
-import org.apache.aries.blueprint.ext.PlaceholdersUtils;
 import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
 import org.apache.aries.blueprint.mutable.MutableCollectionMetadata;
 import org.apache.aries.blueprint.mutable.MutableRefMetadata;

Added: 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/PlaceholdersUtils.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/PlaceholdersUtils.java?rev=1200241&view=auto
==============================================================================
--- 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/PlaceholdersUtils.java
 (added)
+++ 
karaf/trunk/jaas/jasypt/src/main/java/org/apache/karaf/jaas/jasypt/handler/PlaceholdersUtils.java
 Thu Nov 10 09:41:48 2011
@@ -0,0 +1,65 @@
+/**
+ * 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.jaas.jasypt.handler;
+
+import org.apache.aries.blueprint.ComponentDefinitionRegistry;
+import org.apache.aries.blueprint.ExtendedBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+
+/**
+ * Utility for placeholders parsing / validation
+ *
+ * @version $Rev$, $Date$
+ */
+public class PlaceholdersUtils {
+
+    public static void validatePlaceholder(MutableBeanMetadata metadata, 
ComponentDefinitionRegistry registry) {
+        String prefix = getPlaceholderProperty(metadata, "placeholderPrefix");
+        String suffix = getPlaceholderProperty(metadata, "placeholderSuffix");
+        for (String id : registry.getComponentDefinitionNames()) {
+            ComponentMetadata component = registry.getComponentDefinition(id);
+            if (component instanceof ExtendedBeanMetadata) {
+                ExtendedBeanMetadata bean = (ExtendedBeanMetadata) component;
+                if (bean.getRuntimeClass() != null && 
AbstractPropertyPlaceholder.class.isAssignableFrom(bean.getRuntimeClass())) {
+                    String otherPrefix = getPlaceholderProperty(bean, 
"placeholderPrefix");
+                    String otherSuffix = getPlaceholderProperty(bean, 
"placeholderSuffix");
+                    if (prefix.equals(otherPrefix) && 
suffix.equals(otherSuffix)) {
+                        throw new ComponentDefinitionException("Multiple 
placeholders with the same prefix and suffix are not allowed");
+                    }
+                }
+            }
+        }
+    }
+
+    private static String getPlaceholderProperty(BeanMetadata bean, String 
name) {
+        for (BeanProperty property : bean.getProperties()) {
+            if (name.equals(property.getName())) {
+                ValueMetadata value = (ValueMetadata) property.getValue();
+                return value.getStringValue();
+            }
+        }
+        return null;
+    }
+
+}

Modified: karaf/trunk/jaas/modules/pom.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/jaas/modules/pom.xml?rev=1200241&r1=1200240&r2=1200241&view=diff
==============================================================================
--- karaf/trunk/jaas/modules/pom.xml (original)
+++ karaf/trunk/jaas/modules/pom.xml Thu Nov 10 09:41:48 2011
@@ -110,7 +110,6 @@
                         <Import-Package>
                             !${project.artifactId}*,
                             org.apache.karaf.jaas.config,
-                            org.apache.aries.blueprint.ext,
                             *
                         </Import-Package>
                         <Private-Package>

Modified: karaf/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/pom.xml?rev=1200241&r1=1200240&r2=1200241&view=diff
==============================================================================
--- karaf/trunk/pom.xml (original)
+++ karaf/trunk/pom.xml Thu Nov 10 09:41:48 2011
@@ -136,13 +136,13 @@
         
<felix.eventadmin-plugin.version>1.0.2</felix.eventadmin-plugin.version>
         <felix.obr.version>1.0.2</felix.obr.version>
         <aries.application.version>0.3</aries.application.version>
-        <aries.blueprint.version>0.3.1</aries.blueprint.version>
+        <aries.blueprint.version>0.4</aries.blueprint.version>
         <aries.jmx.version>0.3</aries.jmx.version>
         <aries.jpa.version>0.3</aries.jpa.version>
         <aries.jndi.version>0.3</aries.jndi.version>
-        <aries.proxy.version>0.3</aries.proxy.version>
+        <aries.proxy.version>0.4</aries.proxy.version>
         <aries.transaction.version>0.3</aries.transaction.version>
-        <aries.util.version>0.3</aries.util.version>
+        <aries.util.version>0.4</aries.util.version>
         <jansi.version>1.6</jansi.version>
         <jline.version>2.5</jline.version>
         <jsw.version>3.2.3</jsw.version>


Reply via email to