KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > sco > DateSCOFactory


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;
13
14 import com.versant.core.jdo.VersantPersistenceManager;
15 import com.versant.core.jdo.VersantStateManager;
16 import com.versant.core.common.VersantFieldMetaData;
17
18 import javax.jdo.spi.PersistenceCapable;
19 import java.io.Serializable JavaDoc;
20
21 import com.versant.core.common.BindingSupportImpl;
22 import com.versant.core.jdo.VersantPersistenceManager;
23 import com.versant.core.jdo.VersantStateManager;
24
25 /**
26  * Creates a Date SCO from a java.util.Date
27  */

28 public class DateSCOFactory implements VersantSCOFactory,
29         Serializable JavaDoc {
30
31     /**
32      * Create a Date instance that implements the JDOGenieSCO interface and fill
33      * 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 com.versant.core.jdo.sco.Date(owner, stateManager,
40                     fmd, ((java.util.Date JavaDoc) o).getTime());
41         } else if (o instanceof Long JavaDoc) {
42             return new com.versant.core.jdo.sco.Date(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