KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > sco > detached > DetachSCODateFactory


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.sco.detached;
13
14 import com.versant.core.jdo.VersantPersistenceManager;
15 import com.versant.core.jdo.VersantStateManager;
16 import com.versant.core.common.VersantFieldMetaData;
17 import com.versant.core.jdo.sco.VersantSCOFactory;
18 import com.versant.core.jdo.sco.VersantSimpleSCO;
19 import com.versant.core.jdo.VersantPersistenceManager;
20
21 import javax.jdo.spi.PersistenceCapable;
22 import java.io.Serializable JavaDoc;
23
24 import com.versant.core.common.BindingSupportImpl;
25
26 /**
27  * Creates a Detached Date SCO from a java.util.Date
28  */

29 public class DetachSCODateFactory implements VersantSCOFactory,
30         Serializable JavaDoc {
31
32     /**
33      * Create a Detached Date instance and fill it with the data in o.
34      */

35     public VersantSimpleSCO createSCO(PersistenceCapable owner,
36                                        VersantPersistenceManager pm, VersantStateManager stateManager,
37                                        VersantFieldMetaData fmd, Object JavaDoc o) {
38         if (o instanceof java.util.Date JavaDoc) {
39             return new DetachSCODate(owner, stateManager,
40                     fmd, ((java.util.Date JavaDoc) o).getTime());
41         } else if (o instanceof Long JavaDoc) {
42             return new DetachSCODate(owner, stateManager,
43                     fmd, ((Long JavaDoc) o).longValue());
44         } else {
45             throw BindingSupportImpl.getInstance().illegalArgument(o.getClass() + " can not be converted into a Date SCO");
46         }
47     }
48 }
49
Popular Tags