KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > strongtyper > SessionInterfaceGenerator


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.strongtyper;
31
32 import com.genimen.djeneric.repository.DjDomain;
33 import com.genimen.djeneric.repository.DjDomainValue;
34 import com.genimen.djeneric.repository.DjExtent;
35
36 public class SessionInterfaceGenerator extends Generator
37 {
38   DjExtent[] _extents = null;
39   DjDomain[] _domains = null;
40
41   public String JavaDoc getPackageName()
42   {
43     return getItfPackageName();
44   }
45
46   public SessionInterfaceGenerator(DjExtent[] extents, DjDomain[] domains) throws Exception JavaDoc
47   {
48     _extents = extents;
49     _domains = domains;
50     if (extents == null || extents.length == 0) throw new Exception JavaDoc(
51         "Can not generate a session without any Extents selected");
52   }
53
54   public String JavaDoc getClassName()
55   {
56     return getSessionInterfaceName() + (isAbstract() ? getGeneratedSuffix() : "");
57   }
58
59   public String JavaDoc getCode() throws Exception JavaDoc
60   {
61     StringBuffer JavaDoc code = new StringBuffer JavaDoc(5000);
62     if (getPackageName().trim().length() > 0) code.append("package " + getPackageName() + ";\n\n");
63
64     code.append("import java.util.*;\n");
65     //code.append("import " + getImplPackageName() + ".*;\n");
66
//code.append("import com.genimen.djeneric.repository.*;\n");
67
//code.append("import com.genimen.djeneric.repository.exceptions.*;\n\n");
68
code.append(StrongTyper.getRegenerationTags(1));
69
70     code.append("public interface " + getClassName() + "\n{\n");
71
72     code.append(" public final static String DOMAIN_NAME = \"name\";\n");
73     code.append(" public final static String DOMAIN_TYPE = \"type\";\n");
74     code.append(" public final static String DOMAIN_LENGTH = \"length\";\n");
75     code.append(" public final static String DOMAIN_DECIMALS = \"decimals\";\n");
76     code.append(" public final static String DOMAIN_ENFORCE = \"enforce\";\n");
77     code.append(" public final static String DOMAIN_FORMAT_MASK = \"formatmask\";\n");
78     code.append(" public final static String DOMAIN_DESCRIPTION = \"description\";\n");
79     code.append(" public final static String DOMAIN_VALUES = \"values\";\n");
80     code.append(" public final static String DOMAIN_VALUE_DESCRIPTIONS = \"valuedescriptions\";\n\n");
81
82     for (int i = 0; i < _domains.length; i++)
83     {
84
85       if (_domains[i].isDynamic()) continue;
86
87       String JavaDoc name = _domains[i].getName();
88       if (name.equals("byte[]")) name = "bytes";
89
90       code.append(" public final static String TYPE_" + name.toUpperCase() + " = \"" + name + "\";\n");
91
92       DjDomainValue[] values = _domains[i].getValidValues();
93       for (int v = 0; v < values.length; v++)
94       {
95         if (values[v].isDynamic()) continue;
96         code.append(" public final static String VV_" + name.toUpperCase() + "_" + values[v].getValue().toString()
97                     + " = \"" + values[v].getValue().toString() + "\";\n");
98       }
99
100     }
101
102     code.append("\n public HashMap[] getDomains() throws " + getExceptionClassName() + ";\n");
103     code.append(" public HashMap getDomain(String domainName) throws " + getExceptionClassName() + ";\n");
104     code.append("\n");
105
106     for (int i = 0; i < _extents.length; i++)
107     {
108       code.append(" public " + getInterfaceName(_extents[i]) + " create" + _extents[i].getObjectType() + "() throws "
109                   + getExceptionClassName() + ";\n");
110       code.append(" public " + getQbeInterfaceName(_extents[i]) + " create" + _extents[i].getObjectType()
111                   + "Qbe() throws " + getExceptionClassName() + ";\n");
112       code.append(" public " + getOqlInterfaceName() + " create" + _extents[i].getObjectType() + "Oql() throws "
113                   + getExceptionClassName() + ";\n");
114
115       code.append(" public " + getInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType()
116                   + "(long objectId) throws " + getExceptionClassName() + ";\n");
117       code.append(" public " + getInterfaceName(_extents[i]) + "[] get" + _extents[i].getObjectType()
118                   + "Set() throws " + getExceptionClassName() + ";\n");
119       code.append(" public " + getInterfaceName(_extents[i]) + "[] get" + _extents[i].getObjectType() + "Set("
120                   + getQbeInterfaceName(_extents[i]) + " qbe) throws " + getExceptionClassName() + ";\n");
121       code.append(" public " + getInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() + "("
122                   + getQbeInterfaceName(_extents[i]) + " qbe) throws " + getExceptionClassName() + ";\n");
123       code.append(" public " + getCursorInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType()
124                   + "Cursor() throws " + getExceptionClassName() + ";\n");
125       code.append(" public " + getCursorInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() + "Cursor("
126                   + getQbeInterfaceName(_extents[i]) + " qbe) throws " + getExceptionClassName() + ";\n");
127
128       code.append(" public " + getInterfaceName(_extents[i]) + "[] get" + _extents[i].getObjectType() + "Set("
129                   + getOqlInterfaceName() + " oql) throws " + getExceptionClassName() + ";\n");
130       code.append(" public " + getInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() + "("
131                   + getOqlInterfaceName() + " oql) throws " + getExceptionClassName() + ";\n");
132       code.append(" public " + getCursorInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() + "Cursor("
133                   + getOqlInterfaceName() + " oql) throws " + getExceptionClassName() + ";\n");
134       code.append("\n");
135     }
136
137     code.append("\n" + " public boolean isValid();\n" + " public boolean hasOutstandingChanges();\n"
138                 + " public void setCommitAllowed(boolean b);\n" + " public boolean isCommitAllowed();\n"
139                 + " public void commit() throws Exception;\n" + " public void close();\n");
140
141     code.append(StrongTyper.getRegenerationTags(0));
142     code.append("}\n");
143
144     return code.toString();
145   }
146
147 }
Popular Tags