Author: keith
Date: Thu May  1 22:42:26 2008
New Revision: 16454

Log:

Adding a service to take care of dataServices deployment for the Mashup server


Added:
   
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupDataServiceAdmin.java
Modified:
   trunk/mashup/java/modules/admin/service/META-INF/services.xml

Modified: trunk/mashup/java/modules/admin/service/META-INF/services.xml
==============================================================================
--- trunk/mashup/java/modules/admin/service/META-INF/services.xml       
(original)
+++ trunk/mashup/java/modules/admin/service/META-INF/services.xml       Thu May 
 1 22:42:26 2008
@@ -43,4 +43,11 @@
         <parameter 
name="ServiceClass">org.wso2.mashup.admin.service.MashupAdminService</parameter>
         <schema schemaNamespace="http://service.admin.mashup.wso2.org/xsd"/>
     </service>
+    <service name="MashupDataServiceAdmin" scope="transportsession">
+        <Description>
+            This service is used to do dataservices related stuff for the 
Mashup Server.
+        </Description>
+        <parameter 
name="ServiceClass">org.wso2.mashup.admin.service.MashupDataServiceAdmin</parameter>
+        <schema schemaNamespace="http://org.apache.axis2/xsd"/>
+    </service>
 </serviceGroup>
\ No newline at end of file

Added: 
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupDataServiceAdmin.java
==============================================================================
--- (empty file)
+++ 
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupDataServiceAdmin.java
       Thu May  1 22:42:26 2008
@@ -0,0 +1,148 @@
+package org.wso2.mashup.admin.service;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.description.AxisService;
+import org.wso2.wsas.admin.service.util.DataServiceInfo;
+import org.wso2.wsas.admin.service.util.DBServerData;
+import org.wso2.ws.dataservice.DBConstants;
+import org.wso2.mashup.MashupConstants;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import java.util.Iterator;
+import java.io.File;
+import java.io.IOException;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+
+public class MashupDataServiceAdmin extends 
org.wso2.wsas.admin.service.DataServiceAdmin {
+
+    public void saveDataServiceContents(OMElement dataWrapper) throws 
AxisFault {
+
+        String serviceId;
+        MessageContext msgCtx = MessageContext.getCurrentMessageContext();
+        ServiceGroupContext sgCtx = msgCtx.getServiceGroupContext();
+        String username = (String) 
sgCtx.getProperty(MashupConstants.LOGGED_IN_USER_NAME);
+        OMFactory omFactory = OMAbstractFactory.getOMFactory();
+        OMElement configEle = dataWrapper.getFirstChildWithName(new 
QName("data"));
+        if (configEle == null) {
+            throw new AxisFault("Data Service configuration start element 
<data/> is not found");
+        }
+        OMAttribute attribute = configEle.getAttribute(new QName("name"));
+        serviceId = attribute.getAttributeValue();
+        if (serviceId == null) {
+            throw new AxisFault(
+                    "Data Service configuration cannot be continued due to 
missing Data Service name");
+        }
+
+        for (Iterator queries = configEle.getChildrenWithName(new 
QName("query"));
+             queries.hasNext();) {
+            OMElement query = (OMElement) queries.next();
+
+            for (Iterator results = query.getChildrenWithName(new 
QName("result"));
+                 results.hasNext();) {
+                OMElement result = (OMElement) results.next();
+                // Only selected if the all simple version is returned from the
+                // client.
+                OMAttribute rowNameAttribute = result.getAttribute(new 
QName("rowname"));
+                if (rowNameAttribute != null) {
+                    String attValue = rowNameAttribute.getAttributeValue();
+                    result.removeAttribute(rowNameAttribute);
+                    result.addAttribute(omFactory.createOMAttribute(
+                            "rowName", omFactory.createOMNamespace("", ""),
+                            attValue));
+                }
+            }
+
+            for (Iterator params = query.getChildrenWithName(new 
QName("param"));
+                 params.hasNext();) {
+                OMElement param = (OMElement) params.next();
+                // Only selected if the all simple version is returned from the
+                // client.
+                OMAttribute sqlTypeAttribute = param.getAttribute(new 
QName("sqltype"));
+                if (sqlTypeAttribute != null) {
+                    String attValue = sqlTypeAttribute.getAttributeValue();
+                    param.removeAttribute(sqlTypeAttribute);
+                    param.addAttribute(omFactory.createOMAttribute(
+                            "sqlType", omFactory.createOMNamespace("", ""),
+                            attValue));
+                }
+            }
+        }
+
+        String dataServiceFilePath;
+        AxisService axisService = getAxisConfig().getService(serviceId);
+        if (axisService == null) {
+            // New service
+            String axis2RepoDirectory = 
getAxisConfig().getRepository().getPath();
+
+            String dataServiceDirectory = axis2RepoDirectory + File.separator 
+ "scripts" +
+                    File.separator + username;
+            dataServiceFilePath = dataServiceDirectory + File.separator
+                    + serviceId + ".dbs";
+
+            File file = new File(dataServiceFilePath);
+            try {
+                file.createNewFile();
+            } catch (IOException e) {
+                throw new AxisFault(
+                        "Error while creating the file for the new service 
config file for the new service "
+                                + serviceId, e);
+            }
+
+        } else {
+            dataServiceFilePath =
+                    (String) 
axisService.getParameter(DBConstants.DB_SERVICE_CONFIG_FILE)
+                            .getValue();
+        }
+
+        try {
+            BufferedWriter out = new BufferedWriter(new 
FileWriter(dataServiceFilePath));
+            configEle.serialize(out);
+            out.close();
+        } catch (IOException e) {
+            throw new AxisFault(
+                    "Error while writing the contents for the service config 
file for the new service "
+                            + serviceId, e);
+        } catch (XMLStreamException e) {
+
+            throw new AxisFault("Error while serializing the config OMElement 
for the service "
+                    + serviceId, e);
+
+        }
+
+    }
+
+    public DataServiceInfo getDSMetaData(String init) throws AxisFault {
+        return super.getDSMetaData(
+                init);
+    }
+
+    public OMElement getDataServiceContents(String serviceId) throws AxisFault 
{
+        return super.getDataServiceContents(
+                serviceId);
+    }
+
+    public DBServerData[] getDatabaseUrlDriverList() {
+        return super
+                .getDatabaseUrlDriverList();
+    }
+
+    public String[] getHeaderColumnNames(String resourcePath, String 
hasHeaders,
+                                         String dataSourceType) {
+        return super.getHeaderColumnNames(resourcePath, hasHeaders,
+                                          dataSourceType);
+    }
+
+    public String testJDBCConnection(String driverClass, String jdbcURL, 
String username,
+                                     String password) {
+        return super.testJDBCConnection(driverClass, jdbcURL, username,
+                                        password);
+    }
+}
\ No newline at end of file

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to