You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Didier Donsez <di...@imag.fr> on 2006/08/10 13:06:39 UTC

Bug in org.apache.felix.scr + addendum for the elements

Humberto

There is a bug in org.apache.felix.scr
when the component descriptor contains <property> elements

java.lang.ClassCastException: java.lang.String
         at
org.apache.felix.scr.ComponentMetadata.validate(ComponentMetadata.java:254)
         at org.apache.felix.scr.XmlHandler.endElement(XmlHandler.java:175)
         at
org.apache.felix.scr.parser.KXml2SAXParser.parseXML(KXml2SAXParser.java:72)
         at
org.apache.felix.scr.GenericActivator.initialize(GenericActivator.java:148)
         at
org.apache.felix.scr.GenericActivator.start(GenericActivator.java:99)

         at org.apache.felix.framework.Felix._startBundle(Felix.java:1349)
         at org.apache.felix.framework.Felix.startBundle(Felix.java:1283)
         at
org.apache.felix.framework.Felix.setFrameworkStartLevel(Felix.java:765)
         at
org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:206)
         at java.lang.Thread.run(Thread.java:595)

I put the related code section  in comments

--

Moreover, I completed  the current Felix SCR implementation to take into
account <properties> elements.

The modified files are in attachement and the modified source sections
are bracketed by // CHANGED lines

