KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > mapping > SystemVariableGenerator


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mapper.mapping;
24
25 import java.math.BigDecimal JavaDoc;
26
27 import org.xquark.mapping.StorageContext;
28 import org.xquark.mapping.UserGenerator;
29 import org.xquark.mapper.metadata.RepositoryConstants;
30
31 public abstract class SystemVariableGenerator implements UserGenerator, MappingConstants
32 {
33     private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
34     private static final String JavaDoc RCSName = "$Name: $";
35     
36     public abstract Object JavaDoc getValue(StorageContext context);
37     public abstract String JavaDoc getXMLType();
38     public abstract short getType();
39     
40     static SystemVariableGenerator createGenerator(String JavaDoc sysvar)
41     {
42         if (DOCID_VALUE.equals(sysvar))
43             return new SystemVariableGenerator()
44             {
45                 public Object JavaDoc getValue(StorageContext context)
46                 {
47                     return context.getDocumentID();
48                 }
49                 public String JavaDoc getXMLType()
50                 {
51                     return "<simpleType><restriction base=\"string\"><maxLength value=\""
52                             + String.valueOf(RepositoryConstants.ID_LENGTH)
53                             + "\"/></restriction></simpleType>";
54                 }
55                 public short getType()
56                 {
57                     return DOCID_CODE;
58                 }
59             };
60         else if (DOCOID_VALUE.equals(sysvar))
61             return new SystemVariableGenerator()
62             {
63                 public Object JavaDoc getValue(StorageContext context)
64                 {
65                     return new Long JavaDoc(context.getDocumentOID());
66                 }
67                 public String JavaDoc getXMLType()
68                 {
69                     return "int";
70                 }
71                 public short getType()
72                 {
73                     return DOCOID_CODE;
74                 }
75             };
76 // else if (BUCKET_VALUE.equals(sysvar))
77
// return new SystemVariableGenerator()
78
// {
79
// public Object getValue(StorageContext context)
80
// {
81
// return new Long(context.getBucketOID());
82
// }
83
// public String getXMLType()
84
// {
85
// return "long";
86
// }
87
// public short getType()
88
// {
89
// return BUCKET_CODE;
90
// }
91
// };
92
else if (UOID_VALUE.equals(sysvar))
93             return new SystemVariableGenerator()
94             {
95                 public Object JavaDoc getValue(StorageContext context)
96                 {
97                     return new Long JavaDoc(context.getUOID());
98                 }
99                 public String JavaDoc getXMLType()
100                 {
101                     return "long";
102                 }
103                 public short getType()
104                 {
105                     return UOID_CODE;
106                 }
107             };
108         else if (PATHID_VALUE.equals(sysvar))
109             return new SystemVariableGenerator()
110             {
111                 public Object JavaDoc getValue(StorageContext context)
112                 {
113                     return new Integer JavaDoc(context.getPathOID());
114                 }
115                 public String JavaDoc getXMLType()
116                 {
117                     return "short";
118                 }
119                 public short getType()
120                 {
121                     return PATHID_CODE;
122                 }
123             };
124         else if (TAG_VALUE.equals(sysvar))
125             return new SystemVariableGenerator()
126             {
127                 public Object JavaDoc getValue(StorageContext context)
128                 {
129                     return context.getQName();
130                 }
131                 public String JavaDoc getXMLType()
132                 {
133                     return "<simpleType><restriction base=\"string\"><maxLength value=\"255\"/></restriction></simpleType>";
134                 }
135                 public short getType()
136                 {
137                     return TAG_CODE;
138                 }
139             };
140         else if (RANK_VALUE.equals(sysvar))
141             return new SystemVariableGenerator()
142             {
143                 public Object JavaDoc getValue(StorageContext context)
144                 {
145                     return BigDecimal.valueOf(context.getNodeRank());
146                 }
147                 public String JavaDoc getXMLType()
148                 {
149                     return "int";
150                 }
151                 public short getType()
152                 {
153                     return RANK_CODE;
154                 }
155             };
156         else if (LOCAL_VALUE.equals(sysvar))
157             return new SystemVariableGenerator()
158             {
159                 public Object JavaDoc getValue(StorageContext context)
160                 {
161                     return context.getLocalName();
162                 }
163                 public String JavaDoc getXMLType()
164                 {
165                     return "<simpleType><restriction base=\"string\"><maxLength value=\"255\"/></restriction></simpleType>";
166                 }
167                 public short getType()
168                 {
169                     return LOCAL_CODE;
170                 }
171             };
172         else if (URI_VALUE.equals(sysvar))
173             return new SystemVariableGenerator()
174             {
175                 public Object JavaDoc getValue(StorageContext context) {
176                     return context.getNamespaceURI();
177                 }
178                 public String JavaDoc getXMLType()
179                 {
180                     return "<simpleType><restriction base=\"string\"><maxLength value=\"255\"/></restriction></simpleType>";
181                 }
182                 public short getType()
183                 {
184                     return URI_CODE;
185                 }
186             };
187         else return null;
188     }
189 }
190
Popular Tags