You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by hu...@apache.org on 2006/04/21 18:34:43 UTC

svn commit: r395940 [2/2] - in /incubator/felix/trunk: ./ org.apache.felix.scr/ org.apache.felix.scr/src/ org.apache.felix.scr/src/main/ org.apache.felix.scr/src/main/java/ org.apache.felix.scr/src/main/java/org/ org.apache.felix.scr/src/main/java/org/...

Added: incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/ReferenceMetadata.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/ReferenceMetadata.java?rev=395940&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/ReferenceMetadata.java (added)
+++ incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/ReferenceMetadata.java Fri Apr 21 09:34:36 2006
@@ -0,0 +1,285 @@
+/*
+ *   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;
+
+/**
+ * Information associated to a dependency
+ *
+ */
+public class ReferenceMetadata {
+	// Name for the reference (required)
+	private String m_name = null;
+	
+	// Interface name (required)
+    private String m_interface = null;
+    
+    // Cardinality (optional, default="1..1")
+    private String m_cardinality = "1..1";
+    
+    // Target (optional)
+    private String m_target;
+    
+    // Name of the bind method (optional)
+    private String m_bind = null;
+    
+    // Name of the unbind method (optional)
+    private String m_unbind = null;
+    
+    // Policy attribute (optional, default = static)
+    private String m_policy = "static";
+
+    // Flag that is set once the component is verified (its properties cannot be changed)
+    private boolean m_validated = false;
+    
+    // Flags that store the values passed as strings
+    private boolean m_isStatic = true;
+    private boolean m_isOptional = false;
+    private boolean m_isMultiple = false;
+
+    /////////////////////////////////////////////// setters ///////////////////////////////////
+    
+    /**
+     * Setter for the name attribute
+     * 
+     * @param name
+     */
+    public void setName(String name) {
+    	if(m_validated) {
+    		return;
+    	}
+    		
+    	m_name = name;
+    }
+    
+    /**
+     * Setter for the interfaceName attribute
+     * 
+     * @param interfaceName
+     */
+    public void setInterface(String interfaceName) {
+    	if(m_validated) {
+    		return;
+    	}
+    		
+    	m_interface = interfaceName;
+    	
+    }
+    
+    /**
+     * Setter for the cardinality attribute
+     * 
+     * @param cardinality
+     */
+    public void setCardinality(String cardinality) {
+    	if(m_validated) {
+    		return;
+    	}
+    		  	
+    	if(!m_cardinality.equals("0..1") && !m_cardinality.equals("0..n") && !m_cardinality.equals("1..1") && !m_cardinality.equals("1..n")) {
+    		throw new IllegalArgumentException ("Cardinality should take one of the following values: 0..1, 0..n, 1..1, 1..n");
+    	}    	
+    	if(m_cardinality.equals("0..1") || m_cardinality.equals("0..n")) {
+            m_isOptional = true;
+        }
+        if(m_cardinality.equals("0..n") || m_cardinality.equals("1..n")) {
+            m_isMultiple = true;
+        }
+    
+    	m_cardinality = cardinality;
+    }
+    
+    /** 
+     *	Setter for the policy attribute
+     *
+     * @param policy
+     */
+    public void setPolicy(String policy) {
+    	if(m_validated) {
+    		return;
+    	}
+    		
+    	if(!m_policy.equals("static") && !m_policy.equals("dynamic")) {
+    		throw new IllegalArgumentException ("Policy must be either 'static' or 'dynamic'");
+    	}    	
+    	if(policy.equals("static") == false) {
+            m_isStatic = false;
+        }
+
+       	m_policy = policy;
+    }
+    
+    /**
+     * Setter for the target attribute (filter)
+     * 
+     * @param target
+     */
+    public void setTarget(String target) {
+    	if(m_validated) {
+    		return;
+    	}
+    		
+    	//TODO: check if we really need to extend the filter to limit seaches to a particular interface
+        String classnamefilter = "(objectClass="+m_interface+")";
+        if(target != null) {
+            m_target = "(&"+classnamefilter+target+")";
+        }
+        else {
+            m_target = classnamefilter;
+        }    	
+    }
+    
+    /**
+     * Setter for the bind method attribute
+     * 
+     * @param bind
+     */    
+    public void setBind(String bind) {
+    	if(m_validated) {
+    		return;
+    	}
+    		
+    	m_bind = bind;
+    }
+    
+    /**
+     * Setter for the unbind method attribute
+     * 
+     * @param bind
+     */    
+    public void setUnbind(String unbind) {
+    	if(m_validated) {
+    		return;
+    	}
+    		
+    	m_unbind = unbind;
+    }
+    
+    
+    /////////////////////////////////////////////// getters ///////////////////////////////////
+
+    /**
+     * Returns the name of the reference
+     *
+     * @return A string containing the reference's name
+    **/
+    public String getName() {
+        return m_name;
+    }
+
+    /**
+     * Returns the fully qualified name of the class that is used by the component to access the service
+     *
+     * @return A string containing a fully qualified name
+    **/
+    public String getInterface() {
+        return m_interface;
+    }
+
+    /**
+     * Get the cardinality as a string
+     *
+     * @return A string with the cardinality
+    **/
+    public String getCardinality() {
+        return m_cardinality;
+    }
+
+    /**
+     * Get the policy as a string
+     *
+     * @return A string with the policy
+    **/
+    public String getPolicy() {
+        return m_policy;
+    }
+
+    /**
+     * Returns the filter expression that further constrains the set of target services
+     *
+     * @return A string with a filter
+    **/
+    public String getTarget() {
+        return m_target;
+    }
+
+    /**
+     * Get the name of a method in the component implementation class that is used to notify that
+     * a service is bound to the component configuration
+     *
+     * @return a String with the name of the bind method
+    **/
+    public String getBind() {
+        return m_bind;
+    }
+
+    /**
+     * Get the name of a method in the component implementation class that is used to notify that
+     * a service is unbound from the component configuration
+     *
+     * @return a String with the name of the unbind method
+    **/
+    public String getUnbind() {
+        return m_unbind;
+    }
+
+    // Getters for boolean values that determine both policy and cardinality
+
+    /**
+     * Test if dependency's binding policy is static
+     *
+     * @return true if static
+    **/
+    public boolean isStatic() {
+        return m_isStatic;
+    }
+
+    /**
+     * Test if dependency is optional (0..1 or 0..n)
+     *
+     * @return true if the dependency is optional
+    **/
+    public boolean isOptional() {
+        return m_isOptional;
+    }
+
+    /**
+     * Test if dependency is multiple (0..n or 1..n)
+     *
+     * @return true if the dependency is multiple
+    **/
+    public boolean isMultiple() {
+        return m_isMultiple;
+    }
+    
+    /**
+     *  Method used to verify if the semantics of this metadata are correct
+     *
+     */
+    void validate() {
+    	if (m_name == null) {
+    		throw new ComponentException("the name for the reference must be set");
+    	}
+    	
+    	if (m_interface == null) {
+    		throw new ComponentException("the interface for the reference must be set");
+    	}
+    }
+    
+    
+}
\ No newline at end of file

