You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2007/12/21 20:28:13 UTC
svn commit: r606280 [6/6] - in /felix/sandbox/clement/ipojo: composite/
composite/src/ composite/src/main/ composite/src/main/java/
composite/src/main/java/org/ composite/src/main/java/org/apache/
composite/src/main/java/org/apache/felix/ composite/src...
Added: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistrationImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistrationImpl.java?rev=606280&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistrationImpl.java (added)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistrationImpl.java Fri Dec 21 11:28:07 2007
@@ -0,0 +1,257 @@
+/*
+ * 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.felix.ipojo.context;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.InstanceManager;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Internal service registration implementation. This class is used for in the
+ * composition.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ServiceRegistrationImpl implements ServiceRegistration {
+
+ /**
+ * Service Registry.
+ */
+ private ServiceRegistry m_registry = null;
+
+ /**
+ * Interfaces associated with the service object.
+ */
+ private String[] m_classes = null;
+
+ /**
+ * Service Id associated with the service object.
+ */
+ private Long m_serviceId = null;
+
+ /**
+ * Service object.
+ */
+ private Object m_svcObj = null;
+
+ /**
+ * Service factory interface.
+ */
+ private ServiceFactory m_factory = null;
+
+ /**
+ * Associated property dictionary.
+ */
+ private Map m_propMap = null;
+
+ /**
+ * Re-usable service reference.
+ */
+ private ServiceReferenceImpl m_ref = null;
+
+ /**
+ * Property Keys List.
+ */
+ private List m_list = new ArrayList();
+
+ /**
+ * Constructor.
+ *
+ * @param registry : the service registry
+ * @param cm : component instance
+ * @param classes : published interfaces array
+ * @param serviceId : the unique service id
+ * @param svcObj : the service object or the service factory object
+ * @param dict : service properties
+ */
+ public ServiceRegistrationImpl(ServiceRegistry registry, ComponentInstance cm, String[] classes, Long serviceId, Object svcObj, Dictionary dict) {
+ m_registry = registry;
+ m_classes = classes;
+ m_serviceId = serviceId;
+ m_svcObj = svcObj;
+ if (m_svcObj instanceof ServiceFactory) { m_factory = (ServiceFactory) m_svcObj; }
+ initializeProperties(dict);
+
+ // This reference is the "standard" reference for this service and will
+ // always be returned by getReference().
+ // Since all reference to this service are supposed to be equal, we use
+ // the hash code of this reference for
+ // a references to this service in ServiceReference.
+ m_ref = new ServiceReferenceImpl(cm, this);
+ }
+
+ /**
+ * Check if the service registration still valid.
+ * @return true if the service registration is valid.
+ */
+ protected boolean isValid() {
+ return m_svcObj != null;
+ }
+
+ /**
+ * Get the service reference attached with this service registration.
+ * @return the service reference
+ * @see org.osgi.framework.ServiceRegistration#getReference()
+ */
+ public ServiceReference getReference() {
+ return m_ref;
+ }
+
+ /**
+ * Add properties to a service registration.
+ * @param dict : the properties to add
+ * @see org.osgi.framework.ServiceRegistration#setProperties(java.util.Dictionary)
+ */
+ public void setProperties(Dictionary dict) {
+ // Make sure registration is valid.
+ if (!isValid()) {
+ throw new IllegalStateException("The service registration is no longer valid.");
+ }
+ // Set the properties.
+ initializeProperties(dict);
+ // Tell registry about it.
+ m_registry.servicePropertiesModified(this);
+ }
+
+ /**
+ * Unregister the service.
+ * @see org.osgi.framework.ServiceRegistration#unregister()
+ */
+ public void unregister() {
+ if (m_svcObj != null) {
+ m_registry.unregisterService(this);
+ m_svcObj = null;
+ m_factory = null;
+ } else {
+ throw new IllegalStateException("Service already unregistered.");
+ }
+ }
+
+ /**
+ * Look for a property in the service properties.
+ *
+ * @param key : property key
+ * @return the object associated with the key or null if the key is not
+ * present.
+ */
+ protected Object getProperty(String key) {
+ return m_propMap.get(key);
+ }
+
+ /**
+ * Get the property keys.
+ * @return the property keys list.
+ */
+ protected String[] getPropertyKeys() {
+ synchronized (m_propMap) {
+ m_list.clear();
+ Iterator i = m_propMap.entrySet().iterator();
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+ m_list.add(entry.getKey());
+ }
+ return (String[]) m_list.toArray(new String[m_list.size()]);
+ }
+ }
+
+ /**
+ * Get the service object.
+ * @return the service object. Call the service factory if needed.
+ */
+ protected Object getService() {
+ // If the service object is a service factory, then
+ // let it create the service object.
+ if (m_factory != null) {
+ return getFactoryUnchecked();
+ } else {
+ return m_svcObj;
+ }
+ }
+
+ /**
+ * Initialize properties.
+ *
+ * @param dict : service properties to publish.
+ */
+ private void initializeProperties(Dictionary dict) {
+ // Create a case insensitive map.
+ if (m_propMap == null) {
+ m_propMap = new StringMap(false);
+ } else {
+ m_propMap.clear();
+ }
+
+ if (dict != null) {
+ Enumeration keys = dict.keys();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ m_propMap.put(key, dict.get(key));
+ }
+ }
+ // Add the framework assigned properties.
+ m_propMap.put(Constants.OBJECTCLASS, m_classes);
+ m_propMap.put(Constants.SERVICE_ID, m_serviceId);
+ }
+
+ /**
+ * Get a service object via a service factory.
+ * @return the service object via the service factory invocation.
+ */
+ private Object getFactoryUnchecked() {
+ return m_factory.getService(null, this);
+ }
+
+ /**
+ * Unget a service. (Internal Method)
+ *
+ * @param cm : component instance using the service.
+ * @param svcObj : the unget service object.
+ */
+ private void ungetFactoryUnchecked(ComponentInstance cm, Object svcObj) {
+ if (cm instanceof InstanceManager) {
+ m_factory.ungetService(((InstanceManager) cm).getContext().getBundle(), this, svcObj);
+ }
+
+ }
+
+ /**
+ * Unget a service.
+ *
+ * @param cm : component instance using the service.
+ * @param srvObj : the unget service object.
+ */
+ public void ungetService(ComponentInstance cm, Object srvObj) {
+ // If the service object is a service factory, then let is release the
+ // service object.
+ if (m_factory != null) {
+ ungetFactoryUnchecked(cm, srvObj);
+ }
+ }
+
+}
Added: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistry.java?rev=606280&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistry.java (added)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceRegistry.java Fri Dec 21 11:28:07 2007
@@ -0,0 +1,336 @@
+/*
+ * 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.felix.ipojo.context;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.List;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Internal Service Registry. This class is used for in the composition.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ServiceRegistry {
+
+ /**
+ * Service Id index.
+ */
+ private long m_serviceId = 1L;
+
+ /**
+ * List of service listeners.
+ */
+ private List m_listeners = new ArrayList(); // ListenerInfo List
+
+ /**
+ * List of service registration.
+ */
+ private List m_regs = new ArrayList();
+
+ /**
+ * A "real" bundle context to create LDAP filter.
+ */
+ private BundleContext m_bc; // BundleContext to create Filter
+
+ /**
+ * Listener info structure.
+ */
+ private class ListenerInfo {
+ /**
+ * Listener object.
+ */
+ private ServiceListener m_listener;
+ /**
+ * Filter associated with the filter.
+ */
+ private Filter m_filter;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param bc : bundle context.
+ */
+ public ServiceRegistry(BundleContext bc) {
+ m_bc = bc;
+ }
+
+ /**
+ * Add a given service listener with no filter.
+ *
+ * @param arg0 : the service listener to add
+ */
+ public void addServiceListener(ServiceListener arg0) {
+ ListenerInfo li = new ListenerInfo();
+ li.m_listener = arg0;
+ li.m_filter = null;
+ m_listeners.add(li);
+ }
+
+ /**
+ * Unget a service.
+ *
+ * @param cm : instance releasing the service.
+ * @param ref : released reference.
+ * @return true if the unget success
+ */
+ public boolean ungetService(ComponentInstance cm, ServiceReference ref) {
+
+ ServiceRegistrationImpl reg = ((ServiceReferenceImpl) ref).getServiceRegistration();
+ if (reg.isValid()) {
+ reg.ungetService(cm, reg.getService());
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Unregister a service listener.
+ *
+ * @param arg0 : the service listener to remove
+ */
+ public void removeServiceListener(ServiceListener arg0) {
+ m_listeners.remove(arg0);
+ }
+
+ /**
+ * Register a service.
+ *
+ * @param cm : provider instance.
+ * @param clazz : provided interface.
+ * @param svcObj : service object of service factory object.
+ * @param dict : service properties.
+ * @return the created service registration.
+ */
+ public ServiceRegistration registerService(ComponentInstance cm, String clazz, Object svcObj, Dictionary dict) {
+ synchronized (m_regs) {
+ ServiceRegistrationImpl reg = new ServiceRegistrationImpl(this, cm, new String[] { clazz }, new Long(m_serviceId++), svcObj, dict);
+ m_regs.add(reg);
+ fireServiceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()));
+ return reg;
+ }
+ }
+
+ /**
+ * Register a service.
+ *
+ * @param cm : provider instance.
+ * @param clazzes : provided interfaces.
+ * @param svcObj : service object of service factory object.
+ * @param dict : service properties.
+ * @return the created service registration.
+ */
+ public ServiceRegistration registerService(ComponentInstance cm, String[] clazzes, Object svcObj, Dictionary dict) {
+ synchronized (m_regs) {
+ ServiceRegistrationImpl reg = new ServiceRegistrationImpl(this, cm, clazzes, new Long(m_serviceId++), svcObj, dict);
+ m_regs.add(reg);
+ fireServiceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reg.getReference()));
+ return reg;
+ }
+ }
+
+ /**
+ * Dispatch a service event.
+ * @param event : the service to dispatch
+ */
+ private void fireServiceChanged(ServiceEvent event) {
+ synchronized (m_listeners) {
+ // Iterate on the service listener list to notify service listener
+ for (int i = 0; i < m_listeners.size(); i++) {
+ ListenerInfo li = (ListenerInfo) m_listeners.get(i);
+ ServiceReference sr = event.getServiceReference();
+ if (li.m_filter == null) {
+ li.m_listener.serviceChanged(event);
+ }
+ if (li.m_filter != null && li.m_filter.match(sr)) {
+ li.m_listener.serviceChanged(event);
+ }
+ }
+ }
+ }
+
+ /**
+ * Get available (and accessible) service references.
+ *
+ * @param className : required interface
+ * @param expr : LDAP filter
+ * @return : the list of available service references.
+ * @throws InvalidSyntaxException
+ * occurs when the LDAP filter is malformed.
+ */
+ public ServiceReference[] getServiceReferences(String className, String expr) throws InvalidSyntaxException {
+ synchronized (m_regs) {
+ // Define filter if expression is not null.
+ Filter filter = null;
+ if (expr != null) {
+ filter = m_bc.createFilter(expr);
+ }
+
+ List refs = new ArrayList();
+
+ for (int i = 0; i < m_regs.size(); i++) {
+ ServiceRegistrationImpl reg = (ServiceRegistrationImpl) m_regs.get(i);
+ // Determine if the registered services matches the search
+ // criteria.
+ boolean matched = false;
+
+ // If className is null, then look at filter only.
+ if ((className == null) && ((filter == null) || filter.match(reg.getReference()))) {
+ matched = true;
+ } else if (className != null) {
+ // If className is not null, then first match the
+ // objectClass property before looking at the
+ // filter.
+ String[] objectClass = (String[]) ((ServiceRegistrationImpl) reg).getProperty(Constants.OBJECTCLASS);
+ for (int classIdx = 0; classIdx < objectClass.length; classIdx++) {
+ if (objectClass[classIdx].equals(className) && ((filter == null) || filter.match(reg.getReference()))) {
+ matched = true;
+ break;
+ }
+ }
+ }
+
+ // Add reference if it was a match.
+ if (matched) {
+ refs.add(reg.getReference());
+ }
+ }
+
+ if (refs.size() > 0) {
+ return (ServiceReference[]) refs.toArray(new ServiceReference[refs.size()]);
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Look for a service reference.
+ *
+ * @param clazz : required interface.
+ * @return the first available provider or null if none available.
+ */
+ public ServiceReference getServiceReference(String clazz) {
+ synchronized (m_regs) {
+ try {
+ ServiceReference[] refs = getServiceReferences(clazz, null);
+ if (refs != null) {
+ return refs[0];
+ } // If the refs != null we are sure that it exists one reference or more.
+ } catch (InvalidSyntaxException ex) {
+ System.err.println("Scope Service Registry : Problem when looking for service reference" + ex.getMessage());
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Get a service object.
+ * @param cm : component instance requiring the service.
+ * @param ref : the required reference.
+ * @return the service object.
+ */
+ public Object getService(ComponentInstance cm, ServiceReference ref) {
+ synchronized (m_regs) {
+ // Look for the service registration for this ref
+ ServiceRegistrationImpl reg = ((ServiceReferenceImpl) ref).getServiceRegistration();
+ if (reg.isValid()) {
+ // Delegate the service providing to the service registration
+ return reg.getService();
+ } else {
+ return null;
+ }
+ }
+ }
+
+ /**
+ * Get all service references consistent with the given interface and
+ * filter.
+ * @param clazz : the required interface.
+ * @param filter : the LDAP filter.
+ * @return the list of all service reference or null if none available.
+ * @throws InvalidSyntaxException occurs when the LDAP filter is malformed.
+ */
+ public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ synchronized (m_regs) {
+ // Can delegate on getServiceReference, indeed their is no test on
+ // the "modularity" conflict.
+ return getServiceReferences(clazz, filter);
+ }
+ }
+
+ /**
+ * Add a service listener with a filter.
+ * @param listener : the service listener to add
+ * @param filter : LDAP filter
+ */
+ public void addServiceListener(ServiceListener listener, String filter) {
+ // If the filter is null, subscribe with no filter.
+ if (filter == null) {
+ addServiceListener(listener);
+ return;
+ }
+
+ ListenerInfo li = new ListenerInfo();
+ li.m_listener = listener;
+ try {
+ li.m_filter = m_bc.createFilter(filter);
+ } catch (InvalidSyntaxException ex) {
+ System.err.println("Scope Service Registry : Problem when creating a service listener " + ex.getMessage());
+ }
+ m_listeners.add(li);
+ }
+
+ /**
+ * Dispatch a service properties modified event.
+ * @param reg : the implicated service registration.
+ */
+ public void servicePropertiesModified(ServiceRegistrationImpl reg) {
+ fireServiceChanged(new ServiceEvent(ServiceEvent.MODIFIED, reg.getReference()));
+ }
+
+ /**
+ * Unregister a service.
+ * @param reg : the service registration to unregister
+ */
+ public void unregisterService(ServiceRegistrationImpl reg) {
+ m_regs.remove(reg);
+ fireServiceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, reg.getReference()));
+ }
+
+ /**
+ * Reset the service registry.
+ */
+ public void reset() {
+ m_serviceId = 1L;
+ m_listeners = new ArrayList();
+ m_regs = new ArrayList();
+ }
+}
Added: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/StringMap.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/StringMap.java?rev=606280&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/StringMap.java (added)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/context/StringMap.java Fri Dec 21 11:28:07 2007
@@ -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.felix.ipojo.context;
+
+import java.util.Comparator;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Simple utility class that creates a map for string-based keys by extending
+ * <tt>TreeMap</tt>. This map can be set to use case-sensitive or
+ * case-insensitive comparison when searching for the key. Any keys put into
+ * this map will be converted to a <tt>String</tt> using the
+ * <tt>toString()</tt> method, since it is only intended to compare strings.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class StringMap extends TreeMap {
+
+ /**
+ * serialVersionUID.
+ */
+ private static final long serialVersionUID = 6948801857034259744L;
+
+ /**
+ * Constructor.
+ */
+ public StringMap() {
+ this(true);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param caseSensitive : fix if the map if case sensitive or not.
+ */
+ public StringMap(boolean caseSensitive) {
+ super(new StringComparator(caseSensitive));
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param map : initial properties.
+ * @param caseSensitive : fix if the map if case sensitive or not.
+ */
+ public StringMap(Map map, boolean caseSensitive) {
+ this(caseSensitive);
+ putAll(map);
+ }
+
+ /**
+ * Put a record in the map.
+ * @param key : key
+ * @param value : value
+ * @return an object.
+ * @see java.util.TreeMap#put(K, V)
+ */
+ public Object put(Object key, Object value) {
+ return super.put(key.toString(), value);
+ }
+
+ /**
+ * Check if the map is case-sensitive.
+ * @return true if the map is case sensitive.
+ */
+ public boolean isCaseSensitive() {
+ return ((StringComparator) comparator()).isCaseSensitive();
+ }
+
+ /**
+ * Set the case sensitivity.
+ *
+ * @param b : the new case sensitivity.
+ */
+ public void setCaseSensitive(boolean b) {
+ ((StringComparator) comparator()).setCaseSensitive(b);
+ }
+
+ private static class StringComparator implements Comparator {
+ /**
+ * Is the map case sensitive?
+ */
+ private boolean m_isCaseSensitive = true;
+
+ /**
+ * Constructor.
+ *
+ * @param b : true to enable the case sensitivity.
+ */
+ public StringComparator(boolean b) {
+ m_isCaseSensitive = b;
+ }
+
+ /**
+ * Compare to object.
+ * @param o1 : first object to compare
+ * @param o2 : second object to compare
+ * @return the comparison result
+ * @see java.util.Comparator#compare(T, T)
+ */
+ public int compare(Object o1, Object o2) {
+ if (m_isCaseSensitive) {
+ return o1.toString().compareTo(o2.toString());
+ } else {
+ return o1.toString().compareToIgnoreCase(o2.toString());
+ }
+ }
+
+ /**
+ * Check if the comparator is case sensitive.
+ * @return true if the map is case sensitive.
+ */
+ public boolean isCaseSensitive() {
+ return m_isCaseSensitive;
+ }
+
+ /**
+ * Set the case sensitivity.
+ *
+ * @param b : true to enable the case sensitivity
+ */
+ public void setCaseSensitive(boolean b) {
+ m_isCaseSensitive = b;
+ }
+ }
+}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurableProperty.java Fri Dec 21 11:28:07 2007
@@ -469,13 +469,13 @@
try {
m_method.call(new Object[] { m_value });
} catch (NoSuchMethodException e) {
- m_handler.error( "The method " + m_method + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_method + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (IllegalAccessException e) {
- m_handler.error( "The method " + m_method + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_method + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_handler.error( "The method " + m_method + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.error("The method " + m_method + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
@@ -490,13 +490,13 @@
try {
m_method.call(instance, new Object[] { m_value });
} catch (NoSuchMethodException e) {
- m_handler.error( "The method " + m_method + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_method + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (IllegalAccessException e) {
- m_handler.error( "The method " + m_method + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_method + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_handler.error( "The method " + m_method + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.error("The method " + m_method + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java Fri Dec 21 11:28:07 2007
@@ -28,7 +28,7 @@
import org.apache.felix.ipojo.IPojoConfiguration;
import org.apache.felix.ipojo.InstanceManager;
import org.apache.felix.ipojo.PrimitiveHandler;
-import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
import org.apache.felix.ipojo.architecture.PropertyDescription;
import org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler;
import org.apache.felix.ipojo.metadata.Attribute;
@@ -74,9 +74,9 @@
* @param cd : component type description to populate.
* @param metadata : component type metadata.
* @throws ConfigurationException : metadata are incorrect.
- * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentDescription, org.apache.felix.ipojo.metadata.Element)
+ * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentTypeDescription, org.apache.felix.ipojo.metadata.Element)
*/
- public void initializeComponentFactory(ComponentDescription cd, Element metadata) throws ConfigurationException {
+ public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) throws ConfigurationException {
Element[] confs = metadata.getElements("Properties", "");
if (confs.length == 0) { return; }
Element[] configurables = confs[0].getElements("Property");
@@ -228,6 +228,7 @@
/**
* Setter Callback Method.
* Check if the modified field is a configurable property to update the value.
+ * @param pojo : the pojo object on which the field is accessed
* @param fieldName : field name
* @param value : new value
* @see org.apache.felix.ipojo.Handler#onSet(Object, java.lang.String, java.lang.Object)
@@ -249,6 +250,7 @@
/**
* Getter Callback Method.
* Check if the field is a configurable property to push the stored value.
+ * @param pojo : the pojo object on which the field is accessed
* @param fieldName : field name
* @param value : value pushed by the previous handler
* @return the stored value or the previous value.
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java Fri Dec 21 11:28:07 2007
@@ -31,7 +31,6 @@
import org.apache.felix.ipojo.Nullable;
import org.apache.felix.ipojo.PolicyServiceContext;
import org.apache.felix.ipojo.ServiceContext;
-import org.apache.felix.ipojo.composite.CompositeServiceContext;
import org.apache.felix.ipojo.util.ServiceReferenceRankingComparator;
import org.apache.felix.ipojo.util.Tracker;
import org.apache.felix.ipojo.util.TrackerCustomizer;
@@ -224,7 +223,7 @@
m_bindingPolicy = bindingPolicy;
// Fix the policy according to the level
- if ((m_policy == PolicyServiceContext.LOCAL_AND_GLOBAL || m_policy == PolicyServiceContext.LOCAL) && ! ((((IPojoContext) m_handler.getInstanceManager().getContext()).getServiceContext()) instanceof CompositeServiceContext)) {
+ if ((m_policy == PolicyServiceContext.LOCAL_AND_GLOBAL || m_policy == PolicyServiceContext.LOCAL) && ((((IPojoContext) m_handler.getInstanceManager().getContext()).getServiceContext()) == null)) {
// We are not in a composite : BOTH | STRICT => GLOBAL
m_policy = PolicyServiceContext.GLOBAL;
}
@@ -364,13 +363,13 @@
try {
m_callbacks[i].call(ref, getService(ref));
} catch (NoSuchMethodException e) {
- m_handler.error( "The method " + m_callbacks[i].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_callbacks[i].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (IllegalAccessException e) {
- m_handler.error( "The method " + m_callbacks[i].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_callbacks[i].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_handler.error( "The method " + m_callbacks[i].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.error("The method " + m_callbacks[i].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
m_handler.getInstanceManager().stop();
}
}
@@ -415,13 +414,13 @@
try {
m_callbacks[j].callOnInstance(instance, ref, getService(ref));
} catch (NoSuchMethodException e) {
- m_handler.error( "The method " + m_callbacks[j].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_callbacks[j].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (IllegalAccessException e) {
- m_handler.error( "The method " + m_callbacks[j].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_callbacks[j].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_handler.error( "The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.error("The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
@@ -436,13 +435,13 @@
m_callbacks[j].callOnInstance(instance, ref, getService(ref));
}
} catch (NoSuchMethodException e) {
- m_handler.error( "The method " + m_callbacks[j].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_callbacks[j].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (IllegalAccessException e) {
- m_handler.error( "The method " + m_callbacks[j].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_callbacks[j].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_handler.error( "The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.error("The method " + m_callbacks[j].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
@@ -464,13 +463,13 @@
m_callbacks[i].call(ref, getService(ref));
ungetService(ref);
} catch (NoSuchMethodException e) {
- m_handler.error( "The method " + m_callbacks[i].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_callbacks[i].getMethodName() + " does not exist in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (IllegalAccessException e) {
- m_handler.error( "The method " + m_callbacks[i].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
+ m_handler.error("The method " + m_callbacks[i].getMethodName() + " is not accessible in the class " + m_handler.getInstanceManager().getClassName());
m_handler.getInstanceManager().stop();
} catch (InvocationTargetException e) {
- m_handler.error( "The method " + m_callbacks[i].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
+ m_handler.error("The method " + m_callbacks[i].getMethodName() + " in the class " + m_handler.getInstanceManager().getClassName() + "throws an exception : " + e.getTargetException().getMessage());
m_handler.getInstanceManager().setState(ComponentInstance.INVALID);
}
}
@@ -494,7 +493,7 @@
try {
m_clazz = m_handler.getInstanceManager().getContext().getBundle().loadClass(m_specification);
} catch (ClassNotFoundException e) {
- m_handler.error( "Cannot load the interface class for the dependency " + m_field + " [" + m_specification + "]");
+ m_handler.error("Cannot load the interface class for the dependency " + m_field + " [" + m_specification + "]");
}
if (m_isOptional) {
@@ -503,11 +502,11 @@
Class c = getHandler().getInstanceManager().getContext().getBundle().loadClass(m_di);
m_nullable = c.newInstance();
} catch (IllegalAccessException e) {
- m_handler.error( "Cannot load the default-implementation " + m_di + " : " + e.getMessage());
+ m_handler.error("Cannot load the default-implementation " + m_di + " : " + e.getMessage());
} catch (InstantiationException e) {
- m_handler.error( "Cannot load the default-implementation " + m_di + " : " + e.getMessage());
+ m_handler.error("Cannot load the default-implementation " + m_di + " : " + e.getMessage());
} catch (ClassNotFoundException e) {
- m_handler.error( "Cannot load the default-implementation " + m_di + " : " + e.getMessage());
+ m_handler.error("Cannot load the default-implementation " + m_di + " : " + e.getMessage());
}
} else {
m_nullable = Proxy.newProxyInstance(getHandler().getInstanceManager().getClazz().getClassLoader(), new Class[] {m_clazz, Nullable.class}, new NullableObject());
@@ -519,7 +518,7 @@
try {
m_filter = m_handler.getInstanceManager().getContext().createFilter(filter); // Store the filter
} catch (InvalidSyntaxException e1) {
- m_handler.error( "[" + m_handler.getInstanceManager().getClassName() + "] A filter is malformed : " + filter + " - " + e1.getMessage());
+ m_handler.error("[" + m_handler.getInstanceManager().getClassName() + "] A filter is malformed : " + filter + " - " + e1.getMessage());
m_handler.getInstanceManager().stop();
}
m_tracker = new Tracker(m_serviceContext, m_filter, this);
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyCallback.java Fri Dec 21 11:28:07 2007
@@ -164,7 +164,7 @@
}
if (m_methodObj == null) {
- m_dependency.getHandler().error( "The method " + m_method + " cannot be called : method not found");
+ m_dependency.getHandler().error("The method " + m_method + " cannot be called : method not found");
m_dependency.getHandler().getInstanceManager().stop();
} else {
m_methodObj.setAccessible(true);
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java Fri Dec 21 11:28:07 2007
@@ -46,12 +46,6 @@
private Dependency[] m_dependencies = new Dependency[0];
/**
- * State of the handler.
- * Lifecycle controller.
- */
- private boolean m_state;
-
- /**
* Is the handler started.
*/
private boolean m_started;
@@ -89,7 +83,7 @@
if (! m_started) { return; }
synchronized (m_dependencies) {
// Store the initial state
- boolean initialState = m_state;
+ boolean initialState = getValidity();
boolean valid = true;
for (int i = 0; i < m_dependencies.length; i++) {
@@ -105,14 +99,14 @@
// The dependencies are valid
if (!initialState) {
// There is a state change
- m_state = true;
+ setValidity(true);
}
// Else do nothing, the component state stay VALID
} else {
// The dependencies are not valid
if (initialState) {
// There is a state change
- m_state = false;
+ setValidity(false);
}
// Else do nothing, the component state stay UNRESOLVED
}
@@ -299,6 +293,7 @@
/**
* GetterCallback Method.
+ * @param pojo : the pojo object on which the field is accessed
* @param fieldName : the field name.
* @param value : the value passed to the field (by the previous handler).
* @return the object that the dependency handler want to push.
@@ -319,6 +314,8 @@
/**
* Method Entry callback.
+ * @param pojo : pojo object on which the method is invoked.
+ * @param method : method object representing the invoked method.
* @see org.apache.felix.ipojo.Handler#onEntry(Object, Method)
*/
public void onEntry(Object pojo, Method method) {
@@ -332,8 +329,9 @@
/**
* Method Exit callback.
- * @param method : method id.
- * @param returnedObj : returned object.
+ * @param pojo : pojo object on which the method was invoked.
+ * @param method : method object representing the invoked method.
+ * @param returnedObj : returned object by the method.
* @see org.apache.felix.ipojo.Handler#onExit(Object, Method, java.lang.Object)
*/
public void onExit(Object pojo, Method method, Object returnedObj) {
@@ -347,6 +345,7 @@
/**
* Method Error callback.
+ * @param pojo : the pojo object on which the field is accessed
* @param method : method id.
* @param returnedObj : returned object.
* @see org.apache.felix.ipojo.Handler#onExit(Object, Method, java.lang.Object)
@@ -372,6 +371,7 @@
}
// Check the state
m_started = true;
+ setValidity(false);
checkContext();
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java Fri Dec 21 11:28:07 2007
@@ -161,13 +161,13 @@
try {
m_callbacks[i].call();
} catch (NoSuchMethodException e) {
- error( "[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
+ error("[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
getInstanceManager().stop();
} catch (IllegalAccessException e) {
- error( "[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
+ error("[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
getInstanceManager().stop();
} catch (InvocationTargetException e) {
- error( "[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : " + e.getTargetException().getMessage());
+ error("[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : " + e.getTargetException().getMessage());
getInstanceManager().setState(ComponentInstance.INVALID);
}
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java Fri Dec 21 11:28:07 2007
@@ -24,7 +24,7 @@
import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.InstanceManager;
import org.apache.felix.ipojo.PrimitiveHandler;
-import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.FieldMetadata;
import org.apache.felix.ipojo.parser.ManipulationMetadata;
@@ -73,6 +73,7 @@
/**
* GetterCallback.
+ * @param pojo : the pojo object on which the field is accessed
* Return the stored value.
* @param field : field name.
* @param o : value given by the previous handler.
@@ -84,6 +85,7 @@
/**
* SetterCallback.
+ * @param pojo : the pojo object on which the field is accessed
* Store the new field value & invalidate / validate the handler is required.
* @param field : field name.
* @param o : new value.
@@ -94,13 +96,13 @@
if (nv != m_state) {
m_state = nv;
if (m_state) {
- ((InstanceManager) getInstance()).setState(ComponentInstance.VALID);
+ ((InstanceManager) getHandlerManager()).setState(ComponentInstance.VALID);
} else {
- ((InstanceManager) getInstance()).setState(ComponentInstance.INVALID);
+ ((InstanceManager) getHandlerManager()).setState(ComponentInstance.INVALID);
}
}
} else {
- error( "Boolean expected for the lifecycle controller");
+ error("Boolean expected for the lifecycle controller");
getInstanceManager().stop();
}
}
@@ -111,9 +113,9 @@
* @param cd : component description
* @param metadata : component type metadata
* @throws ConfigurationException : occurs if the controller field is not in the POJO class or is not a boolean.
- * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentDescription, org.apache.felix.ipojo.metadata.Element)
+ * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentTypeDescription, org.apache.felix.ipojo.metadata.Element)
*/
- public void initializeComponentFactory(ComponentDescription cd, Element metadata) throws ConfigurationException {
+ public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) throws ConfigurationException {
String field = null;
Element[] lc = metadata.getElements("controller");
// Use only the first controller
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java Fri Dec 21 11:28:07 2007
@@ -189,7 +189,7 @@
svc = m_handler.getInstanceManager().createPojoObject();
break;
default:
- m_handler.error( "[" + m_handler.getInstanceManager().getClassName() + "] Unknown factory policy for " + m_serviceSpecification + " : " + m_factoryPolicy);
+ m_handler.error("[" + m_handler.getInstanceManager().getClassName() + "] Unknown factory policy for " + m_serviceSpecification + " : " + m_factoryPolicy);
getInstanceManager().stop();
}
return svc;
@@ -281,7 +281,7 @@
Properties serviceProperties = getServiceProperties();
if (serviceProperties == null) {
- m_handler.error( "Cannot get the properties of the provided service");
+ m_handler.error("Cannot get the properties of the provided service");
getInstanceManager().stop();
return;
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java Fri Dec 21 11:28:07 2007
@@ -31,7 +31,7 @@
import org.apache.felix.ipojo.IPojoConfiguration;
import org.apache.felix.ipojo.InstanceManager;
import org.apache.felix.ipojo.PrimitiveHandler;
-import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
import org.apache.felix.ipojo.architecture.HandlerDescription;
import org.apache.felix.ipojo.architecture.PropertyDescription;
import org.apache.felix.ipojo.handlers.dependency.Dependency;
@@ -346,6 +346,7 @@
/**
* Setter Callback Method.
* Check if the modified field is a property to update the value.
+ * @param pojo : the pojo object on which the field is accessed
* @param fieldName : field name
* @param value : new value
* @see org.apache.felix.ipojo.Handler#onSet(Object,
@@ -374,6 +375,7 @@
/**
* Getter Callback Method.
* Check if the field is a property to push the stored value.
+ * @param pojo : the pojo object on which the field is accessed
* @param fieldName : field name
* @param value : value pushed by the previous handler
* @return the stored value or the previous value.
@@ -499,9 +501,9 @@
* @param cd : component type description to populate.
* @param metadata : component type metadata.
* @throws ConfigurationException : occurs when the POJO does not implement any interfaces.
- * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentDescription, org.apache.felix.ipojo.metadata.Element)
+ * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentTypeDescription, org.apache.felix.ipojo.metadata.Element)
*/
- public void initializeComponentFactory(ComponentDescription cd, Element metadata) throws ConfigurationException {
+ public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) throws ConfigurationException {
// Change ComponentInfo
Element[] provides = metadata.getElements("provides");
ManipulationMetadata manipulation = new ManipulationMetadata(metadata);
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java Fri Dec 21 11:28:07 2007
@@ -75,9 +75,9 @@
String arg = m_arguments[i];
if (arg.endsWith("[]")) {
arg = arg.substring(0, arg.length() - 2);
- id+= "$" + arg.replace('.', '_') + "__";
+ id += "$" + arg.replace('.', '_') + "__";
} else {
- id+= "$" + arg.replace('.', '_');
+ id += "$" + arg.replace('.', '_');
}
}
return id;
Modified: felix/sandbox/clement/ipojo/core/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/resources/metadata.xml?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/resources/metadata.xml (original)
+++ felix/sandbox/clement/ipojo/core/src/main/resources/metadata.xml Fri Dec 21 11:28:07 2007
@@ -3,37 +3,11 @@
<handler classname="org.apache.felix.ipojo.handlers.lifecycle.controller.ControllerHandler" name="controller" architecture="false"/>
<handler classname="org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler" name="callback" level="1" architecture="false"/>
<handler classname="org.apache.felix.ipojo.handlers.dependency.DependencyHandler" name="requires" level="0" architecture="false">
- <controller field="m_state"/>
+ <!-- <controller field="m_state"/> -->
</handler>
<handler classname="org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler" name="provides" level="3" architecture="false"/>
<handler classname="org.apache.felix.ipojo.handlers.configuration.ConfigurationHandler" name="properties" level="1" architecture="false"/>
<handler classname="org.apache.felix.ipojo.handlers.architecture.ArchitectureHandler" name="architecture" architecture="false">
- <provides>
- <property field="m_name" name="instance.name" value=""/>
- </provides>
-</handler>
-
-<!-- Composite Handler -->
-<handler classname="org.apache.felix.ipojo.composite.instance.InstanceHandler" name="instance" type="composite" architecture="false">
- <controller field="m_isValid"/>
- <requires filter="(&(factory.state=1)(factory.name=*))" field="m_factories" optional="true" architecture="false">
- <callback type="bind" method="bindFactory"/>
- <callback type="unbind" method="unbindFactory"/>
- </requires>
-</handler>
-<handler classname="org.apache.felix.ipojo.composite.service.importer.ImportHandler" name="requires" type="composite" architecture="false">
- <controller field="m_valid"/>
-</handler>
-<handler classname="org.apache.felix.ipojo.composite.service.importer.ExportHandler" name="exports" type="composite" architecture="false">
- <controller field="m_valid"/>
-</handler>
-<handler classname="org.apache.felix.ipojo.composite.service.instantiator.ServiceInstantiatorHandler" name="service" type="composite" architecture="false">
- <controller field="m_isValid"/>
-</handler>
-<handler classname="org.apache.felix.ipojo.composite.service.provides.ProvidedServiceHandler" name="provides" type="composite" architecture="false">
- <controller field="m_valid"/>
-</handler>
-<handler classname="org.apache.felix.ipojo.composite.architecture.ArchitectureHandler" name="architecture" type="composite" architecture="false">
<provides>
<property field="m_name" name="instance.name" value=""/>
</provides>
Modified: felix/sandbox/clement/ipojo/event.admin.handler/src/main/java/org/apache/felix/ipojo/handler/event/EventAdminSubscriberHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/event.admin.handler/src/main/java/org/apache/felix/ipojo/handler/event/EventAdminSubscriberHandler.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/event.admin.handler/src/main/java/org/apache/felix/ipojo/handler/event/EventAdminSubscriberHandler.java (original)
+++ felix/sandbox/clement/ipojo/event.admin.handler/src/main/java/org/apache/felix/ipojo/handler/event/EventAdminSubscriberHandler.java Fri Dec 21 11:28:07 2007
@@ -27,7 +27,7 @@
import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.InstanceManager;
import org.apache.felix.ipojo.PrimitiveHandler;
-import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
import org.apache.felix.ipojo.architecture.PropertyDescription;
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.ManipulationMetadata;
@@ -70,7 +70,7 @@
* @throws ConfigurationException : metadata are incorrect.
* @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentDescription, org.apache.felix.ipojo.metadata.Element)
*/
- public void initializeComponentFactory(ComponentDescription cd, Element metadata) throws ConfigurationException {
+ public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) throws ConfigurationException {
// Update the current component description
Dictionary dict = new Properties();
cd.addProperty(new PropertyDescription("event.topics", Dictionary.class.getName(), dict.toString()));
Modified: felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java (original)
+++ felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java Fri Dec 21 11:28:07 2007
@@ -82,7 +82,7 @@
if (m_fields.contains(name) && m_owner.equals(owner)) {
if (opcode == GETFIELD) {
String gDesc = "()" + desc;
- visitMethodInsn(INVOKEVIRTUAL, owner, "__get" + name, gDesc);
+ visitMethodInsn(INVOKESPECIAL, owner, "__get" + name, gDesc);
return;
} else
if (opcode == PUTFIELD) {
@@ -117,7 +117,7 @@
//mv.visitVarInsn(ALOAD, Type.getArgumentTypes(m_constructorDesc).length);
mv.visitVarInsn(ALOAD, 1); // CM is always the first argument
// 3) Initialize the field
- mv.visitMethodInsn(INVOKESPECIAL, m_owner, "_setComponentManager", "(Lorg/apache/felix/ipojo/InstanceManager;)V");
+ mv.visitMethodInsn(INVOKESPECIAL, m_owner, "_setInstanceManager", "(Lorg/apache/felix/ipojo/InstanceManager;)V");
} else {
mv.visitMethodInsn(opcode, owner, name, desc);
Modified: felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java (original)
+++ felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java Fri Dec 21 11:28:07 2007
@@ -68,7 +68,7 @@
if (owner.equals(m_owner) && m_fields.contains(name)) {
if (opcode == GETFIELD) {
String gDesc = "()" + desc;
- visitMethodInsn(INVOKEVIRTUAL, owner, "__get" + name, gDesc);
+ visitMethodInsn(INVOKESPECIAL, owner, "__get" + name, gDesc);
return;
} else if (opcode == PUTFIELD) {
String sDesc = "(" + desc + ")V";
Modified: felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java (original)
+++ felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java Fri Dec 21 11:28:07 2007
@@ -69,22 +69,22 @@
if (args.length == 0) {
generateEmptyConstructor();
} else {
- generateBCConstructor(access, name, desc, signature, exceptions);
+ generateBCConstructor();
}
// Insert the new constructor
- MethodVisitor mv = super.visitMethod(access, "<init>", newDesc, signature, exceptions);
- return new ConstructorCodeAdapter(mv, m_owner, m_fields, access, name, newDesc);
+ MethodVisitor mv = super.visitMethod(ACC_PRIVATE, "<init>", newDesc, signature, exceptions);
+ return new ConstructorCodeAdapter(mv, m_owner, m_fields, ACC_PRIVATE, name, newDesc);
}
if ((access & ACC_STATIC) == ACC_STATIC) { return super.visitMethod(access, name, desc, signature, exceptions); }
- generateVoidMethod(access, name, desc, signature, exceptions);
+ generateMethodHeader(access, name, desc, signature, exceptions);
FieldVisitor flagField = cv.visitField(Opcodes.ACC_PRIVATE, generateMethodFlag(name, desc), "Z", null, null);
flagField.visitEnd();
- MethodVisitor mv = super.visitMethod(access, PREFIX + name, desc, signature, exceptions);
- return new MethodCodeAdapter(mv, m_owner, access, PREFIX + name, desc, m_fields);
+ MethodVisitor mv = super.visitMethod(ACC_PRIVATE, PREFIX + name, desc, signature, exceptions);
+ return new MethodCodeAdapter(mv, m_owner, ACC_PRIVATE, PREFIX + name, desc, m_fields);
}
/**
@@ -178,8 +178,8 @@
mv.visitEnd();
}
- private void generateBCConstructor(int access, String name, String desc, String signature, String[] exceptions) {
- MethodVisitor mv = cv.visitMethod(ACC_PUBLIC + ACC_STATIC, CONSTRUCTOR, "(Lorg/apache/felix/ipojo/InstanceManager;Lorg/osgi/framework/BundleContext;)Ljava/lang/Object;", signature, exceptions);
+ private void generateBCConstructor() {
+ MethodVisitor mv = cv.visitMethod(ACC_PUBLIC + ACC_STATIC, CONSTRUCTOR, "(Lorg/apache/felix/ipojo/InstanceManager;Lorg/osgi/framework/BundleContext;)Ljava/lang/Object;", null, null);
mv.visitCode();
Label l0 = new Label();
@@ -231,7 +231,7 @@
mv.visitEnd();
}
- private void generateVoidMethod(int access, String name, String desc, String signature, String[] exceptions) {
+ private void generateMethodHeader(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
mv.visitCode();
Type returnType = Type.getReturnType(desc);
@@ -243,7 +243,7 @@
result = args.length + 1;
exception = args.length + 2;
}
-
+
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
@@ -258,7 +258,7 @@
for(int i = 0; i < args.length; i++) {
mv.visitVarInsn(args[i].getOpcode(ILOAD), i+1);
}
- mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, PREFIX+name, desc);
+ mv.visitMethodInsn(INVOKESPECIAL, m_owner, PREFIX+name, desc);
mv.visitInsn(returnType.getOpcode(IRETURN));
mv.visitLabel(l0);
@@ -273,7 +273,7 @@
for(int i = 0; i < args.length; i++) {
mv.visitVarInsn(args[i].getOpcode(ILOAD), i+1);
}
- mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, PREFIX+name, desc);
+ mv.visitMethodInsn(INVOKESPECIAL, m_owner, PREFIX+name, desc);
if(returnType.getSort() != Type.VOID) {
@@ -391,7 +391,7 @@
*/
public void visitEnd() {
// Create the component manager setter method
- createComponentManagerSetter();
+ createSetInstanceManagerMethod();
// Add the getComponentInstance
createGetComponentInstanceMethod();
@@ -404,8 +404,8 @@
/**
* Create the setter method for the __cm field.
*/
- private void createComponentManagerSetter() {
- MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_setComponentManager", "(Lorg/apache/felix/ipojo/InstanceManager;)V", null, null);
+ private void createSetInstanceManagerMethod() {
+ MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_setInstanceManager", "(Lorg/apache/felix/ipojo/InstanceManager;)V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
Modified: felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java (original)
+++ felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java Fri Dec 21 11:28:07 2007
@@ -422,7 +422,7 @@
private void setImports(Attributes att) {
Map imports = parseHeader(att.getValue("Import-Package"));
Map ver = new TreeMap();
- ver.put("version", "0.7.5");
+ ver.put("version", "0.7.6");
if (!imports.containsKey("org.apache.felix.ipojo")) {
imports.put("org.apache.felix.ipojo", ver);
}
Modified: felix/sandbox/clement/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java?rev=606280&r1=606279&r2=606280&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java (original)
+++ felix/sandbox/clement/ipojo/plugin/src/main/java/org/apache/felix/ipojo/plugin/ManipulatorMojo.java Fri Dec 21 11:28:07 2007
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -27,10 +27,11 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
/**
* Package an OSGi jar "bundle" as an "iPOJO bundle".
- *
+ *
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
* @version $Rev$, $Date$
* @goal ipojo-bundle
@@ -42,7 +43,7 @@
/**
* The directory for the generated JAR.
- *
+ *
* @parameter expression="${project.build.directory}"
* @required
*/
@@ -50,7 +51,7 @@
/**
* The directory containing generated classes.
- *
+ *
* @parameter expression="${project.build.outputDirectory}"
* @required
* @readonly
@@ -59,12 +60,12 @@
/**
* The name of the generated JAR file.
- *
+ *
* @parameter alias="jarName" expression="${project.build.finalName}"
* @required
*/
private String m_jarName;
-
+
/**
* Metadata file location.
* @parameter alias="metadata" default-value="metadata.xml"
@@ -72,6 +73,13 @@
private String m_metadata;
/**
+ * If set, the manipulated jar will be attached to the project as a separate artifact.
+ *
+ * @parameter alias="classifier" expression="${ipojo.classifier}"
+ */
+ private String m_classifier;
+
+ /**
* The Maven project.
*
* @parameter expression="${project}"
@@ -81,6 +89,13 @@
private MavenProject m_project;
/**
+ * Used for attaching new artifacts.
+ * @component
+ * @required
+ */
+ private MavenProjectHelper m_helper;
+
+ /**
* Project types which this plugin supports.
* @parameter
*/
@@ -111,7 +126,7 @@
getLog().info("Start bundle manipulation");
// Get metadata file
- File meta = new File(m_outputDirectory + "/" + m_metadata);
+ File meta = new File(m_outputDirectory + File.separator + m_metadata);
getLog().info("Metadata File : " + meta.getAbsolutePath());
if (!meta.exists()) {
// Verify if annotations are ignored
@@ -125,14 +140,14 @@
}
// Get input bundle
- File in = new File(m_buildDirectory + "/" + m_jarName + ".jar");
+ File in = new File(m_buildDirectory + File.separator + m_jarName + ".jar");
getLog().info("Input Bundle File : " + in.getAbsolutePath());
if (!in.exists()) {
throw new MojoExecutionException("the specified bundle file does not exists");
}
-
- File out = new File(m_buildDirectory + "/_out.jar");
-
+
+ File out = new File(m_buildDirectory + File.separator + "_out.jar");
+
Pojoization pojo = new Pojoization();
if (!m_ignoreAnnotations) { pojo.setAnnotationProcessing(); }
pojo.pojoization(in, out, meta);
@@ -140,8 +155,16 @@
getLog().warn((String) pojo.getWarnings().get(i));
}
if (pojo.getErrors().size() > 0) { throw new MojoExecutionException((String) pojo.getErrors().get(0)); }
- in.delete();
- out.renameTo(in);
+
+ if (m_classifier != null) {
+ // The user want to attach the resulting jar
+ // Do not delete in File
+ m_helper.attachArtifact(m_project, "jar", m_classifier, out);
+ } else {
+ // Usual behavior
+ in.delete();
+ out.renameTo(in);
+ }
getLog().info("Bundle manipulation - SUCCESS");
}