View | Details | Raw Unified | Return to bug 268592 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/persistence/sdo/helper/DynamicClassWriter.java (-10 / +140 lines)
Lines 9-28 Link Here
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
11
 *     Oracle - initial API and implementation from Oracle TopLink
11
 *     Oracle - initial API and implementation from Oracle TopLink
12
 *     bdoughan - Mar 18/2009 - 2.0 - Dynamically generated impl classes now
13
 *                                    implement correct interface.
12
 ******************************************************************************/  
14
 ******************************************************************************/  
13
package org.eclipse.persistence.sdo.helper;
15
package org.eclipse.persistence.sdo.helper;
14
16
15
import java.io.ObjectStreamException;
17
import java.io.ObjectStreamException;
16
import java.io.Serializable;
18
import java.io.Serializable;
19
import java.lang.reflect.Field;
17
import java.lang.reflect.Method;
20
import java.lang.reflect.Method;
21
import java.util.List;
18
22
19
import org.eclipse.persistence.sdo.SDOConstants;
23
import org.eclipse.persistence.sdo.SDOConstants;
20
import org.eclipse.persistence.sdo.SDODataObject;
24
import org.eclipse.persistence.sdo.SDODataObject;
25
import org.eclipse.persistence.sdo.SDOProperty;
21
import org.eclipse.persistence.sdo.SDOType;
26
import org.eclipse.persistence.sdo.SDOType;
27
import org.eclipse.persistence.sdo.helper.extension.SDOUtil;
22
import org.eclipse.persistence.internal.libraries.asm.ClassWriter;
28
import org.eclipse.persistence.internal.libraries.asm.ClassWriter;
23
import org.eclipse.persistence.internal.libraries.asm.CodeVisitor;
29
import org.eclipse.persistence.internal.libraries.asm.CodeVisitor;
24
import org.eclipse.persistence.internal.libraries.asm.Constants;
30
import org.eclipse.persistence.internal.libraries.asm.Constants;
25
import org.eclipse.persistence.internal.libraries.asm.Type;
31
import org.eclipse.persistence.internal.libraries.asm.Type;
32
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
33
26
import commonj.sdo.helper.HelperContext;
34
import commonj.sdo.helper.HelperContext;
27
35
28
/**
36
/**
Lines 31-49 Link Here
31
 * and a writeReplace() method.
39
 * and a writeReplace() method.
32
 */
40
 */