Added: incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/ServiceMetadata.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/ServiceMetadata.java?rev=395940&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/ServiceMetadata.java (added)
+++ incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/ServiceMetadata.java Fri Apr 21 09:34:36 2006
@@ -0,0 +1,101 @@
+/*
+ *   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.Iterator;
+import java.util.List;
+
+import org.osgi.service.component.ComponentException;
+
+/**
+ * This class contains the metadata associated to a service that is provided
+ * by a component
+ *
+ */
+public class ServiceMetadata {
+	
+	// 112.4.6 Flag that indicates if the service is a ServiceFactory 
+	private boolean m_serviceFactory = false;
+	
+	// List of provided interfaces
+	private List m_provides = new ArrayList();
+	
+	// Flag that indicates if this metadata has been validated and has become immutable
+	private boolean m_validated = false;
+	
+	/**
+	 * Setter for the servicefactory attribute of the service element
+	 * 
+	 * @param serviceFactory
+	 */
+	public void setServiceFactory(boolean serviceFactory) {
+		if(m_validated) {
+			return;
+		}			
+		
+		m_serviceFactory = serviceFactory;
+	}
+	
+	/**
+	 * Add a provided interface to this service
+	 * 
+	 * @param provide a String containing the name of the provided interface
+	 */
+	public void addProvide(String provide) {
+		if(m_validated) {
+			return;
+		}			
+
+		m_provides.add(provide);
+	}
+	
+	/**
+	 * Return the flag that defines if it is a service factory or not
+	 * 
+	 * @return a boolean flag
+	 */
+	public boolean isServiceFactory() {
+		return m_serviceFactory; 
+	}
+	
+	/**
+     * Returns the implemented interfaces
+     *
+     * @return the implemented interfaces as a string array
+     */
+    public String [] getProvides() {
+        String provides[] = new String[m_provides.size()];
+        Iterator it = m_provides.iterator();
+        int count = 0;
+        while (it.hasNext())
+        {
+            provides[count++] = it.next().toString();
+        }
+        return provides;
+    }
+    
+    /**
+     * Verify if the semantics of this metadata are correct
+     *
+     */
+    void validate() {
+    	if(m_provides.size() == 0) {
+    		throw new ComponentException("At least one provided interface must be given");
+    	}
+    }
+}

