Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java Tue May 22 06:04:18 2012 @@ -25,7 +25,7 @@ import org.apache.felix.scrplugin.helper /** * <code>Reference.java</code>... - * + * */ public class Reference extends AbstractObject { @@ -45,14 +45,14 @@ public class Reference extends AbstractO * Default constructor. */ public Reference() { - this(null, null, -1); + this(null, null); } /** * Constructor from java source. */ - public Reference(final String annotationName, final String sourceLocation, final int lineNumber) { - super(annotationName, sourceLocation, lineNumber); + public Reference(final String annotationName, final String sourceLocation) { + super(annotationName, sourceLocation); } public String getName() { @@ -119,14 +119,6 @@ public class Reference extends AbstractO this.updated = updated; } - public boolean isChecked() { - return checked; - } - - public void setChecked(boolean checked) { - this.checked = checked; - } - /** @since 1.0.9 */ public String getStrategy() { return strategy; @@ -147,68 +139,66 @@ public class Reference extends AbstractO * If errors occur a message is added to the issues list, * warnings can be added to the warnings list. */ - public void validate(final Context context, - final boolean componentIsAbstract) - throws SCRDescriptorException { - final int currentIssueCount = iLog.getNumberOfErrors(); - + public void validate(final Context context, final boolean componentIsAbstract) throws SCRDescriptorException { + final int currentIssueCount = context.getIssueLog().getNumberOfErrors(); +/* // validate name if (StringUtils.isEmpty(this.name)) { - if ( specVersion < Constants.VERSION_1_1 ) { - this.logError( iLog, "Reference has no name" ); + if (specVersion < Constants.VERSION_1_1) { + this.logError(iLog, "Reference has no name"); } } // validate interface if (StringUtils.isEmpty(this.interfacename)) { - this.logError( iLog, "Missing interface name" ); + this.logError(iLog, "Missing interface name"); } // validate cardinality if (this.cardinality == null) { this.cardinality = "1..1"; - } else if (!"0..1".equals(this.cardinality) && !"1..1".equals(this.cardinality) - && !"0..n".equals(this.cardinality) && !"1..n".equals(this.cardinality)) { - this.logError( context.getIssueLog(), "Invalid Cardinality specification " + this.cardinality ); + } else if (!"0..1".equals(this.cardinality) && !"1..1".equals(this.cardinality) && !"0..n".equals(this.cardinality) + && !"1..n".equals(this.cardinality)) { + this.logError(context.getIssueLog(), "Invalid Cardinality specification " + this.cardinality); } // validate policy if (this.policy == null) { this.policy = "static"; } else if (!"static".equals(this.policy) && !"dynamic".equals(this.policy)) { - this.logError( context.getIssueLog(), "Invalid Policy specification " + this.policy ); + this.logError(context.getIssueLog(), "Invalid Policy specification " + this.policy); } // validate strategy if (this.strategy == null) { this.strategy = Constants.REFERENCE_STRATEGY_EVENT; } else if (!Constants.REFERENCE_STRATEGY_EVENT.equals(this.strategy) - && !Constants.REFERENCE_STRATEGY_LOOKUP.equals(this.strategy)) { - this.logError( iLog, "Invalid strategy type " + this.strategy ); + && !Constants.REFERENCE_STRATEGY_LOOKUP.equals(this.strategy)) { + this.logError(iLog, "Invalid strategy type " + this.strategy); } // validate bind and unbind methods if (!isLookupStrategy()) { // set default values - if ( this.bind == null ) { + if (this.bind == null) { this.setBind("bind"); } - if ( this.unbind == null ) { + if (this.unbind == null) { this.setUnbind("unbind"); } final String oldBind = this.bind; final String oldUnbind = this.unbind; this.bind = this.validateMethod(specVersion, this.bind, componentIsAbstract, iLog); this.unbind = this.validateMethod(specVersion, this.unbind, componentIsAbstract, iLog); - if ( context.getIssueLog().getNumberOfErrors() == currentIssueCount ) { - if ( this.bind != null && this.unbind != null ) { + if (context.getIssueLog().getNumberOfErrors() == currentIssueCount) { + if (this.bind != null && this.unbind != null) { // no errors, so we're checked this.checked = true; } else { - if ( this.bind == null ) { + if (this.bind == null) { this.bind = oldBind; } - if ( this.unbind == null ) { + if (this.unbind == null) { this.unbind = oldUnbind; } } @@ -219,55 +209,52 @@ public class Reference extends AbstractO } // validate updated method - if ( this.updated != null ) { - if ( specVersion < Constants.VERSION_1_1_FELIX ) { - this.logError( iLog, "Updated method declaration requires namespace " - + Constants.COMPONENT_DS_SPEC_VERSION_11_FELIX + " or newer" ); + if (this.updated != null) { + if (specVersion < Constants.VERSION_1_1_FELIX) { + this.logError(iLog, "Updated method declaration requires namespace " + + Constants.COMPONENT_DS_SPEC_VERSION_11_FELIX + " or newer"); } } } - protected String validateMethod(final int specVersion, - final String methodName, - final boolean componentIsAbstract, - final IssueLog iLog) - throws SCRDescriptorException { + protected String validateMethod(final int specVersion, final String methodName, final boolean componentIsAbstract, + final IssueLog iLog) throws SCRDescriptorException { final JavaMethod method = this.findMethod(specVersion, methodName); if (method == null) { - if ( !componentIsAbstract ) { - this.logError( iLog, "Missing method " + methodName + " for reference " + (this.getName() == null ? "" : this.getName())); + if (!componentIsAbstract) { + this.logError(iLog, + "Missing method " + methodName + " for reference " + + (this.getName() == null ? "" : this.getName())); } return null; } // method needs to be protected for 1.0 - if ( specVersion == Constants.VERSION_1_0 ) { + if (specVersion == Constants.VERSION_1_0) { if (method.isPublic()) { - this.logWarn( iLog, "Method " + method.getName() + " should be declared protected" ); + this.logWarn(iLog, "Method " + method.getName() + " should be declared protected"); } else if (!method.isProtected()) { - this.logError( iLog, "Method " + method.getName() + " has wrong qualifier, public or protected required" ); + this.logError(iLog, "Method " + method.getName() + " has wrong qualifier, public or protected required"); return null; } } - return method.getName(); + return method.getName();*/ } private static final String TYPE_SERVICE_REFERENCE = "org.osgi.framework.ServiceReference"; private static final String TYPE_MAP = "java.util.Map"; - - public JavaMethod findMethod(final int specVersion, - final String methodName) - throws SCRDescriptorException { - final String[] sig = new String[]{ TYPE_SERVICE_REFERENCE }; - final String[] sig2 = new String[]{ this.getInterfacename() }; - final String[] sig3 = new String[]{ this.getInterfacename(), TYPE_MAP}; +/* + public JavaMethod findMethod(final int specVersion, final String methodName) throws SCRDescriptorException { + final String[] sig = new String[] { TYPE_SERVICE_REFERENCE }; + final String[] sig2 = new String[] { this.getInterfacename() }; + final String[] sig3 = new String[] { this.getInterfacename(), TYPE_MAP }; // service interface or ServiceReference first String realMethodName = methodName; JavaMethod method = this.javaClassDescription.getMethodBySignature(realMethodName, sig); if (method == null) { method = this.javaClassDescription.getMethodBySignature(realMethodName, sig2); - if ( specVersion >= Constants.VERSION_1_1 && method == null ) { + if (specVersion >= Constants.VERSION_1_1 && method == null) { method = this.javaClassDescription.getMethodBySignature(realMethodName, sig3); } } @@ -288,7 +275,7 @@ public class Reference extends AbstractO } if (method == null) { method = this.javaClassDescription.getMethodBySignature(realMethodName, sig2); - if ( specVersion >= Constants.VERSION_1_1 && method == null ) { + if (specVersion >= Constants.VERSION_1_1 && method == null) { method = this.javaClassDescription.getMethodBySignature(realMethodName, sig3); } } @@ -296,18 +283,17 @@ public class Reference extends AbstractO // append type name with service interface and ServiceReference if (method == null) { int lastDot = this.getInterfacename().lastIndexOf('.'); - realMethodName = methodName - + this.getInterfacename().substring(lastDot + 1); + realMethodName = methodName + this.getInterfacename().substring(lastDot + 1); method = this.javaClassDescription.getMethodBySignature(realMethodName, sig); } if (method == null) { method = this.javaClassDescription.getMethodBySignature(realMethodName, sig2); - if ( specVersion >= Constants.VERSION_1_1 && method == null ) { + if (specVersion >= Constants.VERSION_1_1 && method == null) { method = this.javaClassDescription.getMethodBySignature(realMethodName, sig3); } } return method; } - +*/ }
Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Service.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Service.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Service.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Service.java Tue May 22 06:04:18 2012 @@ -26,7 +26,7 @@ import org.apache.felix.scrplugin.SCRDes /** * <code>Service</code> - * + * * contains all service information of a component. */ public class Service { @@ -47,7 +47,7 @@ public class Service { /** * Set the service factory flag. */ - public void setServicefactory(final boolean flag) { + public void setServiceFactory(final boolean flag) { this.isServiceFactory = flag; } @@ -60,14 +60,16 @@ public class Service { /** * Search for an implemented interface. - * @param name The name of the interface. + * + * @param name + * The name of the interface. * @return The interface if it is implemented by this service or null. */ public Interface findInterface(final String name) { final Iterator<Interface> i = this.getInterfaces().iterator(); - while ( i.hasNext() ) { + while (i.hasNext()) { final Interface current = i.next(); - if ( current.getInterfaceName().equals(name) ) { + if (current.getInterfaceName().equals(name)) { return current; } } @@ -76,11 +78,13 @@ public class Service { /** * Add an interface to the list of interfaces. - * @param interf The interface. + * + * @param interf + * The interface. */ public void addInterface(final Interface interf) { // add interface only once - if ( this.findInterface(interf.getInterfaceName()) == null ) { + if (this.findInterface(interf.getInterfaceName()) == null) { this.interfaces.add(interf); } } @@ -90,9 +94,8 @@ public class Service { * If errors occur a message is added to the issues list, * warnings can be added to the warnings list. */ - public void validate(final Context context) - throws SCRDescriptorException { - for(final Interface interf : this.getInterfaces()) { + public void validate(final Context context) throws SCRDescriptorException { + for (final Interface interf : this.getInterfaces()) { interf.validate(context); } } Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java?rev=1341309&r1=1341308&r2=1341309&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java (original) +++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java Tue May 22 06:04:18 2012 @@ -42,9 +42,9 @@ import org.xml.sax.helpers.DefaultHandle /** * <code>ComponentDescriptorIO</code> - * + * * is a helper class to read and write component descriptor files. - * + * */ public class ComponentDescriptorIO { @@ -116,27 +116,26 @@ public class ComponentDescriptorIO { private static final String INTERFACE_QNAME = INTERFACE; - public static Components read(InputStream file) - throws SCRDescriptorException { + public static Components read(InputStream file) throws SCRDescriptorException { try { final XmlHandler xmlHandler = new XmlHandler(); IOUtils.parse(file, xmlHandler); return xmlHandler.components; } catch (TransformerException e) { - throw new SCRDescriptorException( "Unable to read xml", "[stream]", 0, e ); + throw new SCRDescriptorException("Unable to read xml", "[stream]", 0, e); } } /** * Write the component descriptors to the file. + * * @param components * @param file * @throws SCRDescriptorException */ - public static void write(Components components, File file, boolean isScrPrivateFile) - throws SCRDescriptorException { + public static void write(Components components, File file) throws SCRDescriptorException { try { - generateXML(components, IOUtils.getSerializer(file), isScrPrivateFile); + generateXML(components, IOUtils.getSerializer(file)); } catch (TransformerException e) { throw new SCRDescriptorException("Unable to write xml", file.toString(), 0, e); } catch (SAXException e) { @@ -149,17 +148,17 @@ public class ComponentDescriptorIO { /** * Generate the xml top level element and start streaming * the components. + * * @param components * @param contentHandler * @throws SAXException */ - protected static void generateXML(Components components, ContentHandler contentHandler, boolean isScrPrivateFile) - throws SAXException { + protected static void generateXML(Components components, ContentHandler contentHandler) throws SAXException { // detect namespace to use final String namespace; - if ( components.getSpecVersion() == SpecVersion.VERSION_1_0 ) { + if (components.getSpecVersion() == SpecVersion.VERSION_1_0) { namespace = NAMESPACE_URI_1_0; - } else if ( components.getSpecVersion() == SpecVersion.VERSION_1_1 ) { + } else if (components.getSpecVersion() == SpecVersion.VERSION_1_1) { namespace = NAMESPACE_URI_1_1; } else { namespace = NAMESPACE_URI_1_1_FELIX; @@ -171,9 +170,9 @@ public class ComponentDescriptorIO { contentHandler.startElement("", ComponentDescriptorIO.COMPONENTS, ComponentDescriptorIO.COMPONENTS, new AttributesImpl()); IOUtils.newline(contentHandler); - for(final Component component : components.getComponents()) { - if ( component.isDs() ) { - generateXML(namespace, component, contentHandler, isScrPrivateFile); + for (final Component component : components.getComponents()) { + if (component.isDs()) { + generateXML(namespace, component, contentHandler); } } // end wrapper element @@ -185,23 +184,21 @@ public class ComponentDescriptorIO { /** * Write the xml for a {@link Component}. + * * @param component * @param contentHandler * @throws SAXException */ - protected static void generateXML(final String namespace, - final Component component, - final ContentHandler contentHandler, - final boolean isScrPrivateFile) - throws SAXException { + protected static void generateXML(final String namespace, final Component component, final ContentHandler contentHandler) + throws SAXException { final AttributesImpl ai = new AttributesImpl(); IOUtils.addAttribute(ai, COMPONENT_ATTR_ENABLED, component.isEnabled()); - IOUtils.addAttribute(ai, COMPONENT_ATTR_IMMEDIATE,component.isImmediate()); + IOUtils.addAttribute(ai, COMPONENT_ATTR_IMMEDIATE, component.isImmediate()); IOUtils.addAttribute(ai, COMPONENT_ATTR_NAME, component.getName()); IOUtils.addAttribute(ai, COMPONENT_ATTR_FACTORY, component.getFactory()); // attributes new in 1.1 - if ( NAMESPACE_URI_1_1.equals( namespace ) || NAMESPACE_URI_1_1_FELIX.equals( namespace ) ) { + if (NAMESPACE_URI_1_1.equals(namespace) || NAMESPACE_URI_1_1_FELIX.equals(namespace)) { IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy()); IOUtils.addAttribute(ai, COMPONENT_ATTR_ACTIVATE, component.getActivate()); IOUtils.addAttribute(ai, COMPONENT_ATTR_DEACTIVATE, component.getDeactivate()); @@ -212,17 +209,17 @@ public class ComponentDescriptorIO { contentHandler.startElement(namespace, ComponentDescriptorIO.COMPONENT, ComponentDescriptorIO.COMPONENT_QNAME, ai); IOUtils.newline(contentHandler); generateXML(component.getImplementation(), contentHandler); - if ( component.getService() != null ) { + if (component.getService() != null) { generateXML(component.getService(), contentHandler); } - if ( component.getProperties() != null ) { - for(final Property property : component.getProperties()) { - generateXML(property, contentHandler, isScrPrivateFile); + if (component.getProperties() != null) { + for (final Property property : component.getProperties()) { + generateXML(property, contentHandler); } } - if ( component.getReferences() != null ) { - for(final Reference reference : component.getReferences()) { - generateXML(namespace, reference, contentHandler, isScrPrivateFile); + if (component.getReferences() != null) { + for (final Reference reference : component.getReferences()) { + generateXML(namespace, reference, contentHandler); } } IOUtils.indent(contentHandler, 1); @@ -232,35 +229,37 @@ public class ComponentDescriptorIO { /** * Write the xml for a {@link Implementation}. + * * @param implementation * @param contentHandler * @throws SAXException */ - protected static void generateXML(Implementation implementation, ContentHandler contentHandler) - throws SAXException { + protected static void generateXML(Implementation implementation, ContentHandler contentHandler) throws SAXException { final AttributesImpl ai = new AttributesImpl(); - IOUtils.addAttribute(ai, "class", implementation.getClassame()); + IOUtils.addAttribute(ai, "class", implementation.getClassName()); IOUtils.indent(contentHandler, 2); - contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION, ComponentDescriptorIO.IMPLEMENTATION_QNAME, ai); - contentHandler.endElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION, ComponentDescriptorIO.IMPLEMENTATION_QNAME); + contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION, + ComponentDescriptorIO.IMPLEMENTATION_QNAME, ai); + contentHandler.endElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION, + ComponentDescriptorIO.IMPLEMENTATION_QNAME); IOUtils.newline(contentHandler); } /** * Write the xml for a {@link Service}. + * * @param service * @param contentHandler * @throws SAXException */ - protected static void generateXML(Service service, ContentHandler contentHandler) - throws SAXException { + protected static void generateXML(Service service, ContentHandler contentHandler) throws SAXException { final AttributesImpl ai = new AttributesImpl(); - IOUtils.addAttribute(ai, "servicefactory", String.valueOf(service.isServicefactory())); + IOUtils.addAttribute(ai, "servicefactory", String.valueOf(service.isServiceFactory())); IOUtils.indent(contentHandler, 2); contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.SERVICE, ComponentDescriptorIO.SERVICE_QNAME, ai); - if ( service.getInterfaces() != null && service.getInterfaces().size() > 0 ) { + if (service.getInterfaces() != null && service.getInterfaces().size() > 0) { IOUtils.newline(contentHandler); - for(final Interface interf : service.getInterfaces()) { + for (final Interface interf : service.getInterfaces()) { generateXML(interf, contentHandler); } IOUtils.indent(contentHandler, 2); @@ -271,51 +270,40 @@ public class ComponentDescriptorIO { /** * Write the xml for a {@link Interface}. + * * @param interf * @param contentHandler * @throws SAXException */ - protected static void generateXML(Interface interf, ContentHandler contentHandler) - throws SAXException { + protected static void generateXML(Interface interf, ContentHandler contentHandler) throws SAXException { final AttributesImpl ai = new AttributesImpl(); - IOUtils.addAttribute(ai, "interface", interf.getInterfacename()); + IOUtils.addAttribute(ai, "interface", interf.getInterfaceName()); IOUtils.indent(contentHandler, 3); - contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.INTERFACE, ComponentDescriptorIO.INTERFACE_QNAME, ai); + contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.INTERFACE, ComponentDescriptorIO.INTERFACE_QNAME, + ai); contentHandler.endElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.INTERFACE, ComponentDescriptorIO.INTERFACE_QNAME); IOUtils.newline(contentHandler); } /** * Write the xml for a {@link Property}. + * * @param property * @param contentHandler * @throws SAXException */ - protected static void generateXML(Property property, ContentHandler contentHandler, boolean isScrPrivateFile) - throws SAXException { + protected static void generateXML(Property property, ContentHandler contentHandler) throws SAXException { final AttributesImpl ai = new AttributesImpl(); IOUtils.addAttribute(ai, "name", property.getName()); IOUtils.addAttribute(ai, "type", property.getType()); IOUtils.addAttribute(ai, "value", property.getValue()); - // we have to write more information if this is our scr private file - if ( isScrPrivateFile ) { - IOUtils.addAttribute(ai, "private", String.valueOf(property.isPrivate())); - if ( property.getLabel() != null ) { - IOUtils.addAttribute(ai, "label", String.valueOf(property.getLabel())); - } - if ( property.getDescription() != null ) { - IOUtils.addAttribute(ai, "description", String.valueOf(property.getDescription())); - } - if ( property.getCardinality() != null ) { - IOUtils.addAttribute(ai, "cardinality", String.valueOf(property.getCardinality())); - } - } + IOUtils.indent(contentHandler, 2); contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.PROPERTY, ComponentDescriptorIO.PROPERTY_QNAME, ai); - if ( property.getMultiValue() != null && property.getMultiValue().length > 0 ) { + if (property.getMultiValue() != null && property.getMultiValue().length > 0) { // generate a new line first IOUtils.text(contentHandler, "\n"); - for(int i=0; i<property.getMultiValue().length; i++) { + for (int i = 0; i < property.getMultiValue().length; i++) { IOUtils.indent(contentHandler, 3); IOUtils.text(contentHandler, property.getMultiValue()[i]); IOUtils.newline(contentHandler); @@ -328,12 +316,13 @@ public class ComponentDescriptorIO { /** * Write the xml for a {@link Reference}. + * * @param reference * @param contentHandler * @throws SAXException */ - protected static void generateXML(final String namespace,Reference reference, ContentHandler contentHandler, boolean isScrPrivateFile) - throws SAXException { + protected static void generateXML(final String namespace, Reference reference, ContentHandler contentHandler) + throws SAXException { final AttributesImpl ai = new AttributesImpl(); IOUtils.addAttribute(ai, "name", reference.getName()); IOUtils.addAttribute(ai, "interface", reference.getInterfacename()); @@ -344,23 +333,20 @@ public class ComponentDescriptorIO { IOUtils.addAttribute(ai, "unbind", reference.getUnbind()); // attributes new in 1.1-felix (FELIX-1893) - if ( NAMESPACE_URI_1_1_FELIX.equals( namespace ) ) { + if (NAMESPACE_URI_1_1_FELIX.equals(namespace)) { IOUtils.addAttribute(ai, "updated", reference.getUpdated()); } - if ( isScrPrivateFile ) { - IOUtils.addAttribute(ai, "checked", String.valueOf(reference.isChecked())); - IOUtils.addAttribute(ai, "strategy", reference.getStrategy()); - } IOUtils.indent(contentHandler, 2); - contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.REFERENCE, ComponentDescriptorIO.REFERENCE_QNAME, ai); + contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.REFERENCE, ComponentDescriptorIO.REFERENCE_QNAME, + ai); contentHandler.endElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.REFERENCE, ComponentDescriptorIO.REFERENCE_QNAME); IOUtils.newline(contentHandler); } /** * A content handler for parsing the component descriptions. - * + * */ protected static final class XmlHandler extends DefaultHandler { @@ -385,38 +371,36 @@ public class ComponentDescriptorIO { /** Override namespace. */ protected String overrideNamespace; - public void startElement(String uri, String localName, String name, Attributes attributes) - throws SAXException { + public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { // 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 ( this.firstElement ) { + if (this.firstElement) { this.firstElement = false; - if ( localName.equals(COMPONENT) && "".equals(uri) ) { + if (localName.equals(COMPONENT) && "".equals(uri)) { this.overrideNamespace = NAMESPACE_URI_1_0; } } - if ( this.overrideNamespace != null && "".equals(uri) ) { + if (this.overrideNamespace != null && "".equals(uri)) { uri = this.overrideNamespace; } // however the spec also states that the inner elements // of a component are unqualified, so they don't have // the namespace - we allow both: with or without namespace! - if ( this.isComponent && "".equals(uri) ) { + if (this.isComponent && "".equals(uri)) { uri = NAMESPACE_URI_1_0; } // from here on, uri has the namespace regardless of the used xml format - if ( NAMESPACE_URI_1_0.equals( uri ) || NAMESPACE_URI_1_1.equals( uri ) - || NAMESPACE_URI_1_1_FELIX.equals( uri ) ) { + if (NAMESPACE_URI_1_0.equals(uri) || NAMESPACE_URI_1_1.equals(uri) || NAMESPACE_URI_1_1_FELIX.equals(uri)) { - if ( NAMESPACE_URI_1_0.equals(uri) ) { + if (NAMESPACE_URI_1_0.equals(uri)) { components.setSpecVersion(SpecVersion.VERSION_1_0); - } else if ( NAMESPACE_URI_1_1.equals(uri) ) { + } else if (NAMESPACE_URI_1_1.equals(uri)) { components.setSpecVersion(SpecVersion.VERSION_1_1); - } else if ( NAMESPACE_URI_1_1_FELIX.equals(uri) ) { + } else if (NAMESPACE_URI_1_1_FELIX.equals(uri)) { components.setSpecVersion(SpecVersion.VERSION_1_1_FELIX); } @@ -439,7 +423,8 @@ public class ComponentDescriptorIO { this.currentComponent.setFactory(attributes.getValue(COMPONENT_ATTR_FACTORY)); // check for version 1.1 attributes - if ( components.getSpecVersion() == SpecVersion.VERSION_1_1 || components.getSpecVersion() == SpecVersion.VERSION_1_1_FELIX ) { + if (components.getSpecVersion() == SpecVersion.VERSION_1_1 + || components.getSpecVersion() == SpecVersion.VERSION_1_1_FELIX) { this.currentComponent.setConfigurationPolicy(attributes.getValue(COMPONENT_ATTR_POLICY)); this.currentComponent.setActivate(attributes.getValue(COMPONENT_ATTR_ACTIVATE)); this.currentComponent.setDeactivate(attributes.getValue(COMPONENT_ATTR_DEACTIVATE)); @@ -447,40 +432,34 @@ public class ComponentDescriptorIO { } } else if (localName.equals(IMPLEMENTATION)) { // Set the implementation class name (mandatory) - final Implementation impl = new Implementation(); + final Implementation impl = new Implementation(attributes.getValue("class")); this.currentComponent.setImplementation(impl); - impl.setClassname(attributes.getValue("class")); } else if (localName.equals(PROPERTY)) { // read the property, unless it is the service.pid // property which must not be inherited - final String propName = attributes.getValue( "name" ); - if ( !org.osgi.framework.Constants.SERVICE_PID.equals( propName ) ) - { + final String propName = attributes.getValue("name"); + if (!org.osgi.framework.Constants.SERVICE_PID.equals(propName)) { final Property prop = new Property(); - prop.setName( propName ); - prop.setType( attributes.getValue( "type" ) ); + prop.setName(propName); + prop.setType(attributes.getValue("type")); - if ( attributes.getValue( "value" ) != null ) - { - prop.setValue( attributes.getValue( "value" ) ); - this.currentComponent.addProperty( prop ); - } - else - { + if (attributes.getValue("value") != null) { + prop.setValue(attributes.getValue("value")); + this.currentComponent.addProperty(prop); + } else { // hold the property pending as we have a multi value this.pendingProperty = prop; } // check for abstract properties - prop.setLabel( attributes.getValue( "label" ) ); - prop.setDescription( attributes.getValue( "description" ) ); - prop.setCardinality( attributes.getValue( "cardinality" ) ); - final String pValue = attributes.getValue( "private" ); - if ( pValue != null ) - { - prop.setPrivate( Boolean.valueOf( pValue ).booleanValue() ); + prop.setLabel(attributes.getValue("label")); + prop.setDescription(attributes.getValue("description")); + prop.setCardinality(attributes.getValue("cardinality")); + final String pValue = attributes.getValue("private"); + if (pValue != null) { + prop.setPrivate(Boolean.valueOf(pValue).booleanValue()); } } @@ -492,14 +471,15 @@ public class ComponentDescriptorIO { this.currentService = new Service(); - this.currentService.setServicefactory(attributes.getValue("servicefactory")); - + if (attributes.getValue("servicefactory") != null) { + this.currentService.setServiceFactory(Boolean.valueOf(attributes.getValue("servicefactory"))); + } this.currentComponent.setService(this.currentService); } else if (localName.equals(INTERFACE)) { final Interface interf = new Interface(); this.currentService.addInterface(interf); - interf.setInterfacename(attributes.getValue("interface")); + interf.setInterfaceName(attributes.getValue("interface")); } else if (localName.equals(REFERENCE)) { final Reference ref = new Reference(); @@ -512,10 +492,7 @@ public class ComponentDescriptorIO { ref.setBind(attributes.getValue("bind")); ref.setUnbind(attributes.getValue("unbind")); - if ( attributes.getValue("checked") != null ) { - ref.setChecked(Boolean.valueOf(attributes.getValue("checked")).booleanValue()); - } - if ( attributes.getValue("strategy") != null ) { + if (attributes.getValue("strategy") != null) { ref.setStrategy(attributes.getValue("strategy")); } @@ -528,29 +505,27 @@ public class ComponentDescriptorIO { * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String) */ public void endElement(String uri, String localName, String name) throws SAXException { - if ( this.overrideNamespace != null && "".equals(uri) ) { + if (this.overrideNamespace != null && "".equals(uri)) { uri = this.overrideNamespace; } - if ( this.isComponent && "".equals(uri) ) { + if (this.isComponent && "".equals(uri)) { uri = NAMESPACE_URI_1_0; } - if ( NAMESPACE_URI_1_0.equals( uri ) || NAMESPACE_URI_1_1.equals( uri ) - || NAMESPACE_URI_1_1_FELIX.equals( uri ) ) - { - if (localName.equals(COMPONENT) ) { + if (NAMESPACE_URI_1_0.equals(uri) || NAMESPACE_URI_1_1.equals(uri) || NAMESPACE_URI_1_1_FELIX.equals(uri)) { + if (localName.equals(COMPONENT)) { this.components.addComponent(this.currentComponent); this.currentComponent = null; this.isComponent = false; } else if (localName.equals(PROPERTY) && this.pendingProperty != null) { // now split the value final String text = this.pendingProperty.getValue(); - if ( text != null ) { + if (text != null) { final StringTokenizer st = new StringTokenizer(text); final String[] values = new String[st.countTokens()]; int index = 0; - while ( st.hasMoreTokens() ) { + while (st.hasMoreTokens()) { values[index] = st.nextToken(); index++; } @@ -566,9 +541,9 @@ public class ComponentDescriptorIO { * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int) */ public void characters(char[] ch, int start, int length) throws SAXException { - if ( this.pendingProperty != null ) { + if (this.pendingProperty != null) { final String text = new String(ch, start, length); - if ( this.pendingProperty.getValue() == null ) { + if (this.pendingProperty.getValue() == null) { this.pendingProperty.setValue(text); } else { this.pendingProperty.setValue(this.pendingProperty.getValue() + text);