33
public class DynamicClassWriter {
41
public class DynamicClassWriter {
42
    static final String START_PROPERTY_INDEX = "START_PROPERTY_INDEX";
43
    static final String END_PROPERTY_INDEX = "END_PROPERTY_INDEX";
44
    static final String GET = "get";
45
    static final String SET = "set";
46
    static final String LIST = "List";
47
    static final String WRITE_REPLACE = "writeReplace";
48
34
    private Class parentClass;
49
    private Class parentClass;
35
    private String className;
50
    private String typeImplClassDescriptor;
36
    private SDOType type;
51
    private SDOType type;
52
    private Integer startPropertyIndex;
37
53
38
    // hold the context containing all helpers so that we can preserve inter-helper relationships
54
    // hold the context containing all helpers so that we can preserve inter-helper relationships
39
    private HelperContext aHelperContext;
55
    private HelperContext aHelperContext;
40
56
41
    public DynamicClassWriter(String className, SDOType type, HelperContext aContext) {
57
    public DynamicClassWriter(String className, SDOType type, HelperContext aContext) {
42
        aHelperContext = aContext;
58
        this.aHelperContext = aContext;
43
        this.parentClass = SDODataObject.class;
59
        this.parentClass = SDODataObject.class;
44
        this.className = className;
60
        this.typeImplClassDescriptor = className.replace('.', '/');
45
        this.type = type;
61
        this.type = type;
46
        initializeParentClass();
62
        initializeParentClass();
63
64
        if(type.isSubType()) {
65
            try {
66
                Field parentEndPropertyIndexField = PrivilegedAccessHelper.getField(parentClass, END_PROPERTY_INDEX, true);
67
                Integer parentEndPropertyIndex = (Integer) PrivilegedAccessHelper.getValueFromField(parentEndPropertyIndexField, parentClass);
68
                startPropertyIndex = parentEndPropertyIndex + 1;
69
            } catch(NoSuchFieldException e) {
70
                startPropertyIndex = new Integer(0);
71
            } catch(IllegalAccessException e) {
72
                startPropertyIndex = new Integer(0);
73
            }
74
        } else {
75
            startPropertyIndex = new Integer(0);
76
        }
47
    }
77
    }
48
78
49
    private void initializeParentClass() {
79
    private void initializeParentClass() {
Lines 67-76 Link Here
67
        return this.parentClass;
97
        return this.parentClass;
68
    }
98
    }
69
99
70
    public String getClassName() {
71
        return this.className;
72
    }
73
74
    /**
100
    /**
75
     * This is where the byte codes for the generic subclass are defined and the
101
     * This is where the byte codes for the generic subclass are defined and the
76
     * class is created dynamically from them.
102
     * class is created dynamically from them.
Lines 78-84 Link Here
78
    public byte[] createClass() {
104
    public byte[] createClass() {
79
        ClassWriter cw = new ClassWriter(false);
105
        ClassWriter cw = new ClassWriter(false);
80
106
81
        cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_SUPER, className.replace('.', '/'), Type.getType(parentClass).getInternalName(), null, null);
107
        if(null == type.getInstanceClass()) {
108
            cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_SUPER, typeImplClassDescriptor, Type.getType(parentClass).getInternalName(), null, null);
109
        } else {
110
            String[] interfaces = new String[1];
111
            interfaces[0] = type.getInstanceClassName().replace('.', '/');
112
            cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_SUPER, typeImplClassDescriptor, Type.getType(parentClass).getInternalName(), interfaces, null);
113
            addPropertyIndices(cw);
114
            for(Object object: type.getDeclaredProperties()) {
115
                SDOProperty sdoProperty = (SDOProperty) object;
116
                addPropertyGetMethod(cw, sdoProperty);
117
                addPropertySetMethod(cw, sdoProperty);
118
            }
119
        }
82
120
83
        addConstructors(cw);
121
        addConstructors(cw);
84
        addWriteReplace(cw);
122
        addWriteReplace(cw);
Lines 87-93 Link Here
87
        return cw.toByteArray();
125
        return cw.toByteArray();
88
    }
126
    }
89
127
90
    private void addConstructors(ClassWriter cw) {        
128
    private void addPropertyIndices(ClassWriter cw) {
129
        cw.visitField(Constants.ACC_PUBLIC + Constants.ACC_FINAL + Constants.ACC_STATIC, START_PROPERTY_INDEX, "I", startPropertyIndex, null);
130
        int declaredPropsSize = type.getDeclaredProperties().size();
131
132
        Integer endPropertyIndex;
133
        if(declaredPropsSize > 0) {
134
            endPropertyIndex = startPropertyIndex + declaredPropsSize - 2;
135
        } else {
136
            endPropertyIndex = startPropertyIndex - 1;
137
        }
138
        cw.visitField(Constants.ACC_PUBLIC + Constants.ACC_FINAL + Constants.ACC_STATIC, END_PROPERTY_INDEX, "I", endPropertyIndex, null);
139
    }
140
141
    private void addConstructors(ClassWriter cw) {
91
        CodeVisitor mv = cw.visitMethod(Constants.ACC_PUBLIC, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[0]), new String[] { Type.getInternalName(Serializable.class) }, null);
142
        CodeVisitor mv = cw.visitMethod(Constants.ACC_PUBLIC, "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[0]), new String[] { Type.getInternalName(Serializable.class) }, null);
92
        mv.visitVarInsn(Constants.ALOAD, 0);
143
        mv.visitVarInsn(Constants.ALOAD, 0);
93
        mv.visitMethodInsn(Constants.INVOKESPECIAL, Type.getType(parentClass).getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[0]));
144
        mv.visitMethodInsn(Constants.INVOKESPECIAL, Type.getType(parentClass).getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[0]));
Lines 95-104 Link Here
95
        mv.visitMaxs(1, 1);
146
        mv.visitMaxs(1, 1);
96
    }
147
    }
97
148
149
    private void addPropertyGetMethod(ClassWriter cw, SDOProperty property) {
150
        String returnType = SDOUtil.getJavaTypeForProperty(property);
151
        String outerGetMethodName = SDOUtil.getMethodName(property.getName(), returnType);
152
153
        CodeVisitor mv;
154
        String propertyInstanceClassDescriptor;
155
        if(property.isMany()) {
156
            propertyInstanceClassDescriptor = Type.getDescriptor(List.class);
157
        } else if(property.getType().isDataType()) {
158
            propertyInstanceClassDescriptor = Type.getDescriptor(property.getType().getInstanceClass());
159
        } else {
160
            propertyInstanceClassDescriptor = "L" + returnType.replace('.', '/') + ";";
161
        }
162
        mv = cw.visitMethod(Constants.ACC_PUBLIC, outerGetMethodName, "()" + propertyInstanceClassDescriptor, null, null);
163
164
        mv.visitVarInsn(Constants.ALOAD, 0);
165
        mv.visitIntInsn(Constants.BIPUSH, startPropertyIndex + property.getIndexInType());
166
167
        String builtIn = SDOUtil.getBuiltInType(returnType);
168
        if(null != builtIn) {
169
            if(property.getType().isDataType() && !builtIn.equals(LIST)) {
170
                mv.visitMethodInsn(Constants.INVOKEVIRTUAL, typeImplClassDescriptor, GET + builtIn, "(I)" + propertyInstanceClassDescriptor);
171
                int iReturnOpcode = Type.getType(property.getType().getInstanceClass()).getOpcode(Constants.IRETURN);
172
                mv.visitInsn(iReturnOpcode);
173
            } else {
174
                mv.visitMethodInsn(Constants.INVOKEVIRTUAL,  typeImplClassDescriptor, GET, "(I)Ljava/lang/Object;");                        
175
                mv.visitInsn(Constants.ARETURN);
176
            }
177
        } else {
178
            mv.visitMethodInsn(Constants.INVOKEVIRTUAL,  typeImplClassDescriptor, GET, "(I)Ljava/lang/Object;");                        
179
            mv.visitInsn(Constants.ARETURN);
180
        }
181
        mv.visitMaxs(2, 1);
182
    }
183
184
    private void addPropertySetMethod(ClassWriter cw, SDOProperty property) {
185
        String returnType = SDOUtil.getJavaTypeForProperty(property);
186
        String outerSetMethodName = SDOUtil.setMethodName(property.getName());
187
188
        CodeVisitor mv;
189
        String propertyInstanceClassDescriptor;
190
191
        if(property.isMany()) {
192
            propertyInstanceClassDescriptor = Type.getDescriptor(List.class);
193
        } else if(property.getType().isDataType()) {
194
            propertyInstanceClassDescriptor = Type.getDescriptor(property.getType().getInstanceClass());
195
        } else {
196
            propertyInstanceClassDescriptor = "L" + returnType.replace('.', '/') + ";";
197
        }
198
        mv = cw.visitMethod(Constants.ACC_PUBLIC, outerSetMethodName, "(" + propertyInstanceClassDescriptor + ")V", null, null);
199
200
        mv.visitVarInsn(Constants.ALOAD, 0);
201
        mv.visitIntInsn(Constants.BIPUSH, startPropertyIndex + property.getIndexInType());
202
203
        String builtIn = SDOUtil.getBuiltInType(returnType);
204
        int iLoadOpcode = Constants.ALOAD;
205
        if(null != builtIn) {
206
            if(property.getType().isDataType() && !builtIn.equals(LIST)) {
207
                iLoadOpcode = Type.getType(property.getType().getInstanceClass()).getOpcode(Constants.ILOAD);
208
                mv.visitVarInsn(iLoadOpcode, 1);
209
                mv.visitMethodInsn(Constants.INVOKEVIRTUAL, typeImplClassDescriptor, SET + builtIn, "(I" + propertyInstanceClassDescriptor + ")V");
210
            } else {
211
                mv.visitVarInsn(iLoadOpcode, 1);
212
                mv.visitMethodInsn(Constants.INVOKEVIRTUAL,  typeImplClassDescriptor, SET, "(ILjava/lang/Object;)V");                        
213
            }
214
        } else {
215
            mv.visitVarInsn(iLoadOpcode, 1);
216
            mv.visitMethodInsn(Constants.INVOKEVIRTUAL,  typeImplClassDescriptor, SET, "(ILjava/lang/Object;)V");                        
217
        }
218
219
        mv.visitInsn(Constants.RETURN);
220
        if(iLoadOpcode == Constants.DLOAD || iLoadOpcode == Constants.LLOAD) {
221
            mv.visitMaxs(4, 3);
222
        } else {
223
            mv.visitMaxs(3, 2);
224
        }
225
    }
226
98
    private void addWriteReplace(ClassWriter cw) {
227
    private void addWriteReplace(ClassWriter cw) {
99
        Method method;
228
        Method method;
100
        try {
229
        try {
101
            method = parentClass.getDeclaredMethod("writeReplace", new Class[0]);
230
            method = parentClass.getDeclaredMethod(WRITE_REPLACE, new Class[0]);
102
        } catch (NoSuchMethodException e) {
231
        } catch (NoSuchMethodException e) {
103
            return;
232
            return;
104
        }
233
        }
Lines 110-113 Link Here
110
        mv.visitInsn(Constants.ARETURN);
239
        mv.visitInsn(Constants.ARETURN);
111
        mv.visitMaxs(1, 1);
240
        mv.visitMaxs(1, 1);
112
    }
241
    }
242
113
}
243
}
(-)src/org/eclipse/persistence/sdo/helper/extension/SDOUtil.java (-20 / +63 lines)
Lines 18-23 Link Here
18
import java.util.StringTokenizer;
18
import java.util.StringTokenizer;
19
19
20
import org.eclipse.persistence.sdo.SDOConstants;
20
import org.eclipse.persistence.sdo.SDOConstants;
21
import org.eclipse.persistence.sdo.SDOProperty;
22
import org.eclipse.persistence.sdo.SDOType;
21
import org.eclipse.persistence.internal.helper.ClassConstants;
23
import org.eclipse.persistence.internal.helper.ClassConstants;
22
import org.eclipse.persistence.logging.AbstractSessionLog;
24
import org.eclipse.persistence.logging.AbstractSessionLog;
23
25
Lines 467-485 Link Here
467
469
468
    /**
470
    /**
469
     * INTERNAL:
471
     * INTERNAL:
470
     * Return a valid Java get method name for a given string
471
     * @param s
472
     * @return
473
     */
474
    public static String getMethodName(String s) {
475
        StringBuffer stringbuffer = new StringBuffer();
476
        // only log the setMethodName call so we do not get double logs
477
        stringbuffer.append(GET).append(className(s, true, false, false));
478
        return stringbuffer.toString();
479
    }
480
481
    /**
482
     * INTERNAL:
483
     * Return a valid Java get method name for a given string. This method will check
472
     * Return a valid Java get method name for a given string. This method will check
484
     * the returnType to see if it is a boolean/Boolean:  if so, 'is' will be used in
473
     * the returnType to see if it is a boolean/Boolean:  if so, 'is' will be used in
485
     * the method name instead of 'get'.
474
     * the method name instead of 'get'.
Lines 489-501 Link Here
489
     * @return
478
     * @return
490
     */
479
     */
491
    public static String getMethodName(String s, String returnType) {
480
    public static String getMethodName(String s, String returnType) {
492
        if (returnType.equals(ClassConstants.PBOOLEAN.getName()) || returnType.equals(ClassConstants.BOOLEAN.getName())) {
481
        try {
493
            StringBuffer stringbuffer = new StringBuffer();
482
            StringBuffer stringBuffer = new StringBuffer();
494
            // only log the setMethodName call so we do not get double logs
483
            if (returnType.equals(ClassConstants.PBOOLEAN.getName()) || returnType.equals(ClassConstants.BOOLEAN.getName())) {
495
            stringbuffer.append(IS).append(SDOUtil.className(s, true, false, false));
484
                stringBuffer.append(IS);
496
            return stringbuffer.toString();
485
            } else {
486
                stringBuffer.append(GET);
487
            }
488
            stringBuffer.append(SDOUtil.className(s, true, false, false));
489
            return stringBuffer.toString();
490
        } catch(NullPointerException e) {
491
            throw e;
497
        }
492
        }
498
        return getMethodName(s);
499
    }
493
    }
500
494
501
    /**
495
    /**
Lines 651-655 Link Here
651
645
652
        stringbuffer.replace(j, 6, s);
646
        stringbuffer.replace(j, 6, s);
653
        return stringbuffer.toString();
647
        return stringbuffer.toString();
654
    }    
648
    }
649
650
    public static String getJavaTypeForProperty(SDOProperty property) {
651
        if (property.isMany() || ((SDOType)property.getType()).isXsdList()) {
652
            return "java.util.List";
653
        } else {
654
            SDOType propertyType = property.getType();
655
            Class instanceClass = propertyType.getInstanceClass();
656
            if (ClassConstants.ABYTE.equals(instanceClass)) {
657
                return "Byte[]";
658
            } else if (ClassConstants.APBYTE.equals(instanceClass)) {
659
                return "byte[]";
660
            }
661
            return propertyType.getInstanceClassName();
662
        }
663
    }
664
665
    public static String getBuiltInType(String typeName) {
666
        if ((typeName.equals(ClassConstants.PBOOLEAN.getName())) || (typeName.equals(ClassConstants.BOOLEAN.getName()))) {
667
            return "Boolean";
668
        } else if ((typeName.equals(ClassConstants.PBYTE.getName())) || (typeName.equals(ClassConstants.BYTE.getName()))) {
669
            return "Byte";
670
        } else if (typeName.equals("byte[]") || typeName.equals("Byte[]") ||  (typeName.equals(ClassConstants.APBYTE.getName())) || (typeName.equals(ClassConstants.ABYTE.getName()))) {
671
            return "Bytes";
672
        } else if ((typeName.equals(ClassConstants.PCHAR.getName())) || (typeName.equals(ClassConstants.CHAR.getName()))) {
673
            return "Char";
674
        } else if ((typeName.equals(ClassConstants.PDOUBLE.getName())) || (typeName.equals(ClassConstants.DOUBLE.getName()))) {
675
            return "Double";
676
        } else if ((typeName.equals(ClassConstants.PFLOAT.getName())) || (typeName.equals(ClassConstants.FLOAT.getName()))) {
677
            return "Float";
678
        } else if ((typeName.equals(ClassConstants.PLONG.getName())) || (typeName.equals(ClassConstants.LONG.getName()))) {
679
            return "Long";
680
        } else if ((typeName.equals(ClassConstants.PSHORT.getName())) || (typeName.equals(ClassConstants.SHORT.getName()))) {
681
            return "Short";
682
        } else if ((typeName.equals(ClassConstants.PINT.getName())) || (typeName.equals(ClassConstants.INTEGER.getName()))) {
683
            return "Int";
684
        } else if (typeName.equals(ClassConstants.STRING.getName())) {
685
            return "String";
686
        } else if (typeName.equals(ClassConstants.BIGINTEGER.getName())) {
687
            return "BigInteger";
688
        } else if (typeName.equals(ClassConstants.BIGDECIMAL.getName())) {
689
            return "BigDecimal";
690
        } else if (typeName.equals(ClassConstants.UTILDATE.getName())) {
691
            return "Date";
692
        } else if (typeName.equals("java.util.List")) {
693
            return "List";
694
        }
695
        return null;
696
    }
697
655
}
698
}
(-)src/org/eclipse/persistence/sdo/helper/SDOClassGenerator.java (-90 / +49 lines)
Lines 12-20 Link Here
12
 ******************************************************************************/  
12
 ******************************************************************************/  
13
package org.eclipse.persistence.sdo.helper;
13
package org.eclipse.persistence.sdo.helper;
14
14
15
import commonj.sdo.Property;
16
import commonj.sdo.helper.HelperContext;
15
import commonj.sdo.helper.HelperContext;
17
18
import java.io.FileReader;
16
import java.io.FileReader;
19
import java.io.IOException;
17
import java.io.IOException;
20
import java.io.Reader;
18
import java.io.Reader;
Lines 46-52 Link Here
46
    private static final String lsep2 = lsep + lsep;
44
    private static final String lsep2 = lsep + lsep;
47
    private static final String START_PROPERTY_INDEX = "START_PROPERTY_INDEX";
45
    private static final String START_PROPERTY_INDEX = "START_PROPERTY_INDEX";
48
    private Map generatedBuffers;
46
    private Map generatedBuffers;
49
    private boolean generateInterfaces = true;
47
    private boolean interfaceGenerator = true;
48
    private boolean implGenerator = true;
50
    private CodeWriter codeWriter;
49
    private CodeWriter codeWriter;
51
    private SDOClassGeneratorListener sdoClassGeneratorListener;
50
    private SDOClassGeneratorListener sdoClassGeneratorListener;
52
51
Lines 62-67 Link Here
62
        generatedBuffers = new HashMap();
61
        generatedBuffers = new HashMap();
63
    }
62
    }
