[jboss-cvs] JBossAS SVN: r81041 - trunk/system-jmx/src/main/org/jboss/system/metadata.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 14 09:24:23 EST 2008


Author: emuckenhuber
Date: 2008-11-14 09:24:22 -0500 (Fri, 14 Nov 2008)
New Revision: 81041

Added:
   trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceDeploymentClasspathAdapter.java
   trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceLoaderRepositoryAdapter.java
   trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataAdapter.java
Modified:
   trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceDeployment.java
Log:
[JBAS-3768] add JAXB annotations and adapters to the ServiceDeployment for attachment persistence (marshalling/unmarshalling)

Modified: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceDeployment.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceDeployment.java	2008-11-14 14:19:20 UTC (rev 81040)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceDeployment.java	2008-11-14 14:24:22 UTC (rev 81041)
@@ -1,168 +1,182 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.system.metadata;
-
-import java.io.Serializable;
-import java.util.List;
-
-import org.jboss.managed.api.annotation.ManagementDeployment;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementObjectID;
-import org.jboss.managed.api.annotation.ManagementProperty;
-import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig;
-import org.w3c.dom.Element;
-
-/**
- * ServiceDeployment.
- * 
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
- at ManagementObject
- at ManagementDeployment(types={"sar"})
-public class ServiceDeployment
-   implements Serializable
-{
-   private static final long serialVersionUID = 1;
-
-   /** The deployment name */
-   private String name;
-
-   /** The services */
-   private List<ServiceMetaData> services;
-   
-   /** The config */
-   private Element config;
-   
-   /** The loader repository config */
-   private LoaderRepositoryConfig loaderRepositoryConfig;
-
-   /** The classpaths */
-   private List<ServiceDeploymentClassPath> classPaths;
-   
-   /**
-    * Get the name.
-    * 
-    * @return the name.
-    */
-   @ManagementProperty(description="The -service.xml url string")
-   @ManagementObjectID(type="ServiceDeployment")
-   public String getName()
-   {
-      return name;
-   }
-
-   /**
-    * Set the name.
-    * 
-    * @param name the name.
-    */
-   public void setName(String name)
-   {
-      this.name = name;
-   }
-
-   /**
-    * Get the services.
-    * 
-    * @return the services.
-    */
-   @ManagementProperty(description="The mbeans", managed=true)
-   public List<ServiceMetaData> getServices()
-   {
-      return services;
-   }
-
-   /**
-    * Set the services.
-    * 
-    * @param services the services.
-    */
-   public void setServices(List<ServiceMetaData> services)
-   {
-      this.services = services;
-   }
-
-   /**
-    * Get the config.
-    * 
-    * @return the config.
-    */
-   @ManagementProperty(ignored=true)
-   public Element getConfig()
-   {
-      return config;
-   }
-
-   /**
-    * Set the config.
-    * 
-    * @param config the config.
-    */
-   public void setConfig(Element config)
-   {
-      this.config = config;
-   }
-
-   /**
-    * Get the loaderRepositoryConfig.
-    * 
-    * @return the loaderRepositoryConfig.
-    */
-   @ManagementProperty(ignored=true)
-   public LoaderRepositoryConfig getLoaderRepositoryConfig()
-   {
-      return loaderRepositoryConfig;
-   }
-
-   /**
-    * Set the loaderRepositoryConfig.
-    * 
-    * @param loaderRepositoryConfig the loaderRepositoryConfig.
-    */
-   public void setLoaderRepositoryConfig(LoaderRepositoryConfig loaderRepositoryConfig)
-   {
-      this.loaderRepositoryConfig = loaderRepositoryConfig;
-   }
-
-   /**
-    * Get the classPaths.
-    * 
-    * @return the classPaths.
-    */
-   @ManagementProperty(name="classpath", description="The deployment classpath", managed=true)
-   public List<ServiceDeploymentClassPath> getClassPaths()
-   {
-      return classPaths;
-   }
-
-   /**
-    * Set the classPaths.
-    * 
-    * @param classPaths the classPaths.
-    */
-   public void setClassPaths(List<ServiceDeploymentClassPath> classPaths)
-   {
-      this.classPaths = classPaths;
-   }
-}
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.system.metadata;
+
+import java.io.Serializable;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.jboss.managed.api.annotation.ManagementDeployment;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig;
+import org.w3c.dom.Element;
+
+/**
+ * ServiceDeployment.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at ManagementObject
+ at ManagementDeployment(types={"sar"})
+ at XmlRootElement
+public class ServiceDeployment
+   implements Serializable
+{
+   private static final long serialVersionUID = 1;
+
+   /** The deployment name */
+   private String name;
+
+   /** The services */
+   private List<ServiceMetaData> services;
+   
+   /** The config */
+   private Element config;
+   
+   /** The loader repository config */
+   private LoaderRepositoryConfig loaderRepositoryConfig;
+
+   /** The classpaths */
+   private List<ServiceDeploymentClassPath> classPaths;
+   
+   /**
+    * Get the name.
+    * 
+    * @return the name.
+    */
+   @ManagementProperty(description="The -service.xml url string")
+   @ManagementObjectID(type="ServiceDeployment")
+   @XmlTransient
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * Set the name.
+    * 
+    * @param name the name.
+    */
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   /**
+    * Get the services.
+    * 
+    * @return the services.
+    */
+   @ManagementProperty(description="The mbeans", managed=true)
+   @XmlElement(name="mbean")
+   @XmlJavaTypeAdapter(ServiceMetaDataAdapter.class)
+   public List<ServiceMetaData> getServices()
+   {
+      return services;
+   }
+
+   /**
+    * Set the services.
+    * 
+    * @param services the services.
+    */
+   public void setServices(List<ServiceMetaData> services)
+   {
+      this.services = services;
+   }
+
+   /**
+    * Get the config.
+    * 
+    * @return the config.
+    */
+   @ManagementProperty(ignored=true)
+   @XmlTransient
+   public Element getConfig()
+   {
+      return config;
+   }
+
+   /**
+    * Set the config.
+    * 
+    * @param config the config.
+    */
+   public void setConfig(Element config)
+   {
+      this.config = config;
+   }
+
+   /**
+    * Get the loaderRepositoryConfig.
+    * 
+    * @return the loaderRepositoryConfig.
+    */
+   @ManagementProperty(ignored=true)
+   @XmlElement(name = "loader-repository")
+   @XmlJavaTypeAdapter(ServiceLoaderRepositoryAdapter.class)
+   public LoaderRepositoryConfig getLoaderRepositoryConfig()
+   {
+      return loaderRepositoryConfig;
+   }
+
+   /**
+    * Set the loaderRepositoryConfig.
+    * 
+    * @param loaderRepositoryConfig the loaderRepositoryConfig.
+    */
+   public void setLoaderRepositoryConfig(LoaderRepositoryConfig loaderRepositoryConfig)
+   {
+      this.loaderRepositoryConfig = loaderRepositoryConfig;
+   }
+
+   /**
+    * Get the classPaths.
+    * 
+    * @return the classPaths.
+    */
+   @ManagementProperty(name="classpath", description="The deployment classpath", managed=true)
+   @XmlElement(name = "classpath")
+   @XmlJavaTypeAdapter(ServiceDeploymentClasspathAdapter.class)
+   public List<ServiceDeploymentClassPath> getClassPaths()
+   {
+      return classPaths;
+   }
+
+   /**
+    * Set the classPaths.
+    * 
+    * @param classPaths the classPaths.
+    */
+   public void setClassPaths(List<ServiceDeploymentClassPath> classPaths)
+   {
+      this.classPaths = classPaths;
+   }
+}

