Return-Path: Delivered-To: apmail-felix-dev-archive@www.apache.org Received: (qmail 55699 invoked from network); 7 Feb 2009 06:27:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Feb 2009 06:27:36 -0000 Received: (qmail 51438 invoked by uid 500); 7 Feb 2009 06:27:35 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 51417 invoked by uid 500); 7 Feb 2009 06:27:35 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 51406 invoked by uid 99); 7 Feb 2009 06:27:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Feb 2009 22:27:35 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Feb 2009 06:27:23 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 5FD1E234C4B0 for ; Fri, 6 Feb 2009 22:27:02 -0800 (PST) Message-ID: <537617280.1233988022391.JavaMail.jira@brutus> Date: Fri, 6 Feb 2009 22:27:02 -0800 (PST) From: "Felix Meschberger (JIRA)" To: dev@felix.apache.org Subject: [jira] Closed: (FELIX-639) Need more logs from SCR In-Reply-To: <819465388.1216653691818.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/FELIX-639?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Felix Meschberger closed FELIX-639. ----------------------------------- Resolution: Fixed Thanks Pierre for the feedback. So I close this issue now. > Need more logs from SCR > ----------------------- > > Key: FELIX-639 > URL: https://issues.apache.org/jira/browse/FELIX-639 > Project: Felix > Issue Type: Improvement > Components: Declarative Services (SCR) > Affects Versions: scr-1.0.2 > Environment: linux > Reporter: Pierre De Rop > Assignee: Felix Meschberger > Priority: Minor > Fix For: scr-1.0.8 > > Attachments: ComponentMetadata.java, XmlHandler.java > > > As explained in the dev post http://www.mail-archive.com/dev@felix.apache.org/msg05030.html, > I would like the SCR to be improved in order to log some WARNINGs, when a SCR.xml descriptor contains invalid elements, event if it is well formed. > for example, the following SCR.xml has two errors: > > > > bind="setLog" > unbind="unsetLog" > cardinality="1..n" > policy="dynamic"/> > > > > bind="setLog" > unbind="unsetLog" > cardinality="1..n" > policy="dynamic"/> > > bind="setLog2" > unbind="unsetLog2" > cardinality="1..n" > policy="dynamic"/> > > > -> the two components are embedded in an invalid xml root element > -> the component "Component2" has two references with the SAME name > I would like the SCR to log some WARNINGs message, when finding these sort of errors: > 1/ log a WARNING message when finding an unknown/invalid xml element > 2/ log a WARNING message when duplicate reference names are detected for one given component. > Here is a tentative fix which is working for my use cases: > 1/ in the org.apache.felix.scr.impl.ComponentMetadata.validate() method (around line 299): > // Check that the references are ok. > // We'll especially Check if there's not duplicate names in the component references. > HashSet refs = new HashSet(); > Iterator referenceIterator = m_references.iterator(); > while ( referenceIterator.hasNext() ) > { > ReferenceMetadata refMeta = ( ReferenceMetadata ) referenceIterator.next(); > refMeta.validate( this ); > if (! refs.add(refMeta.getName())) { > throw validationFailure( "Detected duplicate reference name: \"" + refMeta.getName() + "\""); > } > } > 2/ in org.apache.felix.scr.impl.XmlHandler.startElement method (around line 215, at the end of the method): > +++ src/main/java/org/apache/felix/scr/impl/XmlHandler.java (working copy) > @@ -211,14 +211,21 @@ > ref.setUnbind( attrib.getProperty( "unbind" ) ); > m_currentComponent.addDependency( ref ); > - } > + } > + else { > + throw new ParseException("Invalid SCR xml element found in " + m_bundle.getLocation() + > + ": \"" + localName + "\"", null); > + } > } > catch ( Exception ex ) > { > ex.printStackTrace(); > throw new ParseException( "Exception during parsing", ex ); > } > - } > + } else { > + throw new ParseException("Invalid SCR xml element found in " + m_bundle.getLocation() + > + ": \"" + localName + "\"", null); > + } > } > -> Here is the complete/modifed method: > public void startElement( String uri, String localName, Properties attrib ) throws ParseException > { > // according to the spec, the elements should have the namespace, > // except when the root element is the "component" element > // So we check this for the first element, we receive. > if ( firstElement ) > { > firstElement = false; > if ( localName.equals( "component" ) && "".equals( uri ) ) > { > overrideNamespace = NAMESPACE_URI; > } > } > if ( overrideNamespace != null && "".equals( uri ) ) > { > uri = overrideNamespace; > } > if ( NAMESPACE_URI.equals( uri ) ) > { > try > { > // 112.4.3 Component Element > if ( localName.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 ( localName.equals( "implementation" ) ) > { > // Set the implementation class name (mandatory) > m_currentComponent.setImplementationClassName( attrib.getProperty( "class" ) ); > } > // 112.4.5 [...] Property Elements > else if ( localName.equals( "property" ) ) > { > 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" ) ); > } > // 112.4.5: If the value attribute is specified, the body of the element is ignored. > if ( attrib.getProperty( "value" ) != null ) > { > prop.setValue( attrib.getProperty( "value" ) ); > m_currentComponent.addProperty( prop ); > } > else > { > // hold the metadata pending > m_pendingProperty = prop; > } > } > // 112.4.5 Properties [...] Elements > else if ( localName.equals( "properties" ) ) > { > readPropertiesEntry( attrib.getProperty( "entry" ) ); > } > // 112.4.6 Service Element > else if ( localName.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 ( localName.equals( "provide" ) ) > { > m_currentService.addProvide( attrib.getProperty( "interface" ) ); > } > // 112.4.7 Reference element > else if ( localName.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 ); > } > else { > throw new ParseException("Invalid SCR xml element found in " + m_bundle.getLocation() + > ": \"" + localName + "\"", null); > } > } > catch ( Exception ex ) > { > ex.printStackTrace(); > throw new ParseException( "Exception during parsing", ex ); > } > } else { > throw new ParseException("Invalid SCR xml element found in " + m_bundle.getLocation() + > ": \"" + localName + "\"", null); > } > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.