Author: pdodds
Date: Thu Sep 14 06:55:30 2006
New Revision: 443357

URL: http://svn.apache.org/viewvc?view=rev&rev=443357
Log:
Added the ability to have a jbi-connections.xml which will inject connections 
into a Service Assembly - also tidied the handling of elements so that both 
fully qualified and unqualified elements will be recognised during the parsing 
of jbi-connections.xml and jbi-services.xml.

Added:
    
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractDescriptorWriter.java
    
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/XmlDescriptorHelper.java
Modified:
    
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyDescriptorMojo.java
    
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
    
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java
    
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
    
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java

Added: 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractDescriptorWriter.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractDescriptorWriter.java?view=auto&rev=443357
==============================================================================
--- 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractDescriptorWriter.java
 (added)
+++ 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/AbstractDescriptorWriter.java
 Thu Sep 14 06:55:30 2006
@@ -0,0 +1,66 @@
+package org.apache.servicemix.maven.plugin.jbi;

+

+import java.util.HashMap;

+import java.util.Iterator;

+import java.util.List;

+import java.util.Map;

+

+import javax.xml.namespace.QName;

+

+import org.apache.servicemix.common.packaging.Consumes;

+import org.apache.servicemix.common.packaging.Provides;

+import org.codehaus.plexus.util.xml.XMLWriter;

+

+public class AbstractDescriptorWriter {

+

+       protected void addStringAttribute(XMLWriter writer, String 
attributeName, String attributeValue) {

+               if (attributeValue != null)

+                       writer.addAttribute(attributeName, attributeValue);

+       }

+

+       protected void addQNameAttribute(XMLWriter writer, String 
attributeName, QName attributeValue, Map namespaceMap) {              

+               if (attributeValue != null) {

+                       StringBuffer attributeStringValue = new StringBuffer();

+                       
attributeStringValue.append(namespaceMap.get(attributeValue

+                                       .getNamespaceURI()));

+                       attributeStringValue.append(":");

+                       
attributeStringValue.append(attributeValue.getLocalPart());

+                       writer.addAttribute(attributeName, 
attributeStringValue.toString());

+               }

+       

+       }

+

+       protected Map getNamespaceMap(List provides, List consumes) {

+               Map namespaceMap = new HashMap();

+               int namespaceCounter = 1;

+               for (Iterator iterator = provides.iterator(); 
iterator.hasNext();) {

+                       Provides providesEntry = (Provides) iterator.next();

+                       resolveMapEntry(namespaceMap, 
providesEntry.getInterfaceName(),

+                                       namespaceCounter);

+                       resolveMapEntry(namespaceMap, 
providesEntry.getServiceName(),

+                                       namespaceCounter);

+               }

+       

+               for (Iterator iterator = consumes.iterator(); 
iterator.hasNext();) {

+                       Consumes consumesEntry = (Consumes) iterator.next();

+                       resolveMapEntry(namespaceMap, 
consumesEntry.getInterfaceName(),

+                                       namespaceCounter);

+                       resolveMapEntry(namespaceMap, 
consumesEntry.getServiceName(),

+                                       namespaceCounter);

+               }

+       

+               return namespaceMap;

+       }

+

+       private void resolveMapEntry(Map namespaceMap, QName qname, int 
namespaceCounter) {

+               if ((qname != null)

+                               && 
(!namespaceMap.containsKey(qname.getNamespaceURI()))) {

+                       if (qname.getPrefix() == null || 
qname.getPrefix().equals("") ) {

+                               namespaceMap.put(qname.getNamespaceURI(), "ns"

+                                               + namespaceCounter++);

+                       } else

+                               namespaceMap.put(qname.getNamespaceURI(), 
qname.getPrefix());

+               }

+       }

+

+}
\ No newline at end of file

Modified: 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyDescriptorMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyDescriptorMojo.java?view=diff&rev=443357&r1=443356&r2=443357
==============================================================================
--- 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyDescriptorMojo.java
 (original)
+++ 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceAssemblyDescriptorMojo.java
 Thu Sep 14 06:55:30 2006
@@ -24,6 +24,9 @@
 import java.util.List;
 import java.util.Set;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.model.Dependency;
@@ -33,7 +36,13 @@
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingException;
+import org.apache.servicemix.common.packaging.Consumes;
+import org.apache.servicemix.common.packaging.Provides;
 import org.codehaus.plexus.util.FileUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  * A Mojo used to build the jbi.xml file for a service unit.
