KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > impl > util > PropertyConvertor


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5
6 package org.exoplatform.services.jcr.impl.util;
7
8 import javax.jcr.*;
9
10 /**
11  * Created by The eXo Platform SARL .
12  *
13  * @author <a HREF="mailto:geaz@users.sourceforge.net">Gennady Azarenkov</a>
14  * @version $Id: PropertyConvertor.java,v 1.6 2004/09/03 09:59:42 geaz Exp $
15  */

16
17 public class PropertyConvertor {
18
19   public static Value convert(Value oldValue, int type) throws IllegalStateException JavaDoc, RepositoryException {
20     Value[] values = new Value[1];
21     values[0] = oldValue;
22     return convert(values, type)[0];
23   }
24
25   public static Value[] convert(Value[] oldValues, int type) throws RepositoryException {
26     Value[] newValues = new Value[oldValues.length];
27     if(oldValues.length == 0)
28         return oldValues;
29     if (oldValues[0] != null && oldValues[0].getType() == type)
30         return oldValues;
31
32     for (int i = 0; i < oldValues.length; i++) {
33       Value value = oldValues[i];
34         switch (type) {
35           case PropertyType.STRING:
36             newValues[i] = (oldValues[i] == null)?new StringValue(null):new StringValue(value.getString());
37             break;
38           case PropertyType.BINARY:
39             newValues[i] = (oldValues[i] == null)?new BinaryValue((String JavaDoc)null):new BinaryValue(value.getStream());
40             break;
41           case PropertyType.BOOLEAN:
42             newValues[i] = (oldValues[i] == null)?new BooleanValue(null):new BooleanValue(value.getBoolean());
43             break;
44           case PropertyType.LONG:
45             newValues[i] = (oldValues[i] == null)?new LongValue(null):new LongValue(value.getLong());
46             break;
47           case PropertyType.DOUBLE:
48             newValues[i] = (oldValues[i] == null)?new DoubleValue(null):new DoubleValue(value.getDouble());
49             break;
50           case PropertyType.DATE:
51             newValues[i] = (oldValues[i] == null)?new DateValue(null):new DateValue(value.getDate());
52             break;
53           case PropertyType.SOFTLINK:
54             newValues[i] = (oldValues[i] == null)?new SoftLinkValue(null):new SoftLinkValue(value.getString());
55             break;
56           case PropertyType.REFERENCE:
57             newValues[i] = (oldValues[i] == null)?new ReferenceValue((String JavaDoc)null):new ReferenceValue(value.getString());
58             break;
59           default:
60             newValues[i] = null;
61 // throw new IllegalArgumentException("unknown type "+type);
62
}
63       }
64       return newValues;
65 // }
66
}
67
68 }
69
Popular Tags