U-1 Support verbose mode in Encoder Tester
authorLixin Tang <ltang@netbeans.org>
Thu, 11 Sep 2008 10:51:18 -0700
changeset 484081fedd1dd7a2
parent 4839 1e4a9946fcad
child 4841 fcceb03ab7b1
U-1 Support verbose mode in Encoder Tester

- Reformat the log message to remove the class name, method name and debug level
- update a few runtime jars that the design-time GUI (especially the tester) depends on
encoder.custom.aip/src/org/netbeans/modules/encoder/custom/aip/EncodingNode.java
encoder.custom.aip/src/org/netbeans/modules/encoder/custom/aip/EncodingOption.java
encoder.custom.aip/src/org/netbeans/modules/encoder/custom/aip/ReadOnlyDelimiterProperty.java
encoder.ui.tester/src/org/netbeans/modules/encoder/ui/tester/impl/LogFormatter.java
     1.1 --- a/encoder.custom.aip/src/org/netbeans/modules/encoder/custom/aip/EncodingNode.java	Thu Aug 28 21:42:47 2008 -0700
     1.2 +++ b/encoder.custom.aip/src/org/netbeans/modules/encoder/custom/aip/EncodingNode.java	Thu Sep 11 10:51:18 2008 -0700
     1.3 @@ -356,7 +356,7 @@
     1.4                      || NodeProperties.NodeType.ARRAY.equals(mEncodingOption.xgetNodeType())) {
     1.5                  PropertySupport.Reflection<String> prop =
     1.6                          new ReadOnlyDelimiterProperty<String>(mEncodingOption,
     1.7 -                                String.class, "getDelimiter");  //NOI18N
     1.8 +                                String.class, "getEndDelimiter");  //NOI18N
     1.9                  prop.setName("delimiter");  //NOI18N
    1.10                  prop.setDisplayName(_bundle.getString("encoding_node.lbl.delimiter"));
    1.11                  propSet.put(prop);
     2.1 --- a/encoder.custom.aip/src/org/netbeans/modules/encoder/custom/aip/EncodingOption.java	Thu Aug 28 21:42:47 2008 -0700
     2.2 +++ b/encoder.custom.aip/src/org/netbeans/modules/encoder/custom/aip/EncodingOption.java	Thu Sep 11 10:51:18 2008 -0700
     2.3 @@ -83,6 +83,7 @@
     2.4      public static final String FIXED_LENGTH_TYPE_PREFIX = "fixedLengthType"; //NOI18N
     2.5      private static final String EMP = ""; //NOI18N
     2.6      private static final String UDS = "_"; //NOI18N
     2.7 +    private static final String MULTI_DELIM_SEPARATOR = ", "; //NOI18N
     2.8  
     2.9      private static final CustomEncoding mDefaultCustomEncoding =
    2.10              CustomEncoding.Factory.newInstance();
    2.11 @@ -312,8 +313,8 @@
    2.12          commitToAppInfo();
    2.13      }
    2.14  
    2.15 -    public String getDelimiter() {
    2.16 -        String delim = computeDelimiter();
    2.17 +    public String getEndDelimiter() {
    2.18 +        String delim = computeEndDelimiter();
    2.19          if (delim == null) {
    2.20              delim = _bundle.getString("encoding_opt.lbl.delim_not_set"); //NOI18N
    2.21          }
    2.22 @@ -1003,7 +1004,7 @@
    2.23              throws ValidationException, SAXException {
    2.24          if (NodeProperties.NodeType.DELIMITED.equals(xgetNodeType())) {
    2.25              //is delimited
    2.26 -            if (computeDelimiter() == null) {
    2.27 +            if (computeEndDelimiter() == null) {
    2.28                  handler.error(
    2.29                          new SAXParseException(
    2.30                              NbBundle.getMessage(
    2.31 @@ -1056,67 +1057,75 @@
    2.32       * @return a comma separate string, e.g. "], }"
    2.33       */
    2.34      private String getDelimitersAsString(DelimiterLevel delimLevel) {
    2.35 -        String delim = null;
    2.36 -        Delimiter[] delimiters;
    2.37 +        String delimString = EMP;
    2.38          // get all delimiters at this delimiter level
    2.39 -        delimiters = delimLevel.getDelimiterArray();
    2.40 -        delim = EMP;
    2.41 +        Delimiter[] delimiters = delimLevel.getDelimiterArray();
    2.42          for (int i = 0; i < delimiters.length; i++) {
    2.43              if (!delimiters[i].isSetBytes()
    2.44                  || !delimiters[i].getBytes().isSetConstant()) {
    2.45 -                // skip non-constant delimiter(s)
    2.46 +                // skip non-constant (i.e. embedded) delimiter(s)
    2.47                  continue;
    2.48              }
    2.49 -            if (delim.length() > 0) {
    2.50 -                delim += ", "; //NOI18N
    2.51 +            if (delimString.length() > 0) {
    2.52 +                // add separator due to multiple delimiters.
    2.53 +                delimString += MULTI_DELIM_SEPARATOR;
    2.54              }
    2.55 -            delim += delimiters[i].getBytes().getConstant();
    2.56 +            delimString += delimiters[i].getBytes().getConstant();
    2.57          }
    2.58 -        if (delim.length() == 0) {
    2.59 -            delim = null;
    2.60 +        if (delimString.length() == 0) {
    2.61 +            delimString = null;
    2.62          }
    2.63 -        return delim;
    2.64 +        return delimString;
    2.65      }
    2.66  
    2.67      /**
    2.68 -     * Compute the delimiter value at current node.
    2.69 -     * @return the computed delimiter value.
    2.70 +     * Compute the end delimiter value at current node.
    2.71 +     * @return the computed end delimiter value.
    2.72       */
    2.73 -    private String computeDelimiter() {
    2.74 +    private String computeEndDelimiter() {
    2.75          // Only delimited or array node needs to compute delimiter
    2.76          if (!NodeProperties.NodeType.DELIMITED.equals(xgetNodeType())
    2.77                  && !NodeProperties.NodeType.ARRAY.equals(xgetNodeType())) {
    2.78              return null;
    2.79          }
    2.80 -        String delim = null;
    2.81 +        String delimAsString = null;
    2.82          DelimiterLevel delimLevel;
    2.83          Delimiter[] delimiters;
    2.84 +        // Check to see if there are local delimiters defined. If so, they
    2.85 +        // takes precedence,
    2.86          if (mDelimiterSet != null) {
    2.87 -            // it means we have local delimiters defined,
    2.88 -            // so we get first delimiter level
    2.89 +            // So we get first delimiter level out of it.
    2.90              delimLevel = mDelimiterSet.getLevelArray(0);
    2.91 -            // we get all delimiters at the given delimiter level as
    2.92 +            // We get all delimiters at the given delimiter level as
    2.93              // comma separated string
    2.94 -            delim = getDelimitersAsString(delimLevel);
    2.95 +            delimAsString = getDelimitersAsString(delimLevel);
    2.96          }
    2.97 -        if (delim != null) {
    2.98 -            return delim;
    2.99 +        if (delimAsString != null) {
   2.100 +            return delimAsString;
   2.101          }
   2.102          SchemaComponent comp;
   2.103          Annotation anno;
   2.104          CustomEncoding customEncoding;
   2.105 -        // Starting from mComponentPath.length - 3, so the current element
   2.106 -        // declaration can be skipped
   2.107 +        // Starting from (mComponentPath.length - 3) and doing bottom-up
   2.108 +        // traverse up the ladder, so the current element declaration can be
   2.109 +        // skipped (i.e. this will skip last 2 SchemaComponent objects in the
   2.110 +        // ladder array, namely, its parent "annotation" node and its
   2.111 +        // grandparent localElement node.) It traverses up the ladder, until it
   2.112 +        // finds an upper hierachy element or elementReference who has
   2.113 +        // annotation that has custom encoding that has node properties with
   2.114 +        // delimiters defined.
   2.115          int level = 0;
   2.116          int i = mComponentPath.length - 3;
   2.117          for (; i >= 0; i--) {
   2.118              comp = mComponentPath[i];
   2.119              if (!(comp instanceof Element)
   2.120                      || comp instanceof ElementReference) {
   2.121 +                // continue to search up in the ladder
   2.122                  continue;
   2.123              }
   2.124              anno = ((Element) comp).getAnnotation();
   2.125              if (anno == null) {
   2.126 +                // continue to search up, and record delimiter level number
   2.127                  level++;
   2.128                  continue;
   2.129              }
   2.130 @@ -1126,32 +1135,39 @@
   2.131                  return _bundle.getString("encoding_opt.lbl.error_retrieving_delim"); //NOI18N
   2.132              }
   2.133              if (customEncoding == null || !customEncoding.isSetNodeProperties()) {
   2.134 +                // continue to search up, and record delimiter level number
   2.135                  level++;
   2.136                  continue;
   2.137              }
   2.138              NodeProperties nProp = customEncoding.getNodeProperties();
   2.139              if (NodeProperties.NodeType.DELIMITED.equals(nProp.getNodeType())
   2.140                  || NodeProperties.NodeType.ARRAY.equals(nProp.getNodeType())) {
   2.141 +                // record delimiter level number
   2.142                  level++;
   2.143              }
   2.144              if (!nProp.isSetDelimiterSet()) {
   2.145 +                // continue to search up
   2.146                  continue;
   2.147              }
   2.148              if (nProp.getDelimiterSet().sizeOfLevelArray() <= level) {
   2.149 +                // defined delimiter level is less than expected. something
   2.150 +                // is not correct.
   2.151                  break;
   2.152              }
   2.153              delimLevel = nProp.getDelimiterSet().getLevelArray(level);
   2.154              delimiters = delimLevel.getDelimiterArray();
   2.155 -            delim = EMP;
   2.156 +            delimAsString = EMP;
   2.157              for (int j = 0; j < delimiters.length; j++) {
   2.158                  if (!delimiters[j].isSetBytes()) {
   2.159                      continue;
   2.160                  }
   2.161                  if (delimiters[j].getBytes().isSetEmbedded()) {
   2.162 -                    if (delim.length() > 0) {
   2.163 -                        delim += ", "; //NOI18N
   2.164 +                    // i.e. embedded delimiter
   2.165 +                    if (delimAsString.length() > 0) {
   2.166 +                        delimAsString += MULTI_DELIM_SEPARATOR;
   2.167                      }
   2.168 -                    delim += (
   2.169 +                    // output as e.g. "...., {embedded:10,2}"
   2.170 +                    delimAsString += (
   2.171                              "{" //NOI18N
   2.172                              + _bundle.getString("encoding_opt.lbl.embedded") //NOI18N
   2.173                              + delimiters[j].getBytes().getEmbedded().getOffset()
   2.174 @@ -1159,18 +1175,19 @@
   2.175                              + delimiters[j].getBytes().getEmbedded().getLength()
   2.176                              + "}"); //NOI18N
   2.177                  } else if (delimiters[j].getBytes().isSetConstant()) {
   2.178 -                    if (delim.length() > 0) {
   2.179 -                        delim += ", "; //NOI18N
   2.180 +                    // i.e. regular constant delimiter
   2.181 +                    if (delimAsString.length() > 0) {
   2.182 +                        delimAsString += MULTI_DELIM_SEPARATOR;
   2.183                      }
   2.184 -                    delim += delimiters[j].getBytes().getConstant();
   2.185 +                    delimAsString += delimiters[j].getBytes().getConstant();
   2.186                  }
   2.187 -            }
   2.188 -            if (delim.length() == 0) {
   2.189 -                delim = null;
   2.190 +            } // end-- for (int j = 0 ...)
   2.191 +            if (delimAsString.length() == 0) {
   2.192 +                delimAsString = null;
   2.193              }
   2.194              break;
   2.195 -        }
   2.196 -        return delim;
   2.197 +        } // end-- for (; i >= 0; i--)
   2.198 +        return delimAsString;
   2.199      }
   2.200  
   2.201      private Annotation annotation() {
     3.1 --- a/encoder.custom.aip/src/org/netbeans/modules/encoder/custom/aip/ReadOnlyDelimiterProperty.java	Thu Aug 28 21:42:47 2008 -0700
     3.2 +++ b/encoder.custom.aip/src/org/netbeans/modules/encoder/custom/aip/ReadOnlyDelimiterProperty.java	Thu Sep 11 10:51:18 2008 -0700
     3.3 @@ -48,6 +48,6 @@
     3.4      @Override
     3.5      public T getValue() throws IllegalAccessException, IllegalArgumentException,
     3.6          InvocationTargetException {
     3.7 -        return (T) mEncodingOption.getDelimiter();
     3.8 +        return (T) mEncodingOption.getEndDelimiter();
     3.9      }
    3.10  }
     4.1 --- a/encoder.ui.tester/src/org/netbeans/modules/encoder/ui/tester/impl/LogFormatter.java	Thu Aug 28 21:42:47 2008 -0700
     4.2 +++ b/encoder.ui.tester/src/org/netbeans/modules/encoder/ui/tester/impl/LogFormatter.java	Thu Sep 11 10:51:18 2008 -0700
     4.3 @@ -45,26 +45,26 @@
     4.4      public synchronized String format(final LogRecord record) {
     4.5          StringBuffer sb = new StringBuffer();
     4.6          // Minimize memory allocations here.
     4.7 -        String srcClassName = record.getSourceClassName();
     4.8 -        if (srcClassName != null) {
     4.9 -            int dot = srcClassName.lastIndexOf(".");
    4.10 -            if (dot > 0) {
    4.11 -                srcClassName = srcClassName.substring(dot + 1);
    4.12 -            }
    4.13 -            sb.append(srcClassName);
    4.14 -        } else {
    4.15 -            sb.append(record.getLoggerName());
    4.16 -        }
    4.17 -        if (record.getSourceMethodName() != null) {
    4.18 -            sb.append("#");
    4.19 -            sb.append(record.getSourceMethodName()).append("()");
    4.20 -        }
    4.21 +//        String srcClassName = record.getSourceClassName();
    4.22 +//        if (srcClassName != null) {
    4.23 +//            int dot = srcClassName.lastIndexOf(".");
    4.24 +//            if (dot > 0) {
    4.25 +//                srcClassName = srcClassName.substring(dot + 1);
    4.26 +//            }
    4.27 +//            sb.append(srcClassName);
    4.28 +//        } else {
    4.29 +//            sb.append(record.getLoggerName());
    4.30 +//        }
    4.31 +//        if (record.getSourceMethodName() != null) {
    4.32 +//            sb.append("#");
    4.33 +//            sb.append(record.getSourceMethodName()).append("()");
    4.34 +//        }
    4.35          /*
    4.36          String debugLevel = record.getLevel().getLocalizedName();
    4.37          sb.append(" [").append(debugLevel).append("]");
    4.38          */
    4.39 -        sb.append(":");
    4.40 -        sb.append(lineSeparator);
    4.41 +//        sb.append(":");
    4.42 +//        sb.append(lineSeparator);
    4.43          String message = formatMessage(record);
    4.44          sb.append(message);
    4.45          sb.append(lineSeparator);