Added: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceDeploymentClasspathAdapter.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceDeploymentClasspathAdapter.java	                        (rev 0)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceDeploymentClasspathAdapter.java	2008-11-14 14:24:22 UTC (rev 81041)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.system.metadata;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.jboss.deployment.DeploymentException;
+import org.jboss.util.StringPropertyReplacer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ServiceDeploymentClasspathAdapter extends XmlAdapter<Object, ServiceDeploymentClassPath>
+{
+
+   @Override
+   public ServiceDeploymentClassPath unmarshal(Object e) throws Exception
+   {
+      Element classpathElement = (Element) e;
+      if (classpathElement.hasAttribute("codebase") == false)
+         throw new DeploymentException("Invalid classpath element missing codebase: " + classpathElement);
+
+      String codebase = classpathElement.getAttribute("codebase").trim();
+      codebase = StringPropertyReplacer.replaceProperties(codebase);
+
+      String archives = null;
+      if (classpathElement.hasAttribute("archives"))
+      {
+         archives = classpathElement.getAttribute("archives").trim();
+         archives = StringPropertyReplacer.replaceProperties(archives);
+         if ("".equals(archives))
+            archives = null;
+      }
+
+      return new ServiceDeploymentClassPath(codebase, archives);
+   }
+
+   @Override
+   public Object marshal(ServiceDeploymentClassPath path) throws Exception
+   {
+      if(path == null)
+         return null;
+      
+      Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+      Element classPath = document.createElement("classpath");
+      classPath.setAttribute("codebase", path.getCodeBase());
+      classPath.setAttribute("archives", path.getArchives());
+      return classPath;
+   }
+}
+

