EMMA Coverage Report (generated Sun May 02 20:42:29 CEST 2010)
[all classes][hu.netmind.beankeeper.model.impl]

COVERAGE SUMMARY FOR SOURCE FILE [StrictPrimitiveHandler.java]

nameclass, %method, %block, %line, %
StrictPrimitiveHandler.java100% (1/1)80%  (8/10)68%  (124/183)79%  (23/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StrictPrimitiveHandler100% (1/1)80%  (8/10)68%  (124/183)79%  (23/29)
getSourceEntry (): ClassEntry 0%   (0/1)0%   (0/3)0%   (0/1)
setAttributeValue (Object, String, Object): void 0%   (0/1)0%   (0/22)0%   (0/1)
getAttributeValue (Object, String): Object 100% (1/1)33%  (6/18)67%  (2/3)
newInstance (Map): Object 100% (1/1)78%  (80/102)79%  (11/14)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
StrictPrimitiveHandler (ClassEntry): void 100% (1/1)100% (18/18)100% (5/5)
getAttributeNames (): List 100% (1/1)100% (7/7)100% (1/1)
getAttributeTypes (): Map 100% (1/1)100% (6/6)100% (1/1)
hasChanged (): boolean 100% (1/1)100% (2/2)100% (1/1)
update (): void 100% (1/1)100% (1/1)100% (1/1)

1/**
2 * Copyright (C) 2007 NetMind Consulting Bt.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18 
19package hu.netmind.beankeeper.model.impl;
20 
21import hu.netmind.beankeeper.service.StoreContext;
22import org.apache.log4j.Logger;
23import java.util.*;
24import java.lang.reflect.*;
25import hu.netmind.beankeeper.common.StoreException;
26import hu.netmind.beankeeper.model.*;
27 
28/**
29 * This type is for boxed primitive objects which need to be stored. It has
30 * a single attribute named 'value', with the type of the primitive object itself.
31 * @author Brautigam Robert
32 * @version Revision: $Revision$
33 */
34public class StrictPrimitiveHandler implements StrictClassHandler
35{
36   private static Logger logger = Logger.getLogger(StrictPrimitiveHandler.class);
37   
38   private ClassEntry sourceEntry;
39   private Map attributeTypes;
40 
41   StrictPrimitiveHandler(ClassEntry sourceEntry)
42   {
43      // Init
44      this.sourceEntry=sourceEntry;
45      attributeTypes = new HashMap();
46      attributeTypes.put("value",sourceEntry.getSourceClass());
47   }
48 
49   public ClassEntry getSourceEntry()
50   {
51      return sourceEntry;
52   }
53 
54   public boolean hasChanged()
55   {
56      return false;
57   }
58 
59   public void update()
60   {
61   }
62 
63   public Map getAttributeTypes()
64   {
65      return new HashMap(attributeTypes);
66   }
67 
68   public List getAttributeNames()
69   {
70      return new ArrayList(attributeTypes.keySet());
71   }
72 
73   /**
74    * Construct the primitive object with the given value.
75    * @param marshalledValues The map that contains the 'value' attribute.
76    */
77   public Object newInstance(Map marshalledValues)
78   {
79      Class clazz = sourceEntry.getSourceClass();
80      Object value = marshalledValues.get("value");
81      if ( value == null )
82         return null;
83      value = TypeUtils.getTypeValue(value,clazz);
84      logger.debug("strict primitive handler instantiates object: "+clazz+", value: "+value+" ("+value.getClass()+")");
85      // First try the exceptional primitive types, who have no
86      // string constructor.
87      if ( (clazz.equals(char.class)) || (clazz.equals(Character.class)) )
88         return new Character( ((Character) value).charValue() );
89      if ( clazz.equals(Date.class) )
90         return new Date( ((Date) value).getTime() );
91      // Others we construct with a String constructor. Most number types
92      // can be constructed with string representations easily.
93      try
94      {
95         Constructor ctor = clazz.getConstructor( new Class[] { String.class } );
96         return ctor.newInstance( new Object[] { value.toString() } );
97      } catch ( Exception e ) {
98         throw new StoreException("could not instantiate primitive type: "+sourceEntry+", with values: "+marshalledValues+", using string constructor.");
99      }
100   }
101 
102   /**
103    * Always throws exception.
104    */
105   public Object getAttributeValue(Object obj, String attributeName)
106   {
107      if ( ! attributeName.equalsIgnoreCase("value") )
108         throw new StoreException("primitive handler has only 'value' attribute, but queried: "+attributeName);
109      return obj;
110   }
111 
112   /**
113    * Always returns exception.
114    */
115   public void setAttributeValue(Object obj, String attributeName, Object value)
116   {
117      throw new StoreException("object value cannot be set, objectclass: "+
118            obj.getClass()+" name: "+attributeName+" on primitive handler for type: "+sourceEntry);
119   }
120 
121}
122 
123 

[all classes][hu.netmind.beankeeper.model.impl]
EMMA 2.0.5312debian (C) Vladimir Roubtsov