64
63
64
    public void setInterfaceGenerator(boolean genIterfaces) {
65
        interfaceGenerator = genIterfaces;
66
    }
67
68
    public void setImplGenerator(boolean genImpls) {
69
        implGenerator = genImpls;
70
    }
71
65
    public static void main(String[] args) {
72
    public static void main(String[] args) {
66
        // default to dynamic context
73
        // default to dynamic context
67
        SDOClassGenerator generator = new SDOClassGenerator(new SDOHelperContext());
74
        SDOClassGenerator generator = new SDOClassGenerator(new SDOHelperContext());
Lines 76-102 Link Here
76
            if (args[i].equals("-help")) {
83
            if (args[i].equals("-help")) {
77
                generator.printUsage(null);
84
                generator.printUsage(null);
78
                System.exit(0);
85
                System.exit(0);
79
            }
86
            } else if (args[i].equals("-sourceFile")) {
80
            if (args[i].equals("-sourceFile")) {
81
                if (i == (argsLength - 1)) {
87
                if (i == (argsLength - 1)) {
82
                    generator.printUsage("sdo_classgenerator_usage_missing_sourcefile_value");
88
                    generator.printUsage("sdo_classgenerator_usage_missing_sourcefile_value");
83
                    System.exit(0);
89
                    System.exit(0);
84
                }
90
                }
85
                sourceFile = args[++i];
91
                sourceFile = args[++i];
86
            }
92
            } else if (args[i].equals("-targetDirectory")) {
87
            if (args[i].equals("-targetDirectory")) {
88
                if (i == (argsLength - 1)) {
93
                if (i == (argsLength - 1)) {
89
                    generator.printUsage("sdo_classgenerator_usage_missing_targetdir");
94
                    generator.printUsage("sdo_classgenerator_usage_missing_targetdir");
90
                    System.exit(0);
95
                    System.exit(0);
91
                }
96
                }
92
                sourceDir = args[++i];
97
                sourceDir = args[++i];
93
            }
98
            } else if (args[i].equals("-logLevel")) {
94
99
                // log level is optional and will default to INFO
95
            // log level is optional and will default to INFO
96
            if (args[i].equals("-logLevel")) {
97
                if (i != (argsLength - 1)) {
100
                if (i != (argsLength - 1)) {
98
                    AbstractSessionLog.getLog().setLevel(Integer.parseInt(args[++i]));
101
                    AbstractSessionLog.getLog().setLevel(Integer.parseInt(args[++i]));
99
                }
102
                }
103
            } else if (args[i].equals("-noInterfaces")) {
104
                generator.setInterfaceGenerator(false);
105
            } else if (args[i].equals("-noImpls")) {
106
                generator.setImplGenerator(false);
100
            }
107
            }
101
        }
108
        }
