You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by zo...@apache.org on 2011/02/27 22:05:20 UTC
svn commit: r1075147 [15/23] - in /aries/tags/blueprint-0.3: ./
blueprint-annotation-api/ blueprint-annotation-api/src/
blueprint-annotation-api/src/main/ blueprint-annotation-api/src/main/java/
blueprint-annotation-api/src/main/java/org/ blueprint-ann...
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ComponentFactoryRecipe.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ComponentFactoryRecipe.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ComponentFactoryRecipe.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ComponentFactoryRecipe.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,63 @@
+/*
+ * 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.aries.blueprint.di;
+
+import java.util.List;
+
+import org.apache.aries.blueprint.ExtendedBlueprintContainer;
+import org.apache.aries.blueprint.ext.ComponentFactoryMetadata;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+/**
+ * Pass-through recipe that allows custom bean manager (represented by a ComponentFactoryMetadata instance)
+ * to fit into the container lifecycle.
+ *
+ * @param <T>
+ */
+public class ComponentFactoryRecipe<T extends ComponentFactoryMetadata> extends AbstractRecipe {
+ private T metadata;
+ private List<Recipe> dependencies;
+
+ public ComponentFactoryRecipe(String name, T metadata,
+ ExtendedBlueprintContainer container, List<Recipe> dependencies) {
+ super(name);
+ this.metadata = metadata;
+ this.dependencies = dependencies;
+ metadata.init(container);
+ }
+
+ @Override
+ protected Object internalCreate() throws ComponentDefinitionException {
+ return metadata.create();
+ }
+
+ public List<Recipe> getDependencies() {
+ return dependencies;
+ }
+
+ @Override
+ public void destroy(Object instance) {
+ metadata.destroy(instance);
+ }
+
+ protected T getMetadata() {
+ return metadata;
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/DependentComponentFactoryRecipe.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/DependentComponentFactoryRecipe.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/DependentComponentFactoryRecipe.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/DependentComponentFactoryRecipe.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.aries.blueprint.di;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.aries.blueprint.ExtendedBlueprintContainer;
+import org.apache.aries.blueprint.container.SatisfiableRecipe;
+import org.apache.aries.blueprint.ext.DependentComponentFactoryMetadata;
+
+/**
+ * Extends ComponentFactoryRecipe to support the dependency management (SatisfiableRecipe) for custom
+ * bean managers (DependentComponentFactoryMetadata instances in this case).
+ */
+public class DependentComponentFactoryRecipe extends ComponentFactoryRecipe<DependentComponentFactoryMetadata>
+ implements SatisfiableRecipe, DependentComponentFactoryMetadata.SatisfactionCallback {
+
+ private SatisfactionListener listener;
+ private AtomicBoolean started = new AtomicBoolean(false);
+
+ public DependentComponentFactoryRecipe(
+ String name, DependentComponentFactoryMetadata metadata,
+ ExtendedBlueprintContainer container, List<Recipe> dependencies) {
+ super(name, metadata, container, dependencies);
+ }
+
+ public String getOsgiFilter() {
+ return getMetadata().getDependencyDescriptor();
+ }
+
+ public boolean isSatisfied() {
+ return getMetadata().isSatisfied();
+ }
+
+ public void start(SatisfactionListener listener) {
+ if (started.compareAndSet(false, true)) {
+ this.listener = listener;
+ getMetadata().startTracking(this);
+ }
+ }
+
+ public void stop() {
+ if (started.compareAndSet(true, false)) {
+ listener = null;
+ getMetadata().stopTracking();
+ }
+ }
+
+ public void notifyChanged() {
+ if (listener != null) {
+ listener.notifySatisfaction(this);
+ }
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ExecutionContext.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ExecutionContext.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ExecutionContext.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ExecutionContext.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,101 @@
+/**
+ *
+ * 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.aries.blueprint.di;
+
+import org.osgi.service.blueprint.container.ReifiedType;
+
+public interface ExecutionContext {
+
+ public static final class Holder {
+
+ private static final ThreadLocal<ExecutionContext> context = new ThreadLocal<ExecutionContext>();
+
+ private Holder() {
+ }
+
+ public static ExecutionContext getContext() {
+ ExecutionContext executionContext = context.get();
+ if (executionContext == null) {
+ throw new IllegalStateException("Execution container has not been set");
+ }
+ return executionContext;
+ }
+
+ public static ExecutionContext setContext(ExecutionContext newContext) {
+ ExecutionContext oldContext = context.get();
+ context.set(newContext);
+ return oldContext;
+ }
+
+ }
+
+ /**
+ * Lock that should be used to synchronized creation of singletons
+ *
+ * @return
+ */
+ public Object getInstanceLock();
+
+ /**
+ * Adds a recipe to the top of the execution stack. If the recipe is already on
+ * the stack, a CircularDependencyException is thrown.
+ * @param recipe the recipe to add to the stack
+ * @throws CircularDependencyException if the recipe is already on the stack
+ */
+ public abstract void push(Recipe recipe) throws CircularDependencyException;
+
+ /**
+ * Removes the top recipe from the execution stack.
+ * @return the top recipe on the stack
+ */
+ public abstract Recipe pop();
+
+ /**
+ * Does this context contain a object with the specified name.
+ *
+ * @param name the unique name of the object instance
+ * @return true if this context contain a object with the specified name
+ */
+ public abstract boolean containsObject(String name);
+
+ /**
+ * Gets the object or recipe with the specified name from the repository.
+ *
+ * @param name the unique name of the object instance
+ * @return the object instance, a recipe to build the object or null
+ */
+ public abstract Object getObject(String name);
+
+ public abstract void addFullObject(String name, Object object);
+
+ public abstract void addPartialObject(String name, Object object);
+
+ public abstract Object removePartialObject(String name);
+
+ public abstract Object getPartialObject(String name);
+
+ public abstract Object convert(Object value, ReifiedType type) throws Exception;
+
+ public abstract boolean canConvert(Object value, ReifiedType type);
+
+ public abstract Class loadClass(String className) throws ClassNotFoundException;
+
+ public abstract Recipe getRecipe(String name);
+
+}
+
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/IdRefRecipe.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/IdRefRecipe.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/IdRefRecipe.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/IdRefRecipe.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,69 @@
+/**
+ *
+ * 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.aries.blueprint.di;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.container.NoSuchComponentException;
+
+/*
+ * The IdRefRecipe is used to inject the reference name into the object (as a String).
+ * The IdRefRecipe ensures the actual reference object exists before the reference name is injected.
+ */
+public class IdRefRecipe extends AbstractRecipe {
+
+ private String idRef;
+
+ public IdRefRecipe(String name, String idRef) {
+ super(name);
+ if (idRef == null) throw new NullPointerException("idRef is null");
+ this.idRef = idRef;
+ }
+
+ public String getIdRef() {
+ return idRef;
+ }
+
+ public List<Recipe> getDependencies() {
+ Recipe recipe = ExecutionContext.Holder.getContext().getRecipe(idRef);
+ if (recipe != null) {
+ return Collections.singletonList(recipe);
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ protected Object internalCreate() throws ComponentDefinitionException {
+ ExecutionContext context = ExecutionContext.Holder.getContext();
+ if (!context.containsObject(idRef)) {
+ throw new NoSuchComponentException(idRef);
+ }
+ return idRef;
+ }
+
+ @Override
+ public String toString() {
+ return "IdRefRecipe[" +
+ "name='" + name + '\'' +
+ ", idRef='" + idRef + '\'' +
+ ']';
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/MapRecipe.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/MapRecipe.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/MapRecipe.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/MapRecipe.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,137 @@
+/**
+ * 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.aries.blueprint.di;
+
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.Hashtable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.aries.blueprint.utils.ReflectionUtils;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+/**
+ * @version $Rev: 896324 $ $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+public class MapRecipe extends AbstractRecipe {
+
+ private final List<Recipe[]> entries;
+ private final Class typeClass;
+
+ public MapRecipe(String name, Class type) {
+ super(name);
+ if (type == null) throw new NullPointerException("type is null");
+ this.typeClass = type;
+ this.entries = new ArrayList<Recipe[]>();
+ }
+
+ public List<Recipe> getDependencies() {
+ List<Recipe> nestedRecipes = new ArrayList<Recipe>(entries.size() * 2);
+ for (Recipe[] entry : entries) {
+ nestedRecipes.add(entry[0]);
+ if (entry[1] != null) {
+ nestedRecipes.add(entry[1]);
+ }
+ }
+ return nestedRecipes;
+ }
+
+ protected Object internalCreate() throws ComponentDefinitionException {
+ Class mapType = getMap(typeClass);
+
+ if (!ReflectionUtils.hasDefaultConstructor(mapType)) {
+ throw new ComponentDefinitionException("Type does not have a default constructor " + mapType.getName());
+ }
+
+ Object o;
+ try {
+ o = mapType.newInstance();
+ } catch (Exception e) {
+ throw new ComponentDefinitionException("Error while creating set instance: " + mapType.getName());
+ }
+
+ Map instance;
+ if (o instanceof Map) {
+ instance = (Map) o;
+ } else if (o instanceof Dictionary) {
+ instance = new DummyDictionaryAsMap((Dictionary) o);
+ } else {
+ throw new ComponentDefinitionException("Specified map type does not implement the Map interface: " + mapType.getName());
+ }
+
+ // add map entries
+ for (Recipe[] entry : entries) {
+ Object key = entry[0].create();
+ Object value = entry[1] != null ? entry[1].create() : null;
+ instance.put(key, value);
+ }
+ return instance;
+ }
+
+ public void put(Recipe key, Recipe value) {
+ if (key == null) throw new NullPointerException("key is null");
+ entries.add(new Recipe[] { key, value});
+ }
+
+ public void putAll(Map<Recipe,Recipe> map) {
+ if (map == null) throw new NullPointerException("map is null");
+ for (Map.Entry<Recipe,Recipe> entry : map.entrySet()) {
+ Recipe key = entry.getKey();
+ Recipe value = entry.getValue();
+ put(key, value);
+ }
+ }
+
+ public static Class getMap(Class type) {
+ if (ReflectionUtils.hasDefaultConstructor(type)) {
+ return type;
+ } else if (SortedMap.class.isAssignableFrom(type)) {
+ return TreeMap.class;
+ } else if (ConcurrentMap.class.isAssignableFrom(type)) {
+ return ConcurrentHashMap.class;
+ } else {
+ return LinkedHashMap.class;
+ }
+ }
+
+ public static class DummyDictionaryAsMap extends AbstractMap {
+
+ private final Dictionary dictionary;
+
+ public DummyDictionaryAsMap(Dictionary dictionary) {
+ this.dictionary = dictionary;
+ }
+
+ @Override
+ public Object put(Object key, Object value) {
+ return dictionary.put(key, value);
+ }
+
+ public Set entrySet() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/PassThroughRecipe.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/PassThroughRecipe.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/PassThroughRecipe.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/PassThroughRecipe.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,52 @@
+/**
+ * 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.aries.blueprint.di;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+/**
+ * @version $Rev: 896324 $ $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+public class PassThroughRecipe extends AbstractRecipe {
+
+ private Object object;
+
+ public PassThroughRecipe(String id, Object object) {
+ super(id);
+ this.prototype = false;
+ this.object = object;
+ }
+
+ protected Object internalCreate() throws ComponentDefinitionException {
+ return object;
+ }
+
+ public List<Recipe> getDependencies() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String toString() {
+ return "EnvironmentRecipe[" +
+ "name='" + name + '\'' +
+ ", object=" + object +
+ ']';
+ }
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/Recipe.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/Recipe.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/Recipe.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/Recipe.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,69 @@
+/**
+ * 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.aries.blueprint.di;
+
+import java.util.List;
+
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+/**
+ * The <code>Recipe</code> interface abstracts the creation of objects
+ *
+ * @version $Rev: 896324 $ $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+public interface Recipe {
+
+ /**
+ * Get the unique name for this recipe.
+ *
+ * @return the unique name for this recipe.
+ */
+ String getName();
+
+ /**
+ * Get the list of constructor dependencies, i.e. explicit and
+ * argument dependencies. These dependencies must be satisfied
+ * before the an object can be created.
+ *
+ * @return a list of constructor dependencies
+ */
+ List<Recipe> getConstructorDependencies();
+
+ /**
+ * Get the list of nested recipes, i.e. all dependencies including
+ * constructor dependencies.
+ *
+ * @return a list of dependencies
+ */
+ List<Recipe> getDependencies();
+
+ /**
+ * Create an instance for this recipe.
+ *
+ * @return a new instance for this recipe
+ * @throws ComponentDefinitionException
+ */
+ Object create() throws ComponentDefinitionException;
+
+ /**
+ * Destroy an instance created by this recipe
+ *
+ * @param instance the instance to be destroyed
+ */
+ void destroy(Object instance);
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/RefRecipe.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/RefRecipe.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/RefRecipe.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/RefRecipe.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,73 @@
+/**
+ *
+ * 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.aries.blueprint.di;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.container.NoSuchComponentException;
+
+public class RefRecipe extends AbstractRecipe {
+
+ private String idRef;
+
+ public RefRecipe(String name, String idRef) {
+ super(name);
+ this.idRef = idRef;
+ }
+
+ public String getIdRef() {
+ return idRef;
+ }
+
+ public void setIdRef(String name) {
+ this.idRef = name;
+ }
+
+ public List<Recipe> getDependencies() {
+ Recipe recipe = ExecutionContext.Holder.getContext().getRecipe(idRef);
+ if (recipe != null) {
+ return Collections.singletonList(recipe);
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ protected Object internalCreate() throws ComponentDefinitionException {
+ ExecutionContext context = ExecutionContext.Holder.getContext();
+ if (!context.containsObject(idRef)) {
+ throw new NoSuchComponentException(idRef);
+ }
+ Object instance = context.getObject(idRef);
+ if (instance instanceof Recipe) {
+ Recipe recipe = (Recipe) instance;
+ instance = recipe.create();
+ }
+ return instance;
+ }
+
+ @Override
+ public String toString() {
+ return "RefRecipe[" +
+ "name='" + name + '\'' +
+ ", idRef='" + idRef + '\'' +
+ ']';
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/Repository.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/Repository.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/Repository.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/Repository.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,77 @@
+/**
+ *
+ * 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.aries.blueprint.di;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+public interface Repository {
+
+ /**
+ * Returns the set of all known object names (recipes, instances or default objects)
+ * @return
+ */
+ Set<String> getNames();
+
+ /**
+ * Return the singleton instance for the given name.
+ * This method will not create the object if it has been created yet.
+ *
+ * @param name
+ * @return the instance or <code>null</code>
+ */
+ Object getInstance(String name);
+
+ /**
+ * Return the recipe for the given name.
+ *
+ * @param name
+ * @return the recipe or <code>null</code>
+ */
+ Recipe getRecipe(String name);
+
+ void putRecipe(String name, Recipe recipe);
+
+ /**
+ * Remove an uninstantiated recipe
+ * @param name
+ * @throws ComponentDefinitionException if the recipe is already instantiated
+ */
+ void removeRecipe(String name);
+
+ Object create(String name) throws ComponentDefinitionException;
+
+ Map<String, Object> createAll(Collection<String> names) throws ComponentDefinitionException;
+
+ <T> List<T> getAllRecipes(Class<T> clazz, String... names);
+
+ Set<Recipe> getAllRecipes(String... names);
+
+ void destroy();
+
+ /**
+ * Lock that should be used to synchronized creation of singletons
+ *
+ * @return
+ */
+ public Object getInstanceLock();
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ValueRecipe.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ValueRecipe.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ValueRecipe.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/di/ValueRecipe.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.aries.blueprint.di;
+
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.List;
+
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+
+/**
+ * This recipe will be used to create an object from a ValueMetadata.
+ * We need to keep the reference to the ValueMetadata so that we can lazily retrieve
+ * the value, allowing for placeholders or such to be used at the last moment.
+ *
+ * @version $Rev: 820286 $, $Date: 2009-09-30 15:45:55 +0100 (Wed, 30 Sep 2009) $
+ */
+public class ValueRecipe extends AbstractRecipe {
+
+ private final ValueMetadata value;
+ private final Object type;
+
+ public ValueRecipe(String name, ValueMetadata value, Object type) {
+ super(name);
+ this.value = value;
+ this.type = type;
+ }
+
+ public List<Recipe> getDependencies() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ protected Object internalCreate() throws ComponentDefinitionException {
+ try {
+ Type type = Object.class;
+ if (this.type instanceof Type) {
+ type = (Type) this.type;
+ } else if (this.type instanceof String) {
+ type = loadClass((String) this.type);
+ }
+ return convert(value.getStringValue(), type);
+ } catch (Exception e) {
+ throw new ComponentDefinitionException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "ValueRecipe[" +
+ "name='" + name + '\'' +
+ ", value=" + value +
+ ", type=" + type +
+ ']';
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholder.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,244 @@
+/**
+ * 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.aries.blueprint.ext;
+
+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;
+
+/**
+ * Abstract class for property placeholders.
+ *
+ * @version $Rev: 916935 $, $Date: 2010-02-27 10:05:06 +0000 (Sat, 27 Feb 2010) $
+ */
+public abstract class AbstractPropertyPlaceholder implements ComponentDefinitionRegistryProcessor {
+
+ 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 processString(String str) {
+ // TODO: we need to handle escapes on the prefix / suffix
+ Matcher matcher = getPattern().matcher(str);
+ while (matcher.find()) {
+ String rep = getProperty(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) {
+ retrieved = true;
+ retrievedValue = processString(metadata.getStringValue());
+ }
+ return retrievedValue;
+ }
+
+ public String getType() {
+ return metadata.getType();
+ }
+
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/ComponentFactoryMetadata.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/ComponentFactoryMetadata.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/ComponentFactoryMetadata.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/ComponentFactoryMetadata.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.aries.blueprint.ext;
+
+import org.apache.aries.blueprint.ExtendedBlueprintContainer;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Target;
+
+/**
+ * Custom metadata that can acts like a built-in bean manager
+ * for the component life-cycle events create and destroy.
+ */
+public interface ComponentFactoryMetadata extends ComponentMetadata, Target {
+ /**
+ * Prime the underlying bean manager with the blueprint container
+ * @param container
+ */
+ void init(ExtendedBlueprintContainer container);
+
+ /**
+ * Create an instance
+ * @return
+ * @throws ComponentDefinitionException
+ */
+ Object create() throws ComponentDefinitionException;
+
+ /**
+ * Destroy an instance previously created
+ * @param instance
+ */
+ void destroy(Object instance);
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/DependentComponentFactoryMetadata.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/DependentComponentFactoryMetadata.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/DependentComponentFactoryMetadata.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/DependentComponentFactoryMetadata.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,60 @@
+/*
+ * 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.aries.blueprint.ext;
+
+/**
+ * Metadata for custom components that need to plug in to the
+ * Blueprint container lifecycle for beans
+ */
+public interface DependentComponentFactoryMetadata extends ComponentFactoryMetadata {
+ /**
+ * Interface that allows to notify the container when the dependencies of the component
+ * become satisfied or unsatified.
+ */
+ interface SatisfactionCallback {
+ /**
+ * Alert the container that the satisfaction status has changed. isSatisfied() should reflect this.
+ */
+ void notifyChanged();
+ }
+
+ /**
+ * Start tracking the dependencies for this component.
+ * @param observer The container callback for alerting the container of status changes
+ */
+ void startTracking(SatisfactionCallback observer);
+
+ /**
+ * Stop tracking the dependencies for this component.
+ */
+ void stopTracking();
+
+ /**
+ * Return a string representation of the dependencies of this component. This will be used
+ * in diagnostics as well as the GRACE_PERIOD event.
+ * @return
+ */
+ String getDependencyDescriptor();
+
+ /**
+ * Are all dependencies of this component satisfied?
+ * @return
+ */
+ boolean isSatisfied();
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/ExtNamespaceHandler.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/ExtNamespaceHandler.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/ExtNamespaceHandler.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/ExtNamespaceHandler.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,343 @@
+/**
+ * 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.aries.blueprint.ext;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.aries.blueprint.ExtendedReferenceListMetadata;
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutableCollectionMetadata;
+import org.apache.aries.blueprint.mutable.MutableComponentMetadata;
+import org.apache.aries.blueprint.mutable.MutableIdRefMetadata;
+import org.apache.aries.blueprint.mutable.MutableMapMetadata;
+import org.apache.aries.blueprint.mutable.MutableRefMetadata;
+import org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata;
+import org.apache.aries.blueprint.mutable.MutableValueMetadata;
+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.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.IdRefMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ReferenceListMetadata;
+import org.osgi.service.blueprint.reflect.ServiceReferenceMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Attr;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A namespace handler for Aries blueprint extensions
+ *
+ * @version $Rev: 924332 $, $Date: 2010-03-17 15:31:29 +0000 (Wed, 17 Mar 2010) $
+ */
+public class ExtNamespaceHandler implements org.apache.aries.blueprint.NamespaceHandler {
+
+ public static final String BLUEPRINT_NAMESPACE = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
+ public static final String BLUEPRINT_EXT_NAMESPACE = "http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0";
+
+ public static final String PROPERTY_PLACEHOLDER_ELEMENT = "property-placeholder";
+ public static final String DEFAULT_PROPERTIES_ELEMENT = "default-properties";
+ public static final String PROPERTY_ELEMENT = "property";
+ public static final String VALUE_ELEMENT = "value";
+ public static final String LOCATION_ELEMENT = "location";
+
+ public static final String ID_ATTRIBUTE = "id";
+ public static final String PLACEHOLDER_PREFIX_ATTRIBUTE = "placeholder-prefix";
+ public static final String PLACEHOLDER_SUFFIX_ATTRIBUTE = "placeholder-suffix";
+ public static final String DEFAULTS_REF_ATTRIBUTE = "defaults-ref";
+ public static final String IGNORE_MISSING_LOCATIONS_ATTRIBUTE = "ignore-missing-locations";
+
+ public static final String SYSTEM_PROPERTIES_ATTRIBUTE = "system-properties";
+ public static final String SYSTEM_PROPERTIES_NEVER = "never";
+ public static final String SYSTEM_PROPERTIES_FALLBACK = "fallback";
+ public static final String SYSTEM_PROPERTIES_OVERRIDE = "override";
+
+ public static final String PROXY_METHOD_ATTRIBUTE = "proxy-method";
+ public static final String PROXY_METHOD_DEFAULT = "default";
+ public static final String PROXY_METHOD_CLASSES = "classes";
+ public static final String PROXY_METHOD_GREEDY = "greedy";
+
+ public static final String ROLE_ATTRIBUTE = "role";
+ public static final String ROLE_PROCESSOR = "processor";
+
+ public static final String FIELD_INJECTION_ATTRIBUTE = "field-injection";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ExtNamespaceHandler.class);
+
+ private int idCounter;
+
+ public URL getSchemaLocation(String namespace) {
+ return getClass().getResource("blueprint-ext.xsd");
+ }
+
+ public Set<Class> getManagedClasses() {
+ return new HashSet<Class>(Arrays.asList(
+ PropertyPlaceholder.class
+ ));
+ }
+
+ public Metadata parse(Element element, ParserContext context) {
+ LOGGER.debug("Parsing element {{}}{}", element.getNamespaceURI(), element.getLocalName());
+ if (nodeNameEquals(element, PROPERTY_PLACEHOLDER_ELEMENT)) {
+ return parsePropertyPlaceholder(context, element);
+ } else {
+ throw new ComponentDefinitionException("Unsupported element: " + element.getNodeName());
+ }
+ }
+
+ public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
+ if (node instanceof Attr && nodeNameEquals(node, PROXY_METHOD_ATTRIBUTE)) {
+ return decorateProxyMethod(node, component, context);
+ } else if (node instanceof Attr && nodeNameEquals(node, ROLE_ATTRIBUTE)) {
+ return decorateRole(node, component, context);
+ } else if (node instanceof Attr && nodeNameEquals(node, FIELD_INJECTION_ATTRIBUTE)) {
+ return decorateFieldInjection(node, component, context);
+ } else {
+ throw new ComponentDefinitionException("Unsupported node: " + node.getNodeName());
+ }
+ }
+
+ private ComponentMetadata decorateFieldInjection(Node node, ComponentMetadata component, ParserContext context) {
+ if (!(component instanceof BeanMetadata)) {
+ throw new ComponentDefinitionException("Attribute " + node.getNodeName() + " can only be used on a <bean> element");
+ }
+
+ if (!(component instanceof MutableBeanMetadata)) {
+ throw new ComponentDefinitionException("Expected an instanceof MutableBeanMetadata");
+ }
+
+ String value = ((Attr) node).getValue();
+ ((MutableBeanMetadata) component).setFieldInjection("true".equals(value) || "1".equals(value));
+ return component;
+ }
+
+ private ComponentMetadata decorateRole(Node node, ComponentMetadata component, ParserContext context) {
+ if (!(component instanceof BeanMetadata)) {
+ throw new ComponentDefinitionException("Attribute " + node.getNodeName() + " can only be used on a <bean> element");
+ }
+ if (!(component instanceof MutableBeanMetadata)) {
+ throw new ComponentDefinitionException("Expected an instance of MutableBeanMetadata");
+ }
+ boolean processor = false;
+ String value = ((Attr) node).getValue();
+ String[] flags = value.trim().split(" ");
+ for (String flag : flags) {
+ if (ROLE_PROCESSOR.equals(flag)) {
+ processor = true;
+ } else {
+ throw new ComponentDefinitionException("Unknown proxy method: " + flag);
+ }
+ }
+ ((MutableBeanMetadata) component).setProcessor(processor);
+ return component;
+ }
+
+ private ComponentMetadata decorateProxyMethod(Node node, ComponentMetadata component, ParserContext context) {
+ if (!(component instanceof ServiceReferenceMetadata)) {
+ throw new ComponentDefinitionException("Attribute " + node.getNodeName() + " can only be used on a <reference> or <reference-list> element");
+ }
+ if (!(component instanceof MutableServiceReferenceMetadata)) {
+ throw new ComponentDefinitionException("Expected an instance of MutableServiceReferenceMetadata");
+ }
+ int method = 0;
+ String value = ((Attr) node).getValue();
+ String[] flags = value.trim().split(" ");
+ for (String flag : flags) {
+ if (PROXY_METHOD_DEFAULT.equals(flag)) {
+ method += ExtendedReferenceListMetadata.PROXY_METHOD_DEFAULT;
+ } else if (PROXY_METHOD_CLASSES.equals(flag)) {
+ method += ExtendedReferenceListMetadata.PROXY_METHOD_CLASSES;
+ } else if (PROXY_METHOD_GREEDY.equals(flag)) {
+ method += ExtendedReferenceListMetadata.PROXY_METHOD_GREEDY;
+ } else {
+ throw new ComponentDefinitionException("Unknown proxy method: " + flag);
+ }
+ }
+ if ((method & ExtendedReferenceListMetadata.PROXY_METHOD_GREEDY) != 0 && !(component instanceof ReferenceListMetadata)) {
+ throw new ComponentDefinitionException("Greedy proxying is only available for <reference-list> element");
+ }
+ ((MutableServiceReferenceMetadata) component).setProxyMethod(method);
+ return component;
+ }
+
+ private Metadata parsePropertyPlaceholder(ParserContext context, Element element) {
+ MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+ metadata.setProcessor(true);
+ metadata.setId(getId(context, element));
+ metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+ metadata.setRuntimeClass(PropertyPlaceholder.class);
+ metadata.setInitMethod("init");
+ String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+ ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE)
+ : "${";
+ metadata.addProperty("placeholderPrefix", createValue(context, prefix));
+ String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+ ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE)
+ : "}";
+ metadata.addProperty("placeholderSuffix", createValue(context, suffix));
+ String defaultsRef = element.hasAttribute(DEFAULTS_REF_ATTRIBUTE) ? element.getAttribute(DEFAULTS_REF_ATTRIBUTE) : null;
+ if (defaultsRef != null) {
+ metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
+ }
+ String ignoreMissingLocations = element.hasAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE) ? element.getAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE) : null;
+ if (ignoreMissingLocations != null) {
+ metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
+ }
+ String systemProperties = element.hasAttribute(SYSTEM_PROPERTIES_ATTRIBUTE) ? element.getAttribute(SYSTEM_PROPERTIES_ATTRIBUTE) : null;
+ if (systemProperties != null) {
+ metadata.addProperty("systemProperties", createValue(context, systemProperties));
+ }
+ // Parse elements
+ List<String> locations = new ArrayList<String>();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node node = nl.item(i);
+ if (node instanceof Element) {
+ Element e = (Element) node;
+ if (BLUEPRINT_EXT_NAMESPACE.equals(e.getNamespaceURI())) {
+ if (nodeNameEquals(e, DEFAULT_PROPERTIES_ELEMENT)) {
+ if (defaultsRef != null) {
+ throw new ComponentDefinitionException("Only one of " + DEFAULTS_REF_ATTRIBUTE + " attribute or " + DEFAULT_PROPERTIES_ELEMENT + " element is allowed");
+ }
+ Metadata props = parseDefaultProperties(context, metadata, e);
+ metadata.addProperty("defaultProperties", props);
+ } else if (nodeNameEquals(e, LOCATION_ELEMENT)) {
+ locations.add(getTextValue(e));
+ }
+ }
+ }
+ }
+ if (!locations.isEmpty()) {
+ metadata.addProperty("locations", createList(context, locations));
+ }
+
+ PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
+
+ return metadata;
+ }
+
+ private Metadata parseDefaultProperties(ParserContext context, MutableBeanMetadata enclosingComponent, Element element) {
+ MutableMapMetadata props = context.createMetadata(MutableMapMetadata.class);
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node node = nl.item(i);
+ if (node instanceof Element) {
+ Element e = (Element) node;
+ if (BLUEPRINT_EXT_NAMESPACE.equals(e.getNamespaceURI())) {
+ if (nodeNameEquals(e, PROPERTY_ELEMENT)) {
+ BeanProperty prop = context.parseElement(BeanProperty.class, enclosingComponent, e);
+ props.addEntry(createValue(context, prop.getName(), String.class.getName()), prop.getValue());
+ }
+ }
+ }
+ }
+ return props;
+ }
+
+ public String getId(ParserContext context, Element element) {
+ if (element.hasAttribute(ID_ATTRIBUTE)) {
+ return element.getAttribute(ID_ATTRIBUTE);
+ } else {
+ return generateId(context);
+ }
+ }
+
+ public void generateIdIfNeeded(ParserContext context, MutableComponentMetadata metadata) {
+ if (metadata.getId() == null) {
+ metadata.setId(generateId(context));
+ }
+ }
+
+ private String generateId(ParserContext context) {
+ String id;
+ do {
+ id = ".ext-" + ++idCounter;
+ } while (context.getComponentDefinitionRegistry().containsComponentDefinition(id));
+ return id;
+ }
+
+ private static ValueMetadata createValue(ParserContext context, String value) {
+ return createValue(context, value, null);
+ }
+
+ private static ValueMetadata createValue(ParserContext context, String value, String type) {
+ MutableValueMetadata m = context.createMetadata(MutableValueMetadata.class);
+ m.setStringValue(value);
+ m.setType(type);
+ return m;
+ }
+
+ private static RefMetadata createRef(ParserContext context, String value) {
+ MutableRefMetadata m = context.createMetadata(MutableRefMetadata.class);
+ m.setComponentId(value);
+ return m;
+ }
+
+ private static IdRefMetadata createIdRef(ParserContext context, String value) {
+ MutableIdRefMetadata m = context.createMetadata(MutableIdRefMetadata.class);
+ m.setComponentId(value);
+ return m;
+ }
+
+ private static CollectionMetadata createList(ParserContext context, List<String> list) {
+ MutableCollectionMetadata m = context.createMetadata(MutableCollectionMetadata.class);
+ m.setCollectionClass(List.class);
+ m.setValueType(String.class.getName());
+ for (String v : list) {
+ m.addValue(createValue(context, v, String.class.getName()));
+ }
+ return m;
+ }
+
+ private static String getTextValue(Element element) {
+ StringBuffer value = new StringBuffer();
+ NodeList nl = element.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node item = nl.item(i);
+ if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
+ value.append(item.getNodeValue());
+ }
+ }
+ return value.toString();
+ }
+
+ private static boolean nodeNameEquals(Node node, String name) {
+ return (name.equals(node.getNodeName()) || name.equals(node.getLocalName()));
+ }
+
+ public static boolean isBlueprintNamespace(String ns) {
+ return BLUEPRINT_NAMESPACE.equals(ns);
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/PlaceholdersUtils.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/PlaceholdersUtils.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/PlaceholdersUtils.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/PlaceholdersUtils.java Sun Feb 27 21:05:07 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.aries.blueprint.ext;
+
+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: 896324 $, $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+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;
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/PropertyPlaceholder.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/PropertyPlaceholder.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/PropertyPlaceholder.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/ext/PropertyPlaceholder.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,142 @@
+/**
+ * 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.aries.blueprint.ext;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Property placeholder that looks for properties in the System properties.
+ *
+ * @version $Rev: 896324 $, $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+public class PropertyPlaceholder extends AbstractPropertyPlaceholder {
+
+ public enum SystemProperties {
+ never,
+ fallback,
+ override
+ }
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PropertyPlaceholder.class);
+
+ private Map defaultProperties;
+ private Properties properties;
+ private List<URL> locations;
+ private boolean ignoreMissingLocations;
+ private SystemProperties systemProperties = SystemProperties.fallback;
+
+ public Map getDefaultProperties() {
+ return defaultProperties;
+ }
+
+ public void setDefaultProperties(Map defaultProperties) {
+ this.defaultProperties = defaultProperties;
+ }
+
+ public List<URL> getLocations() {
+ return locations;
+ }
+
+ public void setLocations(List<URL> locations) {
+ this.locations = locations;
+ }
+
+ public boolean isIgnoreMissingLocations() {
+ return ignoreMissingLocations;
+ }
+
+ public void setIgnoreMissingLocations(boolean ignoreMissingLocations) {
+ this.ignoreMissingLocations = ignoreMissingLocations;
+ }
+
+ public SystemProperties getSystemProperties() {
+ return systemProperties;
+ }
+
+ public void setSystemProperties(SystemProperties systemProperties) {
+ this.systemProperties = systemProperties;
+ }
+
+ public void init() throws Exception {
+ properties = new Properties();
+ if (locations != null) {
+ for (URL url : locations) {
+ InputStream is = null;
+ try {
+ is = url.openStream();
+ } catch (IOException e) {
+ if (ignoreMissingLocations) {
+ LOGGER.debug("Unable to load properties from url " + url + " while ignoreMissingLocations is set to true");
+ } else {
+ throw e;
+ }
+ }
+ if (is != null) {
+ try {
+ properties.load(is);
+ } finally {
+ is.close();
+ }
+ }
+ }
+ }
+ }
+
+ protected String getProperty(String val) {
+ LOGGER.debug("Retrieving property {}", val);
+ Object v = null;
+ if (v == null && systemProperties == SystemProperties.override) {
+ v = System.getProperty(val);
+ if (v != null) {
+ LOGGER.debug("Found system property {} with value {}", val, v);
+ }
+ }
+ if (v == null && properties != null) {
+ v = properties.getProperty(val);
+ if (v != null) {
+ LOGGER.debug("Found property {} from locations with value {}", val, v);
+ }
+ }
+ if (v == null && systemProperties == SystemProperties.fallback) {
+ v = System.getProperty(val);
+ if (v != null) {
+ LOGGER.debug("Found system property {} with value {}", val, v);
+ }
+ }
+ if (v == null && defaultProperties != null) {
+ v = defaultProperties.get(val);
+ if (v != null) {
+ LOGGER.debug("Retrieved property {} value from defaults {}", val, v);
+ }
+ }
+ if (v == null) {
+ LOGGER.debug("Property {} not found", val);
+ }
+ return v != null ? v.toString() : null;
+ }
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanArgument.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanArgument.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanArgument.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanArgument.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,37 @@
+/**
+ * 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.aries.blueprint.mutable;
+
+import org.osgi.service.blueprint.reflect.BeanArgument;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+/**
+ * A mutable version of the <code>BeanArgument</code> that allows modifications.
+ *
+ * @version $Rev: 896324 $, $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+public interface MutableBeanArgument extends BeanArgument {
+
+ void setValue(Metadata value);
+
+ void setValueType(String valueType);
+
+ void setIndex(int index);
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanMetadata.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanMetadata.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanMetadata.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanMetadata.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,64 @@
+/**
+ * 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.aries.blueprint.mutable;
+
+import org.apache.aries.blueprint.ExtendedBeanMetadata;
+import org.osgi.service.blueprint.reflect.BeanArgument;
+import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.Target;
+
+/**
+ * A mutable version of the <code>BeanMetadata</code> that allows modifications.
+ *
+ * @version $Rev: 910448 $, $Date: 2010-02-16 09:50:18 +0000 (Tue, 16 Feb 2010) $
+ */
+public interface MutableBeanMetadata extends ExtendedBeanMetadata, MutableComponentMetadata {
+
+ void setClassName(String className);
+
+ void setInitMethod(String initMethodName);
+
+ void setDestroyMethod(String destroyMethodName);
+
+ void addArgument(BeanArgument argument);
+
+ BeanArgument addArgument(Metadata value, String valueType, int index);
+
+ void removeArgument(BeanArgument argument);
+
+ void addProperty(BeanProperty property);
+
+ BeanProperty addProperty(String name, Metadata value);
+
+ void removeProperty(BeanProperty property);
+
+ void setFactoryMethod(String factoryMethodName);
+
+ void setFactoryComponent(Target factoryComponent);
+
+ void setScope(String scope);
+
+ void setRuntimeClass(Class runtimeClass);
+
+ void setProcessor(boolean processor);
+
+ void setFieldInjection(boolean allowFieldInjection);
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanProperty.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanProperty.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanProperty.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableBeanProperty.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,35 @@
+/**
+ * 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.aries.blueprint.mutable;
+
+import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+/**
+ * A mutable version of the <code>BeanProperty</code> that allows modifications.
+ *
+ * @version $Rev: 896324 $, $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+public interface MutableBeanProperty extends BeanProperty {
+
+ void setName(String name);
+
+ void setValue(Metadata value);
+
+}
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableCollectionMetadata.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableCollectionMetadata.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableCollectionMetadata.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableCollectionMetadata.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,39 @@
+/**
+ * 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.aries.blueprint.mutable;
+
+import org.osgi.service.blueprint.reflect.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+/**
+ * A mutable version of the <code>CollectionMetadata</code> that allows modifications.
+ *
+ * @version $Rev: 896324 $, $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+public interface MutableCollectionMetadata extends CollectionMetadata {
+
+ void setCollectionClass(Class clazz);
+
+ void setValueType(String valueType);
+
+ void addValue(Metadata value);
+
+ void removeValue(Metadata value);
+
+}
\ No newline at end of file
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableComponentMetadata.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableComponentMetadata.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableComponentMetadata.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableComponentMetadata.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,42 @@
+/**
+ * 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.aries.blueprint.mutable;
+
+import java.util.List;
+
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+
+/**
+ * A mutable version of the <code>ComponentMetadata</code> that allows modifications.
+ *
+ * @version $Rev: 896324 $, $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+public interface MutableComponentMetadata extends ComponentMetadata {
+
+ void setId(String id);
+
+ void setActivation(int activation);
+
+ void setDependsOn(List<String> dependsOn);
+
+ void addDependsOn(String dependency);
+
+ void removeDependsOn(String dependency);
+
+}
\ No newline at end of file
Added: aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableIdRefMetadata.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableIdRefMetadata.java?rev=1075147&view=auto
==============================================================================
--- aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableIdRefMetadata.java (added)
+++ aries/tags/blueprint-0.3/blueprint-core/src/main/java/org/apache/aries/blueprint/mutable/MutableIdRefMetadata.java Sun Feb 27 21:05:07 2011
@@ -0,0 +1,32 @@
+/**
+ * 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.aries.blueprint.mutable;
+
+import org.osgi.service.blueprint.reflect.IdRefMetadata;
+
+/**
+ * A mutable version of the <code>IdRefMetadata</code> that allows modifications.
+ *
+ * @version $Rev: 896324 $, $Date: 2010-01-06 06:05:04 +0000 (Wed, 06 Jan 2010) $
+ */
+public interface MutableIdRefMetadata extends IdRefMetadata {
+
+ public void setComponentId(String componentId);
+
+}