View Javadoc

1   package com.tapina.robe.module;
2   
3   import com.tapina.robe.runtime.ByteArrayUtils;
4   import com.tapina.robe.runtime.DataBlock;
5   
6   import java.util.logging.Logger;
7   
8   /***
9    * This interface represents a RISC OS Module.
10   * Other interfaces represent additional capabilities of modules.
11   * @see com.tapina.robe.swi.SWIHandler
12   */
13  public abstract class Module extends DataBlock {
14      private static final int TITLE_STRING = 0x10;
15      private static final int HELP_STRING = 0x14;
16  
17      protected final Logger log = Logger.getLogger(getClass().getName());
18  
19      protected Module() {
20          super(0);
21      }
22  
23      public String getName() {
24          final String className = getClass().getName();
25          return className.substring(className.lastIndexOf('.') + 1);
26      }
27  
28      public String getHelp() {
29          final String name = getName();
30          final StringBuffer help = new StringBuffer(name.length() + 40);
31          help.append(name);
32          if (name.length() < 8) {
33              help.append('\t');
34          }
35          help.append('\t').append("9.99 (06 Jun 2005) ROBE");
36          return help.toString();
37      }
38  
39      byte[] data = null;
40  
41      public final int getSize() {
42          return 0x34 + getName().length() + getHelp().length() + 2;
43      }
44  
45      public final void setSize(int newSize) {
46          throw new UnsupportedOperationException("Cannot set size of a module");
47      }
48  
49      public byte[] getBytes() {
50          if (data == null) {
51              data = new byte[getSize()];
52              final int titleOffset = 0x34;
53              ByteArrayUtils.putInt(data, TITLE_STRING, titleOffset);
54              ByteArrayUtils.putString0(data, titleOffset, getName());
55              final int helpOffset = titleOffset + getName().length() + 1;
56              ByteArrayUtils.putInt(data, HELP_STRING, helpOffset);
57              ByteArrayUtils.putString0(data, helpOffset, getHelp());
58          }
59          return data;
60      }
61  }