KickJava   Java API By Example, From Geeks To Geeks.

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


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 modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes 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,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE 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.DjExtent;
34 import com.genimen.djeneric.repository.DjPersistenceManager;
35 import com.genimen.djeneric.repository.DjProperty;
36
37 public class QbeInterfaceGenerator extends Generator
38 {
39   DjExtent _extent;
40   DjPersistenceManager _mgr;
41
42   public String JavaDoc getPackageName()
43   {
44     return getItfPackageName();
45   }
46
47   public QbeInterfaceGenerator(DjPersistenceManager mgr)
48   {
49     _mgr = mgr;
50   }
51
52   public DjExtent getExtent()
53   {
54     return _extent;
55   }
56
57   public void setExtent(DjExtent extent)
58   {
59     _extent = extent;
60   }
61
62   public String JavaDoc getQbeInterfaceName()
63   {
64     return getQbeInterfaceName(getExtent());
65   }
66
67   public String JavaDoc getClassName()
68   {
69     return getClassName(getExtent()) + (isAbstract() ? getGeneratedSuffix() : "");
70   }
71
72   public String JavaDoc getClassName(DjExtent extent)
73   {
74     return getQbeInterfaceName(extent);
75   }
76
77   public String JavaDoc getCode() throws Exception JavaDoc
78   {
79     StringBuffer JavaDoc code = new StringBuffer JavaDoc(5000);
80     if (getPackageName().trim().length() > 0) code.append("package " + getPackageName() + ";\n\n");
81
82     if (containsBigDecimal(getExtent())) code.append("import java.math.*;\n");
83     code.append(StrongTyper.getRegenerationTags(1));
84
85     code.append("public interface " + getClassName());
86
87     if (getExtent().getSuper() != null)
88     {
89       code.append(" extends " + getClassName(getExtent().getSuper()));
90     }
91
92     code.append("\n");
93
94     code.append("{\n");
95
96     code.append(" public void setQueryOperator(String propertyName, String operator) throws "
97                 + getExceptionClassName() + ";\n");
98     for (int i = 0; i < _extent.getPropertyCount(); i++)
99     {
100       DjProperty prop = _extent.getProperty(i);
101       if (_extent.isInherited(prop)) continue;
102
103       String JavaDoc propInitcap = initCap(prop.getName());
104
105       if (prop.getType() instanceof DjDomain)
106       {
107         code.append(" public " + translateNativeType(prop.getNativeType()) + " get" + propInitcap + "();\n");
108         code.append(" public void set" + propInitcap + "(" + translateNativeType(prop.getNativeType())
109                     + " value) throws " + getExceptionClassName() + ";\n");
110       }
111       else
112       {
113         DjExtent extent = (DjExtent) prop.getType();
114         code.append(" public " + getInterfaceName(extent) + " get" + propInitcap + "() throws "
115                     + getExceptionClassName() + ";\n");
116         code.append(" public void set" + propInitcap + "(" + getInterfaceName(extent) + " value) throws "
117                     + getExceptionClassName() + ";\n");
118       }
119     }
120
121     code.append(StrongTyper.getRegenerationTags(0));
122     code.append("}\n");
123     return code.toString();
124   }
125
126 }
Popular Tags