01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdo.sco.detached;
12:
13: import com.versant.core.jdo.VersantPersistenceManager;
14: import com.versant.core.jdo.VersantStateManager;
15: import com.versant.core.common.VersantFieldMetaData;
16: import com.versant.core.jdo.sco.VersantSCOFactory;
17: import com.versant.core.jdo.sco.VersantSimpleSCO;
18: import com.versant.core.jdo.VersantPersistenceManager;
19:
20: import javax.jdo.spi.PersistenceCapable;
21: import java.io.Serializable;
22:
23: import com.versant.core.common.BindingSupportImpl;
24:
25: /**
26: * Creates a Detached Date SCO from a java.util.Date
27: */
28: public class DetachSCODateFactory implements VersantSCOFactory,
29: Serializable {
30:
31: /**
32: * Create a Detached Date instance and fill it with the data in o.
33: */
34: public VersantSimpleSCO createSCO(PersistenceCapable owner,
35: VersantPersistenceManager pm,
36: VersantStateManager stateManager, VersantFieldMetaData fmd,
37: Object o) {
38: if (o instanceof java.util.Date) {
39: return new DetachSCODate(owner, stateManager, fmd,
40: ((java.util.Date) o).getTime());
41: } else if (o instanceof Long) {
42: return new DetachSCODate(owner, stateManager, fmd,
43: ((Long) o).longValue());
44: } else {
45: throw BindingSupportImpl.getInstance().illegalArgument(
46: o.getClass()
47: + " can not be converted into a Date SCO");
48: }
49: }
50: }
|