You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by li...@apache.org on 2007/10/08 20:48:39 UTC

svn commit: r582929 [2/3] - in /geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors: ./ META-INF/ schema/ src/ src/org/ src/org/apache/ src/org/apache/geronimo/ src/org/apache/geronimo/devtools/ src/org/apache/geronimo/devt...

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/EJBDescriptorTool.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/EJBDescriptorTool.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/EJBDescriptorTool.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/EJBDescriptorTool.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,321 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.ejb;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.devtools.j2g.common.ConsoleOutput;
+import org.apache.geronimo.devtools.j2g.common.IFileMigration;
+import org.apache.geronimo.devtools.j2g.common.IOutput;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+import org.apache.geronimo.devtools.j2g.descriptors.ejb.bean.EntityBeanMigrator;
+import org.apache.geronimo.devtools.j2g.descriptors.ejb.bean.SessionBeanMigrator;
+import org.apache.geronimo.devtools.j2g.util.descriptors.Constants;
+import org.apache.geronimo.devtools.j2g.util.descriptors.env.EnvirionmentElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.naming.NamingElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.security.SecurityElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.xml.XMLConversionHelper;
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.QName;
+
+public class EJBDescriptorTool implements IFileMigration {
+
+    private IOutput out;
+
+    private Log logger = LogFactory.getLog(EJBDescriptorTool.class);
+
+    private EnvirionmentElementProcessor envirionmentElementProcessor;
+
+    private SessionBeanMigrator sessionBeanMigrator;
+
+    private EntityBeanMigrator entityBeanMigrator;
+
+    private NamingElementProcessor namingElementProcessor;
+
+    private SecurityElementProcessor securityElementProcessor;
+        
+    // location of the properties file used to extract the differences
+    private final String PROP_PERSISTENCE_FILENAME = "persistence_differences.properties";
+    private final String PROP_PERSISTENCE_DIRECTORY = System.getenv("ECLIPSE_HOME")+"/plugins/org.apache.geronimo.devtools.j2g.descriptors.ejb/";
+  
+
+    public EJBDescriptorTool() {
+    	
+    	Tool currentTool = Tool.getCurrent();
+    	if (currentTool != null) {
+    		out = currentTool.getOutput();
+    	} else {
+    		out = new ConsoleOutput();
+    	}
+        envirionmentElementProcessor = new EnvirionmentElementProcessor();
+        namingElementProcessor = new NamingElementProcessor(envirionmentElementProcessor);
+        sessionBeanMigrator = new SessionBeanMigrator(envirionmentElementProcessor,
+                namingElementProcessor);
+        entityBeanMigrator = new EntityBeanMigrator(envirionmentElementProcessor,
+                namingElementProcessor);
+        securityElementProcessor = new SecurityElementProcessor();
+
+    }
+
+    /**
+     * migrates both the jboss.xml and jbosscmp-jdbc.xml file to openejb-jar.xml
+     * in geronimo
+     * 
+     * @param file
+     * @return migrate sucess or not
+     */
+
+    public boolean migrate(File file, File rootDirectory) {
+        boolean migrated = false;
+            String directoryName = file.getParent();
+            String jbossFileName = file.getName();
+            logger.debug("Directory Name ==> " + directoryName + " jboss file Name ==> "
+                    + jbossFileName);
+
+            if (jbossFileName.equals(Constants.JBOSS_JBOSS_XML_FILE)) {
+                out.info(EJBDescriptorTool.class.getSimpleName(), "Converting Jboss.xml file in " + directoryName);
+                try {
+                    // check whether the jbosscmp-jdbc.xml file is present and
+                    // if so load it and process it.
+                    Document jbossDocument = XMLConversionHelper.getDocument(file);
+                    Document geronimoDocument = XMLConversionHelper
+                            .getOpenEJBJarDocument(directoryName);
+                    migrate(jbossDocument.getRootElement(), geronimoDocument.getRootElement());
+                    String geronimoOpenEjbJarFileName = directoryName + File.separator
+                            + Constants.GERONIMO_OPEN_EJB_XML_FILE;
+                    XMLConversionHelper.saveOpenEJBDocument(geronimoOpenEjbJarFileName,
+                            geronimoDocument);
+                    migrated = true;
+                    out.info(EJBDescriptorTool.class.getSimpleName(), "Successfully migrated the Jboss.xml file in "
+                            + directoryName + ", with the error and warning messages as shown");
+                } catch (DocumentException e) {
+                	out.error(EJBDescriptorTool.class.getSimpleName(), "Error occured while reading xml descriptor "
+    						+ file.getAbsolutePath()
+    						+ ". It is possible that the migrator cannot download the xml schema or the xml file has incorrect syntax. Nested exception:"
+    						+ e.getMessage());
+                } catch (IOException e) {
+                    out.error(EJBDescriptorTool.class.getSimpleName(), "IO exception " + e.getMessage());
+                }
+            } else if (jbossFileName.equals(Constants.EJB_JAR_XML_FILE)){
+                out.info(EJBDescriptorTool.class.getSimpleName(), "Converting ejb-jar.xml file in " + directoryName);
+                out.info(EJBDescriptorTool.class.getSimpleName(), "Nothing to convert. No changes required for this file");
+            }  else if (jbossFileName.equals(Constants.PERSISTENCE_XML_FILE)) {
+	                out.info(EJBDescriptorTool.class.getSimpleName(), "Converting the persistence.xml file in " + directoryName);
+                try {
+                    // get the dom4j representation from the persistence.xml files
+                    Document persistenceDoc = XMLConversionHelper.getPersistenceDocument(directoryName);
+                    // populate the differences
+                    HashMap<String, String> diffs = populatePersistenceDifferences();
+                    // migrate from the jboss persistence.xml to geronimo's persistence.xml
+                    migratePersistence(persistenceDoc.getRootElement(), diffs);
+                    // construct the path
+                    String geronimoPersistenceFileName = directoryName + File.separator
+                                                                       + Constants.PERSISTENCE_XML_FILE;
+                    // save the file
+                    XMLConversionHelper.saveGeronimoDocument(geronimoPersistenceFileName, persistenceDoc);
+                    migrated = true;
+                    out.info(EJBDescriptorTool.class.getSimpleName(), "Successfully migrated the persistence.xml file in "
+                                + directoryName + ", with the error and warning messages as shown");
+                } catch(DocumentException e) {
+                    out.error(EJBDescriptorTool.class.getSimpleName(), "Error occured while reading xml descriptor "
+                        + file.getAbsolutePath()
+                        + ". It is possible that the migrator cannot download the xml schema or the xml file has incorrect syntax. Nested exception:"
+                        + e.getMessage());
+                } catch(IOException e) {
+                    out.error(EJBDescriptorTool.class.getSimpleName(), "IO exception " + e.getMessage());
+                }
+            }
+        return migrated;
+    }
+
+    private void migratePersistence(Element rootElement, HashMap<String, String> diffs) {
+        // iterate through all the elements and convert them accordingly
+        Element rootChildElement;
+        boolean hasJTA = false;
+        boolean hasNonJTA = false;
+        for(Iterator it = rootElement.elements().iterator(); it.hasNext(); ) {
+            rootChildElement = (Element) it.next();
+            if(rootChildElement.getName().equals("jta-data-source")) {
+                hasJTA = true;
+            } else if(rootChildElement.getName().equals("non-jta-data-source")) {
+                hasNonJTA = true;
+            } else if(rootChildElement.getName().equals("property")) {
+                // swap out the name attribute of each <property> element
+                Attribute nameAttr = rootChildElement.attribute("name");
+                String nameValue = nameAttr.getValue();
+                String replacementValue = null;
+                if(diffs.containsKey(nameValue)) {
+                    replacementValue = diffs.get(nameValue);
+                    if(replacementValue.startsWith("suggestion:")) {
+                        // warn the user that there is a possible solution, but requires further configuration
+                        out.warn(EJBDescriptorTool.class.getSimpleName(), "persistence.xml SUGGESTION: " + nameValue + " should probably be replaced by " + replacementValue +
+                                    " but further configuration may be needed.");
+                    } else {
+                        // replace the property.name element with the analogous
+                        nameAttr.setValue(replacementValue);
+                        // update the tree
+                        rootChildElement.addAttribute("name", replacementValue);
+                        // tell them
+                        out.info(EJBDescriptorTool.class.getSimpleName(), "persistence.xml: " + nameValue + " was replaced by " + replacementValue);
+                    }
+                } else {
+                    out.warn(EJBDescriptorTool.class.getSimpleName(), "You should manually convert this property name: " + nameValue);
+                    continue;
+                }
+            } else {
+                // recurse until I get to the end of the tree or when I see the <property> elements
+                migratePersistence(rootChildElement, diffs);
+            }
+        }
+        // when there is a jta-data-source, provide a non-jta-data-source tag
+        // if it does not already exist
+        if(hasJTA && !hasNonJTA) {
+            QName nonJTA = new QName("non-jta-data-source", rootElement.getNamespace());
+            Element nonJTAElement = rootElement.addElement(nonJTA);
+            out.warn(EJBDescriptorTool.class.getSimpleName(), "You should set the text of <non-jta-data-source> to point to a non-JTA datasource.");
+        }
+    }
+	    
+    private HashMap<String, String> populatePersistenceDifferences() {
+        //  populate the hashmap with info from the properties file
+        HashMap<String, String> diffs = new HashMap<String, String>();
+        Properties mappingProps = new Properties();
+        try {
+        	File propertyFile = new File(PROP_PERSISTENCE_DIRECTORY + PROP_PERSISTENCE_FILENAME);
+            mappingProps.load(new FileInputStream( propertyFile ));
+            // fetch all keys from the properties file
+            Enumeration keys = mappingProps.propertyNames();
+            // for each key, store the analogous into the hashmap
+            while(keys.hasMoreElements()) {
+                String key = (String)keys.nextElement();
+                String value = mappingProps.getProperty(key);
+                diffs.put(key, value);
+            }
+        } catch(Exception e) {
+            out.error(EJBDescriptorTool.class.getSimpleName(), "Cannot find properties file: " + PROP_PERSISTENCE_FILENAME);
+        }
+        return diffs;
+    }
+	  
+
+    private void migrate(Element jbossRootElement, Element geronimoRootElement) {
+
+        // iterate through all the elements and convert them accordingly
+        Element jbossRootChildElement;
+        for (Iterator iter = jbossRootElement.elements().iterator(); iter.hasNext();) {
+            jbossRootChildElement = (Element) iter.next();
+            if (jbossRootChildElement.getName().equals("security-domain")) {
+                securityElementProcessor.setSecurityDomain(jbossRootChildElement.getText());
+            } else if (jbossRootChildElement.getName().equals("enterprise-beans")) {
+                logger.debug("migrating enterprise-beans");
+                // process the enterprise bean element
+                // add enterprise beans element to geronimo
+                // this element is in the same name space as the root element
+                Element geronimoEnterpriseBean = XMLConversionHelper.getGeronimoElement(
+                        geronimoRootElement, "//ejb:enterprise-beans", "enterprise-beans",
+                        geronimoRootElement.getNamespace());
+                migrateEnterpriseBeans(jbossRootChildElement, geronimoEnterpriseBean);
+            } else if (jbossRootChildElement.getName().equals("assembly-descriptor")) {
+                migrateAssemblyDescriptor(jbossRootChildElement, geronimoRootElement);
+            } else {
+                out.warn(EJBDescriptorTool.class.getSimpleName(), "The Element '" + jbossRootChildElement.getName() + "' is not supported",
+                        XMLConversionHelper.getLineNumber(jbossRootChildElement),
+                        XMLConversionHelper.getColumnNumber(jbossRootChildElement));
+                logger.debug("The Element '" + jbossRootChildElement.getName()
+                        + "' is not supported");
+            }
+        }
+    }
+
+    private void migrateAssemblyDescriptor(Element jbossAssemblyDescriptor,
+            Element geronimoRootElement) {
+
+        Element jbossAssemblyDescriptorChildElement;
+        for (Iterator iter = jbossAssemblyDescriptor.elements().iterator(); iter.hasNext();) {
+            jbossAssemblyDescriptorChildElement = (Element) iter.next();
+            if (jbossAssemblyDescriptorChildElement.getName().equals("security-role")) {
+                Element geronimoRoleMapping = securityElementProcessor
+                        .getGeronimoSecurityRoleElement(geronimoRootElement);
+                securityElementProcessor.migrateSecurityRole(jbossAssemblyDescriptorChildElement,
+                        geronimoRoleMapping);
+            } else {
+                out.warn(EJBDescriptorTool.class.getSimpleName(), "The Element '" + jbossAssemblyDescriptorChildElement.getName()
+                        + "' is not supported", XMLConversionHelper
+                        .getLineNumber(jbossAssemblyDescriptorChildElement), XMLConversionHelper
+                        .getColumnNumber(jbossAssemblyDescriptorChildElement));
+                logger.debug("The Element '" + jbossAssemblyDescriptorChildElement.getName()
+                        + "' is not supported");
+            }
+        }
+    }
+
+    /**
+     * this migrates the enterprise-beans part
+     * 
+     * @param jbossEnterpriseBeans
+     * @param geronimoEnterpriseBeans
+     */
+    private void migrateEnterpriseBeans(Element jbossEnterpriseBeans,
+            Element geronimoEnterpriseBeans) {
+
+        Element jbossEnterpriseBeanChildElement;
+        for (Iterator iter = jbossEnterpriseBeans.elements().iterator(); iter.hasNext();) {
+            jbossEnterpriseBeanChildElement = (Element) iter.next();
+            if (jbossEnterpriseBeanChildElement.getName().equals("session")) {
+                // session beans can only come from jboss.xml file
+                logger.debug("migrating session beans");
+                QName qname = new QName("session", geronimoEnterpriseBeans.getNamespace());
+                Element geronimoSession = geronimoEnterpriseBeans.addElement(qname);
+                sessionBeanMigrator.migrateBean(jbossEnterpriseBeanChildElement, geronimoSession);
+            } else if (jbossEnterpriseBeanChildElement.getName().equals("entity")) {
+                logger.debug("migrating entity beans");
+                // get the session ejb name
+                Element ejbNameElement = jbossEnterpriseBeanChildElement.element("ejb-name");
+                String ejbName = ejbNameElement.getText();
+                logger.debug("Converting ejb session with name ==> " + ejbName);
+                // create a session bean in geronimo
+                String xpath = "//ejb:enterprise-beans/ejb:entity[ejb:ejb-name/text() = '"
+                        + ejbName + "']";
+                logger.debug("Find existing ejb using query ==>" + xpath);
+                Element geronimoEntity = XMLConversionHelper.getGeronimoElement(
+                        geronimoEnterpriseBeans, xpath, "entity", geronimoEnterpriseBeans
+                                .getNamespace());
+                entityBeanMigrator.migrateBean(jbossEnterpriseBeanChildElement, geronimoEntity);
+            } else {
+                out.warn(EJBDescriptorTool.class.getSimpleName(), "The Element '" + jbossEnterpriseBeanChildElement.getName()
+                        + "' is not supported", XMLConversionHelper
+                        .getLineNumber(jbossEnterpriseBeanChildElement), XMLConversionHelper
+                        .getColumnNumber(jbossEnterpriseBeanChildElement));
+                logger.debug("The Element '" + jbossEnterpriseBeanChildElement.getName()
+                        + "' is not supported");
+            }
+        }
+    }
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/EJBDescriptorTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationConverter.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationConverter.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationConverter.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationConverter.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,245 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.ejb.annotation;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.devtools.j2g.common.ConsoleOutput;
+import org.apache.geronimo.devtools.j2g.common.IOutput;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+
+//
+// Provides the functionality to convert a JBoss-supported annotation
+// to a Geronimo-supported annotation.
+//
+public class AnnotationConverter {
+    // key - annotation keyword
+    // value -  mappings from JBoss-supported attributes associated with the keyword
+    //          to Geronimo-supported attributes associated with the keyword (may be different)
+    private HashMap<String, HashMap<String, String>> j2gAnnotationDifferences;
+    // location of the properties file used to extract the differences
+    private final String PROP_ANNOTATION_FILENAME = "annotation_differences.properties";
+    private final String PROP_ANNOTATION_DIRECTORY = System.getenv("ECLIPSE_HOME")+"/plugins/org.apache.geronimo.devtools.j2g.descriptors.ejb.annotation/";
+
+    // annotations that MAY require further configuration by the user
+    private final String[] ambiguousAnnotations = {"@Resource", "@MessageDriven"};
+
+    // annotations that WILL require further configuration by the user
+    private final String[] needsConfigurationAnnotations = {"@Stateless", "@Stateful", "@Resource"};
+
+    private final IOutput out;
+
+    private Log log = LogFactory.getLog(AnnotationConverter.class);
+
+    public AnnotationConverter() {
+        Tool currentTool = Tool.getCurrent();
+        if (currentTool != null) {
+            out = currentTool.getOutput();
+        } else {
+            out = new ConsoleOutput();
+        }
+        //  populate the hashmap with the annotation info supported by
+        //  JBoss and Geronimo.
+        j2gAnnotationDifferences = new HashMap<String, HashMap<String, String>>();
+        populateJ2GAnnotations();
+    }
+
+    // ArrayList<String> getAnnotations(String fileStr)
+    //
+    // Takes in a file as a string and returns all of the annotations
+    // present in the file. 
+    //
+    // When there are annotations within annotations, the outter annotation
+    // will appear in the list before the inner annotations.
+    public ArrayList<String> getAnnotations(String fileStr) {
+        // warn the user if there exists JBoss-specific annotations
+        if(fileStr.contains("org.jboss.annotation.ejb.")) {
+            out.warn(AnnotationConverter.class.getSimpleName(), "This file is using JBoss's extension to EJB annotations. Convert them accordingly, as " +
+                     "Geronimo does not support them.");
+        }
+        // list of annotations found from fileStr
+        ArrayList<String> listOfAnnotations = new ArrayList<String>();
+        // true when the part we are examining is a string defined in double quotes
+        boolean isStringMode = false;
+        // stores the last character that was examined
+        char lastChar = ' ';
+        // process the entire filestring and parse annotations
+        for(int i = 0; i < fileStr.length(); i++) {
+            char currChar = fileStr.charAt(i);
+            // determine if we are in stringMode
+            if(isStringMode) {
+                // ignore all occurrences of any letter except for an ending quote
+                if(currChar == '"' && lastChar != '\\') {
+                    isStringMode = false;
+               }
+            } else {  // not in String mode
+                // beginning of an annotation
+                if(currChar == '@') {
+                    // find a matching annotation from the list
+                    Set annotationSet = j2gAnnotationDifferences.keySet();
+                    boolean notFound = true;
+                    String currAnnotation = null;
+                    for(Iterator it = annotationSet.iterator(); it.hasNext() && notFound; ) {
+                        String annotation = (String)it.next();
+                        // check for a match
+                        // ignore annotations without attributes
+                        if(fileStr.substring(i+1, i+1+annotation.length()).equals(annotation) &&
+                                  isNextChar(fileStr, i+annotation.length()+1, '(')) {
+                            // get the position of the closing parentheses
+                            int toPos = getClosingParenthesesPos(fileStr, fileStr.indexOf('(', i));
+                            // grab everything from i --> toPos (inclusive) as our new annotation
+                            currAnnotation = fileStr.substring(i, toPos+1);
+                            // set found flag
+                            notFound = false;
+                        }
+                    }
+                    // add this newly found annotation to the list
+                    if( !notFound ) {
+                        listOfAnnotations.add(currAnnotation);
+                    }
+                } else if(currChar == '"') {
+                    isStringMode = true;
+                }
+            }
+            // set up for next iteration
+            lastChar = currChar;
+        }
+
+        // warn the user if there are possible ambigous annotations in their code
+        // because jboss creates these references automatically, but geronimo does not
+        for(int i = 0; i < ambiguousAnnotations.length; i++) {
+            if(fileStr.contains(ambiguousAnnotations[i])) {
+                out.warn(AnnotationConverter.class.getSimpleName(), ambiguousAnnotations[i] + " annotations may not be fully specified in "
+                                    + "the deployable. To fix this, you can create what these " 
+                                    + "are supposed to reference and set a dependency on it.");
+            }
+        }
+        // warn the user if there will be further configuration needed in the web.xml
+        // becaues jboss creates these references automatically, but geronimo does not
+        for(int i = 0; i < needsConfigurationAnnotations.length; i++) {
+            if(fileStr.contains(needsConfigurationAnnotations[i])) {
+                if(needsConfigurationAnnotations[i].equals("@Resource")) {
+                    out.warn(AnnotationConverter.class.getSimpleName(), "IMPORTANT: You need to update web.xml to include a <resource-ref> if you are referring to a managed connection factory or <message-destination-ref> if you are referring to a message destination (e.g. queue).");
+                } else {
+                    out.warn(AnnotationConverter.class.getSimpleName(), "IMPORTANT: You need to update web.xml to include a <ejb-local-ref> if you wish to use this EJB in a web app." );
+                }
+            }
+        }
+        return listOfAnnotations;
+    }
+
+    // Returns a boolean value specifying whether or not the next non-white
+    // space character (starting from 'start') is the same as 'target'
+    private boolean isNextChar(String fileStr, int start, char target) {
+        for(int i = start; i < fileStr.length(); i++) {
+            if(fileStr.charAt(i) != ' ') {
+                return (fileStr.charAt(i) == target);
+            }
+        }
+        return false;
+    }
+
+    // Returns the position in the 'fileStr' that has the matching closing parenthesis
+    // given the position of the opening parenthesis
+    private int getClosingParenthesesPos(String fileStr, int start) {
+        int unClosedParentheses = 1;
+        for(int i = start+1; i < fileStr.length(); i++) {
+            if(fileStr.charAt(i) == '(') {
+                unClosedParentheses++;
+            } else if(fileStr.charAt(i) == ')') {
+                unClosedParentheses--;
+            }
+            // stop when we found the match
+            if(unClosedParentheses == 0) {
+                return i;
+            }
+        }
+        // not even syntactically correct
+        return -1;
+    }
+
+    // String j2gAnnotation(String jbossAnnotation)
+    //
+    // Takes a JBoss annotation and returns the Geronimo representation of it
+    public String j2gAnnotation(String jbossStr) {
+        AnnotationInstance annotation = new AnnotationInstance(jbossStr);
+        ArrayList<String> attrKeys = annotation.getAttributeKeys();
+        ArrayList<String> attrVals = annotation.getAttributeValues();
+        // store the differences between jboss and geronimo for this annotation
+        HashMap<String, String> mappings = j2gAnnotationDifferences.get(annotation.getKeyword());
+        // list of attribute keys from the annotation
+        ArrayList<String> attributeKeys = annotation.getAttributeKeys();
+        // for each attribute key, replace any difference with the conversion
+        for(int i = 0; i < attributeKeys.size(); i++) {
+            String from = attributeKeys.get(i);
+            String to = mappings.get(from);
+            // replace this attribute if there is a difference between jboss and geronimo
+            if(from != null) {
+                if(to == null) {
+                    // there is no specified conversion in the properties file.
+                } else {
+                    annotation.replaceAttributeKey(from, to);
+                }
+            }
+        }
+        return annotation.toString();
+    }
+
+    private void populateJ2GAnnotations() {
+        //  populate the hashmap with info from the properties file
+        Properties mappingProps = new Properties();
+        try {
+        	File propertyFile = new File(PROP_ANNOTATION_DIRECTORY + PROP_ANNOTATION_FILENAME);    	
+            mappingProps.load(new FileInputStream( propertyFile ));
+            // fetch all keys from the properties file
+            Enumeration keys = mappingProps.propertyNames();
+            // for each key (which is an annotation), store the differences into the hashmap
+            while(keys.hasMoreElements()) {
+                // initialize hashmap for each annotation with the differences in attributes
+                HashMap<String, String> diffs = new HashMap<String, String>();
+                // key is an annotation
+                String key = (String)keys.nextElement();
+                // value is the list of different attributes
+                String value = mappingProps.getProperty(key);
+                // break by attribute
+                String[] attributes = value.split(",");
+                // for each attribute, we are going to store them into the hashmap
+                for(int i = 0; i < attributes.length; i++) {
+                    // break attribute into jboss-supported-attr and geronimo-supported-attr
+                    String[] attrPair = attributes[i].split("-->");
+                    // save this difference
+                    diffs.put(attrPair[0], attrPair[1]);
+                }
+                // save all differences as the value to the annotation
+                j2gAnnotationDifferences.put(key, diffs);
+            }
+        } catch(Exception e) {
+            log.error("Cannot find properties file: " + PROP_ANNOTATION_FILENAME);
+            System.out.println("Cannot find properties file: " + PROP_ANNOTATION_FILENAME);
+        }
+    }
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationInstance.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationInstance.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationInstance.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationInstance.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,157 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.ejb.annotation;
+
+import java.util.ArrayList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class AnnotationInstance {
+
+    private Log log = LogFactory.getLog(AnnotationInstance.class);
+    private String keyword;
+    private ArrayList<String> attributeKeys = new ArrayList<String>();
+    private ArrayList<String> attributeValues = new ArrayList<String>();
+
+
+    public AnnotationInstance(String fullAnnotation) {
+        // replace all whitespace characters that are outside of a string with a no-space
+        fullAnnotation = removeWhiteSpace(fullAnnotation);
+        // parse the annotation into keyword, attributeKeys, and attributeValues and store it
+        keyword = fullAnnotation.substring(fullAnnotation.indexOf("@")+1, fullAnnotation.indexOf("("));
+        String attributeString = fullAnnotation.substring(fullAnnotation.indexOf("(")+1, fullAnnotation.length()-1).trim();
+        // break into individual attributes
+        boolean foundKey = false;
+        String key = "", value = "";
+        // a turing machine that parses the highest level by using 
+        for(int i = 0 ; i < attributeString.length(); i++) {
+            if(foundKey == false && attributeString.charAt(i) != ' ' && attributeString.charAt(i) != ',') {
+                int equalPosition = attributeString.indexOf('=', i);
+                key = attributeString.substring(i, equalPosition).trim();
+                foundKey = true;
+                // jump over key 
+                i += key.length()-1;
+            } else if(foundKey) {
+                int closingPosition = -1;
+                if(attributeString.charAt(i) == '{') {
+                    closingPosition = getMatchingPosition(attributeString, i, '{', '}');
+                } else if(attributeString.charAt(i) == '"') {
+                    closingPosition = getMatchingPosition(attributeString, i, '"', '"');
+                } else {
+                    continue;
+                }
+                // the value will include " or { in the front and back
+                value = attributeString.substring(i, closingPosition+1).trim();
+                foundKey = false;
+                // add key and attribute to the lists
+                attributeKeys.add(key);
+                attributeValues.add(value);
+                // jump over value
+                i += value.length()-1;
+            }
+        }
+    }
+
+    public AnnotationInstance(String key, ArrayList<String> attrKeys, ArrayList<String> attrValues) {
+        keyword = key;
+        attributeKeys = attrKeys;
+        attributeValues = attrValues;
+    }
+
+    private String removeWhiteSpace(String s) {
+        String retval = "";
+        // for each white space character
+        for(int i = 0; i < s.length(); i++) {
+            // everything but whitespaces
+            if(s.charAt(i) != ' ') {
+                retval += s.charAt(i);
+                // the next part of this annotation will be part of a hard coded string
+                if(s.charAt(i) == '"') {
+                    // skip this chunk
+                    String stringChunk = s.substring(i+1, getMatchingPosition(s, i, '"', '"') + 1);
+                    retval += stringChunk;
+                    i = getMatchingPosition(s, i, '"', '"');
+                }
+            }
+        }
+        return retval;
+    }
+
+    private int getMatchingPosition(String str, int start, char open, char close) {
+        int unclosed = 1;
+        for(int i = start+1; i < str.length(); i++) {
+            if(close == str.charAt(i)) {
+                unclosed--;
+            } else if(open == str.charAt(i)) {
+                unclosed++;
+            }
+            // found matching
+            if(unclosed == 0) {
+                return i;
+            }
+        }
+        // not syntactically correct
+        return -1;
+    }
+
+    public String getKeyword() {
+        return keyword;
+    }
+
+    public ArrayList<String> getAttributeKeys() {
+        return attributeKeys;
+    }
+
+    public ArrayList<String> getAttributeValues() {
+        return attributeValues;
+    }
+
+    public void replaceAttributeKey(String from, String to) {
+        // for each attributeKey that needs to be replaced, replace it
+        for(int i = 0; i < attributeKeys.size(); i++) {
+            if(from.equals(attributeKeys.get(i))) {
+                attributeKeys.set(i, to);   // replacing
+            }
+        }
+    }
+
+    public String toString() {
+        // preparing the keyword
+        String key = "@" + keyword;
+        // preparing the attributes
+        String attributes = "";
+        for(int i = 0; i < attributeKeys.size(); i++) {
+            attributes += attributeKeys.get(i) + "=";
+            attributes += attributeValues.get(i);
+            // add a comma after each attribute, except for the last attribute
+            if(i != attributeKeys.size()-1) {
+                attributes += ",";
+            }
+        }
+        // build and return the annotation in string form
+        return (key + "(" + attributes + ")");
+    }
+
+    private String[] trimAll(String[] list) {
+        for(int i = 0; i < list.length; i++) {
+            list[i] = list[i].trim();
+        }
+        return list;
+    }
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationInstance.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationTool.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationTool.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationTool.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationTool.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,275 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.ejb.annotation;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Iterator;
+
+import org.apache.geronimo.devtools.j2g.util.descriptors.Constants;
+import org.apache.geronimo.devtools.j2g.util.descriptors.xml.XMLConversionHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.devtools.j2g.common.ConsoleOutput;
+import org.apache.geronimo.devtools.j2g.common.IFileMigration;
+import org.apache.geronimo.devtools.j2g.common.IOutput;
+import org.apache.geronimo.devtools.j2g.common.XMLMigrationTool;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+import org.dom4j.Element;
+import org.dom4j.Document;
+import org.dom4j.Namespace;
+import org.dom4j.Node;
+import org.dom4j.QName;
+
+public class AnnotationTool implements IFileMigration {
+    private IOutput out;
+    private Log logger = LogFactory.getLog(AnnotationTool.class);
+    // stores the directory in which jboss.xml is found
+    // if there is not a jboss.xml file, the it will
+    // contain the root directory
+    private static File jbossXMLDirectory;
+    private AnnotationConverter converter;
+
+    public AnnotationTool() {
+        Tool currentTool = Tool.getCurrent();
+        if (currentTool != null) {
+            out = currentTool.getOutput();
+        } else {
+            out = new ConsoleOutput();
+        }
+        converter = new AnnotationConverter();
+        jbossXMLDirectory = null;
+    }
+
+    public boolean migrate(File source, File rootDirectory) {
+        boolean migrated = false;
+        if(jbossXMLDirectory == null) {
+            jbossXMLDirectory = getJBossXMLDirectory(rootDirectory);
+        }
+        try {
+            if (source.getCanonicalPath().endsWith(XMLMigrationTool.JAVA_SUFFIX)) {
+                out.info(AnnotationTool.class.getSimpleName(), "Processing annotations for " + source.getCanonicalPath());
+                // get the contents of the file
+                String fileStr = getFileContents(source);
+                // retrieve all annotations
+                ArrayList<String> jbossAnnotations = converter.getAnnotations(fileStr);
+                // The list given by getAnnotations() is ordered such that the outer annotations will
+                // appear before the inner annotations. Therefore, if we replace the outside one first,
+                // then the inside one nothing will be damaged.
+                for (int i = 0; i < jbossAnnotations.size(); i++) {
+                    String geronimoAnnotation = converter.j2gAnnotation(jbossAnnotations.get(i));
+                    if(!jbossAnnotations.get(i).equals(geronimoAnnotation) ) {
+                        out.info(AnnotationTool.class.getSimpleName(), "JBoss annotation: " + jbossAnnotations.get(i));
+                        out.info(AnnotationTool.class.getSimpleName(), "Geronimo annotation: " + geronimoAnnotation);
+                        // swap in the geronimo stuff.
+                        fileStr = fileStr.replace(jbossAnnotations.get(i), geronimoAnnotation);
+                    }
+                }
+                // write what is in the altered string to source file
+                writeContents(source, fileStr);
+                // Use the jbossXMLDirectory as the directory to place
+                // and/or look for the openejb-jar.xml. 
+                Document openEJBDoc = XMLConversionHelper.getOpenEJBJarDocument(jbossXMLDirectory.getAbsolutePath());
+                // synchronize annotations with openejb-jar.xml
+                updateOpenEJBJar(openEJBDoc, jbossAnnotations, source);
+                // save this openejb-jar.xml
+                XMLConversionHelper.saveGeronimoDocument(
+                jbossXMLDirectory.getAbsolutePath() + File.separator + Constants.GERONIMO_OPEN_EJB_XML_FILE,
+                openEJBDoc);
+                out.info(AnnotationTool.class.getSimpleName(), "openejb-jar.xml successfully updated.");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return migrated;
+    }
+    
+    private void updateOpenEJBJar(Document openEJBDoc, ArrayList<String> jbossAnnotations, File source) {
+        // TODO:
+        // Update the openejb-jar.xml based on the annotations.
+        for(int i = 0; i < jbossAnnotations.size(); i++) {
+            AnnotationInstance annotation = new AnnotationInstance(jbossAnnotations.get(i));         
+            // message driven class
+            if(annotation.getKeyword().equals("MessageDriven")) {
+                // the default mdbName is the class name
+                // unless specified otherwise
+                String mdbName = source.getName().substring(0, source.getName().indexOf("."));
+                // TODO:
+                // Maybe there is a way to get the resource-link name, so here is where you want
+                // to retrieve it if possible. Otherwise, the user will have to manually specify one.
+                
+                // resource-link name
+                String resourceLink = null;
+                // check to see if the mdbName is specified to be something different
+                ArrayList<String> attrValues = annotation.getAttributeValues();
+                ArrayList<String> attrKeys = annotation.getAttributeKeys();
+                for(int j = 0; j < attrKeys.size(); j++) {
+                    if(attrKeys.get(j).equals("name")) {
+                        mdbName = attrValues.get(j);
+                    } else if(attrKeys.get(j).equals("mappedName")) {
+                        mdbName = attrValues.get(j);
+                    }
+                }
+                // add this mdb instance to the xml
+                addMessageDrivenInstance(openEJBDoc, mdbName, resourceLink);
+            }
+            // TODO:
+            // Add more variations to the openejb-jar.xml
+            // as I may be missing some cases.
+        }
+    }
+    
+    private void addMessageDrivenInstance(Document openEJBDoc, String name, String link) {
+        Element rootElement = openEJBDoc.getRootElement();
+        // key = element name
+        // value = list of elements under the node with element name (=key)
+        Map elementMaps = XMLConversionHelper.getChildrenHashMap(rootElement);
+        Element enterpriseBeanElement = null;
+        if( !elementMaps.containsKey("enterprise-beans") ) {
+            // create an <enterprise-beans> tag
+            QName qname = new QName("enterprise-beans", rootElement.getNamespace());
+            enterpriseBeanElement = rootElement.addElement(qname);
+        } else {
+            // go through and find an enterprise-beans tag
+            for(Iterator it = rootElement.elementIterator(); it.hasNext(); ) {
+                Element element = (Element)it.next();
+                if(element.getName().equals("enterprise-beans")) {
+                    // save this enterprise-bean element to update later
+                    enterpriseBeanElement = element;
+                }
+            }
+        }
+        // add <message-driven> to enterpriseBeanElement
+        addMDBElement(enterpriseBeanElement, name, link);
+    }
+    
+    private void addMDBElement(Element enterpriseElement, String name, String link) {
+        // TODO:
+        // Check for duplicates in the <enterprise-beans> tag
+
+        Namespace namespace = enterpriseElement.getNamespace();
+        QName mdbQName = new QName("message-driven", namespace);
+        QName ejbQName = new QName("ejb-name", namespace);
+        QName resourceAdapterQName = new QName("resource-adapter", namespace);
+        QName resourceLinkQName = new QName("resource-link", namespace);
+        // Structure:
+        // 
+        // <enterprise-beans>
+        //      <message-driven>
+        //          <ejb-name>
+        //          <resource-adapter>
+        //              <resource-link>
+        Element mdbElement = enterpriseElement.addElement(mdbQName);
+        Element ejbElement = mdbElement.addElement(ejbQName);
+        if(name != null) {
+            ejbElement.setText(name);
+        } else {
+            out.warn(AnnotationTool.class.getSimpleName(), "Unable to determine ejb-name value: supply your own.");
+        }
+        Element resourceAdapterElement = mdbElement.addElement(resourceAdapterQName);
+        Element resourceLinkElement = resourceAdapterElement.addElement(resourceLinkQName);
+        if(link != null) {
+            resourceLinkElement.setText(link);
+        } else {
+            out.warn(AnnotationTool.class.getSimpleName(), "You need to supply your own reference to a resource-link.");
+        }
+    }
+    
+    private File getJBossXMLDirectory(File root) {
+        // if there is a jboss.xml somewhere in the root directory
+        // return the directory in which is resides. Otherwise,
+        // return the root directory itself.
+        List<File> files = getListFromArray(root.listFiles());
+        while(files.size() != 0) {
+            File file = files.get(0);
+            if(file.isDirectory()) {
+                // recurse iteratively
+                List<File> additionalFiles = getListFromArray(file.listFiles());
+                files.addAll(additionalFiles);
+            } else {
+                // check if it is a jboss.xml
+                if(file.getName().equals(Constants.JBOSS_JBOSS_XML_FILE)) {
+                    return file.getParentFile();
+                }
+            }
+            // remove this already-processed file
+            files.remove(0);
+        }
+        return root;
+    }
+
+    private List<File> getListFromArray(File[] arry) {
+        List<File> list = new ArrayList<File>();
+        for(int i = 0; i < arry.length; i++) {
+            list.add(arry[i]);
+        }
+        return list;
+    }
+    
+    private void writeContents(File source, String fileStr) {
+        Writer output = null;
+        try {
+            output = new BufferedWriter(new FileWriter(source));
+            output.write(fileStr);
+        } catch (IOException e) {
+            out.error(AnnotationTool.class.getSimpleName(), "Cannot write to file");
+        } finally {
+            try {
+            if (output != null)
+                output.close();
+            } catch (IOException e) {
+                out.error(AnnotationTool.class.getSimpleName(), "Cannot close file");
+            }
+        }
+    }
+
+    private String getFileContents(File source) {
+        // read and save file in a string buffer
+        StringBuffer fileStrBuffer = new StringBuffer();
+        BufferedReader in = null;
+        try {
+            in = new BufferedReader(new FileReader(source));
+            String line = null;
+            while ((line = in.readLine()) != null) {
+                fileStrBuffer.append(line);
+                fileStrBuffer.append(System.getProperty("line.separator"));
+            }
+        } catch (FileNotFoundException e) {
+            out.error(AnnotationTool.class.getSimpleName(), "Cannot find file");
+        } catch (IOException e) {
+            out.error(AnnotationTool.class.getSimpleName(), "Cannot read file");
+        } finally {
+            try {
+            if (in != null)
+                in.close();
+            } catch (IOException e) {
+                out.error(AnnotationTool.class.getSimpleName(), "Cannot close file");
+            }
+        }
+        return fileStrBuffer.toString();
+    }
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/annotation/AnnotationTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/BeanMigrator.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/BeanMigrator.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/BeanMigrator.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/BeanMigrator.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,196 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.ejb.bean;
+
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.devtools.j2g.common.ConsoleOutput;
+import org.apache.geronimo.devtools.j2g.common.IOutput;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+import org.apache.geronimo.devtools.j2g.util.descriptors.Constants;
+import org.apache.geronimo.devtools.j2g.util.descriptors.env.EnvirionmentElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.naming.NamingElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.xml.XMLConversionHelper;
+import org.dom4j.Element;
+import org.dom4j.QName;
+
+public class BeanMigrator {
+
+    private IOutput out;
+
+    private Log logger = LogFactory.getLog(BeanMigrator.class);
+
+    protected EnvirionmentElementProcessor envirionmentElementProcessor;
+
+    protected NamingElementProcessor namingElementProcessor;
+
+    public BeanMigrator(EnvirionmentElementProcessor envirionmentElementProcessor,
+            NamingElementProcessor namingElementProcessor) {
+    	
+    	Tool currentTool = Tool.getCurrent();
+    	if (currentTool != null) {
+    		out = currentTool.getOutput();
+    	} else {
+    		out = new ConsoleOutput();
+    	}
+        this.envirionmentElementProcessor = envirionmentElementProcessor;
+        this.namingElementProcessor = namingElementProcessor;
+    }
+
+    /**
+     * migrates the common methods for all the methods
+     * 
+     * @param jbossBeanElment
+     * @param geronimoBeanElemnt
+     * @return migrated or not
+     */
+    public boolean migrateBean(Element jbossBeanElment, Element geronimoBeanElemnt) {
+        boolean migrated = true;
+        if (jbossBeanElment.getName().equals("ejb-name")) {
+            // add ejb name to geronimo bean
+            // we have to check the ejb name since ejb name can put by the
+            // jbosscmp-jar as well.
+            String xpath = "//ejb:ejb-name[text() ='" + jbossBeanElment.getText() + "']";
+            logger.debug("Find existing ejb names with xpath ==> " + xpath);
+            if (!XMLConversionHelper.isNodeAvailable(geronimoBeanElemnt, xpath)) {
+                logger.debug("adding ejb-name to bean with name ==> " + jbossBeanElment.getText());
+                QName qname = new QName("ejb-name", geronimoBeanElemnt.getNamespace());
+                Element geronimoEJBName = geronimoBeanElemnt.addElement(qname);
+                geronimoEJBName.setText(jbossBeanElment.getText());
+            } else {
+                logger.debug("ejb-name already exists");
+            }
+
+        } else if (jbossBeanElment.getName().equals("resource-ref")) {
+            QName qname = new QName("resource-ref", geronimoBeanElemnt
+                    .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+            Element geronimoResourceRef = geronimoBeanElemnt.addElement(qname);
+            namingElementProcessor.migrateResourceRef(jbossBeanElment, geronimoResourceRef);
+        } else if (jbossBeanElment.getName().equals("ejb-ref")) {
+            // get the jndi name
+            String jndiName = jbossBeanElment.elementText("jndi-name");
+            // find bean element matching jndiname
+            String xpath = "//enterprise-beans/session[jndi-name/text() ='" + jndiName
+                    + "']/ejb-name";
+            Element element = XMLConversionHelper.getJbossElement(jbossBeanElment.getDocument(),
+                    xpath);
+
+            // check reference for a entity bean
+            if (element == null) {
+                xpath = "//enterprise-beans/entity[jndi-name/text() ='" + jndiName + "']/ejb-name";
+                element = XMLConversionHelper.getJbossElement(jbossBeanElment.getDocument(), xpath);
+            }
+
+            if (element != null) {
+
+                QName qname = new QName("ejb-ref", geronimoBeanElemnt
+                        .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+                Element geronimoEJBRef = geronimoBeanElemnt.addElement(qname);
+                migrateEJBRef(jbossBeanElment, geronimoEJBRef);
+                qname = new QName("ejb-link", geronimoEJBRef
+                        .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+                Element geronimoEJBLink = geronimoEJBRef.addElement(qname);
+                geronimoEJBLink.setText(element.getText());
+
+            } else {
+                out.error(BeanMigrator.class.getSimpleName(), 
+                        "The Element 'ejb-ref' is not supported. It is not possible to determine the EJB name "
+                                + "from the jndi name. Please migrate this element manually",
+                        XMLConversionHelper.getLineNumber(jbossBeanElment), XMLConversionHelper
+                                .getColumnNumber(jbossBeanElment));
+                logger
+                        .error("The Element 'ejb-ref' is not supported. It is not possible to determine the EJB name "
+                                + "from the jndi name. Please migrate this element manually");
+            }
+
+        } else if (jbossBeanElment.getName().equals("ejb-local-ref")) {
+
+            // get the jndi name
+            String jndiName = jbossBeanElment.elementText("local-jndi-name");
+            // find bean element matching jndiname
+            String xpath = "//enterprise-beans/session[local-jndi-name/text() ='" + jndiName
+                    + "']/ejb-name";
+            Element element = XMLConversionHelper.getJbossElement(jbossBeanElment.getDocument(),
+                    xpath);
+
+            // check reference for a entity bean
+            if (element == null) {
+                xpath = "//enterprise-beans/entity[local-jndi-name/text() ='" + jndiName
+                        + "']/ejb-name";
+                element = XMLConversionHelper.getJbossElement(jbossBeanElment.getDocument(), xpath);
+            }
+
+            if (element != null) {
+                logger.debug("EJB reference found");
+                QName qname = new QName("ejb-local-ref", geronimoBeanElemnt
+                        .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+                Element geronimoEJBLocalRef = geronimoBeanElemnt.addElement(qname);
+                migrateEJBLocalRef(jbossBeanElment, geronimoEJBLocalRef);
+                qname = new QName("ejb-link", geronimoEJBLocalRef
+                        .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+                Element geronimoEJBLink = geronimoEJBLocalRef.addElement(qname);
+                geronimoEJBLink.setText(element.getText());
+
+            } else {
+                out.error(BeanMigrator.class.getSimpleName(), 
+                        "The Element 'ejb-local-ref' is not supported. It is not possible to determine the EJB name "
+                                + "from the jndi name. Please migrate this element manually",
+                        XMLConversionHelper.getLineNumber(jbossBeanElment), XMLConversionHelper
+                                .getColumnNumber(jbossBeanElment));
+                logger
+                        .error("The Element 'ejb-local-ref' is not supported. It is not possible to determine the EJB name "
+                                + "from the jndi name. Please migrate this element manually");
+            }
+
+        } else {
+            migrated = false;
+        }
+
+        return migrated;
+    }
+
+    private void migrateEJBRef(Element jbossEJBRef, Element geronimoEJBRef) {
+
+        Element jbossEJBChildRef;
+        for (Iterator iter = jbossEJBRef.elementIterator(); iter.hasNext();) {
+            jbossEJBChildRef = (Element) iter.next();
+            if (jbossEJBChildRef.getName().equals("ejb-ref-name")) {
+                QName qname = new QName("ref-name", geronimoEJBRef
+                        .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+                Element geronimoRefName = geronimoEJBRef.addElement(qname);
+                geronimoRefName.setText(jbossEJBChildRef.getText());
+            }
+        }
+    }
+
+    private void migrateEJBLocalRef(Element jbossEJBRef, Element geronimoEJBRef) {
+
+        Element jbossEJBChildRef;
+        for (Iterator iter = jbossEJBRef.elementIterator(); iter.hasNext();) {
+            jbossEJBChildRef = (Element) iter.next();
+            if (jbossEJBChildRef.getName().equals("ejb-ref-name")) {
+                QName qname = new QName("ref-name", geronimoEJBRef
+                        .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+                Element geronimoRefName = geronimoEJBRef.addElement(qname);
+                geronimoRefName.setText(jbossEJBChildRef.getText());
+            }
+        }
+    }
+
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/BeanMigrator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/EntityBeanMigrator.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/EntityBeanMigrator.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/EntityBeanMigrator.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/EntityBeanMigrator.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,61 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.ejb.bean;
+
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.devtools.j2g.common.ConsoleOutput;
+import org.apache.geronimo.devtools.j2g.common.IOutput;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+import org.apache.geronimo.devtools.j2g.util.descriptors.env.EnvirionmentElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.naming.NamingElementProcessor;
+import org.dom4j.Element;
+
+public class EntityBeanMigrator extends JNDIBeanMigrator {
+
+    private IOutput out;
+    private Log logger = LogFactory.getLog(EntityBeanMigrator.class);
+
+    public EntityBeanMigrator(EnvirionmentElementProcessor envirionmentElementProcessor,
+            NamingElementProcessor namingElementProcessor) {
+        super(envirionmentElementProcessor, namingElementProcessor);
+    	Tool currentTool = Tool.getCurrent();
+    	if (currentTool != null) {
+    		out = currentTool.getOutput();
+    	} else {
+    		out = new ConsoleOutput();
+    	}
+    }
+
+    public boolean migrateBean(Element jbossEntity, Element geronimoEntity) {
+        Element jbossEntityChildElement;
+        for (Iterator iter = jbossEntity.elements().iterator(); iter.hasNext();) {
+            jbossEntityChildElement = (Element) iter.next();
+
+            // do the migration only if super classes can not
+            if (!super.migrateBean(jbossEntityChildElement, geronimoEntity)) {
+                // TODO: entity bean secific migrations
+                out.warn(EntityBeanMigrator.class.getSimpleName(), "The Element '" + jbossEntityChildElement.getName()
+                        + "' is not supported");
+            }
+        }
+        return true;
+    }
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/EntityBeanMigrator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/JNDIBeanMigrator.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/JNDIBeanMigrator.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/JNDIBeanMigrator.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/JNDIBeanMigrator.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,53 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.ejb.bean;
+
+
+import org.apache.geronimo.devtools.j2g.util.descriptors.env.EnvirionmentElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.naming.NamingElementProcessor;
+import org.dom4j.Element;
+import org.dom4j.QName;
+
+public class JNDIBeanMigrator extends BeanMigrator {
+
+
+    public JNDIBeanMigrator(EnvirionmentElementProcessor envirionmentElementProcessor,
+            NamingElementProcessor namingElementProcessor) {
+        super(envirionmentElementProcessor, namingElementProcessor);
+    }
+
+    public boolean migrateBean(Element jbossBeanElment, Element geronimoBeanElemnt) {
+        boolean migrated = true;
+        if (!super.migrateBean(jbossBeanElment, geronimoBeanElemnt)) {
+            if (jbossBeanElment.getName().equals("jndi-name")) {
+                // add ejb name to geronimo session
+                QName qname = new QName("jndi-name", geronimoBeanElemnt.getNamespace());
+                Element geronimoJndiName = geronimoBeanElemnt.addElement(qname);
+                geronimoJndiName.setText(jbossBeanElment.getText());
+            } else if (jbossBeanElment.getName().equals("local-jndi-name")) {
+                // add ejb name to geronimo session
+                QName qname = new QName("local-jndi-name", geronimoBeanElemnt.getNamespace());
+                Element geronimoLocalJndiName = geronimoBeanElemnt.addElement(qname);
+                geronimoLocalJndiName.setText(jbossBeanElment.getText());
+            } else {
+                migrated = false;
+            }
+        }
+        return migrated;
+    }
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/JNDIBeanMigrator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/MessageDrivenBeanMigrator.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/MessageDrivenBeanMigrator.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/MessageDrivenBeanMigrator.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/MessageDrivenBeanMigrator.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,29 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.ejb.bean;
+
+import org.apache.geronimo.devtools.j2g.util.descriptors.env.EnvirionmentElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.naming.NamingElementProcessor;
+
+
+public class MessageDrivenBeanMigrator extends BeanMigrator {
+
+    public MessageDrivenBeanMigrator(EnvirionmentElementProcessor envirionmentElementProcessor,
+            NamingElementProcessor namingElementProcessor) {
+        super(envirionmentElementProcessor, namingElementProcessor);
+    }
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/MessageDrivenBeanMigrator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/SessionBeanMigrator.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/SessionBeanMigrator.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/SessionBeanMigrator.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/SessionBeanMigrator.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,60 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.ejb.bean;
+
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.devtools.j2g.common.ConsoleOutput;
+import org.apache.geronimo.devtools.j2g.common.IOutput;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+import org.apache.geronimo.devtools.j2g.util.descriptors.env.EnvirionmentElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.naming.NamingElementProcessor;
+import org.dom4j.Element;
+
+
+public class SessionBeanMigrator extends JNDIBeanMigrator {
+
+    private static Log logger = LogFactory.getLog(SessionBeanMigrator.class);
+    private IOutput out;
+
+    public SessionBeanMigrator(EnvirionmentElementProcessor envirionmentElementProcessor,
+            NamingElementProcessor namingElementProcessor) {
+        super(envirionmentElementProcessor, namingElementProcessor);
+    	Tool currentTool = Tool.getCurrent();
+    	if (currentTool != null) {
+    		out = currentTool.getOutput();
+    	} else {
+    		out = new ConsoleOutput();
+    	}
+    }
+
+    public boolean migrateBean(Element jbossSession, Element geronimoSession) {
+        Element jbossSessionChildElement;
+        for (Iterator iter = jbossSession.elements().iterator(); iter.hasNext();) {
+            jbossSessionChildElement = (Element) iter.next();
+            // do the migration only if super classes can not
+            if (!super.migrateBean(jbossSessionChildElement, geronimoSession)) {
+                // TODO: session bean secific migrations
+                out.warn(SessionBeanMigrator.class.getSimpleName(), "The Element '" + jbossSessionChildElement.getName()
+                        + "' is not supported");
+            }
+        }
+        return true;
+    }
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/ejb/bean/SessionBeanMigrator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/web/WebDescriptorTool.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/web/WebDescriptorTool.java?rev=582929&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/web/WebDescriptorTool.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/web/WebDescriptorTool.java Mon Oct  8 11:48:35 2007
@@ -0,0 +1,154 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.devtools.j2g.descriptors.web;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.devtools.j2g.common.ConsoleOutput;
+import org.apache.geronimo.devtools.j2g.common.IFileMigration;
+import org.apache.geronimo.devtools.j2g.common.IOutput;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+import org.apache.geronimo.devtools.j2g.util.descriptors.Constants;
+import org.apache.geronimo.devtools.j2g.util.descriptors.env.EnvirionmentElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.naming.NamingElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.security.SecurityElementProcessor;
+import org.apache.geronimo.devtools.j2g.util.descriptors.xml.XMLConversionHelper;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.QName;
+
+public class WebDescriptorTool implements IFileMigration {
+
+    private IOutput out;
+
+    private static Log logger = LogFactory.getLog(WebDescriptorTool.class);
+
+    private EnvirionmentElementProcessor envirionmentElementProcessor;
+
+    private SecurityElementProcessor securityElementProcessor;
+
+    private NamingElementProcessor namingElementProcessor;
+
+    public WebDescriptorTool() {
+    	
+    	Tool currentTool = Tool.getCurrent();
+    	if (currentTool != null) {
+    		out = currentTool.getOutput();
+    	} else {
+    		out = new ConsoleOutput();
+    	}
+        envirionmentElementProcessor = new EnvirionmentElementProcessor();
+        securityElementProcessor = new SecurityElementProcessor();
+        namingElementProcessor = new NamingElementProcessor(envirionmentElementProcessor);
+    }
+
+    public boolean migrate(File file, File rootDirectory) {
+
+        boolean migrated = false;
+            String directoryName = file.getParent();
+            String jbossFileName = file.getName();
+            logger.debug("Directory Name ==> " + directoryName + " jboss file Name ==> "
+                    + jbossFileName);
+            if (jbossFileName.equals(Constants.JBOSS_WEB_XML_FILE)) {
+                out.info(WebDescriptorTool.class.getSimpleName(), "Converting Jboss-web.xml file in " + directoryName);
+                try {
+                    Document jbossDocument = XMLConversionHelper.getDocument(file);
+                    Document geronimoDocument = XMLConversionHelper.createNewGeronimoDocument(
+                            Constants.WEB_NAME_SPACE, Constants.GERONIMO_WEB_XML_ROOT_NODE);
+                    migrate(jbossDocument.getRootElement(), geronimoDocument.getRootElement());
+                    String geronimoWebFileName = directoryName + File.separator
+                            + Constants.GERONIMO_WEB_XML_FILE;
+                    XMLConversionHelper.saveGeronimoDocument(geronimoWebFileName, geronimoDocument);
+                    migrated = true;
+                    out.info(WebDescriptorTool.class.getSimpleName(), "Successfully migrated the jboss-web.xml file in "
+                            + directoryName + ", with the error and warning messages as shown");
+                } catch (DocumentException e) {
+                	out.error(WebDescriptorTool.class.getSimpleName(), "Error occured while reading xml descriptor "
+    						+ file.getAbsolutePath()
+    						+ ". It is possible that the migrator cannot download the xml schema or the xml file has incorrectsyntax. Nested exception:"
+    						+ e.getMessage());
+                } catch (IOException e) {
+                    out.error(WebDescriptorTool.class.getSimpleName(), "IO exception " + e.getMessage());
+                }
+            } else if (jbossFileName.equals(Constants.WEB_XML_FILE)){
+                out.info(WebDescriptorTool.class.getSimpleName(), "Converting web.xml file in " + directoryName);
+                out.info(WebDescriptorTool.class.getSimpleName(), "Nothing to convert. No changes are required for this file");
+            }
+        return migrated;
+    }
+
+    private void migrate(Element jbossRootElement, Element geronimoRootElement) {
+
+        // migrate the web descriptor componets here
+        Element jbossRootChildElement;
+        for (Iterator iter = jbossRootElement.elements().iterator(); iter.hasNext();) {
+            jbossRootChildElement = (Element) iter.next();
+            if (jbossRootChildElement.getName().equals("context-root")) {
+                QName qname = new QName("context-root", geronimoRootElement.getNamespace());
+                Element contextRootElement = geronimoRootElement.addElement(qname);
+                contextRootElement.setText(jbossRootChildElement.getText());
+            } else if (jbossRootChildElement.getName().equals("security-domain")) {
+                QName qname = new QName("security-realm-name", geronimoRootElement.getNamespace());
+                Element realmNameElement = geronimoRootElement.addElement(qname);
+                realmNameElement.setText(jbossRootChildElement.getText());
+                securityElementProcessor.setSecurityDomain(jbossRootChildElement.getText());
+            } else if (jbossRootChildElement.getName().equals("security-role")) {
+                Element geronimoRoleMapping = securityElementProcessor
+                        .getGeronimoSecurityRoleElement(geronimoRootElement);
+                securityElementProcessor.migrateSecurityRole(jbossRootChildElement,
+                        geronimoRoleMapping);
+            } else if (jbossRootChildElement.getName().equals("resource-ref")) {
+                QName qname = new QName("resource-ref", geronimoRootElement
+                        .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+                Element geronimoResourceRef = geronimoRootElement.addElement(qname);
+                namingElementProcessor.migrateResourceRef(jbossRootChildElement,
+                        geronimoResourceRef);
+            } else if (jbossRootChildElement.getName().equals("ejb-ref")) {
+                out.error(WebDescriptorTool.class.getSimpleName(), 
+                        "The Element 'ejb-ref' is not supported. It is not possible to determine the EJB name "
+                                + "from the jndi name. Please migrate this element manually",
+                        XMLConversionHelper.getLineNumber(jbossRootChildElement),
+                        XMLConversionHelper.getColumnNumber(jbossRootChildElement));
+                logger
+                        .debug("The Element 'ejb-ref' is not supported. It is not possible to determine the EJB name "
+                                + "from the jndi name. Please migrate this element manually");
+            } else if (jbossRootChildElement.getName().equals("ejb-local-ref")) {
+                out.error(WebDescriptorTool.class.getSimpleName(), 
+                        "The Element 'ejb-local-ref' is not supported. It is not possible to determine the EJB name "
+                                + "from the jndi name. Please migrate this element manually",
+                        XMLConversionHelper.getLineNumber(jbossRootChildElement),
+                        XMLConversionHelper.getColumnNumber(jbossRootChildElement));
+                logger
+                        .debug("The Element 'ejb-local-ref' is not supported. It is not possible to determine the EJB name "
+                                + "from the jndi name. Please migrate this element manually");
+            } else {
+                out.warn(WebDescriptorTool.class.getSimpleName(), 
+                        "The Element '" + jbossRootChildElement.getName() + "' is not supported. ",
+                        XMLConversionHelper.getLineNumber(jbossRootChildElement),
+                        XMLConversionHelper.getColumnNumber(jbossRootChildElement));
+                logger.debug("The Element '" + jbossRootChildElement.getName()
+                        + "' is not supported. ");
+            }
+        }
+    }
+
+}

Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.descriptors/src/org/apache/geronimo/devtools/j2g/descriptors/web/WebDescriptorTool.java
------------------------------------------------------------------------------
    svn:eol-style = native