Could you commit those changes (since I'm not a commiter) ? and may be
keep the track in JIRA

Best regards

Didier

-- 
---------------------------------------------------------
Didier DONSEZ
Laboratoire LSR, Institut Imag, Universite Joseph Fourier
Bat. C, 220 rue de la Chimie, Domaine Universitaire
BP 53, 38041 Grenoble Cedex 9, France
GPS : lat 45°11'38.3"N, lon 05°46'14.7"E, alt 223m
http://www-adele.imag.fr/users/Didier.Donsez/map/map.html
Tel : +33 4 76 63 55 49           Fax : +33 4 76 63 55 50
mailto:Didier.Donsez@imag.fr
URL: http://www-adele.imag.fr/users/Didier.Donsez
---------------------------------------------------------



Re: Bug in org.apache.felix.scr + addendum for the elements

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Didier,

Could you create a JIRA issue for SCR on this issue?

-> richard

Didier Donsez wrote:
> Humberto
>
> There is a bug in org.apache.felix.scr
> when the component descriptor contains <property> elements
>
> java.lang.ClassCastException: java.lang.String
>         at
> org.apache.felix.scr.ComponentMetadata.validate(ComponentMetadata.java:254) 
>
>         at 
> org.apache.felix.scr.XmlHandler.endElement(XmlHandler.java:175)
>         at
> org.apache.felix.scr.parser.KXml2SAXParser.parseXML(KXml2SAXParser.java:72) 
>
>         at
> org.apache.felix.scr.GenericActivator.initialize(GenericActivator.java:148) 
>
>         at
> org.apache.felix.scr.GenericActivator.start(GenericActivator.java:99)
>
>         at org.apache.felix.framework.Felix._startBundle(Felix.java:1349)
>         at org.apache.felix.framework.Felix.startBundle(Felix.java:1283)
>         at
> org.apache.felix.framework.Felix.setFrameworkStartLevel(Felix.java:765)
>         at
> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:206)
>         at java.lang.Thread.run(Thread.java:595)
>
> I put the related code section  in comments
>
> -- 
>
> Moreover, I completed  the current Felix SCR implementation to take into
> account <properties> elements.
>
> The modified files are in attachement and the modified source sections
> are bracketed by // CHANGED lines
>
> Could you commit those changes (since I'm not a commiter) ? and may be
> keep the track in JIRA
>
> Best regards
>
> Didier
>
> ------------------------------------------------------------------------
>
> /*
>  *   Copyright 2006 The Apache Software Foundation
>  *
>  *   Licensed 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.scr;
>
> import java.util.ArrayList;
> import java.util.HashSet;
> import java.util.Iterator;
> import java.util.List;
> import java.util.Set;
> import java.util.StringTokenizer;
>
> import java.io.InputStream;
>
> import org.apache.felix.scr.parser.KXml2SAXParser;
> import org.apache.felix.scr.parser.ParseException;
> import org.osgi.framework.BundleActivator;
> import org.osgi.framework.BundleContext;
> import org.osgi.framework.Bundle;
> import org.osgi.service.component.ComponentException;
>
> import java.io.BufferedReader;
> import java.io.FileNotFoundException;
> import java.io.IOException;
> import java.io.InputStreamReader;
>
> /**
>  * The GenericActivator is the main startup class. It will read information from the metadata.xml file
>  * descriptors and create the corresponding managers.
>  *
>  */
> public class GenericActivator implements BundleActivator
> {	
> 	// The bundle context
>     private BundleContext m_context = null;
>     
>     // This is a list of component instance managers that belong to a particular bundle
>     private List m_managers = new ArrayList();
>
>     // Flag that sets tracing messages
>     private static boolean m_trace = true;
>     
>     // Flag that sets error messages
>     private static boolean m_error = true;
>
>     // A string containing the version number
>     private static String m_version = "1.0.0 (12012006)";
>
>     // Registry of component names
>     static Set m_componentNames = new HashSet();
>
>     // Static initializations based on system properties
>     static {
>         // Get system properties to see if traces or errors need to be displayed
>         String result = System.getProperty("ds.showtrace");
>         if(result != null && result.equals("true"))
>         {
>             m_trace = true;
>         }
>         result = System.getProperty("ds.showerrors");
>         if(result != null && result.equals("false"))
>         {
>             m_error = false;
>         }
>         result = System.getProperty("ds.showversion");
>         if(result != null && result.equals("true"))
>         {
>             System.out.println("[ Version = "+m_version+" ]\n");
>         }        
>     }
>
>     /**
>     * Called upon starting of the bundle. This method invokes initialize() which
>     * parses the metadata and creates the instance managers
>     *
>     * @param   context  The bundle context passed by the framework
>     * @exception   Exception any exception thrown from initialize
>     */
>     public void start(BundleContext context) throws Exception
>     {
>     	// Stores the context
>         m_context = context;
>         
>         try
>         {
>             initialize();
>         }
>         catch (Exception e)
>         {
>             GenericActivator.error("GenericActivator : in bundle ["
>                 + context.getBundle().getBundleId() + "] : " + e);
>             e.printStackTrace();
>             throw e;
>         }
>     }
>
>     /**
>     * Gets the MetaData location, parses the meta data and requests the processing
>     * of binder instances
>     *
>     * @throws FileNotFoundException if the metadata file is not found
>     * @throws ParseException if the metadata file is not found
>     */
>     private void initialize() throws ParseException {
>         // Get the Metadata-Location value from the manifest
>         String descriptorLocations = (String) m_context.getBundle().getHeaders().get("Service-Component");
>
>         if (descriptorLocations == null)
>         {
>             throw new ComponentException("Service-Component entry not found in the manifest");
>         }
>
>         // 112.4.1: The value of the the header is a comma separated list of XML entries within the Bundle 
> 		StringTokenizer st = new StringTokenizer(descriptorLocations, ", ");
>         
> 		while (st.hasMoreTokens()) {
> 			String descriptorLocation = st.nextToken();
> 			
> 			try {
> 				// CHANGED (BEGIN)
> 				java.net.URL url = m_context.getBundle().getResource(descriptorLocation);
> 				if (url == null)
> 				{
> 				    throw new ComponentException(descriptorLocation+" is not a valid resource");
> 				}
> 				
> 				InputStream stream = url.openStream();
>
> 				BufferedReader in = new BufferedReader(new InputStreamReader(stream)); 
> 				XmlHandler handler = new XmlHandler(m_context); 
> 				// CHANGED (END)
> 	            KXml2SAXParser parser;
>
> 	            parser = new KXml2SAXParser(in); 
>
> 		        parser.parseXML(handler);
>
> 		        // 112.4.2 Component descriptors may contain a single, root component element
> 		        // or one or more component elements embedded in a larger document
> 		        Iterator i = handler.getComponentMetadataList().iterator();
> 		        while (i.hasNext()) {
>                 	try {
>     		            ComponentMetadata metadata = (ComponentMetadata) i.next();
>     		            
>     		            validate(metadata);
>     		        	
>     	                // Request creation of the component manager
>     	                ComponentManager manager = ManagerFactory.createManager(this,metadata);
>                 		
>                 		if(metadata.isFactory()) {
>                 			// 112.2.4 SCR must register a Component Factory service on behalf ot the component
>                 			// as soon as the component factory is satisfied
>                 		}
>                 		else if(metadata.isEnabled()) {
> 		                	// enable the component
> 		                	manager.enable();
> 		                	m_managers.add(manager);
> 		                }
> 	                } catch (Exception e) {
> 						// There is a problem with this particular component, we'll log the error
> 	                	// and proceed to the next one
> 	                	// TODO: log the error
> 						e.printStackTrace();
> 					} 
> 		        }
> 		        
> 		        stream.close();
>
> 			}
> 			catch ( IOException ex ) {
> 				// 112.4.1 If an XML document specified by the header cannot be located in the bundle and its attached
> 				// fragments, SCR must log an error message with the Log Service, if present, and continue.
> 				
> 				error("Component descriptor entry '" + descriptorLocation	+ "' not found");
> 			}
> 			catch (Exception ex) {
> 				ex.printStackTrace();
> 			}
> 		}
>     }
>
>     /**
>     * Stop method that destroys all the instance managers
>     *
>     * @param   context The Bundle Context passed by the framework
>     * @exception Exception any exception thrown during destruction of the instance managers
>     */
>     public void stop(BundleContext context) throws java.lang.Exception
>     {
>         //GenericActivator.trace("GenericActivator : Bundle ["+context.getBundle().getBundleId()+"] will destroy "+m_managers.size()+" instances");
>
>         while (m_managers.size() !=0 )
>         {
>             ComponentManager manager = (ComponentManager)m_managers.get(0);
>             try {
>                 manager.dispose();
>                 m_managers.remove(manager);
>             }
>             catch(Exception e) {
>                 GenericActivator.error("GenericActivator : Exception during invalidate : "+e);
>                 e.printStackTrace();
>             }
>             finally {
>             	m_componentNames.remove(manager.getComponentMetadata().getName());
>             }
>             
>         }
>
>         m_context = null;
>
>         //GenericActivator.trace("GenericActivator : Bundle ["+context.getBundle().getBundleId()+"] STOPPED");
>     }
>
>     /**
>     * Returns the list of instance references currently associated to this activator
>     *
>     * @return the list of instance references
>     */
>     protected List getInstanceReferences()
>     {
>         return m_managers;
>     }
>
>     /**
>     * Returns the BundleContext
>     *
>     * @return the BundleContext
>     */
>     protected BundleContext getBundleContext()
>     {
>         return m_context;
>     }
>
>     /**
>      * Method to display traces
>      *
>      * @param message a string to be displayed
>      * @param metadata ComponentMetadata associated to the message (can be null)
>     **/
>     static void trace(String message, ComponentMetadata metadata)
>     {
>         if(m_trace)
>         {
>             System.out.print("--- ");
>             if(metadata != null) {
>             	System.out.print("[");
>             	System.out.print(metadata.getName());
>             	System.out.print("] ");
>             	System.out.println(message);
>             }
>         }
>     }
>
>     /**
>      * Method to display errors
>      *
>      * @param s a string to be displayed
>     **/
>     static void error(String s) {
>         if(m_error) {
>             System.err.println("### "+s);
>         }
>     }
>
>     /**
>      * Method to display exceptions
>      *
>      * @param ex an exception
>     **/   
>     static void exception(String message, ComponentMetadata metadata, Throwable ex) {
>     	 if(m_error) {
>     		 System.out.println("--- Exception in component "+metadata.getName()+" : "+message+" ---");
>              ex.printStackTrace();
>          }   	
>     }
>
>     /**
>      * This method is used to validate that the component. This method verifies multiple things:
>      * 
>      * 1.- That the name attribute is set and is globally unique
>      * 2.- That an implementation class name has been set 
>      * 3.- That a delayed component provides a service and is not specified to be a factory
>      * - That the serviceFactory attribute for the provided service is not true if the component is a factory or immediate
>      * 
>      * If the component is valid, its name is registered
>      * 
>      * @throws A ComponentException if something is not right
>      */
>     void validate(ComponentMetadata component) throws ComponentException {
>
>     	if(m_componentNames.contains(component.getName()))
>     	{
>     		throw new ComponentException("The component name '"+component.getName()+"' has already been registered.");
>     	}
>     	
>     	m_componentNames.add(component.getName());
>     
>     	component.validate(m_context);
> 	
>     	
>     	trace("Validated and registered component",component);
>     }
> }
>
>   
> ------------------------------------------------------------------------
>
> /*
>  *   Copyright 2006 The Apache Software Foundation
>  *
>  *   Licensed 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.scr;
>
> import org.osgi.service.component.ComponentException;
>
> /**
>  * A properties descriptor that contains the information for properties
>  * defined in the descriptor
>  *
>  */
> public class PropertiesMetadata {
> 		
> 	// Value of the entry
> 	private String m_entry;
> 	
> 	// Flag that indicates if this PropertiesMetadata has been validated and thus has become immutable
> 	private boolean m_validated = false;
>
> 	/**
> 	 * Set the entry
> 	 * 
> 	 * @param entry
> 	 */
> 	public void setEntry(String entry) {
> 		if (m_validated == true) {
> 			return;
> 		}
> 		m_entry = entry;
> 	}
> 		
>     /**
>      * Get the entry of the properties element
>      * 
>      * @return the name of the properties element
>      */
>     public String getEntry() {
>         return m_entry;
>     }
>
>     /**
>      * Method used to verify if the semantics of this metadata are correct
>      */
>     public void validate(){
>     	if(m_entry == null)
>     	{
>     		throw new ComponentException("Properties entry attribute is mandatory");
>     	}
>     }
> }
>
>   
> ------------------------------------------------------------------------
>
> /*
>  *   Copyright 2006 The Apache Software Foundation
>  *
>  *   Licensed 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.scr;
>
> import org.osgi.framework.BundleContext;
>
>
> import java.util.Properties;
> import java.util.ArrayList;
> import java.util.List;
>
> import org.apache.felix.scr.parser.KXml2SAXHandler;
> import org.apache.felix.scr.parser.ParseException;
>
> /**
>  * 
>  * 
>  */
> public class XmlHandler implements KXml2SAXHandler {
>
> // CHANGED (BEGIN)
> 	public XmlHandler(BundleContext context){
> 		this.m_context=context;
> 	}
> 	
> 	private BundleContext m_context;
> // CHANGED (END)
> 	
>     // A reference to the current component
>     private ComponentMetadata m_currentComponent = null;
>
>     // The current service
>     private ServiceMetadata m_currentService = null;
>     
>     // A list of component descriptors contained in the file
>     private List m_components = new ArrayList();
>
>     /**
>      * Method called when a tag opens
>      *
>      * @param   uri
>      * @param   localName
>      * @param   qName
>      * @param   attrib
>      * @exception   ParseException
>     **/
>     public void startElement(String uri,String localName,String qName,Properties attrib) throws ParseException
>     {
>     	try {
>     		
> 	    	// 112.4.3 Component Element
> 	        if (qName.equals("component")) {
>
> 	        	// Create a new ComponentMetadata
> 	        	m_currentComponent = new ComponentMetadata();
>
> 	        	// name attribute is mandatory
> 	        	m_currentComponent.setName(attrib.getProperty("name"));
> 	        	
> 	        	// enabled attribute is optional
> 	        	if(attrib.getProperty("enabled") != null) {
> 	        		m_currentComponent.setEnabled(attrib.getProperty("enabled").equals("true"));
> 	        	}
>
> 	        	// immediate attribute is optional
> 	        	if(attrib.getProperty("immediate") != null) {
> 	        		m_currentComponent.setImmediate(attrib.getProperty("immediate").equals("true"));
> 	        	}
> 	        	
> 	        	// factory attribute is optional
> 	        	if(attrib.getProperty("factory") != null) {
> 	        		m_currentComponent.setFactoryIdentifier(attrib.getProperty("factory"));
> 	        	}
> 		        	
> 	        	// Add this component to the list
> 	            m_components.add(m_currentComponent);
> 	        }
> 	        
> 	        // 112.4.4 Implementation
> 	        else if (qName.equals("implementation"))
> 	        {
> 	        	// Set the implementation class name (mandatory)
> 	        	m_currentComponent.setImplementationClassName(attrib.getProperty("class"));
> 	        }
> 	        // 112.4.5 Properties and Property Elements
> 	        else if (qName.equals("property")) {
> 	        	// 112.4.5: If the value attribute is specified, the body of the element is ignored.
> 	        	if( attrib.getProperty("value") != null) {
> 	        		PropertyMetadata prop = new PropertyMetadata();
> 	        		
> 	        		// name attribute is mandatory
> 	        		prop.setName(attrib.getProperty("name"));
> 	        		
> 	        		// type attribute is optional
> 	        		if(attrib.getProperty("type") != null) {
> 	        			prop.setType(attrib.getProperty("type"));
> 	        		}
> 	        		
> 	        		// value attribute is optional
> 	        		if(attrib.getProperty("value") != null) {
> 	        			prop.setValue(attrib.getProperty("value"));
> 	        		}
> 	            	m_currentComponent.addProperty(prop);
> 	        	}
> 	        	else {
> 	        		// TODO: treat the case where property value is not specified (p. 291)
> 	        	}
> 	        	// TODO: treat the case where a properties file name is provided (p. 292)
> 	        }
> // CHANGED (BEGIN)
> 	        else if(qName.equals("properties")) {
> 			PropertiesMetadata props = new PropertiesMetadata();
> 	        		
> 	        	// entry attribute is mandatory
> 	        	props.setEntry(attrib.getProperty("entry"));
> 	            	m_currentComponent.addProperties(props);
> 	        }
> // CHANGED (END)
> 	        // 112.4.6 Service Element
> 	        else if (qName.equals("service")) {
> 	        	
> 	        	m_currentService = new ServiceMetadata();
> 	        	
> 	        	// servicefactory attribute is optional
> 	        	if(attrib.getProperty("servicefactory") != null) {
> 	        		m_currentService.setServiceFactory(attrib.getProperty("servicefactory").equals("true"));
> 	        	}      	
> 	        	
> 	            m_currentComponent.setService(m_currentService);
> 	        }
> 	        else if (qName.equals("provide")) {
> 	            m_currentService.addProvide(attrib.getProperty("interface"));
> 	        }
> 	        
> 	        // 112.4.7 Reference element
> 	        else if (qName.equals("reference")) {
> 	            ReferenceMetadata ref=new ReferenceMetadata ();
> 	            ref.setName(attrib.getProperty("name"));
> 	            ref.setInterface(attrib.getProperty("interface"));
> 	            
> 	            // Cardinality 
> 	            if(attrib.getProperty("cardinality")!= null) {
> 	            	ref.setCardinality(attrib.getProperty("cardinality"));
> 	            }
> 	            
> 	            if(attrib.getProperty("policy") != null) {
> 	            	ref.setPolicy(attrib.getProperty("policy"));
> 	            }
> 	            
> 	            //if
> 	            ref.setTarget(attrib.getProperty("target"));
> 	            ref.setBind(attrib.getProperty("bind"));
> 	            ref.setUnbind(attrib.getProperty("unbind"));
> 	
> 	            m_currentComponent.addDependency(ref);
> 	        }
>     	}
>     	catch(Exception ex) {
>     		ex.printStackTrace();
>     		throw new ParseException("Exception during parsing",ex);
>     	}
>     }
>
>     /**
>     * Method called when a tag closes
>     *
>     * @param   uri
>     * @param   localName
>     * @param   qName
>     * @exception   ParseException
>     */
>     public void endElement(java.lang.String uri,java.lang.String localName,java.lang.String qName) throws ParseException
>     {
>         if (qName.equals("component"))
>         {
>         	// When the closing tag for a component is found, the component is validated to check if 
>         	// the implementation class has been set
> // CHANGED (BEGIN)
> 		try {
> 			m_currentComponent.validate(m_context);
> 		} catch(Exception ex) {
> 			ex.printStackTrace();
> 			throw new ParseException("Exception during validation",ex);
> 		}
> // CHANGED (END)
>         }
>     }
>
>     /**
>     * Called to retrieve the service descriptors
>     *
>     * @return   A list of service descriptors
>     */
>     List getComponentMetadataList()
>     {
>         return m_components;
>     }
>
> 	public void characters(char[] ch, int offset, int length) throws Exception {
> 		// Not used
> 		
> 	}
>
> 	public void processingInstruction(String target, String data) throws Exception {
> 		// Not used
> 		
> 	}
>
> 	public void setLineNumber(int lineNumber) {
> 		// Not used
> 		
> 	}
>
> 	public void setColumnNumber(int columnNumber) {
> 		// Not used
> 		
> 	}
> }
>
>
>   
> ------------------------------------------------------------------------
>
> /*
>  *   Copyright 2006 The Apache Software Foundation
>  *
>  *   Licensed 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.scr;
>
> import java.util.Iterator;
> import java.util.Properties;
> import java.util.List;
> import java.util.ArrayList;
>
> import org.osgi.service.component.ComponentException;
>
> /**
>  * This class holds the information associated to a component in the descriptor
>  * 
>  */
> public class ComponentMetadata {
> 	// 112.4.3: A Globally unique component name (required)
> 	private String m_name;
> 	
> 	// 112.4.3: Controls whether the component is enabled when the bundle is started. (optional, default is true).
> 	private boolean m_enabled = true;
> 	
> 	// 112.4.3: Factory identified. If set to a non empty string, it indicates that the component is a factory component (optional).
> 	private String m_factory = null;
> 	
> 	// 112.4.3: Controls whether component configurations must be immediately activated after becoming 
> 	// satisfied or whether activation should be delayed. (optional, default value is false).
> 	private boolean m_immediate = false;
> 	
>     // 112.4.4 Implementation Element (required)
>     private String m_implementationClassName = null;
>     
>     // Associated properties (0..*)
>     private Properties m_properties = new Properties();
>     
>     // Associated properties entries (0..*)
>     private List/*<String>*/ m_propertiesEntries = new ArrayList();
>     
>     // Provided services (0..1)
>     private ServiceMetadata m_service = null;
>     
>     // List of service references, (required services 0..*)
>     private List m_references = new ArrayList();
>     
>     // Flag that is set once the component is verified (its properties cannot be changed)
>     private boolean m_validated = false;
>         
>        
>     /////////////////////////////////////////// SETTERS //////////////////////////////////////
>     
>     /**
>      * Setter for the name
>      * 
>      * @param name
>      */
>     public void setName(String name) {
>     	if(m_validated) {
>     		return;
>     	}
>     	m_name = name;
>     }
>     
>     /**
>      * Setter for the enabled property
>      * 
>      * @param enabled
>      */
>     public void setEnabled(boolean enabled) {
>     	if(m_validated) {
>     		return;
>     	}
>     	m_enabled = enabled;
>     }
>     
>     /**
>      * 
>      * @param factoryIdentifier
>      */
>     public void setFactoryIdentifier(String factoryIdentifier) {
>     	if(m_validated) {
>     		return;
>     	}
>     	m_factory = factoryIdentifier;
>     }
>     
>     /**
>      * Setter for the immediate property
>      * 
>      * @param immediate
>      */
>     public void setImmediate(boolean immediate) {
>     	if(m_validated) {
>     		return;
>     	}
>     	m_immediate = immediate;
>     }   
>     
>     /**
>      * Sets the name of the implementation class
>      * 
>      * @param implementationClassName a class name
>      */
>     public void setImplementationClassName(String implementationClassName) {
>     	if(m_validated) {
>     		return;
>     	}
>         m_implementationClassName = implementationClassName;
>     }
>
>     /**
>      * Used to add a property to the instance
>      *
>      * @param newProperty a property metadata object
>      */
>     public void addProperty(PropertyMetadata newProperty) {
>     	if(m_validated) {
>     		return;
>     	}
>     	if(newProperty == null) {
>     		throw new IllegalArgumentException ("Cannot add a null property");
>     	}
>         String key = newProperty.getName();
>         Object value = newProperty.getValue();
>         m_properties.put(key,value);
>     }
>
>     /**
>      * Used to add a properties to the instance
>      *
>      * @param newProperties a properties metadata object
>      */
>     public void addProperties(PropertiesMetadata newProperties) {
>     	if(m_validated) {
>     		return;
>     	}
>     	if(newProperties == null) {
>     		throw new IllegalArgumentException ("Cannot add a null properties");
>     	}
> 	
>         m_propertiesEntries.add(newProperties.getEntry());
>     }
>
>     
>     /**
>      * Used to set a ServiceMetadata object.
>      *
>      * @param service a ServiceMetadata
>      */
>     public void setService(ServiceMetadata service) {
>     	if(m_validated) {
>     		return;
>     	}
>         m_service = service;
>     }
>
>     /**
>      * Used to add a reference metadata to the component
>      *
>      * @param newReference a new ReferenceMetadata to be added
>      */
>     public void addDependency(ReferenceMetadata newReference) {
>     	if(newReference == null) {
>     		throw new IllegalArgumentException ("Cannot add a null ReferenceMetadata");
>     	}
>         m_references.add(newReference);
>     }
>
>     
>     /////////////////////////////////////////// GETTERS //////////////////////////////////////
>     
>     /**
>      * Returns the name of the component
>      * 
>      * @return A string containing the name of the component 
>      */
>     public String getName() {
>     	return m_name;
>     }
>     
>     /**
>      * Returns the value of the enabled flag 
>      * 
>      * @return a boolean containing the value of the enabled flag
>      */
>     public boolean isEnabled() {
>     	return m_enabled;
>     }
>
>     /**
>      * Returns the factory identifier
>      * 
>      * @return A string containing a factory identifier or null
>      */
>     public String getFactoryIdentifier() {
>     	return m_factory;
>     }
>     
>     /**
>      * Returns the flag that defines the activation policy for the component
>      * 
>      * @return a boolean that defines the activation policy
>      */
>     public boolean isImmediate() {
>     	return m_immediate;
>     }
>     
>     /**
>      * Returns the name of the implementation class
>      *
>      * @return the name of the implementation class
>      */
>     public String getImplementationClassName() {
>         return m_implementationClassName;
>     }
>
>     /**
>      * Returns the associated ServiceMetadata
>      * 
>      * @return a ServiceMetadata object or null if the Component does not provide any service
>      */
>     public ServiceMetadata getServiceMetadata() {
>     	return m_service;
>     }
>
>     /**
>      * Returns the property descriptors
>      *
>      * @return the property descriptors as a Collection
>      */
>     public Properties getProperties() {
>         return m_properties;
>     }
>
>     /**
>      * Returns the dependency descriptors
>      *
>      * @return a Collection of dependency descriptors
>      */
>     public List getDependencies() {
>         return m_references;
>     }
>
>     /**
>      * Test to see if this service is a factory
>      *
>      * @return true if it is a factory, false otherwise
>      */
>     public boolean isFactory() {
>         return m_factory != null;
>     }
>     
>     /**
>      * Method used to verify if the semantics of this metadata are correct
>      */
> // CHANGED (BEGIN)
>      void validate(org.osgi.framework.BundleContext bundleContext) throws ComponentException {
>
>     	
>     	// First check if the properties are valid
> /*    	Iterator propertyIterator = m_properties.keySet().iterator();
>     	while ( propertyIterator.hasNext() ) {
>     		((PropertyMetadata)propertyIterator.next()).validate();
>     	}
> */
> // CHANGED (END)
>
> // CHANGED (BEGIN)
> 	// Check the properties entries : load them and their content to the properties
>     	try {
> 		Iterator propertiesIterator = m_propertiesEntries.iterator();
> 		while ( propertiesIterator.hasNext() ) {
> 			String entryLocation=(String)propertiesIterator.next();
> 			
> 			java.net.URL url = bundleContext.getBundle().getResource(entryLocation);
> 			if (url == null)
> 			{
> 			    throw new ComponentException(entryLocation+" is not a valid properties entry");
> 			}
> 			
> 			java.io.InputStream stream = url.openStream();
> 			
> 			java.util.Properties properties=new java.util.Properties();
> 			properties.load(stream);
> 			stream.close();
> 			
> 			m_properties.putAll(properties);	
> 		}
>     	} catch(Exception ex) {
> 		if(ex instanceof ComponentException)
> 			throw (ComponentException)ex;
> 		else
> 			throw new ComponentException(ex.getMessage());
> 	}
> 	// CHANGED (END)
>
>
> 	// Check that the provided services are valid too
>     	if(m_service != null) {
>     		m_service.validate();
>     	}
>     	
>     	// Check that the references are ok
>     	Iterator referenceIterator = m_references.iterator();
>     	while ( referenceIterator.hasNext() ) {
>     		((ReferenceMetadata)referenceIterator.next()).validate();
>     	}
>     	    	
>     	// 112.10 The name of the component is required
>     	if( m_name == null ) {
>     		throw new ComponentException("The component name has not been set");
>     	}
>     	
>     	// 112.10 There must be one implementation element and the class atribute is required
>     	if ( m_implementationClassName == null ) {
>     		throw new ComponentException("The implementation class name has not been set for this component");
>     	}
>     	
>     	// 112.2.3 A delayed component specifies a service, is not specified to be a factory component
>     	// and does not have the immediate attribute of the component element set to true.
>     	if(m_immediate == false && m_service == null) {
>     		throw new ComponentException("Component '"+m_name+"' is specified as being delayed but does not provide any service.");
>     	}    	
>     	
>     	if ( m_factory != null && m_immediate == false) {
>     		throw new ComponentException("A factory cannot be a delayed component");
>     	}
>     	
>     	// TODO: 112.4.6 The serviceFactory attribute (of a provided service) must not be true if 
>     	// the component is a factory component or an immediate component
>
>     	
>     	m_validated = true;
>     	// TODO: put a similar flag on the references and the services
>     }
>
> }
>
>
>
>