[jboss-cvs] JBossAS SVN: r90045 - in projects/mc-tools/trunk: src and 19 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 10 02:26:27 EDT 2009
Author: flavia.rainone at jboss.com
Date: 2009-06-10 02:26:26 -0400 (Wed, 10 Jun 2009)
New Revision: 90045
Added:
projects/mc-tools/trunk/.classpath
projects/mc-tools/trunk/.project
projects/mc-tools/trunk/pom.xml
projects/mc-tools/trunk/src/
projects/mc-tools/trunk/src/main/
projects/mc-tools/trunk/src/main/java/
projects/mc-tools/trunk/src/main/java/org/
projects/mc-tools/trunk/src/main/java/org/jboss/
projects/mc-tools/trunk/src/main/java/org/jboss/mc/
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/IOUtil.java
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JBossBeanXMLMarshaller.java
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JMXAnnotationStrategy.java
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/MetaDataConverter.java
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/ServiceXMLParser.java
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/XMLMigrator.java
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/AutoIncrementNameService.java
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/BeanNameService.java
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/InputNameService.java
projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/UsePropertyService.java
projects/mc-tools/trunk/src/main/resources/
projects/mc-tools/trunk/src/test/
projects/mc-tools/trunk/src/test/java/
projects/mc-tools/trunk/src/test/java/org/
projects/mc-tools/trunk/src/test/java/org/jboss/
projects/mc-tools/trunk/src/test/java/org/jboss/mc/
projects/mc-tools/trunk/src/test/java/org/jboss/mc/tools/
projects/mc-tools/trunk/src/test/java/org/jboss/mc/tools/jmx/
projects/mc-tools/trunk/src/test/resources/
projects/mc-tools/trunk/src/test/resources/org/
projects/mc-tools/trunk/src/test/resources/org/jboss/
projects/mc-tools/trunk/src/test/resources/org/jboss/mc/
projects/mc-tools/trunk/src/test/resources/org/jboss/mc/tools/
projects/mc-tools/trunk/src/test/resources/org/jboss/mc/tools/jmx/
Log:
[JBMICROCONT-444] First version of the jmx->mc migration tool. At this stage, the structure of the packages and how this tool is made available to the final user is 100% subject to change.
Added: projects/mc-tools/trunk/.classpath
===================================================================
--- projects/mc-tools/trunk/.classpath (rev 0)
+++ projects/mc-tools/trunk/.classpath 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
+ <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
+ <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.1.1/activation-1.1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.7.0/ant-1.7.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-junit/1.7.0/ant-junit-1.7.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/bcel/bcel/5.1/bcel-5.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javassist/javassist/3.10.0.GA/javassist-3.10.0.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/sun-jaxb/jaxb-api/2.1.4/jaxb-api-2.1.4.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/aop/jboss-aop/2.1.0.CR3/jboss-aop-2.1.0.CR3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-aop-mc-int/2.2.0.M2/jboss-aop-mc-int-2.2.0.M2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/integration/jboss-classloading-spi/6.0.0.Alpha4/jboss-classloading-spi-6.0.0.Alpha4.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.7.GA/jboss-common-core-2.2.7.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-dependency/2.2.0.M2/jboss-dependency-2.2.0.M2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/mx/jboss-j2se/6.0.0.Beta2/jboss-j2se-6.0.0.Beta2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/mx/jboss-jmx/6.0.0.Beta2/jboss-jmx-6.0.0.Beta2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-jmx-mc-int/2.2.0.M2/jboss-jmx-mc-int-2.2.0.M2.jar" sourcepath="/MC/jmx-mc-int/src/main/java"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/microcontainer/jboss-kernel/2.2.0.M2/jboss-kernel-2.2.0.M2.jar" sourcepath="/MC/kernel/src/main/java"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/man/jboss-managed/2.1.0.SP1/jboss-managed-2.1.0.SP1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/mx/jboss-mbeans/6.0.0.Beta2/jboss-mbeans-6.0.0.Beta2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/mx/jboss-mbeanserver/6.0.0.Beta2/jboss-mbeanserver-6.0.0.Beta2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-mdr/2.0.1.GA/jboss-mdr-2.0.1.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/man/jboss-metatype/2.1.0.SP1/jboss-metatype-2.1.0.SP1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/profiler/jvmti/jboss-profiler-jvmti/1.0.0.CR5/jboss-profiler-jvmti-1.0.0.CR5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-reflect/2.0.2.GA/jboss-reflect-2.0.2.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jbossas/jboss-server-manager/0.1.1.GA/jboss-server-manager-0.1.1.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/test/jboss-test/1.1.1.GA/jboss-test-1.1.1.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jbossxb/2.0.1.GA/jbossxb-2.0.1.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.2/junit-3.8.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
+ <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
+ <classpathentry kind="var" path="M2_REPO/qdox/qdox/1.6.1/qdox-1.6.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/trove/trove/2.1.1/trove-2.1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.9.1/xml-apis-2.9.1.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: projects/mc-tools/trunk/.project
===================================================================
--- projects/mc-tools/trunk/.project (rev 0)
+++ projects/mc-tools/trunk/.project 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,17 @@
+<projectDescription>
+ <name>jboss-mctools</name>
+ <comment>JBoss Microcontainer tools.</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Added: projects/mc-tools/trunk/pom.xml
===================================================================
--- projects/mc-tools/trunk/pom.xml (rev 0)
+++ projects/mc-tools/trunk/pom.xml 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,84 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>4</version>
+ </parent>
+ <groupId>org.jboss.microcontainer.tools</groupId>
+ <artifactId>jboss-mctools</artifactId>
+ <packaging>jar</packaging>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>JBoss Microcontainer Tools</name>
+ <url>http://www.jboss.com/products/jbossmc</url>
+ <description>JBoss Microcontainer tools.</description>
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/mc-tools/trunk</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/mc-tools/trunk</developerConnection>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>/home/fla/.m2/repository/</classpathPrefix>
+ <classpathMavenRepositoryLayout>true</classpathMavenRepositoryLayout>
+ <mainClass>org.jboss.mc.tools.jmx.XMLMigrator</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ <version>2.2.0.M2</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-jmx-mc-int</artifactId>
+ <version>2.2.0.M2</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ <version>2.1.0.SP1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-aop-mc-int</artifactId>
+ <version>2.2.0.M2</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test</groupId>
+ <artifactId>jboss-test</artifactId>
+ <version>1.1.1.GA</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <version>2.0.5.GA</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/IOUtil.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/IOUtil.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/IOUtil.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * Utilities class for handling input/output.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class IOUtil
+{
+ public static boolean inputDecision(String question)
+ {
+ System.out.println(question + " [y/n]: ");
+ String input = null;
+ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+ try
+ {
+ input = reader.readLine();
+ while(!"n".equalsIgnoreCase(input) && !"y".equalsIgnoreCase(input))
+ {
+ System.out.print("Invalid option. " + question + " [y/n]: ");
+ input = reader.readLine();
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unexpected IO error", e);
+ }
+ return "y".equalsIgnoreCase(input);
+ }
+
+ public static String inputName(String prompt)
+ {
+ System.out.println(prompt + ": ");
+ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+ try
+ {
+ return reader.readLine();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unexpected IO error", e);
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/IOUtil.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JBossBeanXMLMarshaller.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JBossBeanXMLMarshaller.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JBossBeanXMLMarshaller.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx;
+
+import java.util.Collection;
+
+import org.jboss.beans.metadata.plugins.AbstractAnnotationMetaData;
+import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData;
+import org.jboss.beans.metadata.plugins.StringValueMetaData;
+import org.jboss.beans.metadata.spi.AnnotationMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.DependencyMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+
+/**
+ * Marshals BeanMetaData into a jboss-beans.xml file format.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+class JBossBeanXMLMarshaller
+{
+ private static String tab = " ";
+ public static String marshall(Collection<? extends BeanMetaData> beanMetaData)
+ {
+ StringBuffer result = new StringBuffer();
+ result.append("<deployment xmlns=\"urn:jboss:bean-deployer:2.0\">");
+ for (BeanMetaData bean: beanMetaData)
+ {
+ result.append("\n");
+ marshal(bean, result);
+ }
+ result.append("\n\n</deployment>");
+ return result.toString();
+ }
+ /**
+ * @param bean
+ * @param result
+ */
+ private static void marshal(BeanMetaData bean, StringBuffer result)
+ {
+ result.append("\n").append(tab);
+ result.append("<bean name=\"").append(bean.getName());
+ result.append("\" class=\"").append(bean.getBean()).append("\">");
+
+ if (bean.getConstructor() != null && !bean.getConstructor().getParameters().isEmpty())
+ {
+ result.append("\n").append(tab).append(tab);
+ result.append("<constructor>\n");
+ for (ParameterMetaData parameter: bean.getConstructor().getParameters())
+ {
+ result.append("\n").append(tab).append(tab).append(tab);
+ result.append("<parameter class=\"").append(parameter.getType()).append("\">");
+ result.append(parameter.getValue().getUnderlyingValue());
+ result.append("</parameter>");
+ }
+ result.append("\n").append(tab).append(tab);
+ result.append("</constructor>\n");
+ }
+
+ for (PropertyMetaData property: bean.getProperties())
+ {
+ result.append("\n").append(tab).append(tab);
+ result.append("<property name=\"").append(property.getName()).append("\">");
+ ValueMetaData value = property.getValue();
+
+ if (value instanceof AbstractInjectionValueMetaData)
+ {
+ AbstractInjectionValueMetaData beanInjection = (AbstractInjectionValueMetaData) value;
+ /*if (((AbstractInjectionValueMetaData) value).getProperty() != null)
+ {
+ result.append("<value-factory bean=\"").append(beanInjection.getValue());
+ result.append("\" method=\"");
+ result.
+ }*/
+ result.append("\n").append(tab).append(tab).append(tab);
+ result.append("<inject bean=\"").append(beanInjection.getValue()).append("\"");
+ if (beanInjection.getProperty() != null)
+ {
+ result.append(" property=\"").append(beanInjection.getProperty()).append("\"");
+ }
+ result.append("/>");
+ result.append("\n").append(tab).append(tab);
+ }
+ else if(value instanceof BeanMetaData)
+ {
+ BeanMetaData anonymousBean = (BeanMetaData) value;
+ result.append("\n").append(tab).append(tab).append(tab);
+ result.append("<bean class=\"").append(anonymousBean.getBean());
+ if (anonymousBean.getProperties().isEmpty())
+ {
+ result.append("/>");
+ }
+ else
+ {
+ for (PropertyMetaData anonymousProperty: anonymousBean.getProperties())
+ {
+ result.append("\n").append(tab).append(tab).append(tab).append(tab);
+ result.append("<property name=\"").append(anonymousProperty.getName());
+ result.append("\">");
+ result.append(((StringValueMetaData)anonymousProperty.getValue()).getValue());
+ result.append("</property>");
+ }
+ result.append("\n").append(tab).append(tab).append(tab);
+ result.append("</bean>");
+ result.append("\n").append(tab).append(tab);
+ }
+ }
+ else if(value instanceof AbstractValueFactoryMetaData)
+ {
+ AbstractValueFactoryMetaData valueFactory = (AbstractValueFactoryMetaData) value;
+ result.append("\n").append(tab).append(tab).append(tab);
+ result.append("<value-factory name=\"").append(valueFactory.getValue());
+ result.append("\" method=").append(valueFactory.getMethod());
+ if (valueFactory.getParameter() != null)
+ {
+ result.append("\" parameter=\"").append(valueFactory.getParameter()).append("\"/>");
+ }
+ else
+ {
+ for (ParameterMetaData factoryParameter: valueFactory.getParameters())
+ {
+ result.append("\n").append(tab).append(tab).append(tab).append(tab);
+ result.append("<parameter>");
+ result.append(factoryParameter.getValue().getUnderlyingValue());
+ result.append("</parameter>");
+ }
+ result.append("\n").append(tab).append(tab).append(tab).append("</value-factory>");
+ }
+ result.append("\n").append(tab).append(tab);
+ }
+ else if (value instanceof StringValueMetaData)
+ {
+ result.append(value.getUnderlyingValue());
+ }
+ else
+ {
+ throw new RuntimeException("Unexpected value type: " + value.getClass().getName());
+ }
+ result.append("</property>");
+ }
+
+ if (bean.getDepends() != null && !bean.getDepends().isEmpty())
+ {
+ for (DependencyMetaData dependency: bean.getDepends())
+ {
+ result.append("\n").append(tab).append(tab);
+ result.append("<depends>").append(dependency.getDependency()).append("</depends>");
+ }
+ }
+
+ if (bean.getAliases() != null && !bean.getAliases().isEmpty())
+ {
+ for (Object alias: bean.getAliases())
+ {
+ result.append("\n").append(tab).append(tab);
+ result.append("<alias>").append(alias).append("</alias>");
+ }
+ }
+
+ if (bean.getAnnotations() != null && !bean.getAnnotations().isEmpty())
+ {
+ for (AnnotationMetaData annotation: bean.getAnnotations())
+ {
+ result.append("\n").append(tab).append(tab).append("<annotation>");
+ result.append(((AbstractAnnotationMetaData) annotation).getAnnotation());
+ result.append("</annotation>");
+ }
+ }
+
+ result.append("\n").append(tab);
+ result.append("</bean>");
+ }
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JBossBeanXMLMarshaller.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JMXAnnotationStrategy.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JMXAnnotationStrategy.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JMXAnnotationStrategy.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx;
+
+import javax.management.ObjectName;
+
+import org.jboss.aop.microcontainer.aspects.jmx.JMX;
+import org.jboss.beans.metadata.plugins.AbstractAnnotationMetaData;
+import org.jboss.beans.metadata.spi.AnnotationMetaData;
+import org.jboss.system.metadata.ServiceMetaData;
+
+/**
+ *
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+interface JMXAnnotationStrategy
+{
+ AnnotationMetaData createAnnotation(ServiceMetaData service);
+}
+
+class AnnotateAllStrategy implements JMXAnnotationStrategy
+{
+ public AnnotationMetaData createAnnotation(ServiceMetaData service)
+ {
+ ObjectName name = service.getObjectName();
+ String interfaceName = service.getInterfaceName();
+ StringBuffer annotation = new StringBuffer('@' + JMX.class.getName());
+ annotation.append("(name=\"").append(name);
+
+ if (interfaceName == null)
+ {
+ annotation.append("\", registerDirectly=false)");
+ }
+ else
+ {
+ annotation.append("\", exposedInterface=").append(interfaceName);
+ annotation.append(".class, registerDirectly=true)");
+ }
+ return new AbstractAnnotationMetaData(annotation.toString());
+ }
+}
+
+class AnnotateWithUserInputStrategy implements JMXAnnotationStrategy
+{
+ private JMXAnnotationStrategy generator = new AnnotateAllStrategy();
+
+ public AnnotationMetaData createAnnotation(ServiceMetaData service)
+ {
+ ObjectName name = service.getObjectName();
+ boolean create = IOUtil.inputDecision("Should a @JMX annotation be injected for beans " + name + "?");
+ return create? generator.createAnnotation(service): null;
+ }
+}
+
+class NoJMXAnnotationStrategy implements JMXAnnotationStrategy
+{
+ public AnnotationMetaData createAnnotation(ServiceMetaData service)
+ {
+ return null;
+ }
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/JMXAnnotationStrategy.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/MetaDataConverter.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/MetaDataConverter.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/MetaDataConverter.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,335 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.beans.metadata.plugins.AbstractAliasMetaData;
+import org.jboss.beans.metadata.plugins.AbstractAnnotationMetaData;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractDependencyMetaData;
+import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.plugins.StringValueMetaData;
+import org.jboss.beans.metadata.spi.AliasMetaData;
+import org.jboss.beans.metadata.spi.AnnotationMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.DependencyMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.mc.tools.jmx.naming.BeanNameService;
+import org.jboss.system.ConfigurationException;
+import org.jboss.system.metadata.ServiceAnnotationMetaData;
+import org.jboss.system.metadata.ServiceAttributeMetaData;
+import org.jboss.system.metadata.ServiceConstructorMetaData;
+import org.jboss.system.metadata.ServiceDependencyMetaData;
+import org.jboss.system.metadata.ServiceDependencyValueMetaData;
+import org.jboss.system.metadata.ServiceElementValueMetaData;
+import org.jboss.system.metadata.ServiceInjectionValueMetaData;
+import org.jboss.system.metadata.ServiceJBXBValueMetaData;
+import org.jboss.system.metadata.ServiceJavaBeanValueMetaData;
+import org.jboss.system.metadata.ServiceMetaData;
+import org.jboss.system.metadata.ServiceMetaDataParser;
+import org.jboss.system.metadata.ServiceTextValueMetaData;
+import org.jboss.system.metadata.ServiceValueFactoryParameterMetaData;
+import org.jboss.system.metadata.ServiceValueFactoryValueMetaData;
+import org.jboss.system.metadata.ServiceValueMetaData;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Converts ServiceMetaData objects to BeanMetaData.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+class MetaDataConverter
+{
+ private boolean xMBeanDDFound = false;
+ private boolean xMBeanDescriptorFound = false;
+ private boolean xMBeanCodeFound = false;
+ private JMXAnnotationStrategy jmxAnnotationStrategy;
+ private BeanNameService nameTranslator;
+
+ public MetaDataConverter(JMXAnnotationStrategy jmxAnnotationGenerator, BeanNameService nameTranslator)
+ {
+ this.jmxAnnotationStrategy = jmxAnnotationGenerator;
+ this.nameTranslator = nameTranslator;
+ }
+
+ public boolean isXMBeanDescriptorFound()
+ {
+ return this.xMBeanDescriptorFound;
+ }
+
+ public boolean isXMBeanDDFound()
+ {
+ return this.xMBeanDDFound;
+ }
+
+ public boolean isXMBeanCodeFound()
+ {
+ return this.xMBeanCodeFound;
+ }
+
+ /**
+ * Converts jmxMetaData (old MicroKernel) into BeanMetaData (Microcontainer)
+ *
+ * @param jmxMetaData metadata to be transformed
+ * @return a collection of BeanMetaData
+ */
+ public Collection<? extends BeanMetaData> convert(Collection<ServiceMetaData> jmxMetaData)
+ {
+ Collection<AbstractBeanMetaData> beanMetaData = new ArrayList<AbstractBeanMetaData>();
+ for (ServiceMetaData service: jmxMetaData)
+ {
+ beanMetaData.add(convert(service));
+ }
+ return beanMetaData;
+ }
+
+ private AbstractBeanMetaData convert(ServiceMetaData service)
+ {
+ // TODO trim e replace!!!!
+ // TODO ControllerMode
+ service.getMode();
+ // update xMBean*Found variables
+ xMBeanDescriptorFound = xMBeanDescriptorFound || service.getXMBeanDescriptor() != null;
+ xMBeanDDFound = xMBeanDDFound || service.getXMBeanDD() != null;
+ xMBeanCodeFound = xMBeanCodeFound || service.getXMBeanCode() != ServiceMetaData.XMBEAN_CODE;
+
+ // create bean metadata and set its class and name properties
+ AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(service.getCode());
+ beanMetaData.setName(nameTranslator.translate(service));
+
+ // convert constructor meta data
+ beanMetaData.setConstructor(convertConstructor(service));
+
+ // convert attribute meta data
+ for(ServiceAttributeMetaData attribute: service.getAttributes())
+ {
+ ValueMetaData newValue = convert(attribute.getValue());
+ PropertyMetaData propertyMetaData = new AbstractPropertyMetaData(attribute.getName(), newValue);
+ beanMetaData.addProperty(propertyMetaData);
+ }
+
+ // convert dependency meta data
+ if (!service.getDependencies().isEmpty())
+ {
+ Set<DependencyMetaData> newDependencies = new HashSet<DependencyMetaData>();
+ for (ServiceDependencyMetaData dependency: service.getDependencies())
+ {
+ String dependencyName = nameTranslator.translate(dependency.getIDependOn());
+ newDependencies.add(new AbstractDependencyMetaData(dependencyName));
+ }
+ beanMetaData.setDepends(newDependencies);
+ }
+
+ // convert alias meta data
+ if (service.getAliases()!= null && !service.getAliases().isEmpty())
+ {
+ Set<AliasMetaData> aliases = new HashSet<AliasMetaData>();
+ for (String alias: service.getAliases())
+ {
+ AbstractAliasMetaData newAlias = new AbstractAliasMetaData();
+ newAlias.setAliasValue(alias);
+ aliases.add(newAlias);
+ }
+ beanMetaData.setAliasMetaData(aliases);
+ }
+
+ // convert annotation meta data
+ Set<AnnotationMetaData> annotations = null;
+ if (!service.getAnnotations().isEmpty())
+ {
+ annotations = new HashSet<AnnotationMetaData>();
+ for (ServiceAnnotationMetaData annotation: service.getAnnotations())
+ {
+ annotations.add(new AbstractAnnotationMetaData(annotation.getAnnotation()));
+ }
+ }
+ // create @JMX annotation metadata when appliable
+ AnnotationMetaData jmxAnnotation = jmxAnnotationStrategy.createAnnotation(service);
+ if (jmxAnnotation != null)
+ {
+ if (annotations == null)
+ {
+ annotations = new HashSet<AnnotationMetaData>();
+ }
+ annotations.add(jmxAnnotation);
+ }
+ beanMetaData.setAnnotations(annotations);
+ return beanMetaData;
+ }
+
+ private ValueMetaData convert(ServiceValueMetaData value)
+ {
+ ValueMetaData newValue = null;
+ if (value instanceof ServiceJavaBeanValueMetaData)
+ {
+ newValue = getAnonymousBean(((ServiceJavaBeanValueMetaData) value).getElement());
+ }
+ else if (value instanceof ServiceJBXBValueMetaData)
+ {
+ // TODO: is there an equivalent for MC?
+ }
+ else if (value instanceof ServiceInjectionValueMetaData)
+ {
+ ServiceInjectionValueMetaData valueMetaData = (ServiceInjectionValueMetaData) value;
+ String dependency = (String) valueMetaData.getDependency();
+ String property = (String) valueMetaData.getProperty();
+ newValue = new AbstractInjectionValueMetaData(nameTranslator.translate(dependency), property);
+ }
+ else if (value instanceof ServiceDependencyValueMetaData)
+ {
+ ServiceDependencyValueMetaData valueMetaData = (ServiceDependencyValueMetaData) value;
+ String dependency = (String) valueMetaData.getDependency();
+ newValue = new AbstractInjectionValueMetaData(nameTranslator.translate(dependency));
+ }
+ else if (value instanceof ServiceValueFactoryValueMetaData)
+ {
+ ServiceValueFactoryValueMetaData valueMetaData = (ServiceValueFactoryValueMetaData) value;
+ String dependency = nameTranslator.translate((String) valueMetaData.getDependency());
+ String method = valueMetaData.getMethod();
+ String defaultValue = valueMetaData.getDefaultValue().getText();
+
+ AbstractValueFactoryMetaData metaData = new AbstractValueFactoryMetaData(dependency, method, defaultValue);
+ if (valueMetaData.getParameterMetaData().size() == 1)
+ {
+ ServiceValueFactoryParameterMetaData parameter = valueMetaData.getParameterMetaData().get(0);
+ if (parameter.getParameterTypeName() == null && parameter.getValueTypeName() == null)
+ {
+ metaData.setParameter(parameter.getTextValue());
+ }
+ }
+ if (metaData.getParameter() == null)
+ {
+ List<ParameterMetaData> newParameters = new ArrayList<ParameterMetaData>();
+ for (ServiceValueFactoryParameterMetaData parameter: valueMetaData.getParameterMetaData())
+ {
+ String textValue = parameter.getTextValue();
+ String type = parameter.getParameterTypeName();
+ String type2 = parameter.getValueTypeName();
+ type = type2 == null? type: type2;
+ ValueMetaData parameterValue = null;
+ if (type == "java.lang.String")
+ {
+ parameterValue = new AbstractValueMetaData(textValue);
+ }
+ else
+ {
+ // TODO: should I create a different parameter for constructor in tis case?
+ throw new RuntimeException("Unsupported");
+ }
+ newParameters.add(new AbstractParameterMetaData(type2 == null? type: type2, parameterValue));
+ }
+ metaData.setParameters(newParameters);
+ }
+ newValue = metaData;
+ }
+ else if (value instanceof ServiceElementValueMetaData)
+ {
+ // TODO what to do in this case?
+ throw new RuntimeException("Unsupported");
+ }
+ else if (value instanceof ServiceTextValueMetaData)
+ {
+ newValue = new StringValueMetaData(((ServiceTextValueMetaData)value).getText());
+ }
+ else if (value instanceof ServiceDependencyMetaData)
+ {
+ ServiceDependencyValueMetaData valueMetaData = (ServiceDependencyValueMetaData) value;
+ if (valueMetaData.getProxyType() != null)
+ {
+ // TODO
+ throw new RuntimeException("Unsupported");
+ }
+ String beanName = nameTranslator.translate(valueMetaData.getDependency());
+ newValue = new AbstractInjectionValueMetaData(beanName);
+ }
+ else
+ {
+ throw new RuntimeException("Unexpected value type: " + (value == null? value: value.getClass().getName()));
+ }
+ return newValue;
+ }
+
+ private AbstractConstructorMetaData convertConstructor(ServiceMetaData service)
+ {
+ AbstractConstructorMetaData beanConstructor = null;
+ ServiceConstructorMetaData constructor = service.getConstructor();
+ String[] parameters = constructor.getParams();
+ String[] signature;
+ try
+ {
+ signature = constructor.getSignature();
+ }
+ catch (ConfigurationException e)
+ {
+ throw new RuntimeException("Unexpected exception", e);
+ }
+ if (parameters != null)
+ {
+ beanConstructor = new AbstractConstructorMetaData();
+ List<ParameterMetaData> newParameters = new ArrayList<ParameterMetaData>();
+ for (int i = 0; i < parameters.length; i++)
+ {
+ AbstractParameterMetaData parameter = new AbstractParameterMetaData();
+ parameter.setValue(new AbstractValueMetaData(parameters[i]));
+ parameter.setType(signature[i]);
+ newParameters.add(parameter);
+ }
+ beanConstructor.setParameters(newParameters);
+ }
+ return beanConstructor;
+ }
+
+ private BeanMetaData getAnonymousBean(Element element)
+ {
+ AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(element.getAttribute("attributeClass"));
+ NodeList properties = element.getElementsByTagName("property");
+ for(int n = 0; n < properties.getLength(); n ++)
+ {
+ // Skip over non-element nodes
+ Node node = properties.item(n);
+ if (node.getNodeType() != Node.ELEMENT_NODE)
+ {
+ continue;
+ }
+ Element property = (Element) node;
+ String name = property.getAttribute("name");
+ String value = ServiceMetaDataParser.getRawElementTextContent(property);
+ beanMetaData.addProperty(new AbstractPropertyMetaData(name, value));
+ }
+ return beanMetaData;
+ }
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/MetaDataConverter.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/ServiceXMLParser.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/ServiceXMLParser.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/ServiceXMLParser.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx;
+
+import java.net.URL;
+import java.util.Collection;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.jboss.system.metadata.ServiceMetaData;
+import org.jboss.system.metadata.ServiceMetaDataParser;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+/**
+ * Parses a jboss-service.xml file.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+class ServiceXMLParser
+{
+ public static Collection<ServiceMetaData> parse(URL url) throws Exception
+ {
+ DocumentBuilderFactory docBuilderFactory = null;
+ docBuilderFactory = DocumentBuilderFactory.newInstance();
+ docBuilderFactory.setValidating(false);
+ InputSource source = new InputSource(url.openStream());
+ DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+ //docBuilder.setEntityResolver(new Resolver());
+ Document doc = docBuilder.parse(source);
+ ServiceMetaDataParser parser = new ServiceMetaDataParser(doc.getDocumentElement());
+ return parser.parse();
+ }
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/ServiceXMLParser.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/XMLMigrator.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/XMLMigrator.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/XMLMigrator.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.Collection;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.mc.tools.jmx.naming.BeanNameService;
+import org.jboss.mc.tools.jmx.naming.UsePropertyService;
+import org.jboss.system.metadata.ServiceMetaData;
+
+/**
+ * Tool for migrating jboss-service.xml files to jboss-beans.xml files.
+ *
+ * Usage: [jmx.enable|jmx.disable] -Dname.translator=[name translator] [files] where
+ * name.translator property is optional and must point to a subclass of org.jboss.mc.tools.jmx.naming.BeanNameTranslator
+ * jmx.enable is optional and indicates that you want to inject the @JMX annotation into your beans for backwards compatibility with JMX"
+ * jmx.disable is optional and indicates that you do not want to inject the @JMX annotation into your beans
+ * files is the list of files you want to migrate, separated by spaces
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ *
+ */
+public class XMLMigrator
+{
+ public static void main(String[] args) throws Exception
+ {
+ // if not args, print usage
+ if (args.length == 0)
+ {
+ System.out.println("Usage: -Dname.translator=[name translator] [jmx.enable|jmx.disable] [files] where");
+ System.out.println(" name.translator property is optional and must point to a subclass of org.jboss.mc.tools.jmx.naming.BeanNameTranslator");
+ System.out.println(" jmx.enable is optional and indicates that you want to inject the @JMX annotation into your beans for backwards compatibility with JMX");
+ System.out.println(" jmx.disable is optional and indicates that you do not want to inject the @JMX annotation into your beans");
+ System.out.println(" files is the list of files you want to migrate, separated by spaces");
+ }
+ // define the jmx annotation strategy
+ JMXAnnotationStrategy jmxAnnotationStrategy = null;
+ for (String arg:args)
+ {
+ if (arg.equals("jmx.enable"))
+ {
+ if (jmxAnnotationStrategy != null)
+ {
+ System.out.println("You must use only one instance of the parameters \"jmx.enable\"/\"jmx.disable\"");
+ System.exit(1);
+ }
+ jmxAnnotationStrategy = new AnnotateAllStrategy();
+ }
+ else if (arg.equals("jmx.disable"))
+ {
+ if (jmxAnnotationStrategy != null)
+ {
+ System.out.println("You must use only one instance of the parameters \"jmx.enable\"/\"jmx.disable\"");
+ System.exit(1);
+ }
+ jmxAnnotationStrategy = new NoJMXAnnotationStrategy();
+ }
+ }
+ if (jmxAnnotationStrategy == null)
+ {
+ jmxAnnotationStrategy = new AnnotateWithUserInputStrategy();
+ }
+ // define the name translator to be used
+ String nameTranslatorClass = System.getProperty("name.translator", UsePropertyService.class.getName());
+ BeanNameService nameTranslator = null;
+ try
+ {
+ nameTranslator = (BeanNameService) Class.forName(nameTranslatorClass).newInstance();
+ }
+ catch(ClassNotFoundException e)
+ {
+ System.out.println("Name translator class " + nameTranslatorClass + " could not be found.");
+ System.exit(1);
+ }
+
+ // create meta data converter
+ MetaDataConverter metaDataConverter = new MetaDataConverter(jmxAnnotationStrategy, nameTranslator);
+ for (String arg: args)
+ {
+ // ignore optional args
+ if (arg.equals("jmx.enable") || arg.equals("jmx.disable") || arg.startsWith("-D"))
+ {
+ continue;
+ }
+ // arg must point to an XML file
+ if (!arg.endsWith(".xml"))
+ {
+ System.out.println("Unexpected file: " + arg + ". Should be an XML file.");
+ System.exit(1);
+ }
+ // check if file exists
+ File file = new File(arg);
+ if (!file.exists())
+ {
+ System.out.println("File not found: " + arg);
+ System.exit(1);
+ }
+ // parse and convert metadata
+ Collection<ServiceMetaData> jmxMetaData = ServiceXMLParser.parse(file.toURL());
+ Collection<? extends BeanMetaData> beanMetaData = metaDataConverter.convert(jmxMetaData);
+ // marshall and print xml file
+ String xmlContent = JBossBeanXMLMarshaller.marshall(beanMetaData);
+ File xmlFile = getOutputFile(arg);
+ System.out.println("Migrating " + arg + " to " + xmlFile.getAbsoluteFile());
+ PrintWriter printWriter = new PrintWriter(xmlFile);
+ printWriter.print(xmlContent);
+ printWriter.close();
+ }
+ if (metaDataConverter.isXMBeanCodeFound())
+ {
+ System.out.println("WARN: Attributes xMBeanCode not supported.");
+ }
+ if (metaDataConverter.isXMBeanDDFound())
+ {
+ System.out.println("WARN: Attributes xMBeanDD not supported.");
+ }
+ if (metaDataConverter.isXMBeanDescriptorFound())
+ {
+ System.out.println("WARN: Elements <xmbean> not supported.");
+ }
+ }
+
+
+ private static File getOutputFile(String inputFile)
+ {
+ int index = inputFile.lastIndexOf("-service.xml");
+ if (index == -1)
+ {
+ index = inputFile.lastIndexOf(".xml");
+ }
+ File xmlFile = new File(inputFile.substring(0, index) + "-beans.xml");
+ if (xmlFile.exists())
+ {
+ xmlFile = getNonExistentFile(xmlFile);
+ }
+ return xmlFile;
+ }
+
+ private static File getNonExistentFile(File xmlFile)
+ {
+ boolean overwrite = IOUtil.inputDecision("File " + xmlFile.getAbsolutePath() + " aready exists. Overwrite?");
+ if (!overwrite)
+ {
+ String fileURL = IOUtil.inputName("Type the name of the output file for " + xmlFile.getAbsoluteFile());
+ if (!fileURL.endsWith(".xml"))
+ {
+ fileURL += ".xml";
+ }
+ xmlFile = new File(fileURL);
+ if (xmlFile.exists())
+ {
+ return getNonExistentFile(xmlFile);
+ }
+ }
+ return xmlFile;
+ }
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/XMLMigrator.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/AutoIncrementNameService.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/AutoIncrementNameService.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/AutoIncrementNameService.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx.naming;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ *
+ */
+public class AutoIncrementNameService extends BeanNameService
+{
+ private int count = 0;
+ private Map<String, String> names = new HashMap<String, String>();
+
+ public String translate(String serviceName)
+ {
+ if (names.containsKey(serviceName))
+ {
+ return names.get(serviceName);
+ }
+ String name = "bean" + ++count;
+ names.put(serviceName, name);
+ return name;
+ }
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/AutoIncrementNameService.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/BeanNameService.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/BeanNameService.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/BeanNameService.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx.naming;
+
+import org.jboss.system.metadata.ServiceMetaData;
+
+/**
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ *
+ */
+public abstract class BeanNameService
+{
+ public String translate(ServiceMetaData service)
+ {
+ return translate(service.getObjectName().getCanonicalName());
+ }
+
+ public abstract String translate(String serviceName);
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/BeanNameService.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/InputNameService.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/InputNameService.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/InputNameService.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx.naming;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.mc.tools.jmx.IOUtil;
+
+/**
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ *
+ */
+public class InputNameService extends BeanNameService
+{
+ private Map<String, String> names = new HashMap<String, String>();
+
+ public String translate(String serviceName)
+ {
+ if (names.containsKey(serviceName))
+ {
+ return names.get(serviceName);
+ }
+ String name = IOUtil.inputName("Type in the name of the bean name of Mbean " + serviceName);
+ names.put(serviceName, name);
+ return name;
+ }
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/InputNameService.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/UsePropertyService.java
===================================================================
--- projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/UsePropertyService.java (rev 0)
+++ projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/UsePropertyService.java 2009-06-10 06:26:26 UTC (rev 90045)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mc.tools.jmx.naming;
+
+
+/**
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class UsePropertyService extends BeanNameService
+{
+ public String translate(String serviceName)
+ {
+ return serviceName;
+ }
+}
\ No newline at end of file
Property changes on: projects/mc-tools/trunk/src/main/java/org/jboss/mc/tools/jmx/naming/UsePropertyService.java
___________________________________________________________________
Name: svn:keywords
+ Date Revision Author HeadURL Id
More information about the jboss-cvs-commits
mailing list