[Registry-dev] svn commit r16609 - in trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin: . utils

svn at wso2.org svn at wso2.org
Wed May 7 02:43:18 PDT 2008


Author: amila
Date: Wed May  7 02:43:13 2008
New Revision: 16609

Log:

added the wsdl and schema dependencies


Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/WSDLMediaTypeHandler.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/XSDMediaTypeHandler.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/SchemaFileProcessor.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/WSDLFileProcessor.java

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/WSDLMediaTypeHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/WSDLMediaTypeHandler.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/WSDLMediaTypeHandler.java	Wed May  7 02:43:13 2008
@@ -33,7 +33,7 @@
     public void setRepository(Repository repository) {
         super.setRepository(repository);
 
-        wsdlFileProcessor = new WSDLFileProcessor(repository);
+        wsdlFileProcessor = new WSDLFileProcessor(repository, this.registry);
     }
 
     public Resource get(RequestContext requestContext) throws RegistryException {

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/XSDMediaTypeHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/XSDMediaTypeHandler.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/XSDMediaTypeHandler.java	Wed May  7 02:43:13 2008
@@ -33,7 +33,7 @@
     public void setRepository(Repository repository) {
         super.setRepository(repository);
 
-        schemaFileProcessor = new SchemaFileProcessor(repository);
+        schemaFileProcessor = new SchemaFileProcessor(repository, this.registry);
     }
 
     public Resource get(RequestContext requestContext) throws RegistryException {

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/SchemaFileProcessor.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/SchemaFileProcessor.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/SchemaFileProcessor.java	Wed May  7 02:43:13 2008
@@ -18,10 +18,7 @@
 
 import org.wso2.registry.jdbc.mediatypes.builtin.DefaultMediaTypeHandler;
 import org.wso2.registry.jdbc.Repository;
-import org.wso2.registry.Resource;
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.ResourceImpl;
-import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.*;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
@@ -35,11 +32,14 @@
 
     private Repository repository;
 
+    private Registry registry;
+
     // remove this when it is not needed
     private int i;
 
-    public SchemaFileProcessor(Repository repository) {
+    public SchemaFileProcessor(Repository repository, Registry registry) {
         this.repository = repository;
+        this.registry = registry;
     }
 
     /**
@@ -185,6 +185,7 @@
                                          boolean processIncludes,
                                          Resource metadata) throws RegistryException {
 
+        List associations = new ArrayList();
         if (processIncludes) {
             // first process the imports and includes
             XmlSchemaObjectCollection includes = xmlSchema.getIncludes();
@@ -209,9 +210,14 @@
                         if (isWSDLInlineSchema) {
                             changeSchemaNames.put(xmlSchemaExternal.getSchemaLocation(),
                                                   newLocation);
+                        } else {
+
                         }
                         // set the new location
                         xmlSchemaExternal.setSchemaLocation(newLocation);
+                        String innerFileNameToSave = (String) processedSchemaMap.get(sourceURI);
+                        String innerXSDPath = getXSDPath(registryBasePath, innerFileNameToSave);
+                        associations.add(innerXSDPath);
                     }
                 }
             }
@@ -224,28 +230,35 @@
             xmlSchema.write(byteArrayOutputStream);
             byte[] xsdContent = byteArrayOutputStream.toByteArray();
 
-            ResourceImpl xsdResource = new ResourceImpl();
+            Resource xsdResource = new ResourceImpl();
             if (metadata != null) {
                 xsdResource.setMediaType(metadata.getMediaType());
                 xsdResource.setDescription(metadata.getDescription());
             }
             xsdResource.setContent(xsdContent);
 
-            String xsdPath;
-            if (RegistryConstants.ROOT_PATH.equals(registryBasePath)) {
-                xsdPath = RegistryConstants.ROOT_PATH + fileNameToSave;
-            } else {
-                xsdPath = registryBasePath + RegistryConstants.PATH_SEPARATOR + fileNameToSave;
-            }
+            String xsdPath = getXSDPath(registryBasePath, fileNameToSave);
             String targetNamespace = xmlSchema.getTargetNamespace();
             xsdResource.addProperty("TargetNameSpace" ,targetNamespace);
 
             repository.put(xsdPath, xsdResource);
 
+            String associationPath;
+            for (Iterator iter = associations.iterator();iter.hasNext();){
+                 associationPath = (String) iter.next();
+                 this.registry.addAssociation("depends", xsdPath, associationPath);
+            }
+
+        }
+    }
 
-            //xmlSchema.write(new FileOutputStream("repository/" + fileNameToSave),
-            //                getDefaultOptionMap());
-            // add this entry to the proccessed wsdl map
+    private String getXSDPath(String registryBasePath, String fileNameToSave) {
+        String xsdPath;
+        if (RegistryConstants.ROOT_PATH.equals(registryBasePath)) {
+            xsdPath = RegistryConstants.ROOT_PATH + fileNameToSave;
+        } else {
+            xsdPath = registryBasePath + RegistryConstants.PATH_SEPARATOR + fileNameToSave;
         }
+        return xsdPath;
     }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/WSDLFileProcessor.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/WSDLFileProcessor.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/WSDLFileProcessor.java	Wed May  7 02:43:13 2008
@@ -17,10 +17,7 @@
 package org.wso2.registry.jdbc.handlers.builtin.utils;
 
 import org.wso2.registry.jdbc.Repository;
-import org.wso2.registry.Resource;
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.RegistryConstants;
-import org.wso2.registry.ResourceImpl;
+import org.wso2.registry.*;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.w3c.dom.Element;
@@ -48,9 +45,11 @@
     public static final String INCLUDE_TAG = "include";
 
     Repository repository;
+    Registry registry;
 
-    public WSDLFileProcessor(Repository repository) {
+    public WSDLFileProcessor(Repository repository, Registry registry) {
         this.repository = repository;
+        this.registry = registry;
     }
 
     /**
@@ -159,7 +158,7 @@
                     xmlSchemaCollection = new XmlSchemaCollection();
                     xmlSchemaCollection.setBaseUri(basuri);
                     xmlSchema = xmlSchemaCollection.read(schemaExtension.getElement());
-                    schemaFileProcessor = new SchemaFileProcessor(repository);
+                    schemaFileProcessor = new SchemaFileProcessor(repository, this.registry);
                     changedLocationMap = new HashMap();
                     schemaFileProcessor.calculateNewSchemaNames(
                             xmlSchema, processedScheamMap, new HashSet(), true, processImports);
@@ -192,7 +191,7 @@
                                        String registryBasePath,
                                        boolean processImports,
                                        Resource metadata) throws RegistryException {
-
+        List associations = new ArrayList();
         if (processImports) {
             // first we have to process the imports and change the
             // schema locations suite for the registry
@@ -215,6 +214,11 @@
                     // set the import location according to the new location
                     wsdlImport.setLocationURI((String)processedWSDLMap.get(
                             innerDefinition.getDocumentBaseURI()));
+                    // add this wsdl as an association
+                    String innerImportedResourceName =
+                            (String) processedWSDLMap.get(innerDefinition.getDocumentBaseURI());
+                    String innerWsdlPath = getWSDLPath(registryBasePath, innerImportedResourceName);
+                    associations.add(innerWsdlPath);
                 }
             }
         }
@@ -231,14 +235,8 @@
 
             // create a resource this wsdlResourceContent and put it to the registry with the name importedResourceName (in some path)
 
-            String wsdlPath;
-            if (RegistryConstants.ROOT_PATH.equals(registryBasePath)) {
-                wsdlPath = RegistryConstants.ROOT_PATH + importedResourceName;
-            } else {
-                wsdlPath =
-                        registryBasePath + RegistryConstants.PATH_SEPARATOR + importedResourceName;
-            }
-            ResourceImpl wsdlResource = new ResourceImpl();
+            String wsdlPath = getWSDLPath(registryBasePath, importedResourceName);
+            Resource wsdlResource = new ResourceImpl();
 
             if (metadata != null) {
                 wsdlResource.setMediaType(metadata.getMediaType());
@@ -246,25 +244,49 @@
             }
 
             // getting the paramentes
-            String targetNamespace = wsdlDefinition.getTargetNamespace();
-            String name = wsdlDefinition.getQName().getLocalPart();
-            String document = wsdlDefinition.getDocumentationElement().getTextContent();
-            wsdlResource.addProperty("TargetNamespace" ,targetNamespace);
-            if (name != null) {
-                wsdlResource.addProperty("Name" ,name);
+            if (wsdlDefinition.getQName() != null) {
+                String name = wsdlDefinition.getQName().getLocalPart();
+                if (name != null) {
+                    wsdlResource.addProperty("Name", name);
+                }
             }
-            if (document != null) {
-                wsdlResource.addProperty("documentation" ,document);
+
+            if (wsdlDefinition.getDocumentationElement() != null) {
+                String document = wsdlDefinition.getDocumentationElement().getTextContent();
+                if (document != null) {
+                    wsdlResource.addProperty("documentation", document);
+                }
             }
+
+            String targetNamespace = wsdlDefinition.getTargetNamespace();
+            wsdlResource.addProperty("TargetNamespace" ,targetNamespace);
+
             wsdlResource.setContent(wsdlResourceContent);
 
             repository.put(wsdlPath, wsdlResource);
 
+            // add the associations
+            String associatedWSDL = null;
+            for (Iterator iter = associations.iterator(); iter.hasNext();) {
+                associatedWSDL = (String) iter.next();
+                this.registry.addAssociation("depends", wsdlPath, associatedWSDL);
+            }
+
         } catch (WSDLException e) {
             throw new RegistryException("Invalid WSDL file");
         }
     }
 
+    private String getWSDLPath(String registryBasePath, String importedResourceName) {
+        String wsdlPath;
+        if (RegistryConstants.ROOT_PATH.equals(registryBasePath)) {
+            wsdlPath = RegistryConstants.ROOT_PATH + importedResourceName;
+        } else {
+            wsdlPath = registryBasePath + RegistryConstants.PATH_SEPARATOR + importedResourceName;
+        }
+        return wsdlPath;
+    }
+
     private void changeLocations(Element element, Map changedLocationMap) {
         NodeList nodeList = element.getChildNodes();
         String tagName;



More information about the Registry-dev mailing list