102
        if (null == sourceFile) {
109
        if (null == sourceFile) {
Lines 130-148 Link Here
130
        
137
        
131
        // Because we can no longer use Helper.cr() inside of message bundles, we must break
138
        // Because we can no longer use Helper.cr() inside of message bundles, we must break
132
        // up the message into separate lines and use Helper.cr() here instead. (bug6470503)
139
        // up the message into separate lines and use Helper.cr() here instead. (bug6470503)
133
        String messageString = ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_1of6", new Object[] { Helper.getShortClassName(getClass()) });
140
        String messageString = ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_1of8", new Object[] { Helper.getShortClassName(getClass()) });
134
		messageString += Helper.cr() + Helper.cr();
141
        messageString += Helper.cr() + Helper.cr();
135
		messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_2of6");
142
        messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_2of8");
136
		messageString += Helper.cr();
143
        messageString += Helper.cr();
137
		messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_3of6");
144
        messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_3of8");
138
		messageString += Helper.cr();
145
        messageString += Helper.cr();
139
		messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_4of6");
146
        messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_4of8");
140
		messageString += Helper.cr();
147
        messageString += Helper.cr();
141
		messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_5of6");
148
        messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_5of8");
142
		messageString += Helper.cr();
149
        messageString += Helper.cr();
143
		messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_6of6");
150
        messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_6of8");
144
		messageString += Helper.cr();
151
        messageString += Helper.cr();
145
		
152
        messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_7of8");
153
        messageString += Helper.cr();
154
        messageString += ToStringLocalization.buildMessage("sdo_classgenerator_usage_help_8of8");
155
        messageString += Helper.cr();
156
146
        System.out.println(messageString);
157
        System.out.println(messageString);
147
    }
158
    }