Added: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceLoaderRepositoryAdapter.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceLoaderRepositoryAdapter.java	                        (rev 0)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceLoaderRepositoryAdapter.java	2008-11-14 14:24:22 UTC (rev 81041)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.system.metadata;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.jboss.mx.loading.LoaderRepositoryFactory;
+import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * A LoaderRepositoryAdapter.
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceLoaderRepositoryAdapter extends XmlAdapter<Object, LoaderRepositoryConfig>
+{
+   
+   @Override
+   public LoaderRepositoryConfig unmarshal(Object e) throws Exception
+   {
+      return LoaderRepositoryFactory.parseRepositoryConfig((Element) e);
+   }
+
+   @Override
+   public Element marshal(LoaderRepositoryConfig config) throws Exception
+   {
+      if(config == null)
+         return null;
+      
+      // TODO: move this to a separate 'marshaler' 
+      Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+      // <loader-repository>
+      Element loaderRepository = document.createElement("loader-repository");
+      loaderRepository.setAttribute("loaderRepositoryClass", config.repositoryClassName);
+      loaderRepository.setTextContent(config.repositoryName.getCanonicalName());
+      // <loader-repository-config>
+      Element loaderRepositoryConfig = document.createElement("loader-repository-config");
+      loaderRepositoryConfig.setAttribute("configParserClass", config.configParserClassName);
+      loaderRepositoryConfig.setTextContent(config.repositoryConfig);
+      // Append <loader-repository-config/>
+      loaderRepository.appendChild(loaderRepositoryConfig);
+      //
+      return loaderRepository;
+   }
+}

Added: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataAdapter.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataAdapter.java	                        (rev 0)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataAdapter.java	2008-11-14 14:24:22 UTC (rev 81041)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.system.metadata;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import org.w3c.dom.Element;
+
+/**
+ * A ServiceMetaDataAdapter.
+ * 
+ * @author <a href="weston.price at jboss.org">Weston Price</a>
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceMetaDataAdapter extends XmlAdapter<Object, ServiceMetaData>
+{
+   
+   @Override
+   public ServiceMetaData unmarshal(Object e) throws Exception
+   {
+      ServiceMetaDataParser parser = new ServiceMetaDataParser((Element)e);      
+      List<ServiceMetaData> services = parser.parse();      
+      
+      ServiceMetaData md = null;
+      
+      if(services != null)
+      {
+         md = services.get(0);
+         
+      }
+      return md;
+   }
+
+   @Override
+   public Element marshal(ServiceMetaData service) throws Exception
+   {
+      ServiceMetaData2ElementConverter marshaller = new ServiceMetaData2ElementConverter();
+      return marshaller.createServiceMetaDataElement(service);
+   }
+}




More information about the jboss-cvs-commits mailing list