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 JDO specific 
21   * modifiers for fields of a persistence-capable class.
22   *
23   * @author Michael Bouschen
24   */
25  public class PersistenceModifier 
26  {
27      /*** Constant representing an unspecified field modifier */
28      public static final int UNSPECIFIED = 0;
29  
30      /*** Constant representing a none field modifier.  */
31      public static final int NONE = 1;
32  
33      /*** Constant representing a transactional field modifier. */
34      public static final int TRANSACTIONAL = 2;
35  
36      /*** Constant representing a persistence field modifier. */
37      public static final int PERSISTENT  = 4;
38  
39      /*** Constant representing a possibly persistence field modifier. */
40      public static final int POSSIBLY_PERSISTENT  = 8;
41  
42      /***
43       * Returns a string representation of the specified persistence modifer. 
44       * @param persistenceModifier the persistence modifer, one of  
45       * {@link #UNSPECIFIED}, {@link #NONE}, {@link #PERSISTENT},
46       * {@link #TRANSACTIONAL}, or {@link #POSSIBLY_PERSISTENT}.
47       * @return the string representation of the PersistenceModifer constant
48       */
49      public static String toString(int persistenceModifier) 
50      {
51          switch (persistenceModifier) {
52          case NONE :
53              return "none"; //NOI18N
54          case TRANSACTIONAL :
55              return "transactional"; //NOI18N
56          case PERSISTENT:
57              return "persistent"; //NOI18N
58          case POSSIBLY_PERSISTENT:
59              return "possibly-persistent"; //NOI18N
60          default:
61              return "UNSPECIFIED"; //NOI18N
62          }
63      }
64      
65      /***
66       * Returns the PersistenceModifier constant for the specified string.
67       * @param persistenceModifier the string representation of the persistence 
68       * modifer
69       * @return the persistence modifer, one of {@link #UNSPECIFIED}, 
70       * {@link #NONE}, {@link #PERSISTENT} or {@link #TRANSACTIONAL}
71       **/
72      public static int toPersistenceModifier(String persistenceModifier)
73      {
74          if ((persistenceModifier == null) || (persistenceModifier.length() == 0))
75              return UNSPECIFIED;
76   
77          if ("none".equals(persistenceModifier)) //NOI18N
78              return NONE;
79          else if ("transactional".equals(persistenceModifier)) //NOI18N
80              return TRANSACTIONAL;
81          else if ("persistent".equals(persistenceModifier)) //NOI18N
82              return PERSISTENT;
83          else if ("possibly-persistent".equals(persistenceModifier)) //NOI18N
84              return POSSIBLY_PERSISTENT;
85          else
86              return UNSPECIFIED;
87      }
88  }