148
159
Lines 212-218 Link Here
212
223
213
    public Map generate(CodeWriter aCodeWriter, java.util.List types) {
224
    public Map generate(CodeWriter aCodeWriter, java.util.List types) {
214
        generatedBuffers = new HashMap();
225
        generatedBuffers = new HashMap();
215
        generateInterfaces = true;
216
        codeWriter = aCodeWriter;
226
        codeWriter = aCodeWriter;
217
227
218
        for (int i = 0; i < types.size(); i++) {
228
        for (int i = 0; i < types.size(); i++) {
Lines 224-231 Link Here
224
                String packageDir = nextBuffer.getPackageName();
234
                String packageDir = nextBuffer.getPackageName();
225
                packageDir = packageDir.replace('.', '/');
235
                packageDir = packageDir.replace('.', '/');
226
236
227
                getCodeWriter().writeInterface(packageDir, nextBuffer.getInterfaceName() + ".java", nextBuffer.getInterfaceBuffer());
237
                if(interfaceGenerator) {
228
                getCodeWriter().writeImpl(packageDir, nextBuffer.getClassName() + ".java", nextBuffer.getClassBuffer());
238
                    getCodeWriter().writeInterface(packageDir, nextBuffer.getInterfaceName() + ".java", nextBuffer.getInterfaceBuffer());
239
                }
240
                if(implGenerator) {
241
                    getCodeWriter().writeImpl(packageDir, nextBuffer.getClassName() + ".java", nextBuffer.getClassBuffer());
242
                }
229
            }
243
            }
230
        }
244
        }
