View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package org.apache.jdo.model.jdo;
18  
19  /***
20   * This interface provides constants denoting the identity type
21   * of a persistence-capable class.
22   *
23   * @author Michael Bouschen
24   */
25  public class JDOIdentityType 
26  {
27      /*** Constant representing an unspecified jdo identity */
28      public static final int UNSPECIFIED = 0;
29  
30      /*** Constant representing jdo identity managed by the database. */
31      public static final int DATASTORE = 1;
32  
33      /*** Constant representing jdo identity managed by the application. */
34      public static final int APPLICATION = 2;
35  
36      /*** Constant representing unmanaged jdo identity. */
37      public static final int NONDURABLE = 4;
38      
39      /***
40       * Returns a string representation of the specified identity type constant.
41       * @param jdoIdentityType the JDO identity type, one of 
42       * {@link #APPLICATION}, {@link #DATASTORE}, or {@link #NONDURABLE}
43       * @return the string representation of the JDOIdentityType constant
44       */
45      public static String toString(int jdoIdentityType) {
46          switch ( jdoIdentityType) {
47          case DATASTORE :
48              return "datastore"; //NOI18N
49          case APPLICATION :
50              return "application"; //NOI18N
51          case NONDURABLE:
52              return "nondurable"; //NOI18N
53          default:
54              return "UNSPECIFIED"; //NOI18N
55          }
56      }
57      
58      /***
59       * Returns the JDOIdentityType constant, one of {@link #APPLICATION}, 
60       * {@link #DATASTORE}, or {@link #NONDURABLE} for the specified string.
61       * @param jdoIdentityType the string representation of the 
62       * JDO identity type
63       * @return the JDO identity type
64       **/
65      public static int toJDOIdentityType(String jdoIdentityType)
66      {
67          if ((jdoIdentityType == null) || (jdoIdentityType.length() == 0))
68              return UNSPECIFIED;
69   
70          if ("datastore".equals(jdoIdentityType)) //NOI18N
71              return DATASTORE;
72          else if ("application".equals(jdoIdentityType)) //NOI18N
73              return APPLICATION;
74          else if ("nondurable".equals(jdoIdentityType)) //NOI18N
75              return NONDURABLE;
76          else
77              return UNSPECIFIED;
78      }
79  }