01: /*
02: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/sourcecontrol/ArrayGenerator.java,v 1.1 2005/04/20 22:21:19 paulby Exp $
03: *
04: * Sun Public License Notice
05: *
06: * The contents of this file are subject to the Sun Public License Version
07: * 1.0 (the "License"). You may not use this file except in compliance with
08: * the License. A copy of the License is available at http://www.sun.com/
09: *
10: * The Original Code is the Java 3D(tm) Scene Graph Editor.
11: * The Initial Developer of the Original Code is Jan Becicka.
12: * Portions created by Jan Becicka are Copyright (C) 2002.
13: * All Rights Reserved.
14: *
15: * Contributor(s): Jan Becicka.
16: *
17: **/
18: package org.jdesktop.j3dedit.scenegrapheditor.sourcecontrol;
19:
20: import java.lang.reflect.Array;
21:
22: /**
23: *
24: * @author Jan Becicka
25: * @version
26: */
27: public class ArrayGenerator extends BeanCodeGenerator {
28:
29: public ArrayGenerator(Object bean, NamePool naming) {
30: super (bean, naming);
31: }
32:
33: /** Override this method, if you want to create your own declaration
34: */
35: protected void createDeclarationCode() {
36: declarationCode = beanClassName + "[] " + getFieldName()
37: + ";\n";
38: }
39:
40: /** Override this method, if you want to create parametric constructor constr
41: */
42: protected void createConstructionCode() {
43: StringBuffer buf = new StringBuffer();
44:
45: buf.append(getFieldName() + " = new " + beanClassName + "[] {");
46: int len = Array.getLength(bean);
47: for (int i = 0; i < len; i++) {
48: buf.append(createIdentifier(Array.get(bean, i)));
49: if (i != len - 1)
50: buf.append(" ,");
51: }
52: buf.append("};\n");
53:
54: constructionCode = buf.toString();
55: }
56:
57: /** Override this method, if you want to have different default instance (e.g. YourNean(10))
58: * @return instance of bean
59: */
60: protected Object createDefaultInstanceOfBean() {
61: return new Object();
62: }
63:
64: protected String getClassName() {
65: if (bean.getClass().isArray()) {
66: String name = bean.getClass().getName();
67: if (name.length() <= 2)
68: return naming.getPrimitiveClassFromArray(bean)
69: .getName();
70: return name.substring(2, name.length() - 1);
71: } else
72: return super.getClassName();
73: }
74:
75: }
|