@@ -48,6 +57,30 @@
  */
 public class GenerateServiceAssemblyDescriptorMojo extends AbstractJbiMojo {
 
+       private static final String JBI_NAMESPACE = 
"http://java.sun.com/xml/ns/jbi";;
+
+       public class Connection {
+               private Consumes consumes;
+
+               private Provides provides;
+
+               public Consumes getConsumes() {
+                       return consumes;
+               }
+
+               public void setConsumes(Consumes consumes) {
+                       this.consumes = consumes;
+               }
+
+               public Provides getProvides() {
+                       return provides;
+               }
+
+               public void setProvides(Provides provides) {
+                       this.provides = provides;
+               }
+       }
+
        public static final String UTF_8 = "UTF-8";
 
        /**
@@ -86,6 +119,14 @@
        private String generatedDescriptorLocation;
 
        /**
+        * The location of a file containing the connections elements that can 
be
+        * merged into the jbi.xml
+        * 
+        * @parameter 
expression="${basedir}/src/main/resources/jbi-connections.xml"
+        */
+       private File jbiConnectionsFile;
+
+       /**
         * Dependency graph
         */
        private JbiResolutionListener listener;
@@ -180,9 +221,105 @@
 
                List orderedServiceUnits = reorderServiceUnits(serviceUnits);
 
+               List connections = getConnections();
+
                JbiServiceAssemblyDescriptorWriter writer = new 
JbiServiceAssemblyDescriptorWriter(
                                encoding);
-               writer.write(descriptor, name, description, 
orderedServiceUnits);
+               writer.write(descriptor, name, description, orderedServiceUnits,
+                               connections);
+       }
+
+       /**
+        * Used to return a list of connections if they have been found in the
+        * jbiConnectionsFile
+        * 
+        * @return A list of connections
+        * @throws MojoExecutionException
+        */
+       private List getConnections() throws MojoExecutionException {
+
+               if (jbiConnectionsFile.exists())
+                       return parseConnectionsXml();
+               else
+                       return new ArrayList();
+       }
+
+       /**
+        * Parse the jbiConnectionsFile
+        * 
+        * @return
+        * @throws MojoExecutionException
+        */
+       private List parseConnectionsXml() throws MojoExecutionException {
+               getLog().info(
+                               "Picking up connections from "
+                                               + 
jbiConnectionsFile.getAbsolutePath());
+               List connections = new ArrayList();
+               try {
+                       DocumentBuilderFactory dbf = 
DocumentBuilderFactory.newInstance();
+                       dbf.setNamespaceAware(true);
+                       DocumentBuilder db = dbf.newDocumentBuilder();
+                       Document doc = db.parse(jbiConnectionsFile);
+
+                       Node servicesNode = doc.getFirstChild();
+                       if (servicesNode instanceof Element) {                  
        
+                               if (XmlDescriptorHelper.isElement(servicesNode, 
JBI_NAMESPACE,
+                                               "connections")) {
+                                       // We will process the children
+                                       Element servicesElement = (Element) 
servicesNode;
+                                       NodeList children = 
servicesElement.getChildNodes();
+                                       for (int i = 0; i < 
children.getLength(); i++) {
+                                               if 
(XmlDescriptorHelper.isElement(children.item(i),
+                                                               JBI_NAMESPACE, 
"connection")) {
+                                                       Connection connection = 
new Connection();
+                                                       NodeList 
connectionChildren = children.item(i)
+                                                                       
.getChildNodes();
+                                                       for (int x = 0; x < 
connectionChildren.getLength(); x++) {
+                                                               if 
(connectionChildren.item(x) instanceof Element) {
+                                                                       Element 
childElement = (Element) connectionChildren
+                                                                               
        .item(x);
+                                                                       if 
(XmlDescriptorHelper.isElement(childElement,
+                                                                               
        JBI_NAMESPACE,
+                                                                               
        "consumer")) {
+                                                                               
Consumes newConsumes = new Consumes();
+                                                                               
newConsumes
+                                                                               
                .setEndpointName(XmlDescriptorHelper
+                                                                               
                                .getEndpointName(childElement));
+                                                                               
newConsumes
+                                                                               
                .setInterfaceName(XmlDescriptorHelper
+                                                                               
                                .getInterfaceName(childElement));
+                                                                               
newConsumes
+                                                                               
                .setServiceName(XmlDescriptorHelper
+                                                                               
                                .getServiceName(childElement));
+                                                                               
connection.setConsumes(newConsumes);
+                                                                       } else 
if (XmlDescriptorHelper.isElement(childElement,
+                                                                               
        JBI_NAMESPACE,
+                                                                               
        "provider")) {
+                                                                               
Provides newProvides = new Provides();
+                                                                               
newProvides
+                                                                               
                .setEndpointName(XmlDescriptorHelper
+                                                                               
                                .getEndpointName(childElement));
+                                                                               
newProvides
+                                                                               
                .setInterfaceName(XmlDescriptorHelper
+                                                                               
                                .getInterfaceName(childElement));
+                                                                               
newProvides
+                                                                               
                .setServiceName(XmlDescriptorHelper
+                                                                               
                                .getServiceName(childElement));
+                                                                               
connection.setProvides(newProvides);
+                                                                       }
+                                                               }
+                                                       }
+                                                       
connections.add(connection);
+                                               }
+                                       }
+                               }
+                       }
+                       getLog().info("Found " + connections.size() + " 
connections");
+                       return connections;
+               } catch (Exception e) {
+                       throw new MojoExecutionException("Unable to parse "
+                                       + jbiConnectionsFile.getAbsolutePath());
+               }
        }
 
        /**
@@ -203,8 +340,8 @@
                // project.getModel().getDependencies().iterator();
 
                // For now we will need to reparse the pom without processing
-               Iterator dependencies = getReparsedDependencies();              
-               
+               Iterator dependencies = getReparsedDependencies();
+
                List orderedServiceUnits = new ArrayList();
                while (dependencies.hasNext()) {
                        Dependency dependency = (Dependency) 
dependencies.next();

Modified: 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java?view=diff&rev=443357&r1=443356&r2=443357
==============================================================================
--- 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
 (original)
+++ 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitDescriptorMojo.java
 Thu Sep 14 06:55:30 2006
@@ -33,6 +33,8 @@
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingException;
+import org.apache.servicemix.common.packaging.Consumes;
+import org.apache.servicemix.common.packaging.Provides;
 import org.apache.servicemix.common.packaging.ServiceUnitAnalyzer;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
@@ -206,11 +208,12 @@
                                getLog().info(
                                                "Created Service Unit Analyzer 
" + serviceUnitAnalyzer);
                                
serviceUnitAnalyzer.init(serviceUnitArtifactsDir);
-                               
+
                                // Need to determine whether we are using the 
dummy analyzer
                                // if so we need to give it the services file
                                if (serviceUnitAnalyzer instanceof 
JbiServiceFileAnalyzer) {
-                                       
((JbiServiceFileAnalyzer)serviceUnitAnalyzer).setJbiServicesFile(jbiServicesFile);
+                                       ((JbiServiceFileAnalyzer) 
serviceUnitAnalyzer)
+                                                       
.setJbiServicesFile(jbiServicesFile);
                                }
                                
consumes.addAll(serviceUnitAnalyzer.getConsumes());
                                
provides.addAll(serviceUnitAnalyzer.getProvides());

Modified: 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java?view=diff&rev=443357&r1=443356&r2=443357
==============================================================================
--- 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java
 (original)
+++ 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceAssemblyDescriptorWriter.java
 Thu Sep 14 06:55:30 2006
@@ -20,9 +20,12 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
+import 
org.apache.servicemix.maven.plugin.jbi.GenerateServiceAssemblyDescriptorMojo.Connection;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 import org.codehaus.plexus.util.xml.XMLWriter;
 
@@ -30,7 +33,8 @@
  * Helper that can be used to write the jbi.xml for a service assembly
  * 
  */
-public class JbiServiceAssemblyDescriptorWriter {
+public class JbiServiceAssemblyDescriptorWriter extends
+               AbstractDescriptorWriter {
 
        private final String encoding;
 
@@ -39,7 +43,7 @@
        }
 
        public void write(File descriptor, String name, String description,
-                       List uris) throws JbiPluginException {
+                       List uris, List connections) throws JbiPluginException {
                FileWriter w;
                try {
                        w = new FileWriter(descriptor);
@@ -71,10 +75,65 @@
 
                }
 
+               if (!connections.isEmpty()) {
+                       writer.startElement("connections");
+
+                       Map namespaceMap = buildNamespaceMap(connections);
+                       for (Iterator it = connections.iterator(); 
it.hasNext();) {
+                               
GenerateServiceAssemblyDescriptorMojo.Connection connection = 
(GenerateServiceAssemblyDescriptorMojo.Connection) it
+                                               .next();
+                               writeConnection(namespaceMap, writer, 
connection);
+
+                       }
+                       writer.endElement();
+               }
+
                writer.endElement();
                writer.endElement();
 
                close(w);
+       }
+
+       private Map buildNamespaceMap(List connections) {
+               List consumes = new ArrayList();
+               List provides = new ArrayList();
+               for (Iterator it = connections.iterator(); it.hasNext();) {
+                       GenerateServiceAssemblyDescriptorMojo.Connection 
connection = (GenerateServiceAssemblyDescriptorMojo.Connection) it
+                                       .next();
+                       consumes.add(connection.getConsumes());
+                       provides.add(connection.getProvides());
+               }
+
+               return getNamespaceMap(provides, consumes);
+
+       }
+
+       private void writeConnection(Map namespaceMap, XMLWriter writer,
+                       Connection connection) {
+               writer.startElement("connection");
+               if (connection.getConsumes() != null) {
+                       writer.startElement("consumer");
+                       addQNameAttribute(writer, "interface-name", connection
+                                       .getConsumes().getInterfaceName(), 
namespaceMap);
+                       addQNameAttribute(writer, "service-name", 
connection.getConsumes()
+                                       .getServiceName(), namespaceMap);
+                       addStringAttribute(writer, "endpoint-name", connection
+                                       .getConsumes().getEndpointName());
+                       writer.endElement();
+               }
+               if (connection.getProvides() != null) {
+                       writer.startElement("provider");
+                       addQNameAttribute(writer, "interface-name", connection
+                                       .getProvides().getInterfaceName(), 
namespaceMap);
+                       addQNameAttribute(writer, "service-name", 
connection.getProvides()
+                                       .getServiceName(), namespaceMap);
+                       addStringAttribute(writer, "endpoint-name", connection
+                                       .getProvides().getEndpointName());
+                       writer.endElement();
+               }
+
+               writer.endElement();
+
        }
 
        private void writeServiceUnit(XMLWriter writer,

Modified: 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java?view=diff&rev=443357&r1=443356&r2=443357
==============================================================================
--- 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
 (original)
+++ 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceFileAnalyzer.java
 Thu Sep 14 06:55:30 2006
@@ -20,7 +20,6 @@
 import java.util.ArrayList;

 import java.util.List;

 

-import javax.xml.namespace.QName;

 import javax.xml.parsers.DocumentBuilder;

 import javax.xml.parsers.DocumentBuilderFactory;

 

@@ -44,6 +43,8 @@
 

        List provides = new ArrayList();

 

+       private static final String JBI_NAMESPACE = 
"http://java.sun.com/xml/ns/jbi";;

+

        public List getConsumes() {

                return consumes;

        }

@@ -69,75 +70,42 @@
                        Document doc = db.parse(jbiServicesFile);

 

                        Node servicesNode = doc.getFirstChild();

-                       if (servicesNode instanceof Element) {

-                               if (((Element) 
servicesNode).getNodeName().equals("services")) {

-                                       // We will process the children

-                                       Element servicesElement = (Element) 
servicesNode;

-                                       NodeList children = 
servicesElement.getChildNodes();

-                                       for (int i = 0; i < 
children.getLength(); i++) {

-                                               if (children.item(i) instanceof 
Element) {

-                                                       Element childElement = 
(Element) children.item(i);

-                                                       if 
(childElement.getNodeName().equals("consumes")) {

-                                                               Consumes 
newConsumes = new Consumes();

-                                                               newConsumes

-                                                                               
.setEndpointName(getEndpointName(childElement));

-                                                               newConsumes

-                                                                               
.setInterfaceName(getInterfaceName(childElement));

-                                                               newConsumes

-                                                                               
.setServiceName(getServiceName(childElement));

-                                                               
consumes.add(newConsumes);

-                                                       } else if 
(childElement.getNodeName().equals(

-                                                                       
"provides")) {

-                                                               Provides 
newProvides = new Provides();

-                                                               newProvides

-                                                                               
.setEndpointName(getEndpointName(childElement));

-                                                               newProvides

-                                                                               
.setInterfaceName(getInterfaceName(childElement));

-                                                               newProvides

-                                                                               
.setServiceName(getServiceName(childElement));

-                                                               
provides.add(newProvides);

-                                                       }

+                       if (XmlDescriptorHelper.isElement(servicesNode, 
JBI_NAMESPACE,

+                                       "services")) {

+                               // We will process the children

+                               Element servicesElement = (Element) 
servicesNode;

+                               NodeList children = 
servicesElement.getChildNodes();

+                               for (int i = 0; i < children.getLength(); i++) {

+                                       if (children.item(i) instanceof 
Element) {

+                                               Element childElement = 
(Element) children.item(i);

+                                               if 
(XmlDescriptorHelper.isElement(childElement,

+                                                               JBI_NAMESPACE, 
"consumes")) {

+                                                       Consumes newConsumes = 
new Consumes();

+                                                       
newConsumes.setEndpointName(XmlDescriptorHelper

+                                                                       
.getEndpointName(childElement));

+                                                       
newConsumes.setInterfaceName(XmlDescriptorHelper

+                                                                       
.getInterfaceName(childElement));

+                                                       
newConsumes.setServiceName(XmlDescriptorHelper

+                                                                       
.getServiceName(childElement));

+                                                       
consumes.add(newConsumes);

+                                               } else if 
(XmlDescriptorHelper.isElement(childElement,

+                                                               JBI_NAMESPACE, 
"provides")) {

+                                                       Provides newProvides = 
new Provides();

+                                                       
newProvides.setEndpointName(XmlDescriptorHelper

+                                                                       
.getEndpointName(childElement));

+                                                       
newProvides.setInterfaceName(XmlDescriptorHelper

+                                                                       
.getInterfaceName(childElement));

+                                                       
newProvides.setServiceName(XmlDescriptorHelper

+                                                                       
.getServiceName(childElement));

+                                                       
provides.add(newProvides);

                                                }

                                        }

                                }

                        }

+

                } catch (Exception e) {

                        throw new MojoExecutionException("Unable to parse "

                                        + jbiServicesFile.getAbsolutePath());

                }

-

-       }

-

-       private QName getServiceName(Element childElement) {

-               if (childElement.hasAttribute("service-name")) {

-                       String prefixAndLocalPart = childElement

-                                       .getAttribute("service-name");

-                       String prefix = prefixAndLocalPart.substring(0, 
prefixAndLocalPart

-                                       .indexOf(':'));

-                       String localPart = 
prefixAndLocalPart.substring(prefixAndLocalPart

-                                       .indexOf(':')+1);

-                       return new 
QName(childElement.lookupNamespaceURI(prefix), localPart);

-               }

-               return null;

-       }

-

-       private QName getInterfaceName(Element childElement) {

-               if (childElement.hasAttribute("interface-name")) {

-                       String prefixAndLocalPart = childElement

-                                       .getAttribute("interface-name");

-                       String prefix = prefixAndLocalPart.substring(0, 
prefixAndLocalPart

-                                       .indexOf(':'));

-                       String localPart = 
prefixAndLocalPart.substring(prefixAndLocalPart

-                                       .indexOf(':')+1);

-                       return new 
QName(childElement.lookupNamespaceURI(prefix), localPart);

-               }

-               return null;

-       }

-

-       private String getEndpointName(Element childElement) {

-               if (childElement.hasAttribute("endpoint-name")) {

-                       return childElement.getAttribute("endpoint-name");

-               }

-               return null;

        }

 }


Modified: 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java?view=diff&rev=443357&r1=443356&r2=443357
==============================================================================
--- 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java
 (original)
+++ 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiServiceUnitDescriptorWriter.java
 Thu Sep 14 06:55:30 2006
@@ -36,7 +36,7 @@
  * Helper that is used to write the jbi.xml for a service unit
  * 
  */
-public class JbiServiceUnitDescriptorWriter {
+public class JbiServiceUnitDescriptorWriter extends AbstractDescriptorWriter {
 
        private final String encoding;
 
@@ -109,59 +109,6 @@
                writer.endElement();
 
                close(w);
-       }
-
-       private void addStringAttribute(XMLWriter writer, String attributeName,
-                       String attributeValue) {
-               if (attributeValue != null)
-                       writer.addAttribute(attributeName, attributeValue);
-       }
-
-       private void addQNameAttribute(XMLWriter writer, String attributeName,
-                       QName attributeValue, Map namespaceMap) {               
-               if (attributeValue != null) {
-                       StringBuffer attributeStringValue = new StringBuffer();
-                       
attributeStringValue.append(namespaceMap.get(attributeValue
-                                       .getNamespaceURI()));
-                       attributeStringValue.append(":");
-                       
attributeStringValue.append(attributeValue.getLocalPart());
-                       writer.addAttribute(attributeName, 
attributeStringValue.toString());
-               }
-
-       }
-
-       private Map getNamespaceMap(List provides, List consumes) {
-               Map namespaceMap = new HashMap();
-               int namespaceCounter = 1;
-               for (Iterator iterator = provides.iterator(); 
iterator.hasNext();) {
-                       Provides providesEntry = (Provides) iterator.next();
-                       resolveMapEntry(namespaceMap, 
providesEntry.getInterfaceName(),
-                                       namespaceCounter);
-                       resolveMapEntry(namespaceMap, 
providesEntry.getServiceName(),
-                                       namespaceCounter);
-               }
-
-               for (Iterator iterator = consumes.iterator(); 
iterator.hasNext();) {
-                       Consumes consumesEntry = (Consumes) iterator.next();
-                       resolveMapEntry(namespaceMap, 
consumesEntry.getInterfaceName(),
-                                       namespaceCounter);
-                       resolveMapEntry(namespaceMap, 
consumesEntry.getServiceName(),
-                                       namespaceCounter);
-               }
-
-               return namespaceMap;
-       }
-
-       private void resolveMapEntry(Map namespaceMap, QName qname,
-                       int namespaceCounter) {
-               if ((qname != null)
-                               && 
(!namespaceMap.containsKey(qname.getNamespaceURI()))) {
-                       if (qname.getPrefix() == null || 
qname.getPrefix().equals("") ) {
-                               namespaceMap.put(qname.getNamespaceURI(), "ns"
-                                               + namespaceCounter++);
-                       } else
-                               namespaceMap.put(qname.getNamespaceURI(), 
qname.getPrefix());
-               }
        }
 
        private void close(Writer closeable) {

Added: 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/XmlDescriptorHelper.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/XmlDescriptorHelper.java?view=auto&rev=443357
==============================================================================
--- 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/XmlDescriptorHelper.java
 (added)
+++ 
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/XmlDescriptorHelper.java
 Thu Sep 14 06:55:30 2006
@@ -0,0 +1,69 @@
+package org.apache.servicemix.maven.plugin.jbi;

+

+import javax.xml.namespace.QName;

+

+import org.w3c.dom.Element;

+import org.w3c.dom.Node;

+

+public class XmlDescriptorHelper {

+

+       public static QName getServiceName(Element childElement) {

+               if (childElement.hasAttribute("service-name")) {

+                       String prefixAndLocalPart = childElement

+                                       .getAttribute("service-name");

+                       String prefix = prefixAndLocalPart.substring(0, 
prefixAndLocalPart

+                                       .indexOf(':'));

+                       String localPart = 
prefixAndLocalPart.substring(prefixAndLocalPart

+                                       .indexOf(':') + 1);

+                       return new 
QName(childElement.lookupNamespaceURI(prefix), localPart);

+               }

+               return null;

+       }

+

+       public static QName getInterfaceName(Element childElement) {

+               if (childElement.hasAttribute("interface-name")) {

+                       String prefixAndLocalPart = childElement

+                                       .getAttribute("interface-name");

+                       String prefix = prefixAndLocalPart.substring(0, 
prefixAndLocalPart

+                                       .indexOf(':'));

+                       String localPart = 
prefixAndLocalPart.substring(prefixAndLocalPart

+                                       .indexOf(':') + 1);

+                       return new 
QName(childElement.lookupNamespaceURI(prefix), localPart);

+               }

+               return null;

+       }

+

+       public static boolean isElement(Node node, String namespaceUrl,

+                       String localPart) {

+               if (node instanceof Element) {

+                       Element element = (Element) node;

+                       System.out.println("Got Element nodeName:" + 
element.getNodeName()

+                                       + " namespaceUri:" + 
element.getNamespaceURI()

+                                       + " localName:" + 
element.getLocalName());

+                       if (localPart.equals(element.getNodeName()))

+                               return true;

+                       else {

+                               // Compare the namespace URI and localname

+                               System.out.println(namespaceUrl + "="

+                                               + element.getNamespaceURI() + " 
is "

+                                               + 
namespaceUrl.equals(element.getNamespaceURI()));

+                               System.out.println(localPart + "="

+                                               + element.getLocalName() + " is 
"

+                                               + 
localPart.equals(element.getLocalName()));

+                               if 
((namespaceUrl.equals(element.getNamespaceURI()))

+                                               && 
(localPart.equals(element.getLocalName()))) {

+                                       return true;

+                               }

+                       }

+               }

+               return false;

+       }

+

+       public static String getEndpointName(Element childElement) {

+               if (childElement.hasAttribute("endpoint-name")) {

+                       return childElement.getAttribute("endpoint-name");

+               }

+               return null;

+       }

+

+}



Reply via email to