KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > api > PStateGraph


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.api;
25
26 /**
27  * This class, which is entirely static, defines the state graphs for various
28  * JORM objects.
29  * @author P. Dechamboux
30  */

31 public class PStateGraph {
32     /**
33      * It defines the state graph that represents the lifecycle of PBinding
34      * objects. This means that, knowing a particular state and the action to
35      * be performed, it computes the transition to the next state that should be
36      * taken by this PBinding after the execution of this action.
37      * @param currentstate The state before the execution of the action.
38      * @param action The action to be performed.
39      * @return The state after the execution of the action.
40      */

41     public static byte nextStatePBinding(byte currentstate, byte action) {
42         switch (currentstate) {
43         case PBinding.LIFECYCLE_ACTIVEFORIO:
44             switch (action) {
45             case PBinding.ACTION_WRITE:
46             case PBinding.ACTION_READ:
47             case PBinding.ACTION_EXIST:
48             case PBinding.ACTION_BIND:
49                 return currentstate;
50             case PBinding.ACTION_EXPORT:
51                 return PBinding.LIFECYCLE_NEWTOWRITE;
52             case PBinding.ACTION_UNBIND:
53                 return PBinding.LIFECYCLE_NOTBOUND;
54             case PBinding.ACTION_UNEXPORT:
55                 return PBinding.LIFECYCLE_DELTOWRITE;
56             default :
57                 return PBinding.LIFECYCLE_ERROR;
58             }
59         case PBinding.LIFECYCLE_NEWTOWRITE:
60             switch (action) {
61             case PBinding.ACTION_WRITE:
62             case PBinding.ACTION_BIND:
63                 return PBinding.LIFECYCLE_ACTIVEFORIO;
64             case PBinding.ACTION_EXPORT:
65                 return currentstate;
66             case PBinding.ACTION_UNBIND:
67             case PBinding.ACTION_UNEXPORT:
68                 return PBinding.LIFECYCLE_NOTBOUND;
69             case PBinding.ACTION_READ:
70             case PBinding.ACTION_EXIST:
71                 return PBinding.LIFECYCLE_NEWTOWRITE;
72             default :
73                 return PBinding.LIFECYCLE_ERROR;
74             }
75         case PBinding.LIFECYCLE_DELTOWRITE:
76             switch (action) {
77             case PBinding.ACTION_WRITE:
78             case PBinding.ACTION_UNBIND:
79                 return PBinding.LIFECYCLE_NOTBOUND;
80             case PBinding.ACTION_BIND:
81                 return PBinding.LIFECYCLE_ACTIVEFORIO;
82             case PBinding.ACTION_EXPORT:
83                 return PBinding.LIFECYCLE_NEWTOWRITE;
84             case PBinding.ACTION_UNEXPORT:
85                 return currentstate;
86             case PBinding.ACTION_READ:
87             case PBinding.ACTION_EXIST:
88             default :
89                 return PBinding.LIFECYCLE_ERROR;
90             }
91         case PBinding.LIFECYCLE_NOTBOUND:
92             switch (action) {
93             case PBinding.ACTION_BIND:
94                 return PBinding.LIFECYCLE_ACTIVEFORIO;
95             case PBinding.ACTION_EXPORT:
96                 return PBinding.LIFECYCLE_NEWTOWRITE;
97             case PBinding.ACTION_UNBIND:
98                 return currentstate;
99             case PBinding.ACTION_WRITE:
100             case PBinding.ACTION_READ:
101             case PBinding.ACTION_EXIST:
102             case PBinding.ACTION_UNEXPORT:
103             default :
104                 return PBinding.LIFECYCLE_ERROR;
105             }
106         default :
107             return PBinding.LIFECYCLE_ERROR;
108         }
109     }
110 }
111
Popular Tags