axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ami...@apache.org
Subject svn commit: r565239 [2/5] - in /webservices/axis2/trunk/java: ./ modules/distribution/ modules/distribution/src/main/assembly/ modules/kernel/conf/ modules/rmi/ modules/rmi/src/ modules/rmi/src/org/ modules/rmi/src/org/apache/ modules/rmi/src/org/apach...
Date Mon, 13 Aug 2007 05:06:04 GMT
Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/RMIServiceDeployer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/RMIServiceDeployer.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/RMIServiceDeployer.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/RMIServiceDeployer.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.deploy;
+
+import org.apache.axis2.deployment.Deployer;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.axis2.deployment.DeploymentClassLoader;
+import org.apache.axis2.deployment.repository.util.DeploymentFileData;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.rmi.metadata.Parameter;
+import org.apache.axis2.rmi.deploy.config.Config;
+import org.apache.axis2.rmi.deploy.config.Service;
+import org.apache.axis2.rmi.deploy.config.PackageToNamespaceMap;
+import org.apache.axis2.rmi.Configurator;
+import org.apache.axis2.rmi.databind.XmlStreamParser;
+import org.apache.axis2.rmi.exception.MetaDataPopulateException;
+import org.apache.axis2.rmi.exception.XmlParsingException;
+import org.apache.axis2.rmi.exception.ConfigFileReadingException;
+import org.apache.axis2.rmi.exception.SchemaGenerationException;
+import org.apache.axis2.util.Loader;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axiom.om.util.StAXUtils;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
+import java.io.*;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipEntry;
+
+
+public class RMIServiceDeployer implements Deployer {
+
+    private ConfigurationContext configurationContext;
+    private AxisConfiguration axisConfiguration;
+
+    public void init(ConfigurationContext configCtx) {
+        this.configurationContext = configCtx;
+        this.axisConfiguration = this.configurationContext.getAxisConfiguration();
+
+    }
+
+    public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
+
+        try {
+
+            DeploymentClassLoader deploymentClassLoader =
+                    new DeploymentClassLoader(new URL[]{deploymentFileData.getFile().toURL()}, null,
+                            Thread.currentThread().getContextClassLoader());
+            deploymentFileData.setClassLoader(deploymentClassLoader);
+            String absolutePath = deploymentFileData.getFile().getAbsolutePath();
+
+            // gettting the file reader for zipinput stream
+            Config configObject = getConfig(absolutePath);
+
+            Configurator configurator = new Configurator();
+
+            if (configObject.getExtensionClasses() != null) {
+                String[] extensionClasses = configObject.getExtensionClasses().getExtensionClass();
+                if (extensionClasses != null) {
+                    Class extensionClass;
+                    for (int i = 0; i < extensionClasses.length; i++) {
+                        extensionClass = Loader.loadClass(deploymentClassLoader, extensionClasses[i]);
+                        configurator.addExtension(extensionClass);
+                    }
+                }
+            }
+
+            if (configObject.getPackageToNamespaceMapings() != null) {
+                PackageToNamespaceMap[] packageToNamespaceMapings =
+                        configObject.getPackageToNamespaceMapings().getPackageToNamespaceMap();
+                if (packageToNamespaceMapings != null) {
+                    for (int i = 0; i < packageToNamespaceMapings.length; i++) {
+                        configurator.addPackageToNamespaceMaping(packageToNamespaceMapings[i].getPackageName(),
+                                packageToNamespaceMapings[i].getNamespace());
+                    }
+                }
+            }
+
+            Service[] services = configObject.getServices().getService();
+            ClassDeployer classDeployer =
+                    new ClassDeployer(configurationContext, deploymentClassLoader, configurator);
+            Class serviceClass;
+
+            for (int i = 0; i < services.length; i++) {
+                serviceClass = Loader.loadClass(deploymentClassLoader, services[i].getServiceClass());
+                classDeployer.deployClass(serviceClass);
+            }
+
+        } catch (ClassNotFoundException e) {
+            throw new DeploymentException("Service class not found", e);
+        } catch (AxisFault axisFault) {
+            throw new DeploymentException("axis fault", axisFault);
+        } catch (MalformedURLException e) {
+            throw new DeploymentException("zip file url is not correct", e);
+        } catch (IOException e) {
+            throw new DeploymentException("zip file not found", e);
+        } catch (ConfigFileReadingException e) {
+            throw new DeploymentException("config file reading problem", e);
+        }
+    }
+
+    private Config getConfig(String zipFilePath) throws ConfigFileReadingException {
+        try {
+            InputStream configFileInputStream = getConfigFileInputStream(zipFilePath);
+            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(configFileInputStream);
+
+            Configurator configurator = new Configurator();
+            configurator.addPackageToNamespaceMaping("org.apache.axis2.rmi.deploy.config",
+                    "http://ws.apache.org/axis2/rmi");
+            Map processedTypeMap = new HashMap();
+            Map processedSchemaMap = new HashMap();
+            Parameter parameter = new Parameter(Config.class, "config");
+            parameter.setNamespace("http://ws.apache.org/axis2/rmi");
+            parameter.populateMetaData(configurator, processedTypeMap);
+            parameter.generateSchema(configurator, processedSchemaMap);
+
+            XmlStreamParser xmlStreamParser = new XmlStreamParser(processedTypeMap, configurator, processedSchemaMap);
+            return (Config) xmlStreamParser.getObjectForParameter(xmlReader, parameter);
+        } catch (IOException e) {
+            throw new ConfigFileReadingException("Can not read configuration file", e);
+        } catch (XMLStreamException e) {
+            throw new ConfigFileReadingException("xml stream exception with configuration file", e);
+        } catch (MetaDataPopulateException e) {
+            throw new ConfigFileReadingException("metadata population problem with configuration file", e);
+        } catch (XmlParsingException e) {
+            throw new ConfigFileReadingException("xml stream reading problem with configuration file", e);
+        } catch (SchemaGenerationException e) {
+            throw new ConfigFileReadingException("problem in generating schema", e);
+        }
+    }
+
+    private InputStream getConfigFileInputStream(String zipFilePath) throws IOException {
+
+        ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFilePath));
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        ZipEntry zipEntry;
+        byte[] buffer = new byte[1024];
+        int read;
+        while ((zipEntry = zipInputStream.getNextEntry()) != null) {
+            if (zipEntry.getName().equals("META-INF" + File.separator + "config.xml")) {
+                while ((read = zipInputStream.read(buffer)) > 0) {
+                    byteArrayOutputStream.write(buffer, 0, read);
+                }
+            }
+
+        }
+        return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+    }
+
+    public void setDirectory(String directory) {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void setExtension(String extension) {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void unDeploy(String fileName) throws DeploymentException {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Config.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Config.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Config.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Config.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.deploy.config;
+
+public class Config {
+
+   private Services services;
+   private ExtensionClasses extensionClasses;
+   private PackageToNamespaceMapings packageToNamespaceMapings;
+
+    public Services getServices() {
+        return services;
+    }
+
+    public void setServices(Services services) {
+        this.services = services;
+    }
+
+    public ExtensionClasses getExtensionClasses() {
+        return extensionClasses;
+    }
+
+    public void setExtensionClasses(ExtensionClasses extensionClasses) {
+        this.extensionClasses = extensionClasses;
+    }
+
+    public PackageToNamespaceMapings getPackageToNamespaceMapings() {
+        return packageToNamespaceMapings;
+    }
+
+    public void setPackageToNamespaceMapings(PackageToNamespaceMapings packageToNamespaceMapings) {
+        this.packageToNamespaceMapings = packageToNamespaceMapings;
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/ExtensionClasses.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/ExtensionClasses.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/ExtensionClasses.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/ExtensionClasses.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.deploy.config;
+
+
+public class ExtensionClasses {
+
+    private String[] extensionClass;
+
+    public String[] getExtensionClass() {
+        return extensionClass;
+    }
+
+    public void setExtensionClass(String[] extensionClass) {
+        this.extensionClass = extensionClass;
+    }
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/PackageToNamespaceMap.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/PackageToNamespaceMap.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/PackageToNamespaceMap.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/PackageToNamespaceMap.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.deploy.config;
+
+
+public class PackageToNamespaceMap {
+    
+    private String packageName;
+    private String namespace;
+
+    public String getPackageName() {
+        return packageName;
+    }
+
+    public void setPackageName(String packageName) {
+        this.packageName = packageName;
+    }
+
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/PackageToNamespaceMapings.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/PackageToNamespaceMapings.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/PackageToNamespaceMapings.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/PackageToNamespaceMapings.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.deploy.config;
+
+
+public class PackageToNamespaceMapings {
+    
+    private PackageToNamespaceMap[] packageToNamespaceMap;
+
+    public PackageToNamespaceMap[] getPackageToNamespaceMap() {
+        return packageToNamespaceMap;
+    }
+
+    public void setPackageToNamespaceMap(PackageToNamespaceMap[] packageToNamespaceMap) {
+        this.packageToNamespaceMap = packageToNamespaceMap;
+    }
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Service.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Service.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Service.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Service.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.deploy.config;
+
+
+public class Service {
+
+    private String serviceClass;
+
+    public String getServiceClass() {
+        return serviceClass;
+    }
+
+    public void setServiceClass(String serviceClass) {
+        this.serviceClass = serviceClass;
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Services.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Services.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Services.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/deploy/config/Services.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.deploy.config;
+
+public class Services {
+
+   private Service[] service;
+
+    public Service[] getService() {
+        return service;
+    }
+
+    public void setService(Service[] service) {
+        this.service = service;
+    }
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/ConfigFileReadingException.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/ConfigFileReadingException.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/ConfigFileReadingException.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/ConfigFileReadingException.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.exception;
+
+
+public class ConfigFileReadingException extends Exception {
+
+    public ConfigFileReadingException() {
+        super();
+    }
+
+    public ConfigFileReadingException(String message) {
+        super(message);
+    }
+
+    public ConfigFileReadingException(Throwable cause) {
+        super(cause);
+    }
+
+    public ConfigFileReadingException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/MetaDataPopulateException.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/MetaDataPopulateException.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/MetaDataPopulateException.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/MetaDataPopulateException.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.exception;
+
+
+public class MetaDataPopulateException extends Exception {
+    public MetaDataPopulateException() {
+    }
+
+    public MetaDataPopulateException(String message) {
+        super(message);
+    }
+
+    public MetaDataPopulateException(Throwable cause) {
+        super(cause);
+    }
+
+    public MetaDataPopulateException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/SchemaGenerationException.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/SchemaGenerationException.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/SchemaGenerationException.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/SchemaGenerationException.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.exception;
+
+public class SchemaGenerationException extends Exception {
+
+    public SchemaGenerationException() {
+    }
+
+    public SchemaGenerationException(String message) {
+        super(message);
+    }
+
+    public SchemaGenerationException(Throwable cause) {
+        super(cause);
+    }
+
+    public SchemaGenerationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/XmlParsingException.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/XmlParsingException.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/XmlParsingException.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/XmlParsingException.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.exception;
+
+
+public class XmlParsingException extends Exception {
+    
+    public XmlParsingException() {
+    }
+
+    public XmlParsingException(String message) {
+        super(message);
+    }
+
+    public XmlParsingException(Throwable cause) {
+        super(cause);
+    }
+
+    public XmlParsingException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/XmlSerializingException.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/XmlSerializingException.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/XmlSerializingException.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/exception/XmlSerializingException.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.exception;
+
+
+public class XmlSerializingException extends Exception {
+
+    public XmlSerializingException() {
+    }
+
+    public XmlSerializingException(String message) {
+        super(message);
+    }
+
+    public XmlSerializingException(Throwable cause) {
+        super(cause);
+    }
+
+    public XmlSerializingException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Attribute.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Attribute.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Attribute.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Attribute.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.metadata;
+
+import org.apache.axis2.rmi.Configurator;
+import org.apache.axis2.rmi.util.Util;
+import org.apache.axis2.rmi.util.Constants;
+import org.apache.axis2.rmi.metadata.xml.XmlElement;
+import org.apache.axis2.rmi.exception.MetaDataPopulateException;
+import org.apache.axis2.rmi.exception.SchemaGenerationException;
+
+import java.lang.reflect.Method;
+import java.beans.PropertyDescriptor;
+import java.util.Map;
+import java.util.List;
+
+public class Attribute {
+
+    /**
+     * property descriptor for this attribute
+     */
+    private PropertyDescriptor propertyDescriptor;
+    /**
+     * name of the attribute this is the name of the XmlElement as well
+     */
+    private String name;
+
+    /**
+     * namespce of this attribute
+     * this is always the namespace of the parent type
+     */
+    private String namespace;
+
+    /**
+     * getter method of the attribute
+     */
+    private Method getterMethod;
+
+    /**
+     * setter method of the attribute
+     */
+    private Method setterMethod;
+
+    /**
+     * attribute metadata type
+     */
+    private Type type;
+
+    /**
+     * is this attribute an array
+     */
+    private boolean isArray;
+
+    /**
+     * schmema element corresponding to this attribute
+     * always an attribute refer to and schema XmlElement
+     */
+    private XmlElement element;
+
+    /**
+     * boolean variable to check to see whether we generated the
+     * element for this schema.
+     * although we can check for null value of the element we prefer
+     * to keep a seperate variable.
+     */
+    private boolean isSchemaGenerated;
+
+    /**
+     * class type of the attribute class
+     */
+    private int classType;
+
+    /**
+     * default constructor
+     */
+    public Attribute() {
+    }
+
+    /**
+     * constructor with the property descriptor
+     *
+     * @param propertyDescriptor
+     */
+    public Attribute(PropertyDescriptor propertyDescriptor,
+                     String namespace) {
+        this.propertyDescriptor = propertyDescriptor;
+        this.namespace = namespace;
+    }
+
+    public void populateMetaData(Configurator configurator,
+                                 Map processedTypeMap)
+            throws MetaDataPopulateException {
+        this.name = this.propertyDescriptor.getName();
+        this.getterMethod = this.propertyDescriptor.getReadMethod();
+        this.setterMethod = this.propertyDescriptor.getWriteMethod();
+        Class baseClass;
+        try {
+            this.classType = Util.getClassType(this.propertyDescriptor.getPropertyType());
+
+            if ((this.classType & Constants.COLLECTION_TYPE) == Constants.COLLECTION_TYPE){
+               // i.e. if this is collection type
+               this.isArray = true;
+               baseClass = Object.class;
+            // TODO : handle maps
+            } else {
+                this.isArray = this.propertyDescriptor.getPropertyType().isArray();
+                if (this.isArray) {
+                    baseClass = this.propertyDescriptor.getPropertyType().getComponentType();
+                } else {
+                    baseClass = this.propertyDescriptor.getPropertyType();
+                }
+            }
+
+            if (processedTypeMap.containsKey(baseClass)){
+                this.type = (Type) processedTypeMap.get(baseClass);
+            } else {
+                this.type = new Type(baseClass);
+                processedTypeMap.put(baseClass, this.type);
+                this.type.populateMetaData(configurator, processedTypeMap);
+            }
+        } catch (IllegalAccessException e) {
+            throw new MetaDataPopulateException("Can not instataite class "
+                    + this.propertyDescriptor.getPropertyType().getName(), e);
+        } catch (InstantiationException e) {
+            throw new MetaDataPopulateException("Can not instataite class "
+                    + this.propertyDescriptor.getPropertyType().getName(), e);
+        }
+
+    }
+
+
+    /**
+     * this method sets the XMLElement correctly. this method should be called only
+     * if this is not processed
+     * @param configurator
+     * @param schemaMap
+     * @throws SchemaGenerationException
+     */
+    public void generateSchema(Configurator configurator,
+                               Map schemaMap)
+            throws SchemaGenerationException {
+        // here we have to send the XmlElement correctly
+       this.isSchemaGenerated = true;
+       this.element = new XmlElement(!this.isArray && this.type.getJavaClass().isPrimitive());
+       this.element.setName(this.name);
+       this.element.setNamespace(this.namespace);
+       this.element.setTopElement(false);
+
+       if (!this.type.isSchemaGenerated()){
+          this.type.generateSchema(configurator,schemaMap);
+       }
+       this.element.setType(this.type.getXmlType());
+       this.element.setArray(this.isArray);
+
+    }
+
+    public PropertyDescriptor getPropertyDescriptor() {
+        return propertyDescriptor;
+    }
+
+    public void setPropertyDescriptor(PropertyDescriptor propertyDescriptor) {
+        this.propertyDescriptor = propertyDescriptor;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Method getGetterMethod() {
+        return getterMethod;
+    }
+
+    public void setGetterMethod(Method getterMethod) {
+        this.getterMethod = getterMethod;
+    }
+
+    public Method getSetterMethod() {
+        return setterMethod;
+    }
+
+    public void setSetterMethod(Method setterMethod) {
+        this.setterMethod = setterMethod;
+    }
+
+    public Type getType() {
+        return type;
+    }
+
+    public void setType(Type type) {
+        this.type = type;
+    }
+
+    public boolean isArray() {
+        return isArray;
+    }
+
+    public void setArray(boolean array) {
+        isArray = array;
+    }
+
+    public XmlElement getElement() {
+        return element;
+    }
+
+    public void setElement(XmlElement element) {
+        this.element = element;
+    }
+
+    public boolean isSchemaGenerated() {
+        return isSchemaGenerated;
+    }
+
+    public void setSchemaGenerated(boolean schemaGenerated) {
+        isSchemaGenerated = schemaGenerated;
+    }
+
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    public int getClassType() {
+        return classType;
+    }
+
+    public void setClassType(int classType) {
+        this.classType = classType;
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Operation.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Operation.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Operation.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Operation.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,403 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.metadata;
+
+import org.apache.axis2.rmi.metadata.xml.XmlElement;
+import org.apache.axis2.rmi.metadata.xml.XmlSchema;
+import org.apache.axis2.rmi.metadata.xml.XmlImport;
+import org.apache.axis2.rmi.metadata.xml.XmlType;
+import org.apache.axis2.rmi.Configurator;
+import org.apache.axis2.rmi.util.Constants;
+import org.apache.axis2.rmi.exception.MetaDataPopulateException;
+import org.apache.axis2.rmi.exception.SchemaGenerationException;
+
+import javax.xml.namespace.QName;
+import javax.wsdl.*;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.extensions.ExtensionRegistry;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.extensions.soap.SOAPBody;
+import javax.wsdl.extensions.soap.SOAPFault;
+import java.lang.reflect.Method;
+import java.util.*;
+
+public class Operation {
+
+    /**
+     * javaMethod name
+     */
+    private String name;
+
+    /**
+     * namespace to which javaMethod belongs
+     * most of the time this is same as the service namespace
+     */
+    private String namespace;
+    /**
+     * service class method for this javaMethod
+     */
+    private Method javaMethod;
+
+    /**
+     * input parameters list for this method(javaMethod)
+     * this consists of a list of Parameter objects
+     */
+    private List inputParameters;
+
+    /**
+     * return type of the javaMethod
+     */
+    private Parameter outputParameter;
+
+    /**
+     * generated XmlElement for the input
+     */
+    private XmlElement inputElement;
+
+    /**
+     * generated XmlElement for the output
+     */
+    private XmlElement outPutElement;
+
+
+
+    /**
+     * default constructor
+     */
+    public Operation() {
+        this.inputParameters = new ArrayList();
+
+    }
+
+    /**
+     * constructor with the java method for this javaMethod
+     *
+     * @param operation
+     */
+    public Operation(Method operation) {
+        this();
+        this.javaMethod = operation;
+    }
+
+    public void populateMetaData(Configurator configurator,
+                                 Map processedTypeMap,
+                                 Map exceptionClassToParameterMap)
+            throws MetaDataPopulateException {
+        // set the name. namespace should already have set by the service
+        this.name = this.javaMethod.getName();
+
+        //populate input parameters
+        Class[] inputTypes = this.javaMethod.getParameterTypes();
+        Parameter parameter;
+        for (int i = 0; i < inputTypes.length; i++) {
+            parameter = new Parameter(inputTypes[i],"param" + i);
+            parameter.populateMetaData(configurator, processedTypeMap);
+            this.inputParameters.add(parameter);
+        }
+
+        // populate output parameter
+        Class returnType = this.javaMethod.getReturnType();
+        if (!returnType.equals(void.class)) {
+            // i.e. we have a return type
+            this.outputParameter = new Parameter(returnType, "return");
+            this.outputParameter.populateMetaData(configurator, processedTypeMap);
+        }
+
+        // populate exception data
+        Class[] exceptionType = this.javaMethod.getExceptionTypes();
+        String exceptionName;
+        String namespace;
+        for (int i=0;i<exceptionType.length;i++){
+            exceptionName = exceptionType[i].getName();
+            exceptionName = exceptionName.substring(exceptionName.lastIndexOf(".") + 1);
+            namespace = configurator.getNamespace(exceptionType[i].getPackage().getName());
+            parameter = new Parameter(exceptionType[i],exceptionName,namespace);
+            parameter.populateMetaData(configurator,processedTypeMap);
+            if (!exceptionClassToParameterMap.containsKey(exceptionType[i])){
+                exceptionClassToParameterMap.put(exceptionType[i],parameter);
+            }
+        }
+    }
+
+    public void generateSchema(Configurator configurator,
+                               Map schemaMap,
+                               Map exceptionClassToParameterMap)
+            throws SchemaGenerationException {
+        // here we have to generate the input element and out put elements
+        // putting the other relavent schema parts to the schemaMap
+
+        // get the schema to add the complex type
+        if (schemaMap.get(this.namespace) == null) {
+            // create a new namespace for this schema
+            schemaMap.put(this.namespace, new XmlSchema(this.namespace));
+        }
+        XmlSchema xmlSchema = (XmlSchema) schemaMap.get(this.namespace);
+
+
+        if (!configurator.isBare()) {
+
+            // generating the input element
+            this.inputElement = new XmlElement(false);
+            this.inputElement.setName(this.name);
+            this.inputElement.setNamespace(this.namespace);
+            this.inputElement.setTopElement(true);
+            xmlSchema.addElement(this.inputElement);
+
+            // set the complex type for this element
+            XmlType xmlType = new XmlType();
+            xmlType.setAnonymous(true);
+            xmlType.setSimpleType(false);
+
+            Parameter parameter;
+            for (Iterator iter = this.inputParameters.iterator(); iter.hasNext();) {
+                parameter = (Parameter) iter.next();
+                if (!parameter.isSchemaGenerated()){
+                   parameter.generateSchema(configurator,schemaMap);
+                }
+                parameter.getElement().setTopElement(false);
+                xmlType.addElement(parameter.getElement());
+                QName elementTypeQName = parameter.getElement().getType().getQname();
+                if (!xmlSchema.containsNamespace(elementTypeQName.getNamespaceURI())) {
+                    // if the element namespace does not exists we have to add it
+                    if (!elementTypeQName.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
+                        XmlImport xmlImport = new XmlImport(elementTypeQName.getNamespaceURI());
+                        xmlSchema.addImport(xmlImport);
+                    }
+                    xmlSchema.addNamespace(elementTypeQName.getNamespaceURI());
+                }
+            }
+
+            this.inputElement.setType(xmlType);
+
+            // generate the output Element
+            this.outPutElement = new XmlElement(false);
+            this.outPutElement.setName(this.name + "Response");
+            this.outPutElement.setNamespace(this.namespace);
+            this.outPutElement.setTopElement(true);
+            xmlSchema.addElement(this.outPutElement);
+
+            xmlType = new XmlType();
+            xmlType.setAnonymous(true);
+            xmlType.setSimpleType(false);
+            if (this.outputParameter != null) {
+                if (!this.outputParameter.isSchemaGenerated()){
+                    this.outputParameter.generateSchema(configurator,schemaMap);
+                }
+                xmlType.addElement(this.outputParameter.getElement());
+                QName elementTypeQName = this.outputParameter.getElement().getType().getQname();
+                if (!xmlSchema.containsNamespace(elementTypeQName.getNamespaceURI())) {
+                    // if the element namespace does not exists we have to add it
+                    if (!elementTypeQName.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
+                        XmlImport xmlImport = new XmlImport(elementTypeQName.getNamespaceURI());
+                        xmlSchema.addImport(xmlImport);
+                    }
+                    xmlSchema.addNamespace(elementTypeQName.getNamespaceURI());
+                }
+            }
+            this.outPutElement.setType(xmlType);
+
+        } else {
+            //TODO: generate the code for bare case
+        }
+
+    }
+
+    /**
+     * creates the corresponding wsdl message for input
+     *
+     * @param definition
+     * @return input message
+     */
+    public Message getWSDLInputMessage(Definition definition){
+        Message inputMessage = definition.createMessage();
+        inputMessage.setUndefined(false);
+        inputMessage.setQName(new QName(this.namespace,this.name + "RequestMessage"));
+        Part part = definition.createPart();
+        part.setName("input");
+        part.setElementName(new QName(this.inputElement.getNamespace(),this.inputElement.getName()));
+        inputMessage.addPart(part);
+        return inputMessage;
+    }
+
+    /**
+     * creates the corresponding wsdl message for output
+     * @param definition
+     * @return output message
+     */
+    public Message getWSDLOutputMessage(Definition definition){
+        Message outputMessage = definition.createMessage();
+        outputMessage.setUndefined(false);
+        outputMessage.setQName(new QName(this.namespace,this.name + "ResponseMessage"));
+        Part part = definition.createPart();
+        part.setName("output");
+        part.setElementName(new QName(this.outPutElement.getNamespace(),this.outPutElement.getName()));
+        outputMessage.addPart(part);
+        return outputMessage;
+    }
+
+
+
+    public javax.wsdl.Operation getWSDLOperation(Definition definition,
+                                                 Message inputMessage,
+                                                 Message outputMessage,
+                                                 Map faultMessageMap){
+        javax.wsdl.Operation operation = definition.createOperation();
+        operation.setUndefined(false);
+        operation.setName(this.name);
+        Input input = definition.createInput();
+        input.setMessage(inputMessage);
+        input.setName("input");
+
+        Output output = definition.createOutput();
+        output.setMessage(outputMessage);
+        output.setName("output");
+        operation.setInput(input);
+        operation.setOutput(output);
+        operation.setStyle(OperationType.REQUEST_RESPONSE);
+
+        // add fault messages
+        Class[] exceptionClasses = this.javaMethod.getExceptionTypes();
+        Message faultMessage;
+        Fault fault;
+        String faultName;
+        for (int i = 0; i < exceptionClasses.length; i++) {
+           faultName = exceptionClasses[i].getName();
+           faultName = faultName.substring(faultName.lastIndexOf(".") + 1);
+           faultMessage = (Message) faultMessageMap.get(exceptionClasses[i]);
+           fault = definition.createFault();
+           fault.setMessage(faultMessage);
+           fault.setName("fault" + faultName);
+           operation.addFault(fault);
+        }
+
+        return operation;
+    }
+
+    public BindingOperation getWSDLBindingOperation(Definition definition,
+                                                    javax.wsdl.Operation operation)
+            throws SchemaGenerationException {
+        BindingOperation bindingOperation = definition.createBindingOperation();
+        bindingOperation.setName(this.name);
+        bindingOperation.setOperation(operation);
+
+        BindingInput bindingInput = definition.createBindingInput();
+        bindingOperation.setBindingInput(bindingInput);
+
+        BindingOutput bindingOutput = definition.createBindingOutput();
+        bindingOperation.setBindingOutput(bindingOutput);
+
+        ExtensionRegistry extensionRegistry = null;
+        try {
+            extensionRegistry = WSDLFactory.newInstance().newPopulatedExtensionRegistry();
+            SOAPOperation soapOperation = (SOAPOperation)extensionRegistry.createExtension(
+                    BindingOperation.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/","operation"));
+            soapOperation.setSoapActionURI("urn:" + this.name);
+            soapOperation.setStyle("document");
+            bindingOperation.addExtensibilityElement(soapOperation);
+
+            SOAPBody inputSoapBody = (SOAPBody)extensionRegistry.createExtension(
+                    BindingInput.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/","body"));
+            inputSoapBody.setUse("literal");
+            bindingInput.addExtensibilityElement(inputSoapBody);
+
+            SOAPBody outputSoapBody = (SOAPBody)extensionRegistry.createExtension(
+                    BindingOutput.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/","body"));
+            outputSoapBody.setUse("literal");
+            bindingOutput.addExtensibilityElement(outputSoapBody);
+
+            // adding fault messages
+            Class[] exceptionClasses = this.javaMethod.getExceptionTypes();
+            BindingFault bindingFault;
+            String faultName;
+            for (int i = 0; i < exceptionClasses.length; i++) {
+                faultName = exceptionClasses[i].getName();
+                faultName = faultName.substring(faultName.lastIndexOf(".") + 1);
+                bindingFault = definition.createBindingFault();
+                bindingFault.setName("fault" + faultName);
+                bindingOperation.addBindingFault(bindingFault);
+
+                SOAPFault soapFault = (SOAPFault)extensionRegistry.createExtension(
+                    BindingFault.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/","fault"));
+                soapFault.setUse("literal");
+                soapFault.setName("fault" + faultName);
+                bindingFault.addExtensibilityElement(soapFault);
+            }
+
+
+        } catch (WSDLException e) {
+            throw new SchemaGenerationException("Can not crete a wsdl factory");
+        }
+
+        return bindingOperation;
+    }
+
+    public Parameter getOutputParameter() {
+        return outputParameter;
+    }
+
+    public void setOutputParameter(Parameter outputParameter) {
+        this.outputParameter = outputParameter;
+    }
+
+    public XmlElement getInputElement() {
+        return inputElement;
+    }
+
+    public void setInputElement(XmlElement inputElement) {
+        this.inputElement = inputElement;
+    }
+
+    public XmlElement getOutPutElement() {
+        return outPutElement;
+    }
+
+    public void setOutPutElement(XmlElement outPutElement) {
+        this.outPutElement = outPutElement;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Method getJavaMethod() {
+        return javaMethod;
+    }
+
+    public void setJavaMethod(Method javaMethod) {
+        this.javaMethod = javaMethod;
+    }
+
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    public List getInputParameters() {
+        return inputParameters;
+    }
+
+    public void setInputParameters(List inputParameters) {
+        this.inputParameters = inputParameters;
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Parameter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Parameter.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Parameter.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Parameter.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.metadata;
+
+import org.apache.axis2.rmi.Configurator;
+import org.apache.axis2.rmi.util.Util;
+import org.apache.axis2.rmi.util.Constants;
+import org.apache.axis2.rmi.metadata.xml.XmlElement;
+import org.apache.axis2.rmi.exception.MetaDataPopulateException;
+import org.apache.axis2.rmi.exception.SchemaGenerationException;
+
+import java.util.Map;
+import java.util.List;
+
+/**
+ * this class is used to keep the Parameter details of a java method
+ */
+public class Parameter {
+
+    /**
+     * java class represents this parameter
+     */
+    private Class javaClass;
+    /**
+     * parameter name
+     */
+    private String name;
+
+    /**
+     * namespace of this parameter
+     * this should always null. i.e no namespace for an parameter
+     */
+    private String namespace;
+
+    /**
+     * XmlType of the parameter
+     */
+    private Type type;
+
+    /**
+     * is this parameter is array type
+     */
+    private boolean isArray;
+
+    /**
+     * xml Element corresponding to this parameter
+     */
+    private XmlElement element;
+
+    /**
+     * whether the schema is generated or not
+     */
+    private boolean isSchemaGenerated;
+
+    /**
+     * type of the parameter class
+     */
+    private int classType;
+
+
+    /**
+     * default constructor
+     */
+    public Parameter() {
+    }
+
+    public Parameter(Class javaClass, String name, String namespace) {
+        this.javaClass = javaClass;
+        this.name = name;
+        this.namespace = namespace;
+    }
+
+
+    public Parameter(Class javaClass, String name) {
+        this(javaClass,name,null);
+    }
+
+    public void populateMetaData(Configurator configurator,
+                                 Map processedTypeMap)
+            throws MetaDataPopulateException {
+
+        Class baseClass;
+        try {
+            this.classType = Util.getClassType(this.javaClass);
+            if ((this.classType & Constants.COLLECTION_TYPE) == Constants.COLLECTION_TYPE) {
+                // i.e this is a collection class
+                this.isArray = true;
+                baseClass = Object.class;
+                //TODO: handle map type
+            } else {
+                // populate the type for this parameter
+                this.isArray = this.javaClass.isArray();
+
+                if (this.isArray) {
+                    baseClass = this.javaClass.getComponentType();
+                } else {
+                    baseClass = this.javaClass;
+                }
+            }
+
+            if (processedTypeMap.containsKey(baseClass)) {
+                // i.e we have already process this type
+                this.type = (Type) processedTypeMap.get(baseClass);
+            } else {
+                this.type = new Type(baseClass);
+                // we have to do this before calling to populate meta data
+                // to avoid cirecular references
+                processedTypeMap.put(baseClass, this.type);
+                this.type.populateMetaData(configurator, processedTypeMap);
+            }
+        } catch (IllegalAccessException e) {
+            throw new MetaDataPopulateException("Can not instataite class "
+                    + this.javaClass.getName(), e);
+        } catch (InstantiationException e) {
+            throw new MetaDataPopulateException("Can not instataite class "
+                    + this.javaClass.getName(), e);
+        }
+    }
+
+    /**
+     * this method sets the XMLElement correctly. this method should be called only
+     * if this is not processed
+     *
+     * @param configurator
+     * @param schemaMap
+     * @throws org.apache.axis2.rmi.exception.SchemaGenerationException
+     *
+     */
+    public void generateSchema(Configurator configurator,
+                               Map schemaMap)
+            throws SchemaGenerationException {
+        // here we have to send the XmlElement correctly
+        this.isSchemaGenerated = true;
+        this.element = new XmlElement(!this.isArray && this.type.getJavaClass().isPrimitive());
+        this.element.setName(this.name);
+        this.element.setNamespace(this.namespace);
+
+        if (!this.type.isSchemaGenerated()) {
+            this.type.generateSchema(configurator, schemaMap);
+        }
+        this.element.setType(this.type.getXmlType());
+        this.element.setArray(this.isArray);
+
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Type getType() {
+        return type;
+    }
+
+    public void setType(Type type) {
+        this.type = type;
+    }
+
+    public Class getJavaClass() {
+        return javaClass;
+    }
+
+    public void setJavaClass(Class javaClass) {
+        this.javaClass = javaClass;
+    }
+
+    public boolean isArray() {
+        return isArray;
+    }
+
+    public void setArray(boolean array) {
+        isArray = array;
+    }
+
+    public XmlElement getElement() {
+        return element;
+    }
+
+    public void setElement(XmlElement element) {
+        this.element = element;
+    }
+
+    public boolean isSchemaGenerated() {
+        return isSchemaGenerated;
+    }
+
+    public void setSchemaGenerated(boolean schemaGenerated) {
+        isSchemaGenerated = schemaGenerated;
+    }
+
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    public int getClassType() {
+        return classType;
+    }
+
+    public void setClassType(int classType) {
+        this.classType = classType;
+    }
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Service.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Service.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Service.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Service.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,439 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.metadata;
+
+import org.apache.axis2.rmi.Configurator;
+import org.apache.axis2.rmi.util.Util;
+import org.apache.axis2.rmi.util.Constants;
+import org.apache.axis2.rmi.metadata.xml.XmlSchema;
+import org.apache.axis2.rmi.metadata.xml.XmlImport;
+import org.apache.axis2.rmi.exception.MetaDataPopulateException;
+import org.apache.axis2.rmi.exception.SchemaGenerationException;
+
+import javax.wsdl.*;
+import javax.wsdl.extensions.ExtensionRegistry;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.factory.WSDLFactory;
+import javax.xml.namespace.QName;
+import java.util.*;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+
+public class Service {
+
+    /**
+     * name of the service
+     */
+    private String name;
+    private String namespace;
+    /**
+     * java class for which we going to create the service
+     */
+    private Class javaClass;
+
+    /**
+     * this list contains a List of Operation objects representing
+     * operations of the java class
+     */
+    private List operations;
+
+    /**
+     * wsdl definition for this service
+     */
+    private Definition wsdlDefinition;
+
+    private Map processedTypeMap;
+    private Configurator configurator;
+    private Map schemaMap;
+
+    private PortType portType;
+    private Binding httpSoapBinding;
+    private javax.wsdl.Service wsdlService;
+
+
+    //TODO: generate code for this binding.
+    private Binding httpSoap12Binding;
+
+    /**
+     * this map keeps the exception class name and exception relavent parameter
+     * used in serialization. we need to keep the message name unique within the
+     * service. so exceptionclass map should be global
+     */
+    private Map exceptionClassToParameterMap;
+
+    /**
+     * this map keeps the exception QName and exception relavent parameter
+     */
+    private Map exceptionQNameToParameterMap;
+
+    /**
+     * default constructor
+     */
+    public Service() {
+        this.operations = new ArrayList();
+        this.exceptionClassToParameterMap = new HashMap();
+        this.exceptionQNameToParameterMap = new HashMap();
+    }
+
+    /**
+     * constracutor with the java class name
+     *
+     * @param javaClass
+     */
+    public Service(Class javaClass, Configurator configurator) {
+        this();
+        this.javaClass = javaClass;
+        this.configurator = configurator;
+    }
+
+
+    /**
+     * this method suppose to fill all the operations data using the java
+     * class given. here we assume that the javaClass is properly set.
+     */
+    public void populateMetaData() throws MetaDataPopulateException {
+        // set the service name using the java class name
+        this.name = javaClass.getName();
+        // remove the package part
+        this.name = this.name.substring(this.name.lastIndexOf(".") + 1);
+        this.namespace = configurator.getNamespace(javaClass.getPackage().getName());
+        this.processedTypeMap = new HashMap();
+
+        // populate operations
+        //TODO: this method returns uninherited methods find a way to get them as well
+        Method[] javaMethods = this.javaClass.getDeclaredMethods();
+        Method javaMethod;
+        Operation operation;
+        for (int i = 0; i < javaMethods.length; i++) {
+            javaMethod = javaMethods[i];
+            // we generate oprations only from the public methods
+            //TODO : remove overload methods
+            if (Modifier.isPublic(javaMethod.getModifiers()) &&
+                    !Modifier.isAbstract(javaMethod.getModifiers())) {
+                operation = new Operation(javaMethod);
+                operation.setNamespace(this.namespace);
+                operation.populateMetaData(configurator, this.processedTypeMap, this.exceptionClassToParameterMap);
+                this.operations.add(operation);
+            }
+        }
+
+        // add the extension classes if they have not already populated
+        Class extensionClass = null;
+        Type extensionType = null;
+        for (Iterator iter = this.configurator.getExtensionClasses().iterator(); iter.hasNext();) {
+            extensionClass = (Class) iter.next();
+            if (!this.processedTypeMap.containsKey(extensionClass)) {
+                extensionType = new Type(extensionClass);
+                this.processedTypeMap.put(extensionClass, extensionType);
+                extensionType.populateMetaData(this.configurator, this.processedTypeMap);
+            }
+        }
+    }
+
+    private void generateSchema() throws SchemaGenerationException {
+        //first we have to generate the input and output elements
+        // to operations
+
+        // create schema map object and add the target namespace object
+        this.schemaMap = new HashMap();
+        this.schemaMap.put(this.namespace, new XmlSchema(this.namespace));
+        Operation operation;
+        for (Iterator iter = this.operations.iterator(); iter.hasNext();) {
+            operation = (Operation) iter.next();
+            operation.generateSchema(configurator,
+                    this.schemaMap,
+                    this.exceptionClassToParameterMap);
+        }
+
+        // add exception class elements to the schema
+        generateSchemaForExceptionParameters();
+
+        // generate the schema for other extension classes
+        Class extensionClass = null;
+        Type extensionType = null;
+        for (Iterator iter = this.configurator.getExtensionClasses().iterator(); iter.hasNext();) {
+            extensionClass = (Class) iter.next();
+            extensionType = (Type) this.processedTypeMap.get(extensionClass);
+            if (!extensionType.isSchemaGenerated()) {
+                extensionType.generateSchema(this.configurator, this.schemaMap);
+            }
+        }
+
+        Types types = this.wsdlDefinition.createTypes();
+        this.wsdlDefinition.setTypes(types);
+        XmlSchema xmlSchema;
+        for (Iterator iter = this.schemaMap.values().iterator(); iter.hasNext();) {
+            xmlSchema = (XmlSchema) iter.next();
+            xmlSchema.generateWSDLSchema();
+            types.addExtensibilityElement(xmlSchema.getWsdlSchema());
+        }
+
+    }
+
+    private void generateSchemaForExceptionParameters() throws SchemaGenerationException {
+        Parameter parameter;
+        for (Iterator iter = this.exceptionClassToParameterMap.values().iterator(); iter.hasNext();) {
+            parameter = (Parameter) iter.next();
+            if (!parameter.isSchemaGenerated()) {
+                parameter.generateSchema(configurator, schemaMap);
+            }
+            QName elementTypeQName = parameter.getElement().getType().getQname();
+            // get the schema to add the complex type
+            if (schemaMap.get(elementTypeQName.getNamespaceURI()) == null) {
+                // create a new namespace for this schema
+                schemaMap.put(elementTypeQName.getNamespaceURI(), new XmlSchema(elementTypeQName.getNamespaceURI()));
+            }
+            XmlSchema xmlSchema = (XmlSchema) schemaMap.get(elementTypeQName.getNamespaceURI());
+            if (!xmlSchema.containsNamespace(elementTypeQName.getNamespaceURI())) {
+                if (!elementTypeQName.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
+                    XmlImport xmlImport = new XmlImport(elementTypeQName.getNamespaceURI());
+                    xmlSchema.addImport(xmlImport);
+                }
+                xmlSchema.addNamespace(elementTypeQName.getNamespaceURI());
+            }
+            parameter.getElement().setTopElement(true);
+            xmlSchema.addElement(parameter.getElement());
+            this.exceptionQNameToParameterMap.put(elementTypeQName, parameter);
+        }
+    }
+
+    public void generateWSDL() throws SchemaGenerationException {
+        try {
+            this.wsdlDefinition = WSDLFactory.newInstance().newDefinition();
+            //TODO: keep the namespace prefix map if needed
+            this.wsdlDefinition.addNamespace(Util.getNextNamespacePrefix(),this.namespace);
+            this.wsdlDefinition.addNamespace(Util.getNextNamespacePrefix(),"http://schemas.xmlsoap.org/wsdl/soap/");
+            this.wsdlDefinition.setTargetNamespace(this.namespace);
+            // first generate the schemas
+            generateSchema();
+            generatePortType();
+            generateBindings();
+            generateService();
+            generateOperationsAndMessages();
+        } catch (WSDLException e) {
+            throw new SchemaGenerationException("Error in creating a new wsdl definition",e);
+        }
+    }
+
+    private void generatePortType(){
+        this.portType = this.wsdlDefinition.createPortType();
+        this.portType.setUndefined(false);
+        this.portType.setQName(new QName(this.namespace, this.name + "PortType"));
+        this.wsdlDefinition.addPortType(portType);
+    }
+
+    private void generateBindings() throws SchemaGenerationException {
+        this.httpSoapBinding = this.wsdlDefinition.createBinding();
+        this.httpSoapBinding.setUndefined(false);
+        this.httpSoapBinding.setQName(new QName(this.namespace, this.name + "HttpSoapBinding"));
+        this.httpSoapBinding.setPortType(this.portType);
+        // add soap transport parts
+        ExtensionRegistry extensionRegistry = null;
+        try {
+            extensionRegistry = WSDLFactory.newInstance().newPopulatedExtensionRegistry();
+            SOAPBinding soapBinding = (SOAPBinding)extensionRegistry.createExtension(
+                    Binding.class,new QName("http://schemas.xmlsoap.org/wsdl/soap/","binding"));
+            soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
+            soapBinding.setStyle("document");
+            this.httpSoapBinding.addExtensibilityElement(soapBinding);
+        } catch (WSDLException e) {
+            throw new SchemaGenerationException("Can not crete a wsdl factory");
+        }
+        this.wsdlDefinition.addBinding(this.httpSoapBinding);
+        this.wsdlDefinition.getBindings().put(this.httpSoapBinding.getQName(),
+                this.httpSoapBinding);
+    }
+
+    private void generateService()
+            throws SchemaGenerationException {
+        // now add the binding portType and messages corresponding to every operation
+        javax.wsdl.Service service = this.wsdlDefinition.createService();
+        service.setQName(new QName(this.namespace,this.name));
+
+        Port port = this.wsdlDefinition.createPort();
+        port.setName(this.name + "HttpSoapPort");
+        port.setBinding(this.httpSoapBinding);
+        ExtensionRegistry extensionRegistry = null;
+        try {
+            extensionRegistry = WSDLFactory.newInstance().newPopulatedExtensionRegistry();
+            SOAPAddress soapAddress = (SOAPAddress)extensionRegistry.createExtension(
+                    Port.class,new QName("http://schemas.xmlsoap.org/wsdl/soap/","address"));
+            soapAddress.setLocationURI("http://localhost:8080/axis2/services/" + this.name);
+            port.addExtensibilityElement(soapAddress);
+        } catch (WSDLException e) {
+            throw new SchemaGenerationException("Can not crete a wsdl factory");
+        }
+        service.addPort(port);
+        this.wsdlDefinition.addService(service);
+    }
+
+    private void generateOperationsAndMessages()
+            throws SchemaGenerationException {
+        Operation operation;
+        Message inputMessage;
+        Message outputMessage;
+        javax.wsdl.Operation wsdlOperation;
+        BindingOperation bindingOperation;
+
+        //generate messages for exceptions
+        Map exceptionMessagesMap = new HashMap();
+        Class exceptionClass;
+        Parameter parameter;
+        Message faultMessage;
+        String messageName;
+        Part part;
+
+        for (Iterator iter = this.exceptionClassToParameterMap.keySet().iterator(); iter.hasNext();) {
+            exceptionClass = (Class) iter.next();
+            parameter = (Parameter) this.exceptionClassToParameterMap.get(exceptionClass);
+            messageName = exceptionClass.getName();
+            messageName = messageName.substring(messageName.lastIndexOf(".") + 1);
+            faultMessage = this.wsdlDefinition.createMessage();
+            faultMessage.setUndefined(false);
+            faultMessage.setQName(new QName(this.namespace, messageName));
+
+            part = this.wsdlDefinition.createPart();
+            part.setName("fault");
+            // add this element namespace to the definition
+            if (this.wsdlDefinition.getPrefix(parameter.getElement().getNamespace()) == null){
+                this.wsdlDefinition.addNamespace(Util.getNextNamespacePrefix(), parameter.getElement().getNamespace());
+            }
+            part.setElementName(parameter.getElement().getType().getQname());
+            faultMessage.addPart(part);
+            exceptionMessagesMap.put(exceptionClass,faultMessage);
+            this.wsdlDefinition.addMessage(faultMessage);
+        }
+
+        for (Iterator iter = this.operations.iterator(); iter.hasNext();) {
+            operation = (Operation) iter.next();
+            // add input and out put messages
+            inputMessage = operation.getWSDLInputMessage(this.wsdlDefinition);
+            outputMessage = operation.getWSDLOutputMessage(this.wsdlDefinition);
+            this.wsdlDefinition.addMessage(inputMessage);
+            this.wsdlDefinition.addMessage(outputMessage);
+
+            wsdlOperation = operation.getWSDLOperation(this.wsdlDefinition,
+                                                       inputMessage,
+                                                       outputMessage,
+                                                       exceptionMessagesMap);
+            this.portType.addOperation(wsdlOperation);
+            bindingOperation = operation.getWSDLBindingOperation(
+                    this.wsdlDefinition,wsdlOperation);
+            this.httpSoapBinding.addBindingOperation(bindingOperation);
+
+        }
+    }
+
+    /**
+     * this method returns the operation for the given name if found
+     * otherwise return null
+     * @param operationName
+     * @return operation
+     */
+
+    public Operation getOperation(String operationName){
+        Operation operation = null;
+        boolean operationFound = false;
+        for (Iterator iter = this.operations.iterator();iter.hasNext();){
+            operation = (Operation) iter.next();
+            if (operation.getName().equals(operationName)){
+                operationFound = true;
+                break;
+            }
+        }
+        if (operationFound){
+            return operation;
+        } else {
+            return null;
+        }
+    }
+
+    public Parameter getExceptionParameter(Class exceptionClass){
+        return (Parameter) this.exceptionClassToParameterMap.get(exceptionClass);
+    }
+
+    public Parameter getExceptionParameter(QName exceptionElementQname){
+        return (Parameter) this.exceptionQNameToParameterMap.get(exceptionElementQname);
+    }
+
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Class getJavaClass() {
+        return javaClass;
+    }
+
+    public void setJavaClass(Class javaClass) {
+        this.javaClass = javaClass;
+    }
+
+    public List getOperations() {
+        return operations;
+    }
+
+    public void setOperations(List operations) {
+        this.operations = operations;
+    }
+
+    public Definition getWsdlDefinition() {
+        return wsdlDefinition;
+    }
+
+    public void setWsdlDefinition(Definition wsdlDefinition) {
+        this.wsdlDefinition = wsdlDefinition;
+    }
+
+    public Map getProcessedTypeMap() {
+        return processedTypeMap;
+    }
+
+    public void setProcessedTypeMap(Map processedTypeMap) {
+        this.processedTypeMap = processedTypeMap;
+    }
+
+    public Configurator getConfigurator() {
+        return configurator;
+    }
+
+    public void setConfigurator(Configurator configurator) {
+        this.configurator = configurator;
+    }
+
+    public Map getSchemaMap() {
+        return schemaMap;
+    }
+
+    public void setSchemaMap(Map schemaMap) {
+        this.schemaMap = schemaMap;
+    }
+
+
+}

Added: webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Type.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Type.java?view=auto&rev=565239
==============================================================================
--- webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Type.java (added)
+++ webservices/axis2/trunk/java/modules/rmi/src/org/apache/axis2/rmi/metadata/Type.java Sun Aug 12 22:05:58 2007
@@ -0,0 +1,279 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.rmi.metadata;
+
+import org.apache.axis2.rmi.Configurator;
+import org.apache.axis2.rmi.metadata.xml.XmlType;
+import org.apache.axis2.rmi.metadata.xml.XmlSchema;
+import org.apache.axis2.rmi.metadata.xml.XmlImport;
+import org.apache.axis2.rmi.exception.MetaDataPopulateException;
+import org.apache.axis2.rmi.exception.SchemaGenerationException;
+import org.apache.axis2.rmi.util.JavaTypeToQNameMap;
+import org.apache.axis2.rmi.util.Constants;
+
+import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Iterator;
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+
+public class Type {
+
+    /**
+     * java class corresponds to this XmlType object
+     */
+    private Class javaClass;
+
+    /**
+     * list of attribute objects for this java class
+     */
+    private List attributes;
+
+    /**
+     * name of the Type : class name
+     */
+    private String name;
+
+    /**
+     * namespace of the type : depends on the package
+     */
+    private String namespace;
+
+    /**
+     * parent type for this type
+     */
+    private Type parentType;
+
+    /**
+     * xml metadata type correponding to this type object
+     */
+    private XmlType xmlType;
+
+    private boolean isSchemaGenerated;
+
+
+    public Type() {
+        this.attributes = new ArrayList();
+    }
+
+    public Type(Class javaClass) {
+        this();
+        this.javaClass = javaClass;
+    }
+
+    /**
+     * popualate the meta data corresponding to this type
+     * @param configurator
+     */
+    public void populateMetaData(Configurator configurator,
+                                 Map processedTypeMap)
+            throws MetaDataPopulateException {
+        // java class should alrady have populated.
+
+        // if javaTypeToQNameMap contains this key then this is an either
+        // primitive type or a Simple known type. we don't have to populate
+        // the attribues
+        try {
+            if (!JavaTypeToQNameMap.containsKey(this.javaClass)) {
+                this.name = this.javaClass.getName();
+                this.name = this.name.substring(this.name.lastIndexOf(".") + 1);
+                this.namespace = configurator.getNamespace(this.javaClass.getPackage().getName());
+
+                Class superClass = this.javaClass.getSuperclass();
+
+                // if the supper class is Object class nothing to warry
+                if (!superClass.equals(Object.class) && !superClass.equals(Exception.class)) {
+                    // then this is an extension class and we have to processit
+                    if (!processedTypeMap.containsKey(superClass)) {
+                        Type superClassType = new Type(superClass);
+                        processedTypeMap.put(superClass, superClassType);
+                        superClassType.populateMetaData(configurator, processedTypeMap);
+                    }
+                    this.setParentType((Type) processedTypeMap.get(superClass));
+                }
+
+                // we need informatin only about this class
+                // supper class information is processed in the super class type
+                BeanInfo beanInfo = Introspector.getBeanInfo(this.javaClass, this.javaClass.getSuperclass());
+                PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+                Attribute attribute;
+                for (int i = 0; i < propertyDescriptors.length; i++) {
+                    // remove the class descriptor
+                    attribute = new Attribute(propertyDescriptors[i], this.namespace);
+                    attribute.populateMetaData(configurator, processedTypeMap);
+                    this.attributes.add(attribute);
+                }
+            }
+        } catch (IntrospectionException e) {
+            throw new MetaDataPopulateException(
+                    "Error Occured while getting the Bean info of the class " + this.javaClass.getName(), e);
+        }
+
+    }
+
+    /**
+     * this method sets the xmlType correctly. this method should only be invoked
+     * if it has not already processed
+     * @param configurator
+     * @param schemaMap
+     */
+
+    public void generateSchema(Configurator configurator,
+                               Map schemaMap)
+            throws SchemaGenerationException {
+
+        // here we have to populate the xmlType object properly
+        this.isSchemaGenerated = true;
+        if (JavaTypeToQNameMap.containsKey(this.javaClass)){
+            // i.e. this is a basic type
+            // no need to process or add this to schema list
+            this.xmlType = new XmlType(JavaTypeToQNameMap.getTypeQName(this.javaClass));
+            this.xmlType.setSimpleType(true);
+        } else {
+
+            // get the schema to add the complex type
+            if (schemaMap.get(this.namespace) == null){
+                // create a new namespace for this schema
+                schemaMap.put(this.namespace, new XmlSchema(this.namespace));
+            }
+            XmlSchema xmlSchema = (XmlSchema) schemaMap.get(this.namespace);
+
+            // we have to generate a complex type for this
+            this.xmlType = new XmlType(new QName(this.namespace,this.name));
+            this.xmlType.setSimpleType(false);
+
+             // set the parent type for this type
+            if (this.parentType != null){
+                Type parentType = this.parentType;
+                if (!parentType.isSchemaGenerated()){
+                    parentType.generateSchema(configurator,schemaMap);
+                }
+                this.xmlType.setParentType(parentType.getXmlType());
+                // import the complex type namespace if needed.
+                if (!xmlSchema.containsNamespace(this.xmlType.getParentType().getQname().getNamespaceURI())){
+                    // if the element namespace does not exists we have to add it
+                    if (!this.xmlType.getParentType().getQname().getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
+                        XmlImport xmlImport = new XmlImport(this.xmlType.getParentType().getQname().getNamespaceURI());
+                        xmlSchema.addImport(xmlImport);
+                    }
+                    xmlSchema.addNamespace(this.xmlType.getParentType().getQname().getNamespaceURI());
+                }
+
+            }
+
+            // add elements of the attributes
+            Attribute attribute;
+            for (Iterator iter = this.attributes.iterator();iter.hasNext();){
+                attribute = (Attribute) iter.next();
+                if (!attribute.isSchemaGenerated()){
+                    // if it is not already processed process it.
+                    attribute.generateSchema(configurator,schemaMap);
+                }
+                this.xmlType.addElement(attribute.getElement());
+                // we have to set the namespaces of these element complex types properly
+                QName elementTypeQName = attribute.getElement().getType().getQname();
+                if (!xmlSchema.containsNamespace(elementTypeQName.getNamespaceURI())){
+                    // if the element namespace does not exists we have to add it
+                    if (!elementTypeQName.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
+                        XmlImport xmlImport = new XmlImport(elementTypeQName.getNamespaceURI());
+                        xmlSchema.addImport(xmlImport);
+                    }
+                    xmlSchema.addNamespace(elementTypeQName.getNamespaceURI());
+                }
+
+            }
+            // finally add this complex type to schema map
+            xmlSchema.addComplexType(this.xmlType);
+
+        }
+
+    }
+
+    public void populateAllAttributes(List attributesList){
+        // we have to first add the parent details to keep the order.
+        if (this.parentType != null){
+            this.parentType.populateAllAttributes(attributesList);
+        }
+        attributesList.addAll(this.attributes);
+    }
+
+    public List getAllAttributes(){
+        List allAttributesList = new ArrayList();
+        populateAllAttributes(allAttributesList);
+        return allAttributesList;
+    }
+
+    public boolean isSchemaGenerated() {
+        return isSchemaGenerated;
+    }
+
+    public void setSchemaGenerated(boolean schemaGenerated) {
+        isSchemaGenerated = schemaGenerated;
+    }
+
+    public Class getJavaClass() {
+        return javaClass;
+    }
+
+    public void setJavaClass(Class javaClass) {
+        this.javaClass = javaClass;
+    }
+
+    public List getAttributes() {
+        return attributes;
+    }
+
+    public void setAttributes(List attributes) {
+        this.attributes = attributes;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    public XmlType getXmlType() {
+        return xmlType;
+    }
+
+    public void setXmlType(XmlType xmlType) {
+        this.xmlType = xmlType;
+    }
+
+    public Type getParentType() {
+        return parentType;
+    }
+
+    public void setParentType(Type parentType) {
+        this.parentType = parentType;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message