001: /*
002: * Distributed as part of c3p0 v.0.9.1.2
003: *
004: * Copyright (C) 2005 Machinery For Change, Inc.
005: *
006: * Author: Steve Waldman <swaldman@mchange.com>
007: *
008: * This library is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU Lesser General Public License version 2.1, as
010: * published by the Free Software Foundation.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License
018: * along with this software; see the file LICENSE. If not, write to the
019: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: */
022:
023: package com.mchange.v2.codegen.bean;
024:
025: import java.util.*;
026: import java.lang.reflect.Modifier;
027: import java.io.IOException;
028: import com.mchange.v2.codegen.CodegenUtils;
029: import com.mchange.v2.codegen.IndentedWriter;
030:
031: public class SimpleStateBeanImportExportGeneratorExtension implements
032: GeneratorExtension {
033: int ctor_modifiers = Modifier.PUBLIC;
034:
035: public Collection extraGeneralImports() {
036: return Collections.EMPTY_SET;
037: }
038:
039: public Collection extraSpecificImports() {
040: return Collections.EMPTY_SET;
041: }
042:
043: public Collection extraInterfaceNames() {
044: return Collections.EMPTY_SET;
045: }
046:
047: static class SimplePropertyMask implements Property {
048: Property p;
049:
050: SimplePropertyMask(Property p) {
051: this .p = p;
052: }
053:
054: public int getVariableModifiers() {
055: return Modifier.PRIVATE;
056: }
057:
058: public String getName() {
059: return p.getName();
060: }
061:
062: public String getSimpleTypeName() {
063: return p.getSimpleTypeName();
064: }
065:
066: public String getDefensiveCopyExpression() {
067: return null;
068: }
069:
070: public String getDefaultValueExpression() {
071: return null;
072: }
073:
074: public int getGetterModifiers() {
075: return Modifier.PUBLIC;
076: }
077:
078: public int getSetterModifiers() {
079: return Modifier.PUBLIC;
080: }
081:
082: public boolean isReadOnly() {
083: return false;
084: }
085:
086: public boolean isBound() {
087: return false;
088: }
089:
090: public boolean isConstrained() {
091: return false;
092: }
093: }
094:
095: public void generate(ClassInfo info, Class super classType,
096: Property[] props, Class[] propTypes, IndentedWriter iw)
097: throws IOException {
098: int num_props = props.length;
099: Property[] masked = new Property[num_props];
100: for (int i = 0; i < num_props; ++i)
101: masked[i] = new SimplePropertyMask(props[i]);
102:
103: iw
104: .println("protected static class SimpleStateBean implements ExportedState");
105: iw.println("{");
106: iw.upIndent();
107:
108: for (int i = 0; i < num_props; ++i) {
109: masked[i] = new SimplePropertyMask(props[i]);
110: BeangenUtils.writePropertyMember(masked[i], iw);
111: iw.println();
112: BeangenUtils.writePropertyGetter(masked[i], iw);
113: iw.println();
114: BeangenUtils.writePropertySetter(masked[i], iw);
115: }
116:
117: iw.downIndent();
118: iw.println("}");
119: }
120: }
|