You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by pm...@apache.org on 2007/07/02 20:30:40 UTC
svn commit: r552557 [1/6] - in /geronimo/sandbox/j2g/plugins:
org.apache.geronimo.j2g.descriptors.app/
org.apache.geronimo.j2g.descriptors.cmp/
org.apache.geronimo.j2g.descriptors.ejb/
org.apache.geronimo.j2g.descriptors.web/ org.apache.geronimo.j2g.de...
Author: pmcmahan
Date: Mon Jul 2 11:30:34 2007
New Revision: 552557
URL: http://svn.apache.org/viewvc?view=rev&rev=552557
Log:
GERONIMO-3255 refactoring to reduce number of plugins
Added:
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/commons-logging.properties
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/app/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/app/ApplicationDescriptorTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPDescriptorTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPEntityBeanMigrator.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/EJBJarXmlProcessor.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelation.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelationshipRole.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/Relationships.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/bean/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/bean/BeanMigrator.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/bean/EntityBeanMigrator.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/bean/JNDIBeanMigrator.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/bean/MessageDrivenBeanMigrator.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/bean/SessionBeanMigrator.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/web/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/web/WebDescriptorTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test-resources/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test-resources/ejb-jar.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test-resources/geronimo-application.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test-resources/geronimo-web.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test-resources/jboss-app.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test-resources/jboss.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test-resources/jbosscmp-jdbc.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test-resources/openejb-jar.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/app/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/app/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/app/test/TestApplicationDescriptorTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/cmp/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/cmp/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/cmp/test/TestCMPDescriptorsTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/cmp/test/TestEJBjarXmlProcessor.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/ejb/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/ejb/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/ejb/test/TestEJBDescriptorTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/web/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/web/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/test/org/apache/geronimo/j2g/descriptors/web/test/TestWebDescriptorTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/commons-logging.properties
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/datasource/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/datasource/DSResourcesTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/jms/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/jms/JMSResourcesTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/mail/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/mail/MailResourcesTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/security/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/security/SecurityResourcesTool.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/ds/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/ds/hsqldb-ds.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/ds/hsqldb-geronimo-plan.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/ds/mysql-ds.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/ds/mysql-geronimo-plan.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/ds/oracle-ds.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/ds/oracle-geronimo-plan.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/jms/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/jms/geronimo-jms-resource-plan.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/jms/jbossmq-destinations-service.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/jms/jms-ds.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/jms/jms-geronimo-plan.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/mail/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/mail/err/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/mail/err/mail-service.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/mail/geronimo-mail-service.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/mail/mail-geronimo-plan.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/mail/mail-service.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/geronimo-secutiry-plan.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/login-config.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test-apps/security/security-geronimo-plan.xml
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/datasource/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/datasource/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/datasource/test/DSResouresToolTestCase.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/jms/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/jms/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/jms/test/JMSResouresToolTestCase.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/mail/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/mail/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/mail/test/MailResouresToolTestCase.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/security/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/security/test/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/test/org/apache/geronimo/j2g/resources/security/test/SecurityResouresToolTestCase.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/APIReplaceVisitor.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/DependenceJavaMigration.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/NodesVisitor.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/Anybody.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/DigestCallback.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoLoginModule.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/GeronimoSimpleGroup.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/Nobody.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/dependence/compatibility/PasswordHasher.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/environment/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/environment/AbsoluteNameSolver.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/environment/BlockVisitor.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/environment/EjbEnvJavaMigration.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/environment/MethodsVisitor.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/environment/NameSolvingException.java
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources/src/org/apache/geronimo/j2g/sources/environment/VarContext.java
Removed:
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors.app/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors.cmp/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors.ejb/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors.web/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources.datasource/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources.jms/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources.mail/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources.security/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.dependence/
geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.sources.environment/
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/commons-logging.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/commons-logging.properties?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/commons-logging.properties (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/commons-logging.properties Mon Jul 2 11:30:34 2007
@@ -0,0 +1,30 @@
+/**
+ * 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.
+ */
+ # Set root logger level to DEBUG and its only appender to console.
+log4j.rootLogger=INFO
+
+#define loggers
+#pluging logger
+log4j.logger.com.ibm.j2g= DEBUG,console
+
+# console is set to be a ConsoleAppender.
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+
+# console uses PatternLayout.
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+#log4j.appender.console.layout.ConversionPattern=[%t] %-5p %l - %m%n
+log4j.appender.console.layout.ConversionPattern=[%t] %-5p - %m%n
\ No newline at end of file
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/app/ApplicationDescriptorTool.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/app/ApplicationDescriptorTool.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/app/ApplicationDescriptorTool.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/app/ApplicationDescriptorTool.java Mon Jul 2 11:30:34 2007
@@ -0,0 +1,151 @@
+/**
+ * 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.j2g.descriptors.app;
+
+
+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.j2g.common.ConsoleOutput;
+import org.apache.geronimo.j2g.common.IFileMigration;
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.Tool;
+import org.apache.geronimo.j2g.util.descriptors.Constants;
+import org.apache.geronimo.j2g.util.descriptors.security.SecurityElementProcessor;
+import org.apache.geronimo.j2g.util.descriptors.xml.XMLConversionHelper;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.QName;
+
+public class ApplicationDescriptorTool implements IFileMigration {
+
+ private IOutput out;
+
+ private String directoryName;
+
+ private Log logger = LogFactory.getLog(ApplicationDescriptorTool.class);
+
+ private SecurityElementProcessor securityElementProcessor;
+
+ public ApplicationDescriptorTool() {
+ Tool currentTool = Tool.getCurrent();
+ if (currentTool != null) {
+ out = currentTool.getOutput();
+ } else {
+ out = new ConsoleOutput();
+ }
+ securityElementProcessor = new SecurityElementProcessor();
+ }
+
+ public boolean migrate(File file) {
+ boolean migrated = false;
+ directoryName = file.getParent();
+ String jbossFileName = file.getName();
+ logger.debug("Directory Name ==> " + directoryName + " jboss file Name ==> "
+ + jbossFileName);
+
+ if (jbossFileName.equals(Constants.JBOSS_JBOSS_APPLICATION_XML_FILE)) {
+ out.info("Converting Jboss-app.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.createNewGeronimoDocument(
+ Constants.APPLICATION_NAME_SPACE, "application");
+ migrate(jbossDocument.getRootElement(), geronimoDocument.getRootElement());
+ String geronimoOpenEjbJarFileName = directoryName + File.separator
+ + Constants.GERONIMO_APPLICATION_XML_FILE;
+ XMLConversionHelper.saveGeronimoDocument(geronimoOpenEjbJarFileName,
+ geronimoDocument);
+ migrated = true;
+ out.info("Successfully migrated the Jboss-app.xml file in "
+ + directoryName + ", with the error and warning messages as shown");
+ } catch (DocumentException e) {
+ out.error("Errors occurs while reading xml descriptor "
+ + file.getAbsolutePath()
+ + ". It is possible that the migrator cannot download an xml schema or xml file has a wrong syntax. Nested exception:"
+ + e.getMessage());
+ } catch (IOException e) {
+ out.error("IO exception " + e.getMessage());
+ }
+ } else if (jbossFileName.equals(Constants.APPLICATION_XML_FILE)){
+ out.info("Converting application.xml file in " + directoryName);
+ out.info("Nothing to convert. Keep the file as it is");
+ }
+ return migrated;
+ }
+
+ private void migrate(Element jbossRootElement, Element geronimoRootElement) {
+
+ 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("unauthenticated-principal")) {
+ // set the default principal in security element processor
+ securityElementProcessor.setDefaultPrincipal(jbossRootChildElement.getText());
+ } else if (jbossRootChildElement.getName().equals("security-role")) {
+ Element geronimoRoleMapping = securityElementProcessor
+ .getGeronimoSecurityRoleElement(geronimoRootElement);
+ securityElementProcessor.migrateSecurityRole(jbossRootChildElement,
+ geronimoRoleMapping);
+ } else {
+ out.warn("The Element '" + jbossRootChildElement.getName() + "' does not support ",
+ XMLConversionHelper.getLineNumber(jbossRootChildElement),
+ XMLConversionHelper.getColumnNumber(jbossRootChildElement));
+ logger.debug("The Element '" + jbossRootChildElement.getName()
+ + "' does not support ");
+ }
+ }
+ }
+
+ private void migrateModule(Element jbossModule, Element geronimoModule) {
+
+ Element jbossModuleChildElement;
+ for (Iterator iter = jbossModule.elements().iterator(); iter.hasNext();) {
+ jbossModuleChildElement = (Element) iter.next();
+ if (jbossModuleChildElement.getName().equals("service")) {
+ // TODO: figure out properly
+ // for the moment we add connector element to replace the
+ // service
+ String serviceName = jbossModuleChildElement.getText();
+ String firstPart = serviceName.substring(0, serviceName.lastIndexOf("."));
+ // add conector element
+ QName qname = new QName("connector", geronimoModule.getNamespace());
+ Element connectorElement = geronimoModule.addElement(qname);
+ connectorElement.setText(firstPart + ".rar");
+
+ // add alt-dd element
+ qname = new QName("alt-dd", geronimoModule.getNamespace());
+ Element altDDElement = geronimoModule.addElement(qname);
+ altDDElement.setText(firstPart + ".xml");
+ } else {
+ out.warn("The Element '" + jbossModuleChildElement.getName()
+ + "' does not support ", XMLConversionHelper
+ .getLineNumber(jbossModuleChildElement), XMLConversionHelper
+ .getColumnNumber(jbossModuleChildElement));
+ logger.debug("The Element '" + jbossModuleChildElement.getName()
+ + "' does not support ");
+ }
+ }
+ }
+}
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPDescriptorTool.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPDescriptorTool.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPDescriptorTool.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPDescriptorTool.java Mon Jul 2 11:30:34 2007
@@ -0,0 +1,447 @@
+/**
+ * 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.j2g.descriptors.comp;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.j2g.common.ConsoleOutput;
+import org.apache.geronimo.j2g.common.IFileMigration;
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.Tool;
+import org.apache.geronimo.j2g.descriptors.comp.dto.EJBRelation;
+import org.apache.geronimo.j2g.descriptors.comp.dto.EJBRelationshipRole;
+import org.apache.geronimo.j2g.descriptors.comp.dto.Relationships;
+import org.apache.geronimo.j2g.util.descriptors.Constants;
+import org.apache.geronimo.j2g.util.descriptors.env.EnvirionmentElementProcessor;
+import org.apache.geronimo.j2g.util.descriptors.xml.XMLConversionHelper;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.QName;
+
+public class CMPDescriptorTool implements IFileMigration {
+
+ private IOutput out;
+
+ private Log logger = LogFactory.getLog(CMPDescriptorTool.class);
+
+ private EnvirionmentElementProcessor envirionmentElementProcessor;
+
+ private CMPEntityBeanMigrator cmpEntityBeanMigrator;
+
+ private String directoryName;
+
+ private Map ejbKeyColumnMapper;
+
+ public CMPDescriptorTool() {
+ Tool currentTool = Tool.getCurrent();
+ if (currentTool != null){
+ out = currentTool.getOutput();
+ } else {
+ out = new ConsoleOutput();
+ }
+ envirionmentElementProcessor = new EnvirionmentElementProcessor();
+ cmpEntityBeanMigrator = new CMPEntityBeanMigrator();
+ ejbKeyColumnMapper = new HashMap();
+ }
+
+ public boolean migrate(File file) {
+ boolean migrated = false;
+ directoryName = file.getParent();
+ String jbossFileName = file.getName();
+ logger.debug("Directory Name ==> " + directoryName + " jboss file Name ==> "
+ + jbossFileName);
+
+ if (jbossFileName.equals(Constants.JBOSS_JBOSS_CMP_JDBC_XML_FILE)) {
+ out.info("Converting file " + file.getAbsolutePath() + ".");
+ try {
+ // check whether the jbosscmp-jdbc.xml file is present and
+ // if so load it and process it.
+ String geronimoOpenEjbJarFileName = directoryName + File.separator
+ + Constants.GERONIMO_OPEN_EJB_XML_FILE;
+ File tempFile = new File(geronimoOpenEjbJarFileName);
+ if (tempFile.exists()) {
+ System.out.println("Deleting the pre-existing openejb-jar.xml file");
+ tempFile.delete();
+ }
+ Document jbossDocument = XMLConversionHelper.getDocument(file);
+ Document geronimoDocument = XMLConversionHelper.getOpenEJBJarDocument(directoryName);
+ migrate(jbossDocument.getRootElement(), geronimoDocument.getRootElement());
+ XMLConversionHelper.saveOpenEJBDocument(geronimoOpenEjbJarFileName,
+ geronimoDocument);
+ migrated = true;
+ out.info("Successfully migrated the Jbosscmp-jdbc.xml file in "
+ + directoryName + ", with the error and warning messages as shown");
+ } catch (DocumentException e) {
+ out.error("Errors occurs 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("IO exception " + e.getMessage());
+ }
+ }
+ return migrated;
+ }
+
+ private void migrate(Element jbossRootElement, Element geronimoRootElement) {
+ Element jbossRootChildElement;
+ logger.debug("migrating the root elements");
+ for (Iterator iter = jbossRootElement.elements().iterator(); iter.hasNext();) {
+ jbossRootChildElement = (Element) iter.next();
+ if (jbossRootChildElement.getName().equals("defaults")) {
+ logger.debug("migrating the defaults");
+ migrateDefaults(jbossRootChildElement, geronimoRootElement);
+ } else if (jbossRootChildElement.getName().equals("enterprise-beans")) {
+ logger.debug("migrating the 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("relationships")) {
+ QName qname = new QName("relationships", geronimoRootElement.getNamespace());
+ Element geronimoReleationship = geronimoRootElement.addElement(qname);
+ migrateRelationships(jbossRootChildElement, geronimoReleationship);
+ } else {
+ out.warn("The Element '" + jbossRootChildElement.getName() + "' is not supported ",
+ XMLConversionHelper.getLineNumber(jbossRootChildElement),
+ XMLConversionHelper.getColumnNumber(jbossRootChildElement));
+ logger.debug("The Element '" + jbossRootChildElement.getName()
+ + "' is not supported ");
+ }
+ }
+ }
+
+ private void migrateRelationships(Element jbossRelationships, Element geronimoRelationships) {
+
+ Element jbossRelationshipsChildElement;
+ String fileName = directoryName + File.separator + Constants.EJB_JAR_XML_FILE;
+ EJBJarXmlProcessor ejbJarXmlProcessor = new EJBJarXmlProcessor(fileName);
+ try {
+ Relationships relationships = ejbJarXmlProcessor.getRelationships();
+ for (Iterator iter = jbossRelationships.elements().iterator(); iter.hasNext();) {
+ jbossRelationshipsChildElement = (Element) iter.next();
+ if (jbossRelationshipsChildElement.getName().equals("ejb-relation")) {
+ QName qname = new QName("ejb-relation", geronimoRelationships.getNamespace());
+ Element geronimoEJBRelation = geronimoRelationships.addElement(qname);
+
+ Element ejbRelationName = jbossRelationshipsChildElement
+ .element("ejb-relation-name");
+ migrateEJBRelation(jbossRelationshipsChildElement, geronimoEJBRelation,
+ relationships.getEJBRelation(ejbRelationName.getText().trim()));
+ }
+ }
+ } catch (DocumentException e) {
+ out.error("No ejb-jar.xml file exists can not migrate ralationships");
+ }
+ }
+
+ private void migrateEJBRelation(Element jbossEJBRelation, Element geronimoEJBRelation,
+ EJBRelation ejbRelation) {
+
+ Element jbossEJBRelationChildElement;
+ Element noKeyFieldsRelationshipRole = null;
+ Element noCmrFieldRelationshipRole = null;
+ boolean isRelationshipRoleMigrated = false;
+ for (Iterator iter = jbossEJBRelation.elements().iterator(); iter.hasNext();) {
+ jbossEJBRelationChildElement = (Element) iter.next();
+ if (jbossEJBRelationChildElement.getName().equals("ejb-relation-name")) {
+ QName qname = new QName("ejb-relation-name", geronimoEJBRelation.getNamespace());
+ Element geronimoEJBRelationName = geronimoEJBRelation.addElement(qname);
+ geronimoEJBRelationName.setText(jbossEJBRelationChildElement.getText());
+ } else if (jbossEJBRelationChildElement.getName().equals("relation-table-mapping")) {
+ QName qname = new QName("many-to-many-table-name", geronimoEJBRelation
+ .getNamespace());
+ Element geronimoManyToMany = geronimoEJBRelation.addElement(qname);
+ migrateRelationTableMapping(jbossEJBRelationChildElement, geronimoManyToMany);
+ } else if (jbossEJBRelationChildElement.getName().equals("ejb-relationship-role")) {
+ Element keyFields = jbossEJBRelationChildElement.element("key-fields");
+ if ((keyFields == null) || (keyFields.elements().isEmpty())) {
+ logger.debug("Key field is empty no neet to convert this element");
+ // we store this element to process later if other ejb-relationship-role
+ // does not have a cmr field.
+ noKeyFieldsRelationshipRole = jbossEJBRelationChildElement;
+ } else {
+ QName qname = new QName("ejb-relationship-role", geronimoEJBRelation
+ .getNamespace());
+ Element ejbRelationshipRoleName = jbossEJBRelationChildElement
+ .element("ejb-relationship-role-name");
+ EJBRelationshipRole ejbRelationshipRole =
+ ejbRelation.getEJBRelationshipRole(ejbRelationshipRoleName.getText().trim());
+ if (ejbRelationshipRole.getCmrFieldName() != null) {
+ Element geronimoEJBRelationshipRole = geronimoEJBRelation.addElement(qname);
+
+ migrateEJBRelationshipRole(jbossEJBRelationChildElement,
+ geronimoEJBRelationshipRole, ejbRelationshipRole);
+ isRelationshipRoleMigrated = true;
+ } else {
+ // we store this ejb-relationship-role element to process later
+ noCmrFieldRelationshipRole = jbossEJBRelationChildElement;
+ }
+ }
+ }
+ }
+
+ if (!isRelationshipRoleMigrated) {
+ // i.e. the ejbrelationship role which has the key fields does not contain a cmr field.
+ QName qname = new QName("ejb-relationship-role", geronimoEJBRelation
+ .getNamespace());
+ Element geronimoEJBRelationshipRole = geronimoEJBRelation.addElement(qname);
+ migrateEJBRelationshipRole(noKeyFieldsRelationshipRole,
+ noCmrFieldRelationshipRole,
+ geronimoEJBRelationshipRole,
+ ejbRelation);
+ }
+ }
+
+ private void migrateEJBRelationshipRole(Element jbossNoKeyEJBRelationshipRole,
+ Element jbossNoCmrEJBRelationshipRole,
+ Element geronimoEJBRelationshipRole,
+ EJBRelation ejbRelation) {
+
+ // adding ejb-relationship-role element
+ Element jbossNoKeyEJBRelationshipRoleName =
+ jbossNoKeyEJBRelationshipRole.element("ejb-relationship-role-name");
+ QName qname = new QName("ejb-relationship-role-name", geronimoEJBRelationshipRole
+ .getNamespace());
+ Element ejbRoleNameElement = geronimoEJBRelationshipRole.addElement(qname);
+ ejbRoleNameElement.setText(jbossNoKeyEJBRelationshipRoleName.getText());
+
+ EJBRelationshipRole ejbNoKeyRelationshipRole =
+ ejbRelation.getEJBRelationshipRole(jbossNoKeyEJBRelationshipRoleName.getText().trim());
+
+ // add the relationship role source
+ qname = new QName("relationship-role-source", geronimoEJBRelationshipRole
+ .getNamespace());
+ Element ejbRoleSourceElement = geronimoEJBRelationshipRole.addElement(qname);
+
+ qname = new QName("ejb-name", geronimoEJBRelationshipRole.getNamespace());
+ Element ejbNameElement = ejbRoleSourceElement.addElement(qname);
+ ejbNameElement.setText(ejbNoKeyRelationshipRole.getSource());
+
+ // add cmr field
+ // add the cmr field name field
+ if (ejbNoKeyRelationshipRole.getCmrFieldName() != null) {
+ qname = new QName("cmr-field", geronimoEJBRelationshipRole.getNamespace());
+ Element cmrFieldElement = geronimoEJBRelationshipRole.addElement(qname);
+
+ qname = new QName("cmr-field-name", geronimoEJBRelationshipRole.getNamespace());
+ Element cmrFieldName = cmrFieldElement.addElement(qname);
+ cmrFieldName.setText(ejbNoKeyRelationshipRole.getCmrFieldName());
+ } else {
+ out.error("No cmr field given to relation ship " + ejbRelation.getEjbRelationName());
+ }
+
+ // put foreign-key-column-on-source
+ if (ejbNoKeyRelationshipRole.getMultiplicity().equals("Many")){
+ qname = new QName("foreign-key-column-on-source", geronimoEJBRelationshipRole.getNamespace());
+ geronimoEJBRelationshipRole.addElement(qname);
+ }
+
+
+ // add role mapping
+ Element jbossNoCMREJBRelationshipRoleName =
+ jbossNoKeyEJBRelationshipRole.element("ejb-relationship-role-name");
+ EJBRelationshipRole ejbNoCmrRelationshipRole =
+ ejbRelation.getEJBRelationshipRole(jbossNoCMREJBRelationshipRoleName.getText().trim());
+
+ // add key fields
+ Element jbossNoCMRKeyFieles = jbossNoCmrEJBRelationshipRole.element("key-fields");
+ qname = new QName("role-mapping", geronimoEJBRelationshipRole.getNamespace());
+ Element geronimoRoleMapping = geronimoEJBRelationshipRole.addElement(qname);
+ migrateKeyFields(jbossNoCMRKeyFieles, geronimoRoleMapping,
+ (Map) ejbKeyColumnMapper.get(ejbNoCmrRelationshipRole.getSource()));
+
+
+ }
+
+ private void migrateEJBRelationshipRole(Element jbossEJBRelationshipRole,
+ Element geronimoEJBRelationshipRole, EJBRelationshipRole ejbRelationshipRole) {
+ Element jbossRelationshipChildElement;
+ String ejbName = null;
+ for (Iterator iter = jbossEJBRelationshipRole.elements().iterator(); iter.hasNext();) {
+ jbossRelationshipChildElement = (Element) iter.next();
+
+ if (jbossRelationshipChildElement.getName().equals("ejb-relationship-role-name")) {
+ // add ejb relationship element
+ QName qname = new QName("ejb-relationship-role-name", geronimoEJBRelationshipRole
+ .getNamespace());
+ Element ejbRoleNameElement = geronimoEJBRelationshipRole.addElement(qname);
+ ejbRoleNameElement.setText(jbossRelationshipChildElement.getText());
+
+ // add the relationship role source
+ qname = new QName("relationship-role-source", geronimoEJBRelationshipRole
+ .getNamespace());
+ Element ejbRoleSourceElement = geronimoEJBRelationshipRole.addElement(qname);
+
+ qname = new QName("ejb-name", geronimoEJBRelationshipRole.getNamespace());
+ Element ejbNameElement = ejbRoleSourceElement.addElement(qname);
+ ejbNameElement.setText(ejbRelationshipRole.getSource());
+
+ // add the cmr field name field
+ qname = new QName("cmr-field", geronimoEJBRelationshipRole.getNamespace());
+ Element cmrFieldElement = geronimoEJBRelationshipRole.addElement(qname);
+
+ qname = new QName("cmr-field-name", geronimoEJBRelationshipRole.getNamespace());
+ Element cmrFieldName = cmrFieldElement.addElement(qname);
+ cmrFieldName.setText(ejbRelationshipRole.getCmrFieldName());
+
+ ejbName = ejbRelationshipRole.getSource();
+
+
+ } else if (jbossRelationshipChildElement.getName().equals("key-fields")) {
+ QName qname = new QName("role-mapping", geronimoEJBRelationshipRole.getNamespace());
+ Element geronimoRoleMapping = geronimoEJBRelationshipRole.addElement(qname);
+ migrateKeyFields(jbossRelationshipChildElement, geronimoRoleMapping,
+ (Map) ejbKeyColumnMapper.get(ejbName));
+ }
+ }
+
+ }
+
+ private void migrateKeyFields(Element jbossKeyField, Element geronimoRoleMapping,
+ Map keyFieldMap) {
+
+ Element jbossKeyFieldChild;
+ for (Iterator iter = jbossKeyField.elements().iterator(); iter.hasNext();) {
+ jbossKeyFieldChild = (Element) iter.next();
+ if (jbossKeyFieldChild.getName().equals("key-field")) {
+ QName qname = new QName("cmr-field-mapping", geronimoRoleMapping.getNamespace());
+ Element geronimoCMRFieldMapping = geronimoRoleMapping.addElement(qname);
+ migrateKeyField(jbossKeyFieldChild, geronimoCMRFieldMapping, keyFieldMap);
+ }
+ }
+ }
+
+ private void migrateKeyField(Element jbossKeyField, Element geronimoCMRFieldMapping,
+ Map keyFieldMap) {
+ Element jbossKeyFieldChild;
+ for (Iterator iter = jbossKeyField.elements().iterator(); iter.hasNext();) {
+ jbossKeyFieldChild = (Element) iter.next();
+ if (jbossKeyFieldChild.getName().equals("field-name")) {
+ QName qname = new QName("key-column", geronimoCMRFieldMapping.getNamespace());
+ Element geronimoKeyColumn = geronimoCMRFieldMapping.addElement(qname);
+ // get the table column name
+ geronimoKeyColumn.setText((String) keyFieldMap.get(jbossKeyFieldChild.getText().trim()));
+ } else if (jbossKeyFieldChild.getName().equals("column-name")) {
+ QName qname = new QName("foreign-key-column", geronimoCMRFieldMapping
+ .getNamespace());
+ Element geronimoForegnKeyColumn = geronimoCMRFieldMapping.addElement(qname);
+ geronimoForegnKeyColumn.setText(jbossKeyFieldChild.getText());
+ }
+ }
+ }
+
+ /**
+ * this method may be use ful in future
+ *
+ * @param jbossTableMappingElement
+ * @param geronimoManytoManyTable
+ */
+
+ private void migrateRelationTableMapping(Element jbossTableMappingElement,
+ Element geronimoManytoManyTable) {
+
+ Element jbossTableMappingChildElement;
+ for (Iterator iter = jbossTableMappingElement.elements().iterator(); iter.hasNext();) {
+ jbossTableMappingChildElement = (Element) iter.next();
+ if (jbossTableMappingChildElement.getName().equals("table-name")) {
+ geronimoManytoManyTable.setText(jbossTableMappingChildElement.getText());
+ }
+ }
+ }
+
+ /**
+ * 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("entity")) {
+
+ // get the entity ejb name
+ Element ejbNameElement = jbossEnterpriseBeanChildElement.element("ejb-name");
+ String ejbName = ejbNameElement.getText().trim();
+ 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());
+ cmpEntityBeanMigrator.migrateBean(jbossEnterpriseBeanChildElement, geronimoEntity);
+ // put the key columns to hash map
+ ejbKeyColumnMapper.put(ejbName, cmpEntityBeanMigrator.getKeyColumnMap());
+ }
+ }
+ }
+
+ private void migrateDefaults(Element jbossDefaultsElement, Element geronimoRootElement) {
+
+ Element jbossDefaultsChildElement;
+ for (Iterator iter = jbossDefaultsElement.elements().iterator(); iter.hasNext();) {
+ jbossDefaultsChildElement = (Element) iter.next();
+ if (jbossDefaultsChildElement.getName().equals("datasource")) {
+ // creates the cmp connection factory element
+ logger.debug("migrating the datasource");
+ QName qname = new QName("cmp-connection-factory", geronimoRootElement
+ .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+ Element geronimoCMPConnectionFactoryElement = geronimoRootElement.addElement(qname);
+ logger.debug("cmp-connection-factory added to geromimo");
+ String jndiName = jbossDefaultsChildElement.getText();
+ String artifactID;
+ if (!envirionmentElementProcessor.isJndiNameProcessed(jndiName)) {
+ artifactID = envirionmentElementProcessor.addDependencyModule(jndiName,
+ geronimoCMPConnectionFactoryElement.getDocument().getRootElement());
+ } else {
+ artifactID = envirionmentElementProcessor.getArtifactID(jndiName);
+ }
+ qname = new QName("resource-link", geronimoCMPConnectionFactoryElement
+ .getNamespaceForPrefix(Constants.NAMING_NAME_SPACE_PREFIX));
+ Element geronimoResourceLink = geronimoCMPConnectionFactoryElement
+ .addElement(qname);
+ geronimoResourceLink.setText(artifactID);
+ logger.debug("resource-link added to geronimo");
+ } else {
+ out.warn("The Element '" + jbossDefaultsChildElement.getName()
+ + "' is not supported", XMLConversionHelper
+ .getLineNumber(jbossDefaultsChildElement), XMLConversionHelper
+ .getColumnNumber(jbossDefaultsChildElement));
+ logger.debug("The Element '" + jbossDefaultsChildElement.getName()
+ + "' is not supported");
+ }
+ }
+ }
+}
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPEntityBeanMigrator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPEntityBeanMigrator.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPEntityBeanMigrator.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/CMPEntityBeanMigrator.java Mon Jul 2 11:30:34 2007
@@ -0,0 +1,132 @@
+/**
+ * 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.j2g.descriptors.comp;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.j2g.common.ConsoleOutput;
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.Tool;
+import org.apache.geronimo.j2g.util.descriptors.xml.XMLConversionHelper;
+import org.dom4j.Element;
+import org.dom4j.QName;
+
+
+public class CMPEntityBeanMigrator {
+
+ private IOutput out;
+
+ private Log logger = LogFactory.getLog(CMPEntityBeanMigrator.class);
+
+ // this is used to keep the filed name and column name
+ // key field name vaue column name
+ private Map keyColumnMap;
+
+ public CMPEntityBeanMigrator () {
+ Tool currentTool = Tool.getCurrent();
+ if (currentTool != null) {
+ out = currentTool.getOutput();
+ } else {
+ out = new ConsoleOutput();
+ }
+ }
+
+ public void migrateBean(Element jbossEntity, Element geronimoEntity) {
+
+ Element jbossEntityChildElement;
+ keyColumnMap = new HashMap();
+ for (Iterator iter = jbossEntity.elements().iterator(); iter.hasNext();) {
+ jbossEntityChildElement = (Element) iter.next();
+ if (jbossEntityChildElement.getName().equals("ejb-name")) {
+ // we have to check the ejb name since ejb name can put by the
+ // jboss.xml as well.
+ String xpath = "//ejb:ejb-name[text() ='" + jbossEntityChildElement.getText()
+ + "']";
+ logger.debug("Find existing ejb names with xpath ==> " + xpath);
+ if (!XMLConversionHelper.isNodeAvailable(geronimoEntity, xpath)) {
+ logger.debug("migrating the ejb name");
+ QName qname = new QName("ejb-name", geronimoEntity.getNamespace());
+ Element geronimoEJBName = geronimoEntity.addElement(qname);
+ geronimoEJBName.setText(jbossEntityChildElement.getText());
+ logger.debug("added ejb-name to geromimo");
+ }
+
+ } else if (jbossEntityChildElement.getName().equals("table-name")) {
+ logger.debug("migrating the table name");
+ QName qname = new QName("table-name", geronimoEntity.getNamespace());
+ Element geronimoTableName = geronimoEntity.addElement(qname);
+ geronimoTableName.setText(jbossEntityChildElement.getText());
+ logger.debug("added table name");
+ } else if (jbossEntityChildElement.getName().equals("cmp-field")) {
+ QName qname = new QName("cmp-field-mapping", geronimoEntity.getNamespace());
+ Element geronimoCMPFieldMapping = geronimoEntity.addElement(qname);
+ migrateCMPFieldMapping(jbossEntityChildElement, geronimoCMPFieldMapping);
+ } else {
+ out.warn("The Element '" + jbossEntityChildElement.getName() + "' is not suported",
+ XMLConversionHelper.getLineNumber(jbossEntityChildElement),
+ XMLConversionHelper.getColumnNumber(jbossEntityChildElement));
+ logger.debug("The Element '" + jbossEntityChildElement.getName()
+ + "' is not suported");
+ }
+
+ }
+ }
+
+ private void migrateCMPFieldMapping(Element jbossCMPField, Element geronimoCMPFieldMapping) {
+
+ Element jbossCMPFieldChild;
+ String fieldName = null;
+ String columnName = null;
+ for (Iterator iter = jbossCMPField.elements().iterator(); iter.hasNext();) {
+ jbossCMPFieldChild = (Element) iter.next();
+ if (jbossCMPFieldChild.getName().equals("field-name")) {
+ QName qname = new QName("cmp-field-name", geronimoCMPFieldMapping.getNamespace());
+ Element geronimoCMPFieldName = geronimoCMPFieldMapping.addElement(qname);
+ geronimoCMPFieldName.setText(jbossCMPFieldChild.getText());
+ fieldName = jbossCMPFieldChild.getText().trim();
+ } else if (jbossCMPFieldChild.getName().equals("column-name")) {
+ QName qname = new QName("table-column", geronimoCMPFieldMapping.getNamespace());
+ Element geronimoTableColumn = geronimoCMPFieldMapping.addElement(qname);
+ geronimoTableColumn.setText(jbossCMPFieldChild.getText());
+ columnName = jbossCMPFieldChild.getText().trim();
+ } else {
+ out.warn("The Element '" + jbossCMPFieldChild.getName() + "' is not suported",
+ XMLConversionHelper.getLineNumber(jbossCMPFieldChild),
+ XMLConversionHelper.getColumnNumber(jbossCMPFieldChild));
+ logger.debug("The Element '" + jbossCMPFieldChild.getName()
+ + "' is not suported");
+ }
+ }
+
+ if ((fieldName != null) && (columnName != null)){
+ keyColumnMap.put(fieldName,columnName);
+ }
+ }
+
+ public Map getKeyColumnMap() {
+ return keyColumnMap;
+ }
+
+ public void setKeyColumnMap(Map keyColumnMap) {
+ this.keyColumnMap = keyColumnMap;
+ }
+}
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/EJBJarXmlProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/EJBJarXmlProcessor.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/EJBJarXmlProcessor.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/EJBJarXmlProcessor.java Mon Jul 2 11:30:34 2007
@@ -0,0 +1,98 @@
+/**
+ * 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.j2g.descriptors.comp;
+
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.geronimo.j2g.descriptors.comp.dto.EJBRelation;
+import org.apache.geronimo.j2g.descriptors.comp.dto.EJBRelationshipRole;
+import org.apache.geronimo.j2g.descriptors.comp.dto.Relationships;
+import org.apache.geronimo.j2g.util.descriptors.xml.XMLConversionHelper;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+
+public class EJBJarXmlProcessor {
+
+ private String fileName;
+
+ public EJBJarXmlProcessor(String fileName) {
+ this.fileName = fileName;
+ }
+
+ /**
+ * @return relationships of the ejb jar xml file
+ */
+
+ public Relationships getRelationships() throws DocumentException {
+ Document document = XMLConversionHelper.getDocument(new File(fileName));
+ List ejbRelations = document.selectNodes("//relationships/ejb-relation");
+
+ Relationships relationships = new Relationships();
+
+ Element ejbRelationsChileElement;
+ for (Iterator iter = ejbRelations.iterator(); iter.hasNext();) {
+ ejbRelationsChileElement = (Element) iter.next();
+ if (ejbRelationsChileElement.getName().equals("ejb-relation")) {
+ relationships.addEJBRealtion(getEJBRelation(ejbRelationsChileElement));
+ }
+ }
+
+ return relationships;
+ }
+
+ private EJBRelation getEJBRelation(Element ejbRelationElement) {
+
+ EJBRelation ejbRelation = new EJBRelation();
+ Element ejbRelationChildElement;
+ for (Iterator iter = ejbRelationElement.elements().iterator(); iter.hasNext();) {
+ ejbRelationChildElement = (Element) iter.next();
+ if (ejbRelationChildElement.getName().equals("ejb-relation-name")) {
+ ejbRelation.setEjbRelationName(ejbRelationChildElement.getText().trim());
+ } else if (ejbRelationChildElement.getName().equals("ejb-relationship-role")) {
+ ejbRelation.addRelationshipRole(getEJBRelationshipRole(ejbRelationChildElement));
+ }
+ }
+ return ejbRelation;
+ }
+
+ private EJBRelationshipRole getEJBRelationshipRole(Element ejbRelationshipRoleElement) {
+
+ EJBRelationshipRole ejbRelationshipRole = new EJBRelationshipRole();
+ Element ejbRelationshipRoleChildElement;
+ for (Iterator iter = ejbRelationshipRoleElement.elements().iterator(); iter.hasNext();) {
+ ejbRelationshipRoleChildElement = (Element) iter.next();
+ if (ejbRelationshipRoleChildElement.getName().equals("ejb-relationship-role-name")) {
+ ejbRelationshipRole.setName(ejbRelationshipRoleChildElement.getText().trim());
+ } else if (ejbRelationshipRoleChildElement.getName().equals("multiplicity")) {
+ ejbRelationshipRole.setMultiplicity(ejbRelationshipRoleChildElement.getText().trim());
+ } else if (ejbRelationshipRoleChildElement.getName().equals("relationship-role-source")) {
+ Element ejbName = ejbRelationshipRoleChildElement.element("ejb-name");
+ ejbRelationshipRole.setSource(ejbName.getText().trim());
+ } else if (ejbRelationshipRoleChildElement.getName().equals("cmr-field")){
+ Element cmrFieldName = ejbRelationshipRoleChildElement.element("cmr-field-name");
+ ejbRelationshipRole.setCmrFieldName(cmrFieldName.getText().trim());
+ }
+ }
+ return ejbRelationshipRole;
+ }
+
+}
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelation.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelation.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelation.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelation.java Mon Jul 2 11:30:34 2007
@@ -0,0 +1,56 @@
+/**
+ * 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.j2g.descriptors.comp.dto;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * keep ejb relation details of the ejb-jar.xml file
+ *
+ */
+public class EJBRelation {
+ private String ejbRelationName;
+
+ private Map ejbRelationshipRoles;
+
+ public EJBRelation(String ejbRelationName) {
+ this.ejbRelationName = ejbRelationName;
+ this.ejbRelationshipRoles = new HashMap();
+ }
+
+ public EJBRelation() {
+ this.ejbRelationshipRoles = new HashMap();
+ }
+
+ public void addRelationshipRole(EJBRelationshipRole ejbRelationshipRole) {
+ ejbRelationshipRoles.put(ejbRelationshipRole.getName(), ejbRelationshipRole);
+ }
+
+ public EJBRelationshipRole getEJBRelationshipRole(String name) {
+ return (EJBRelationshipRole) this.ejbRelationshipRoles.get(name);
+ }
+
+ public String getEjbRelationName() {
+ return ejbRelationName;
+ }
+
+ public void setEjbRelationName(String ejbRelationName) {
+ this.ejbRelationName = ejbRelationName;
+ }
+
+}
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelationshipRole.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelationshipRole.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelationshipRole.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/EJBRelationshipRole.java Mon Jul 2 11:30:34 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.j2g.descriptors.comp.dto;
+
+public class EJBRelationshipRole {
+
+ private String name;
+
+ private String multiplicity;
+
+ private String source;
+
+ private String cmrFieldName;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMultiplicity() {
+ return multiplicity;
+ }
+
+ public void setMultiplicity(String multiplicity) {
+ this.multiplicity = multiplicity;
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public String getCmrFieldName() {
+ return cmrFieldName;
+ }
+
+ public void setCmrFieldName(String cmrFieldName) {
+ this.cmrFieldName = cmrFieldName;
+ }
+}
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/Relationships.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/Relationships.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/Relationships.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/comp/dto/Relationships.java Mon Jul 2 11:30:34 2007
@@ -0,0 +1,39 @@
+/**
+ * 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.j2g.descriptors.comp.dto;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Relationships {
+
+ private Map ejbRelations;
+
+ public Relationships() {
+ this.ejbRelations = new HashMap();
+ }
+
+ public void addEJBRealtion(EJBRelation ejbRelation) {
+ this.ejbRelations.put(ejbRelation.getEjbRelationName(), ejbRelation);
+ }
+
+ public EJBRelation getEJBRelation(String name) {
+ return (EJBRelation) this.ejbRelations.get(name);
+ }
+
+}
Added: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java?view=auto&rev=552557
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java (added)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.descriptors/src/org/apache/geronimo/j2g/descriptors/ejb/EJBDescriptorTool.java Mon Jul 2 11:30:34 2007
@@ -0,0 +1,216 @@
+/**
+ * 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.j2g.descriptors.ejb;
+
+
+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.j2g.common.ConsoleOutput;
+import org.apache.geronimo.j2g.common.IFileMigration;
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.Tool;
+import org.apache.geronimo.j2g.descriptors.ejb.bean.EntityBeanMigrator;
+import org.apache.geronimo.j2g.descriptors.ejb.bean.SessionBeanMigrator;
+import org.apache.geronimo.j2g.util.descriptors.Constants;
+import org.apache.geronimo.j2g.util.descriptors.env.EnvirionmentElementProcessor;
+import org.apache.geronimo.j2g.util.descriptors.naming.NamingElementProcessor;
+import org.apache.geronimo.j2g.util.descriptors.security.SecurityElementProcessor;
+import org.apache.geronimo.j2g.util.descriptors.xml.XMLConversionHelper;
+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;
+
+ 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) {
+ 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("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("Successfully migrated the Jboss.xml file in "
+ + directoryName + ", with the error and warning messages as shown");
+ } catch (DocumentException e) {
+ out.error("Errors occurs while reading xml descriptor "
+ + file.getAbsolutePath()
+ + ". It is possible that the migrator cannot download an xml schema or xml file has a wrong syntax. Nested exception:"
+ + e.getMessage());
+ } catch (IOException e) {
+ out.error("IO exception " + e.getMessage());
+ }
+ } else if (jbossFileName.equals(Constants.EJB_JAR_XML_FILE)){
+ out.info("Converting ejb-jar.xml file in " + directoryName);
+ out.info("Nothing to convert. Keep the file as it is");
+ }
+ return migrated;
+ }
+
+ 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("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("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("The Element '" + jbossEnterpriseBeanChildElement.getName()
+ + "' is not supported", XMLConversionHelper
+ .getLineNumber(jbossEnterpriseBeanChildElement), XMLConversionHelper
+ .getColumnNumber(jbossEnterpriseBeanChildElement));
+ logger.debug("The Element '" + jbossEnterpriseBeanChildElement.getName()
+ + "' is not supported");
+ }
+ }
+ }
+}