[jboss-cvs] JBossAS SVN: r68471 - trunk/connector/src/main/org/jboss/resource/deployers/management.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 20 17:33:35 EST 2007


Author: alex.loubyansky at jboss.com
Date: 2007-12-20 17:33:35 -0500 (Thu, 20 Dec 2007)
New Revision: 68471

Added:
   trunk/connector/src/main/org/jboss/resource/deployers/management/XAConnectionFactoryProperty.java
Log:
JBAS-4671 missed addition

Added: trunk/connector/src/main/org/jboss/resource/deployers/management/XAConnectionFactoryProperty.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/deployers/management/XAConnectionFactoryProperty.java	                        (rev 0)
+++ trunk/connector/src/main/org/jboss/resource/deployers/management/XAConnectionFactoryProperty.java	2007-12-20 22:33:35 UTC (rev 68471)
@@ -0,0 +1,181 @@
+/*
+  * 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.resource.deployers.management;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+import org.jboss.managed.plugins.WritethroughManagedPropertyImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.MetaTypeFactory;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryPropertyMetaData;
+import org.jboss.resource.metadata.mcf.XAConnectionPropertyMetaData;
+
+/**
+ * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @version <tt>$Revision: $</tt>
+ */
+public class XAConnectionFactoryProperty
+   extends ManagedPropertyImpl
+{
+   private static final long serialVersionUID = 1;
+
+   private MetaValueFactory metaValueFactory;
+   private ManagedObjectFactory moFactory;
+
+
+   public XAConnectionFactoryProperty(String s)
+   {
+      super(s);
+   }
+
+   public XAConnectionFactoryProperty(Fields fields)
+   {
+      super(fields);
+   }
+
+   public XAConnectionFactoryProperty(ManagedObject managedObject, Fields fields)
+   {
+      super(managedObject, fields);
+   }
+
+
+   public MetaType getMetaType()
+   {
+      return getMapMetaType();
+   }
+
+   public void setField(String fieldName, Serializable value)
+   {
+      if(Fields.META_TYPE.equals(fieldName))
+         value = getMapMetaType();
+      super.setField(fieldName, value);
+   }
+
+   /**
+    * Write the value back to the attachment if there is a PropertyInfo
+    * in the Fields.PROPERTY_INFO field.
+    */
+   @Override
+   @SuppressWarnings("unchecked")
+   public void setValue(Serializable value)
+   {
+      super.setValue(value);
+
+      PropertyInfo propertyInfo = getField(Fields.PROPERTY_INFO, PropertyInfo.class);
+      if (propertyInfo != null)
+      {
+         Serializable attachment = getManagedObject().getAttachment();
+         if (attachment != null)
+         {
+            MetaValue metaValue;
+            if (value instanceof MetaValue)
+            {
+               Map<String,String> map = (Map<String,String>)getMetaValueFactory().unwrap((MetaValue)value, getMapType());
+               List<XAConnectionPropertyMetaData> list = new ArrayList<XAConnectionPropertyMetaData>();
+               for(String name : map.keySet())
+               {
+                  String entry = map.get(name);
+                  XAConnectionPropertyMetaData prop = new XAConnectionPropertyMetaData();
+                  prop.setName(name);
+                  prop.setValue(entry);
+                  list.add(prop);
+               }
+               metaValue = getMetaValueFactory().create(list, propertyInfo.getType());
+            }
+            else
+            {
+               metaValue = getMetaValueFactory().create(value);
+            }
+
+            InstanceClassFactory icf = getMOFactory().getInstanceClassFactory(attachment.getClass());
+            BeanInfo beanInfo = propertyInfo.getBeanInfo();
+            icf.setValue(beanInfo, this, attachment, metaValue);
+         }
+      }
+   }
+
+   private ManagedObjectFactory getMOFactory()
+   {
+      if(moFactory == null)
+         moFactory = ManagedObjectFactoryBuilder.create();
+      return moFactory;
+   }
+
+   private MetaValueFactory getMetaValueFactory()
+   {
+      if(metaValueFactory == null)
+         metaValueFactory = MetaValueFactory.getInstance();
+      return metaValueFactory;
+   }
+
+   /**
+    * Expose only plain ManangedPropertyImpl.
+    *
+    * @return simpler ManagedPropertyImpl
+    * @throws java.io.ObjectStreamException for any error
+    */
+   private Object writeReplace() throws ObjectStreamException
+   {
+      ManagedPropertyImpl managedProperty = new ManagedPropertyImpl(getManagedObject(), getFields());
+      managedProperty.setTargetManagedObject(getTargetManagedObject());
+      return managedProperty;
+   }
+
+   private MetaType getMapMetaType()
+   {
+      Type type = getMapType();
+      return MetaTypeFactory.getInstance().resolve(type);
+   }
+
+   private Type getMapType()
+   {
+      Type type;
+      try
+      {
+            type = getClass().getMethod("mapOfStrings").getGenericReturnType();
+      }
+      catch(NoSuchMethodException e)
+      {
+         throw new IllegalStateException("Failed to find compoditeValueMap method.");
+      }
+      return type;
+   }
+
+   public Map<String, String> mapOfStrings()
+   {
+      return null;
+   }
+}




More information about the jboss-cvs-commits mailing list