Added: incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/XmlHandler.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/XmlHandler.java?rev=395940&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/XmlHandler.java (added)
+++ incubator/felix/trunk/org.apache.felix.scr/src/main/java/org/apache/felix/scr/XmlHandler.java Fri Apr 21 09:34:36 2006
@@ -0,0 +1,209 @@
+/*
+ *   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.Properties;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.declarativeservices.scr.KXml2SAXHandler;
+import org.apache.felix.declarativeservices.scr.ParseException;
+
+/**
+ * 
+ * 
+ */
+public class XmlHandler implements KXml2SAXHandler {
+
+    // 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)
+	        }
+	        else if(qName.equals("properties")) {
+	        	// TODO: implement the properties tag
+	        }
+	        // 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
+        	m_currentComponent.validate();
+        }
+    }
+
+    /**
+    * 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
+		
+	}
+}
+

Added: incubator/felix/trunk/org.apache.felix.scr/todolist.txt
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.scr/todolist.txt?rev=395940&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.scr/todolist.txt (added)
+++ incubator/felix/trunk/org.apache.felix.scr/todolist.txt Fri Apr 21 09:34:36 2006
@@ -0,0 +1,66 @@
+Component Description
+
+112.4.1 Service Component Header 
+[    ] Process multi-entry (comma separated) header
+[    ] Support fragments
+[    ] Log error with log service in case header cannot be located
+
+112.4.2 XML Document
+[    ] Use document namespace
+
+112.4.3 Component Element
+[    ] Verify that the name of a component is globally unique
+[ OK ] Enabled set to true when not present
+[ OK ] Support null factory attribute
+[ OK ] Immediate set to false by default
+
+112.4.4 Implementation Element
+[ OK ] Check that the implementation element is present
+
+112.4.5 Properties and Property Elements
+[ OK ] Support property
+[    ] Support Configuration Admin's service
+[    ] Element body with multiple lines
+[    ] Support properties (file)
+
+112.4.6 Service Element
+[ OK ] Support for optional declaration
+[ OK ] Support for provides
+
+112.4.7 Reference Element
+[ OK ] Name of the reference
+[ OK ] Interface
+[ OK ] Cardinality
+[ OK ] Policy
+[ OK ] Target
+[ OK ] bind
+[ OK ] unbind
+
+Component Lifecycle
+
+[ OK ] 112.5.1 Enabled
+[ OK ] 112.5.2 Satisfied
+[ OK ] 112.5.3 Immediate
+[ OK ] 112.5.4 Delayed
+[    ] 112.5.5 Factory
+[ OK ] 112.5.6 Activation
+[ OK ] 112.5.7 Binding Services
+[ OK ] 112.5.8 Activate Method
+[    ] 112.5.9 Component Context
+[    ] 112.5.10 Bound Service Replacement
+[    ] 112.5.11 Deactivation
+[ OK ] 112.5.12 Deactivate Method
+[ OK ] 112.5.13 Unbinding
+
+[    ] 112.6 Component Properties
+[    ] 112.7 Deployment
+
+Service Component Runtime
+
+[    ] 112.8.1 Relationship to OSGi Framework
+[    ] 112.8.2 Starting and Stopping SCR
+
+Security
+
+[    ] 112.9.1 Service Permissions
+[    ] 112.9.2 Using hasPermission

Modified: incubator/felix/trunk/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/pom.xml?rev=395940&r1=395939&r2=395940&view=diff
==============================================================================
--- incubator/felix/trunk/pom.xml (original)
+++ incubator/felix/trunk/pom.xml Fri Apr 21 09:34:36 2006
@@ -35,6 +35,7 @@
     <module>org.apache.felix.upnp.tester</module>      
     <module>org.apache.felix.upnp.sample.tv</module>
     <module>org.apache.felix.http.jetty</module>
+	<module>org.apache.felix.scr</module>
   </modules>
 
   <repositories>