231
        return generatedBuffers;
245
        return generatedBuffers;
Lines 235-241 Link Here
235
    private ClassBuffer buildClassForType(SDOType sdoType) {
249
    private ClassBuffer buildClassForType(SDOType sdoType) {
236
        ClassBuffer classBuffer = new ClassBuffer(sdoClassGeneratorListener);
250
        ClassBuffer classBuffer = new ClassBuffer(sdoClassGeneratorListener);
237
        classBuffer.setSdoType(sdoType);
251
        classBuffer.setSdoType(sdoType);
238
        classBuffer.setGenerateInterface(generateInterfaces);
252
        classBuffer.setGenerateInterface(interfaceGenerator);
239
        classBuffer.setSdoTypeName(sdoType.getName());
253
        classBuffer.setSdoTypeName(sdoType.getName());
240
        StringBuffer currentClassBuffer = new StringBuffer();
254
        StringBuffer currentClassBuffer = new StringBuffer();
241
        if (sdoClassGeneratorListener != null) {
255
        if (sdoClassGeneratorListener != null) {
Lines 299-305 Link Here
299
        }
313
        }
300
314
301
        currentClassBuffer.append("extends ").append(implExtends);
315
        currentClassBuffer.append("extends ").append(implExtends);
302
        if (generateInterfaces) {
316
        if (interfaceGenerator) {
303
            currentClassBuffer.append(" implements ")//
317
            currentClassBuffer.append(" implements ")//
304
            .append(interfaceName);
318
            .append(interfaceName);
305
        }
319
        }
Lines 308-314 Link Here
308
        classBuffer.getMethodBuffer().append(buildNoArgCtor(fullClassName));
322
        classBuffer.getMethodBuffer().append(buildNoArgCtor(fullClassName));
309
        currentClassBuffer.append(indent).append(" {").append(lsep2);
323
        currentClassBuffer.append(indent).append(" {").append(lsep2);
310
324
311
        if (generateInterfaces) {
325
        if (interfaceGenerator) {
312
            StringBuffer currentInterfaceBuffer = new StringBuffer();
326
            StringBuffer currentInterfaceBuffer = new StringBuffer();
313
            if (sdoClassGeneratorListener != null) {
327
            if (sdoClassGeneratorListener != null) {
314
                sdoClassGeneratorListener.preInterfacePackage(currentInterfaceBuffer);
328
                sdoClassGeneratorListener.preInterfacePackage(currentInterfaceBuffer);
Lines 468-474 Link Here
468
     * @param className
482
     * @param className
469
     */
483
     */
470
    private void buildGetMethodBuffer(ClassBuffer classBuffer, SDOProperty property, java.util.List documentation) {
484
    private void buildGetMethodBuffer(ClassBuffer classBuffer, SDOProperty property, java.util.List documentation) {
471
        String returnType = getJavaTypeForProperty(property);
485
        String returnType = SDOUtil.getJavaTypeForProperty(property);
472
        String methodName = SDOUtil.getMethodName(property.getName(), returnType);
486
        String methodName = SDOUtil.getMethodName(property.getName(), returnType);
473
487
474
        if (!(property.getType().isChangeSummaryType() && methodName.equals("getChangeSummary"))) {
488
        if (!(property.getType().isChangeSummaryType() && methodName.equals("getChangeSummary"))) {
Lines 484-490 Link Here
484
            pushIndent();
498
            pushIndent();
485
            classBuffer.getMethodBuffer().append(indent).append("return ");
499
            classBuffer.getMethodBuffer().append(indent).append("return ");
486
            //cast return value        
500
            //cast return value        
487
            String builtIn = getBuiltInType(returnType);
501
            String builtIn = SDOUtil.getBuiltInType(returnType);
488
502
489
            if (builtIn != null) {
503
            if (builtIn != null) {
490
                String wrapperCall = getWrapperCall(returnType);
504
                String wrapperCall = getWrapperCall(returnType);
Lines 513-519 Link Here
513
            popIndent();
527
            popIndent();
514
            classBuffer.getMethodBuffer().append(indent).append("}").append(lsep2);
528
            classBuffer.getMethodBuffer().append(indent).append("}").append(lsep2);
515
        }
529
        }
516
        if (generateInterfaces) {
530
        if (interfaceGenerator) {
517
            classBuffer.getInterfaceBuffer().append(indent);
531
            classBuffer.getInterfaceBuffer().append(indent);
518
            classBuffer.getInterfaceBuffer().append("public ");
532
            classBuffer.getInterfaceBuffer().append("public ");
519
            classBuffer.getInterfaceBuffer().append(returnType).append(" ");
533
            classBuffer.getInterfaceBuffer().append(returnType).append(" ");
Lines 546-552 Link Here
546
        classBuffer.getMethodBuffer().append(methodName);
560
        classBuffer.getMethodBuffer().append(methodName);
547
        classBuffer.getMethodBuffer().append("(");
561
        classBuffer.getMethodBuffer().append("(");
548
562
549
        String paramType = getJavaTypeForProperty(property);
563
        String paramType = SDOUtil.getJavaTypeForProperty(property);
550
564
551
        classBuffer.getMethodBuffer().append(paramType).append(" value");
565
        classBuffer.getMethodBuffer().append(paramType).append(" value");
552
566
Lines 563-569 Link Here
563
        classBuffer.getMethodBuffer().append(indent).append("}");
577
        classBuffer.getMethodBuffer().append(indent).append("}");
564
        classBuffer.getMethodBuffer().append(lsep2);
578
        classBuffer.getMethodBuffer().append(lsep2);
565
579
566
        if (generateInterfaces) {
580
        if (interfaceGenerator) {
567
            classBuffer.getInterfaceBuffer().append(indent);
581
            classBuffer.getInterfaceBuffer().append(indent);
568
            classBuffer.getInterfaceBuffer().append("public void ");
582
            classBuffer.getInterfaceBuffer().append("public void ");
569
            classBuffer.getInterfaceBuffer().append(methodName);
583
            classBuffer.getInterfaceBuffer().append(methodName);
Lines 590-635 Link Here
590
        indent = buf.toString();
604
        indent = buf.toString();
591
    }
605
    }
592
606
593
    /**
594
     * INTERNAL:
595
     * @param qualifiedName
596
     * @param targetNamespace
597
     * @return
598
     */
599
    private String getBuiltInType(String typeName) {
600
        if ((typeName.equals(ClassConstants.PBOOLEAN.getName())) || (typeName.equals(ClassConstants.BOOLEAN.getName()))) {
601
            return "Boolean";
602
        } else if ((typeName.equals(ClassConstants.PBYTE.getName())) || (typeName.equals(ClassConstants.BYTE.getName()))) {
603
            return "Byte";
604
        } else if ((typeName.equals(ClassConstants.APBYTE.getName())) || (typeName.equals(ClassConstants.ABYTE.getName()))) {
605
            return "Bytes";
606
        } else if ((typeName.equals(ClassConstants.PCHAR.getName())) || (typeName.equals(ClassConstants.CHAR.getName()))) {
607
            return "Char";
608
        } else if ((typeName.equals(ClassConstants.PDOUBLE.getName())) || (typeName.equals(ClassConstants.DOUBLE.getName()))) {
609
            return "Double";
610
        } else if ((typeName.equals(ClassConstants.PFLOAT.getName())) || (typeName.equals(ClassConstants.FLOAT.getName()))) {
611
            return "Float";
612
        } else if ((typeName.equals(ClassConstants.PLONG.getName())) || (typeName.equals(ClassConstants.LONG.getName()))) {
613
            return "Long";
614
        } else if ((typeName.equals(ClassConstants.PSHORT.getName())) || (typeName.equals(ClassConstants.SHORT.getName()))) {
615
            return "Short";
616
        } else if ((typeName.equals(ClassConstants.PINT.getName())) || (typeName.equals(ClassConstants.INTEGER.getName()))) {
617
            return "Int";
618
        } else if (typeName.equals(ClassConstants.STRING.getName())) {
619
            return "String";
620
        } else if (typeName.equals(ClassConstants.BIGINTEGER.getName())) {
621
            return "BigInteger";
622
        } else if (typeName.equals(ClassConstants.BIGDECIMAL.getName())) {
623
            return "BigDecimal";
624
        } else if (typeName.equals(ClassConstants.UTILDATE.getName())) {
625
            return "Date";
626
        } else if (typeName.equals("java.util.List")) {
627
            return "List";
628
        }
629
630
        return null;
631
    }
632
633
    public void setGeneratedBuffers(Map generatedBuffersMap) {
607
    public void setGeneratedBuffers(Map generatedBuffersMap) {
634
        generatedBuffers = generatedBuffersMap;
608
        generatedBuffers = generatedBuffersMap;
635
    }
609
    }
Lines 655-675 Link Here
655
        return null;
629
        return null;
656
    }
630
    }
657
631
658
    private String getJavaTypeForProperty(SDOProperty property) {
659
        if (property.isMany() || ((SDOType)property.getType()).isXsdList()) {
660
            return "java.util.List";
661
        } else {
662
            SDOType propertyType = property.getType();
663
            Class instanceClass = propertyType.getInstanceClass();
664
            if (ClassConstants.ABYTE.equals(instanceClass)) {
665
                return "Byte[]";
666
            } else if (ClassConstants.APBYTE.equals(instanceClass)) {
667
                return "byte[]";
668
            }
669
            return propertyType.getInstanceClassName();
670
        }
671
    }
672
673
    public void setCodeWriter(CodeWriter theCodeWriter) {
632
    public void setCodeWriter(CodeWriter theCodeWriter) {
674
        codeWriter = theCodeWriter;
633
        codeWriter = theCodeWriter;
675
    }
634
    }
(-)src/org/eclipse/persistence/sdo/helper/SDOTypesGenerator.java (+1 lines)
Lines 2432-2437 Link Here
2432
            if(sdoType == null) {
2432
            if(sdoType == null) {
2433
                sdoType = new SDOType(typeURI, typeName, sdoTypeHelper);
2433
                sdoType = new SDOType(typeURI, typeName, sdoTypeHelper);
2434
                sdoType.setXsdLocalName(complexType.getName());
2434
                sdoType.setXsdLocalName(complexType.getName());
2435
                sdoType.preInitialize(packageName, namespaceResolvers);
2435
            }
2436
            }
2436
            sdoType.setXsd(true);
2437
            sdoType.setXsd(true);
2437
            if(!sdoType.getQName().equals(sdoType.getXsdType())) {
2438
            if(!sdoType.getQName().equals(sdoType.getXsdType())) {
(-)src/org/eclipse/persistence/sdo/SDOType.java (-1 / +3 lines)
Lines 758-764 Link Here
758
        getXmlDescriptor().setJavaClassName(getImplClassName());
758
        getXmlDescriptor().setJavaClassName(getImplClassName());
759
        // load classes by classloader by getting the current instance class
759
        // load classes by classloader by getting the current instance class
760
        getInstanceClass();
760
        getInstanceClass();
761
        getImplClass();
762
761
763
        // See SDOResolvable enhancement
762
        // See SDOResolvable enhancement
764
        String schemaContext = getName();
763
        String schemaContext = getName();
Lines 807-812 Link Here
807
            sdoRefMapping.setField(xmlField);
806
            sdoRefMapping.setField(xmlField);
808
            xmlDescriptor.addMapping(sdoRefMapping);
807
            xmlDescriptor.addMapping(sdoRefMapping);
809
        }
808
        }
809
        if(!isDataType()) {
810
            getImplClass();
811
        }
810
    }
812
    }
811
813
812
    /**
814
    /**
(-)src/org/eclipse/persistence/sdo/types/SDODataType.java (-1 / +1 lines)
Lines 23-34 Link Here
23
23
24
    public SDODataType(String aUri, String aName, SDOTypeHelper sdoTypeHelper) {
24
    public SDODataType(String aUri, String aName, SDOTypeHelper sdoTypeHelper) {
25
        super(aUri, aName, sdoTypeHelper);
25
        super(aUri, aName, sdoTypeHelper);
26
        isDataType = true;
26
    }
27
    }
27
28
28
    public SDODataType(String aUri, String aName, Class aClass, SDOTypeHelper sdoTypeHelper) {
29
    public SDODataType(String aUri, String aName, Class aClass, SDOTypeHelper sdoTypeHelper) {
29
        this(aUri, aName, sdoTypeHelper);
30
        this(aUri, aName, sdoTypeHelper);
30
        setInstanceClass(aClass);
31
        setInstanceClass(aClass);
31
        isDataType = true;
32
        xmlDescriptor = null;
32
        xmlDescriptor = null;
33
    }
33
    }
34
34

Return to bug 268592