[jboss-svn-commits] JBL Code SVN: r29520 - in labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm: xml and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 1 12:56:06 EDT 2009
Author: whitingjr
Date: 2009-10-01 12:56:05 -0400 (Thu, 01 Oct 2009)
New Revision: 29520
Added:
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelEntry.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelList.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelMapDataAdapter.java
Log:
Added xml JAXB classes for marshalling data.
Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelEntry.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelEntry.java (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelEntry.java 2009-10-01 16:56:05 UTC (rev 29520)
@@ -0,0 +1,44 @@
+ /*
+ * 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 uk.ac.ncl.sdia.a8905943.stm.xml.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlValue;
+
+public class ModelEntry
+{
+ @XmlAttribute
+ public String modelClass;
+ @XmlValue
+ public Long entityId;
+
+ public ModelEntry()
+ {
+ }
+ public ModelEntry (Long id, String fqcn)
+ {
+ this.modelClass = fqcn;
+ this.entityId = id;
+ }
+
+}
Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelList.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelList.java (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelList.java 2009-10-01 16:56:05 UTC (rev 29520)
@@ -0,0 +1,58 @@
+ /*
+ * 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 uk.ac.ncl.sdia.a8905943.stm.xml.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+ at XmlRootElement
+ at XmlType (name="ModelListType")
+public class ModelList
+{
+ private List<ModelEntry> itemList;
+
+ public List<ModelEntry> getItem()
+ {
+ return itemList;
+ }
+
+ public void setItem(List<ModelEntry> item)
+ {
+ this.itemList = item;
+ }
+ public ModelList()
+ {
+ this.itemList = new ArrayList<ModelEntry>();
+ }
+ public void addItem(ModelEntry entry)
+ {
+ this.itemList.add(entry);
+ }
+ public int getSize()
+ {
+ return (null != this.itemList ? this.itemList.size() : 0);
+ }
+}
Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelMapDataAdapter.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelMapDataAdapter.java (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelMapDataAdapter.java 2009-10-01 16:56:05 UTC (rev 29520)
@@ -0,0 +1,75 @@
+ /*
+ * 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 uk.ac.ncl.sdia.a8905943.stm.xml.model;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import org.apache.commons.lang.ClassUtils;
+
+import uk.ac.ncl.sdia.a8905943.handle.FieldUtils;
+
+public class ModelMapDataAdapter extends XmlAdapter<ModelList, Map<String, List<Object>>>
+{
+ @Override
+ public ModelList marshal(Map<String, List<Object>> modelMap) throws Exception
+ {
+ ModelList returnValue = new ModelList();
+ FieldUtils fieldUtils = new FieldUtils();
+ for (String fqcn : modelMap.keySet())
+ {
+ for (Object entity : modelMap.get(fqcn))
+ {
+ returnValue.addItem( new ModelEntry(fieldUtils.getValue( fieldUtils.findIdField(entity.getClass()), entity), fqcn));
+ }
+ }
+ return returnValue;
+ }
+ @Override
+ public Map<String, List<Object>> unmarshal(ModelList serialisedModel) throws Exception
+ {
+ Map<String, List<Object>> returnValue = new ConcurrentHashMap<String, List<Object>>();
+ for (ModelEntry entry : serialisedModel.getItem())
+ {
+ Class entityClass = ClassUtils.getClass(entry.modelClass);
+ Constructor constructor = entityClass.getConstructor(java.lang.Long.class);
+ Object instance = constructor.newInstance(entry.entityId);
+
+ if (!returnValue.containsKey(entry.modelClass))
+ {// place a list object in the map for the entity type
+ returnValue.put(entry.modelClass, new ArrayList<Object>());
+ }
+ if (!returnValue.get(entry.modelClass).contains(instance))
+ {// place the entity instance in the map if not present already
+ returnValue.get(entry.modelClass).add(instance);
+ }
+ }
+ return returnValue;
+ }
+
+}
More information about the jboss-svn-commits
mailing list