You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2011/03/29 23:19:09 UTC
svn commit: r1086753 - in /cxf/trunk/rt/core/src/main/java/org/apache/cxf:
bus/blueprint/ configuration/blueprint/
Author: dkulp
Date: Tue Mar 29 21:19:08 2011
New Revision: 1086753
URL: http://svn.apache.org/viewvc?rev=1086753&view=rev
Log:
Add configuration stuff into blueprint bus
Added:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBeanLocator.java (with props)
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java (with props)
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/Messages.properties (with props)
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBus.java
cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBeanLocator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBeanLocator.java?rev=1086753&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBeanLocator.java (added)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBeanLocator.java Tue Mar 29 21:19:08 2011
@@ -0,0 +1,124 @@
+/**
+ * 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.cxf.bus.blueprint;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.aries.blueprint.ExtendedBlueprintContainer;
+import org.apache.aries.blueprint.container.BeanRecipe;
+import org.apache.aries.blueprint.di.Recipe;
+import org.apache.cxf.bus.extension.ExtensionManagerImpl;
+import org.apache.cxf.configuration.ConfiguredBeanLocator;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+
+/**
+ *
+ */
+public class BlueprintBeanLocator implements ConfiguredBeanLocator {
+ ConfiguredBeanLocator orig;
+ ExtendedBlueprintContainer container;
+
+ public BlueprintBeanLocator(ConfiguredBeanLocator orig, BlueprintContainer cont) {
+ this.orig = orig;
+ this.container = (ExtendedBlueprintContainer)cont;
+
+ if (orig instanceof ExtensionManagerImpl) {
+ List<String> names = new ArrayList<String>(container.getComponentIds());
+ ((ExtensionManagerImpl)orig).removeBeansOfNames(names);
+ }
+ }
+
+
+ /** {@inheritDoc}*/
+ public List<String> getBeanNamesOfType(Class<?> type) {
+ Set<String> names = new LinkedHashSet<String>();
+ for (String s : container.getComponentIds()) {
+ Recipe r = container.getRepository().getRecipe(s);
+ if (r instanceof BeanRecipe
+ && type.isAssignableFrom(((BeanRecipe)r).getType())) {
+ names.add(s);
+ }
+ }
+ names.addAll(orig.getBeanNamesOfType(type));
+ return new ArrayList<String>(names);
+ }
+
+ /** {@inheritDoc}*/
+ public <T> Collection<? extends T> getBeansOfType(Class<T> type) {
+ List<T> list = new ArrayList<T>();
+ for (String s : container.getComponentIds()) {
+ Recipe r = container.getRepository().getRecipe(s);
+ if (r instanceof BeanRecipe
+ && type.isAssignableFrom(((BeanRecipe)r).getType())) {
+
+ list.add(type.cast(container.getComponentInstance(s)));
+ }
+ }
+ list.addAll(orig.getBeansOfType(type));
+ return list;
+ }
+
+ /** {@inheritDoc}*/
+ public <T> boolean loadBeansOfType(Class<T> type, BeanLoaderListener<T> listener) {
+ List<String> names = new ArrayList<String>();
+ for (String s : container.getComponentIds()) {
+ Recipe r = container.getRepository().getRecipe(s);
+ if (r instanceof BeanRecipe
+ && type.isAssignableFrom(((BeanRecipe)r).getType())) {
+ names.add(s);
+ }
+ }
+ Collections.reverse(names);
+ boolean loaded = false;
+ for (String s : names) {
+ BeanRecipe r = (BeanRecipe)container.getRepository().getRecipe(s);
+ Class<?> beanType = r.getType();
+ Class<? extends T> t = beanType.asSubclass(type);
+ if (listener.loadBean(s, t)) {
+ Object o = container.getComponentInstance(s);
+ if (listener.beanLoaded(s, type.cast(o))) {
+ return true;
+ }
+ loaded = true;
+ }
+ }
+ return loaded || orig.loadBeansOfType(type, listener);
+ }
+
+ public boolean hasConfiguredPropertyValue(String beanName, String propertyName, String value) {
+ Recipe r = container.getRepository().getRecipe(beanName);
+ if (r instanceof BeanRecipe) {
+ BeanRecipe br = (BeanRecipe)r;
+ Object o = br.getProperty(propertyName);
+ if (o == null) {
+ return false;
+ }
+ //TODO - need to check the values of the property
+ return false;
+ }
+ return orig.hasConfiguredPropertyValue(beanName, propertyName, value);
+ }
+
+}
Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBeanLocator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBeanLocator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBus.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBus.java?rev=1086753&r1=1086752&r2=1086753&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBus.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/BlueprintBus.java Tue Mar 29 21:19:08 2011
@@ -22,13 +22,18 @@ package org.apache.cxf.bus.blueprint;
import org.apache.aries.blueprint.utils.BundleDelegatingClassLoader;
import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.cxf.configuration.ConfiguredBeanLocator;
+import org.apache.cxf.configuration.Configurer;
import org.osgi.framework.BundleContext;
+import org.osgi.service.blueprint.container.BlueprintContainer;
/**
*
*/
public class BlueprintBus extends ExtensionManagerBus {
+
BundleContext context;
+ BlueprintContainer container;
public BlueprintBus() {
}
@@ -38,6 +43,12 @@ public class BlueprintBus extends Extens
super.setExtension(new BundleDelegatingClassLoader(c.getBundle(),
this.getClass().getClassLoader()),
ClassLoader.class);
- //setExtension(new ConfigurerImpl(c), Configurer.class);
+ }
+ public void setBlueprintContainer(BlueprintContainer con) {
+ container = con;
+ setExtension(new ConfigurerImpl(con), Configurer.class);
+ setExtension(new BlueprintBeanLocator(getExtension(ConfiguredBeanLocator.class), container),
+ ConfiguredBeanLocator.class);
+
}
}
Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java?rev=1086753&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java (added)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java Tue Mar 29 21:19:08 2011
@@ -0,0 +1,170 @@
+/**
+ * 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.cxf.bus.blueprint;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.aries.blueprint.ExtendedBlueprintContainer;
+import org.apache.aries.blueprint.container.BeanRecipe;
+import org.apache.aries.blueprint.di.Recipe;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.configuration.Configurable;
+import org.apache.cxf.configuration.Configurer;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+
+/**
+ *
+ */
+public class ConfigurerImpl implements Configurer {
+ private static final Logger LOG = LogUtils.getL7dLogger(ConfigurerImpl.class);
+ ExtendedBlueprintContainer container;
+
+ private final Map<String, List<MatcherHolder>> wildCardBeanDefinitions
+ = new HashMap<String, List<MatcherHolder>>();
+
+ static class MatcherHolder {
+ Matcher matcher;
+ String wildCardId;
+ public MatcherHolder(String orig, Matcher matcher) {
+ wildCardId = orig;
+ this.matcher = matcher;
+ }
+ }
+
+
+ public ConfigurerImpl(BlueprintContainer con) {
+ container = (ExtendedBlueprintContainer)con;
+ initializeWildcardMap();
+ }
+ private boolean isWildcardBeanName(String bn) {
+ return bn.indexOf('*') != -1 || bn.indexOf('?') != -1
+ || (bn.indexOf('(') != -1 && bn.indexOf(')') != -1);
+ }
+
+ private void initializeWildcardMap() {
+ for (String s : container.getComponentIds()) {
+ if (isWildcardBeanName(s)) {
+ Recipe r = container.getRepository().getRecipe(s);
+ if (r instanceof BeanRecipe) {
+ Class c = ((BeanRecipe)r).getType();
+ String orig = s;
+ if (s.charAt(0) == '*') {
+ //old wildcard
+ s = "." + s.replaceAll("\\.", "\\.");
+ }
+ Matcher matcher = Pattern.compile(s).matcher("");
+ List<MatcherHolder> m = wildCardBeanDefinitions.get(c.getName());
+ if (m == null) {
+ m = new ArrayList<MatcherHolder>();
+ wildCardBeanDefinitions.put(c.getName(), m);
+ }
+ MatcherHolder holder = new MatcherHolder(orig, matcher);
+ m.add(holder);
+ }
+ }
+ }
+ }
+
+ public void configureBean(Object beanInstance) {
+ configureBean(null, beanInstance, true);
+ }
+
+ public void configureBean(String bn, Object beanInstance) {
+ configureBean(bn, beanInstance, true);
+ }
+ public synchronized void configureBean(String bn, Object beanInstance, boolean checkWildcards) {
+ if (null == bn) {
+ bn = getBeanName(beanInstance);
+ }
+
+ if (null == bn) {
+ return;
+ }
+ if (checkWildcards) {
+ configureWithWildCard(bn, beanInstance);
+ }
+
+ Recipe r = container.getRepository().getRecipe(bn);
+ if (r instanceof BeanRecipe) {
+ ((BeanRecipe)r).setProperties(beanInstance);
+ }
+ }
+ private void configureWithWildCard(String bn, Object beanInstance) {
+ if (!wildCardBeanDefinitions.isEmpty()) {
+ Class<?> clazz = beanInstance.getClass();
+ while (!Object.class.equals(clazz)) {
+ String className = clazz.getName();
+ List<MatcherHolder> matchers = wildCardBeanDefinitions.get(className);
+ if (matchers != null) {
+ for (MatcherHolder m : matchers) {
+ synchronized (m.matcher) {
+ m.matcher.reset(bn);
+ if (m.matcher.matches()) {
+ configureBean(m.wildCardId, beanInstance, false);
+ return;
+ }
+ }
+ }
+ }
+ clazz = clazz.getSuperclass();
+ }
+ }
+ }
+
+ protected String getBeanName(Object beanInstance) {
+ if (beanInstance instanceof Configurable) {
+ return ((Configurable)beanInstance).getBeanName();
+ }
+ String beanName = null;
+ Method m = null;
+ try {
+ m = beanInstance.getClass().getDeclaredMethod("getBeanName", (Class[])null);
+ } catch (NoSuchMethodException ex) {
+ try {
+ m = beanInstance.getClass().getMethod("getBeanName", (Class[])null);
+ } catch (NoSuchMethodException e) {
+ //ignore
+ }
+ }
+ if (m != null) {
+ try {
+ beanName = (String)(m.invoke(beanInstance));
+ } catch (Exception ex) {
+ LogUtils.log(LOG, Level.WARNING, "ERROR_DETERMINING_BEAN_NAME_EXC", ex);
+ }
+ }
+
+ if (null == beanName) {
+ LogUtils.log(LOG, Level.FINE, "COULD_NOT_DETERMINE_BEAN_NAME_MSG",
+ beanInstance.getClass().getName());
+ }
+
+ return beanName;
+ }
+
+}
Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/Messages.properties?rev=1086753&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/Messages.properties (added)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/Messages.properties Tue Mar 29 21:19:08 2011
@@ -0,0 +1,26 @@
+#
+#
+# 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.
+#
+#
+NO_MATCHING_BEAN_MSG = Could not find a definition for bean with id {0} - no injection will be performed.
+COULD_NOT_DETERMINE_BEAN_NAME_MSG = Could not determine bean name for instance of class {0}.
+ERROR_DETERMINING_BEAN_NAME_EXC = Failed to determine bean name.
+JAXB_PROPERTY_EDITOR_EXC = Property editor failed to bind element {0}.
+WILDCARD_BEAN_ID_WITH_NO_CLASS_MSG = Configuration bean with id {0} that uses a ''*'' or wildcard must have a class attribute.
+ONE_WILDCARD_BEAN_ID_PER_CLASS_MSG = A wildcard configuration bean with id {0} already exists for class {1}. The wildcard bean with id {2} will be ignored.
Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/blueprint/Messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java?rev=1086753&r1=1086752&r2=1086753&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java Tue Mar 29 21:19:08 2011
@@ -247,11 +247,11 @@ public abstract class AbstractBPBeanDefi
&& !cdr.containsComponentDefinition(name)) {
//Create a bus
- //FIXME - mgmt stuff, configuration stuff, etc...
MutableBeanMetadata bus = context.createMetadata(MutableBeanMetadata.class);
bus.setId(name);
bus.setRuntimeClass(BlueprintBus.class);
bus.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
+ bus.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
bus.setDestroyMethod("shutdown");
bus.setInitMethod("initialize");