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;
12:
13: import com.versant.core.jdo.VersantPersistenceManager;
14: import com.versant.core.jdo.VersantStateManager;
15: import com.versant.core.common.VersantFieldMetaData;
16:
17: import javax.jdo.spi.PersistenceCapable;
18: import java.io.Serializable;
19:
20: import com.versant.core.common.BindingSupportImpl;
21: import com.versant.core.jdo.VersantPersistenceManager;
22: import com.versant.core.jdo.VersantStateManager;
23:
24: /**
25: * Creates a Date SCO from a java.util.Date
26: */
27: public class DateSCOFactory implements VersantSCOFactory, Serializable {
28:
29: /**
30: * Create a Date instance that implements the JDOGenieSCO interface and fill
31: * it with the data in o.
32: */
33: public VersantSimpleSCO createSCO(PersistenceCapable owner,
34: VersantPersistenceManager pm,
35: VersantStateManager stateManager, VersantFieldMetaData fmd,
36: Object o) {
37: if (o instanceof java.util.Date) {
38: return new com.versant.core.jdo.sco.Date(owner,
39: stateManager, fmd, ((java.util.Date) o).getTime());
40: } else if (o instanceof Long) {
41: return new com.versant.core.jdo.sco.Date(owner,
42: stateManager, fmd, ((Long) o).longValue());
43: } else {
44: throw BindingSupportImpl.getInstance().illegalArgument(
45: o.getClass()
46: + " can not be converted into a Date SCO");
47: }
48: }
49: }
|