View Javadoc

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