You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2020/08/23 20:16:46 UTC
svn commit: r1881117 [4/6] - in /xmlbeans/trunk/src:
main/java/org/apache/xmlbeans/impl/repackage/
main/java/org/apache/xmlbeans/impl/richParser/
main/java/org/apache/xmlbeans/impl/schema/
main/java/org/apache/xmlbeans/impl/tool/ main/java/org/apache/x...
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XsbDumper.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XsbDumper.java?rev=1881117&r1=1881116&r2=1881117&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XsbDumper.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XsbDumper.java Sun Aug 23 20:16:45 2020
@@ -15,30 +15,21 @@
package org.apache.xmlbeans.impl.tool;
-import java.util.*;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipEntry;
-import java.io.*;
-import java.math.BigInteger;
-
-
+import org.apache.xmlbeans.*;
import org.apache.xmlbeans.impl.common.QNameHelper;
import org.apache.xmlbeans.impl.util.HexBin;
-import org.apache.xmlbeans.QNameSet;
-import org.apache.xmlbeans.SchemaLocalAttribute;
-import org.apache.xmlbeans.SchemaParticle;
-import org.apache.xmlbeans.SchemaProperty;
-import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.soap.SOAPArrayType;
-import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
+
import javax.xml.namespace.QName;
+import java.io.*;
+import java.math.BigInteger;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
-public class XsbDumper
-{
- public static void printUsage()
- {
+public class XsbDumper {
+ public static void printUsage() {
System.out.println("Prints the contents of an XSB file in human-readable form.");
System.out.println("An XSB file contains schema meta information needed to ");
System.out.println("perform tasks such as binding and validation.");
@@ -47,110 +38,118 @@ public class XsbDumper
System.out.println();
}
- public static void main(String[] args)
- {
+ public static void main(String[] args) {
if (args.length == 0) {
printUsage();
System.exit(0);
return;
}
- for (int i = 0; i < args.length; i++)
- {
+ for (int i = 0; i < args.length; i++) {
dump(new File(args[i]), true);
}
}
- private static void dump(File file, boolean force)
- {
- if (file.isDirectory())
- {
+ private static void dump(File file, boolean force) {
+ if (file.isDirectory()) {
File[] files = file.listFiles(
- new FileFilter()
- {
- public boolean accept(File file)
- { return file.isDirectory() || file.isFile() && file.getName().endsWith(".xsb"); }
+ new FileFilter() {
+ public boolean accept(File file) {
+ return file.isDirectory() || file.isFile() && file.getName().endsWith(".xsb");
+ }
}
);
- for (int i = 0; i < files.length; i++)
- {
+ for (int i = 0; i < files.length; i++) {
dump(files[i], false);
}
- }
- else if (file.getName().endsWith(".jar") || file.getName().endsWith(".zip"))
- {
+ } else if (file.getName().endsWith(".jar") || file.getName().endsWith(".zip")) {
dumpZip(file);
- }
- else if (force || file.getName().endsWith(".xsb"))
- {
- try
- {
+ } else if (force || file.getName().endsWith(".xsb")) {
+ try {
System.out.println(file.toString());
dump(new FileInputStream(file), " ");
System.out.println();
- }
- catch (FileNotFoundException e)
- {
+ } catch (FileNotFoundException e) {
System.out.println(e.toString());
}
}
}
- public static void dumpZip(File file)
- {
- try
- {
+ public static void dumpZip(File file) {
+ try {
ZipFile zipFile = new ZipFile(file);
Enumeration e = zipFile.entries();
- while (e.hasMoreElements())
- {
- ZipEntry entry = (ZipEntry)e.nextElement();
- if (entry.getName().endsWith(".xsb"))
- {
+ while (e.hasMoreElements()) {
+ ZipEntry entry = (ZipEntry) e.nextElement();
+ if (entry.getName().endsWith(".xsb")) {
System.out.println(entry.getName());
dump(zipFile.getInputStream(entry), " ");
System.out.println();
}
}
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
System.out.println(e.toString());
}
}
- public static void dump(InputStream input)
- {
+ public static void dump(InputStream input) {
dump(input, "", System.out);
}
- public static void dump(InputStream input, String indent)
- {
+ public static void dump(InputStream input, String indent) {
dump(input, indent, System.out);
}
- public static void dump(InputStream input, String indent, PrintStream output)
- {
+ public static void dump(InputStream input, String indent, PrintStream output) {
XsbDumper dumper = new XsbDumper(input, indent, output);
dumper.dumpAll();
}
- private XsbDumper(InputStream stream, String indent, PrintStream ostream)
- {
+ private XsbDumper(InputStream stream, String indent, PrintStream ostream) {
_input = new DataInputStream(stream);
_indent = indent;
_out = ostream;
}
- void flush() { _out.flush(); }
- void emit(String str) { _out.println(_indent + str); flush(); }
- void emit() { _out.println(); flush(); }
- void error(Exception e) { _out.println(e.toString()); flush(); IllegalStateException e2 = new IllegalStateException( e.getMessage() ); e2.initCause( e ); throw e2; }
- void error(String str) { _out.println(str); flush(); IllegalStateException e2 = new IllegalStateException( str ); throw e2; }
+ void flush() {
+ _out.flush();
+ }
+
+ void emit(String str) {
+ _out.println(_indent + str);
+ flush();
+ }
+
+ void emit() {
+ _out.println();
+ flush();
+ }
+
+ void error(Exception e) {
+ _out.println(e.toString());
+ flush();
+ IllegalStateException e2 = new IllegalStateException(e.getMessage());
+ e2.initCause(e);
+ throw e2;
+ }
+
+ void error(String str) {
+ _out.println(str);
+ flush();
+ IllegalStateException e2 = new IllegalStateException(str);
+ throw e2;
+ }
+
private String _indent;
private PrintStream _out;
- void indent() { _indent += " "; }
- void outdent() { _indent = _indent.substring(0, _indent.length() - 2); }
+
+ void indent() {
+ _indent += " ";
+ }
+
+ void outdent() {
+ _indent = _indent.substring(0, _indent.length() - 2);
+ }
public static final int DATA_BABE = 0xDA7ABABE;
public static final int MAJOR_VERSION = 2;
@@ -164,17 +163,22 @@ public class XsbDumper
public static final int FILETYPE_SCHEMAMODELGROUP = 6;
public static final int FILETYPE_SCHEMAATTRIBUTEGROUP = 7;
- static String filetypeString(int code)
- {
- switch (code)
- {
- case FILETYPE_SCHEMAINDEX: return "FILETYPE_SCHEMAINDEX";
- case FILETYPE_SCHEMATYPE: return "FILETYPE_SCHEMATYPE";
- case FILETYPE_SCHEMAELEMENT: return "FILETYPE_SCHEMAELEMENT";
- case FILETYPE_SCHEMAATTRIBUTE: return "FILETYPE_SCHEMAATTRIBUTE";
- case FILETYPE_SCHEMAPOINTER: return "FILETYPE_SCHEMAPOINTER";
- case FILETYPE_SCHEMAMODELGROUP: return "FILETYPE_SCHEMAMODELGROUP";
- case FILETYPE_SCHEMAATTRIBUTEGROUP: return "FILETYPE_SCHEMAATTRIBUTEGROUP";
+ static String filetypeString(int code) {
+ switch (code) {
+ case FILETYPE_SCHEMAINDEX:
+ return "FILETYPE_SCHEMAINDEX";
+ case FILETYPE_SCHEMATYPE:
+ return "FILETYPE_SCHEMATYPE";
+ case FILETYPE_SCHEMAELEMENT:
+ return "FILETYPE_SCHEMAELEMENT";
+ case FILETYPE_SCHEMAATTRIBUTE:
+ return "FILETYPE_SCHEMAATTRIBUTE";
+ case FILETYPE_SCHEMAPOINTER:
+ return "FILETYPE_SCHEMAPOINTER";
+ case FILETYPE_SCHEMAMODELGROUP:
+ return "FILETYPE_SCHEMAMODELGROUP";
+ case FILETYPE_SCHEMAATTRIBUTEGROUP:
+ return "FILETYPE_SCHEMAATTRIBUTEGROUP";
default:
return "Unknown FILETYPE (" + code + ")";
}
@@ -190,19 +194,38 @@ public class XsbDumper
public static final int FLAG_PART_FINALEXT = 256;
public static final int FLAG_PART_FINALREST = 512;
- static String particleflagsString(int flags)
- {
+ static String particleflagsString(int flags) {
StringBuilder result = new StringBuilder();
- if ((flags & FLAG_PART_SKIPPABLE) != 0) result.append("FLAG_PART_SKIPPABLE | ");
- if ((flags & FLAG_PART_FIXED) != 0) result.append("FLAG_PART_FIXED | ");
- if ((flags & FLAG_PART_NILLABLE) != 0) result.append("FLAG_PART_NILLABLE | ");
- if ((flags & FLAG_PART_BLOCKEXT) != 0) result.append("FLAG_PART_BLOCKEXT | ");
- if ((flags & FLAG_PART_BLOCKREST) != 0) result.append("FLAG_PART_BLOCKREST | ");
- if ((flags & FLAG_PART_BLOCKSUBST) != 0) result.append("FLAG_PART_BLOCKSUBST | ");
- if ((flags & FLAG_PART_ABSTRACT) != 0) result.append("FLAG_PART_ABSTRACT | ");
- if ((flags & FLAG_PART_FINALEXT) != 0) result.append("FLAG_PART_FINALEXT | ");
- if ((flags & FLAG_PART_FINALREST) != 0) result.append("FLAG_PART_FINALREST | ");
- if (result.length() == 0) result.append("0 | ");
+ if ((flags & FLAG_PART_SKIPPABLE) != 0) {
+ result.append("FLAG_PART_SKIPPABLE | ");
+ }
+ if ((flags & FLAG_PART_FIXED) != 0) {
+ result.append("FLAG_PART_FIXED | ");
+ }
+ if ((flags & FLAG_PART_NILLABLE) != 0) {
+ result.append("FLAG_PART_NILLABLE | ");
+ }
+ if ((flags & FLAG_PART_BLOCKEXT) != 0) {
+ result.append("FLAG_PART_BLOCKEXT | ");
+ }
+ if ((flags & FLAG_PART_BLOCKREST) != 0) {
+ result.append("FLAG_PART_BLOCKREST | ");
+ }
+ if ((flags & FLAG_PART_BLOCKSUBST) != 0) {
+ result.append("FLAG_PART_BLOCKSUBST | ");
+ }
+ if ((flags & FLAG_PART_ABSTRACT) != 0) {
+ result.append("FLAG_PART_ABSTRACT | ");
+ }
+ if ((flags & FLAG_PART_FINALEXT) != 0) {
+ result.append("FLAG_PART_FINALEXT | ");
+ }
+ if ((flags & FLAG_PART_FINALREST) != 0) {
+ result.append("FLAG_PART_FINALREST | ");
+ }
+ if (result.length() == 0) {
+ result.append("0 | ");
+ }
return result.substring(0, result.length() - 3);
}
@@ -211,14 +234,23 @@ public class XsbDumper
public static final int FLAG_PROP_JAVAOPTIONAL = 4;
public static final int FLAG_PROP_JAVAARRAY = 8;
- static String propertyflagsString(int flags)
- {
+ static String propertyflagsString(int flags) {
StringBuilder result = new StringBuilder();
- if ((flags & FLAG_PROP_ISATTR) != 0) result.append("FLAG_PROP_ISATTR | ");
- if ((flags & FLAG_PROP_JAVASINGLETON) != 0) result.append("FLAG_PROP_JAVASINGLETON | ");
- if ((flags & FLAG_PROP_JAVAOPTIONAL) != 0) result.append("FLAG_PROP_JAVAOPTIONAL | ");
- if ((flags & FLAG_PROP_JAVAARRAY) != 0) result.append("FLAG_PROP_JAVAARRAY | ");
- if (result.length() == 0) result.append("0 | ");
+ if ((flags & FLAG_PROP_ISATTR) != 0) {
+ result.append("FLAG_PROP_ISATTR | ");
+ }
+ if ((flags & FLAG_PROP_JAVASINGLETON) != 0) {
+ result.append("FLAG_PROP_JAVASINGLETON | ");
+ }
+ if ((flags & FLAG_PROP_JAVAOPTIONAL) != 0) {
+ result.append("FLAG_PROP_JAVAOPTIONAL | ");
+ }
+ if ((flags & FLAG_PROP_JAVAARRAY) != 0) {
+ result.append("FLAG_PROP_JAVAARRAY | ");
+ }
+ if (result.length() == 0) {
+ result.append("0 | ");
+ }
return result.substring(0, result.length() - 3);
}
@@ -227,72 +259,111 @@ public class XsbDumper
public static final int FIELD_LOCALATTR = 2;
public static final int FIELD_LOCALELT = 3;
- static String containerfieldTypeString(int code)
- {
- switch (code)
- {
- case FIELD_NONE: return "FIELD_NONE";
- case FIELD_GLOBAL: return "FIELD_GLOBAL";
- case FIELD_LOCALATTR: return "FIELD_LOCALATTR";
- case FIELD_LOCALELT: return "FIELD_LOCALELT";
+ static String containerfieldTypeString(int code) {
+ switch (code) {
+ case FIELD_NONE:
+ return "FIELD_NONE";
+ case FIELD_GLOBAL:
+ return "FIELD_GLOBAL";
+ case FIELD_LOCALATTR:
+ return "FIELD_LOCALATTR";
+ case FIELD_LOCALELT:
+ return "FIELD_LOCALELT";
default:
return "Unknown container field type (" + code + ")";
}
}
// type flags
- static final int FLAG_SIMPLE_TYPE = 0x1;
- static final int FLAG_DOCUMENT_TYPE = 0x2;
- static final int FLAG_ORDERED = 0x4;
- static final int FLAG_BOUNDED = 0x8;
- static final int FLAG_FINITE = 0x10;
- static final int FLAG_NUMERIC = 0x20;
- static final int FLAG_STRINGENUM = 0x40;
- static final int FLAG_UNION_OF_LISTS = 0x80;
- static final int FLAG_HAS_PATTERN = 0x100;
+ static final int FLAG_SIMPLE_TYPE = 0x1;
+ static final int FLAG_DOCUMENT_TYPE = 0x2;
+ static final int FLAG_ORDERED = 0x4;
+ static final int FLAG_BOUNDED = 0x8;
+ static final int FLAG_FINITE = 0x10;
+ static final int FLAG_NUMERIC = 0x20;
+ static final int FLAG_STRINGENUM = 0x40;
+ static final int FLAG_UNION_OF_LISTS = 0x80;
+ static final int FLAG_HAS_PATTERN = 0x100;
static final int FLAG_ORDER_SENSITIVE = 0x200;
- static final int FLAG_TOTAL_ORDER = 0x400;
- static final int FLAG_COMPILED = 0x800;
- static final int FLAG_BLOCK_EXT = 0x1000;
- static final int FLAG_BLOCK_REST = 0x2000;
- static final int FLAG_FINAL_EXT = 0x4000;
- static final int FLAG_FINAL_REST = 0x8000;
- static final int FLAG_FINAL_UNION = 0x10000;
- static final int FLAG_FINAL_LIST = 0x20000;
- static final int FLAG_ABSTRACT = 0x40000;
- static final int FLAG_ATTRIBUTE_TYPE = 0x80000;
+ static final int FLAG_TOTAL_ORDER = 0x400;
+ static final int FLAG_COMPILED = 0x800;
+ static final int FLAG_BLOCK_EXT = 0x1000;
+ static final int FLAG_BLOCK_REST = 0x2000;
+ static final int FLAG_FINAL_EXT = 0x4000;
+ static final int FLAG_FINAL_REST = 0x8000;
+ static final int FLAG_FINAL_UNION = 0x10000;
+ static final int FLAG_FINAL_LIST = 0x20000;
+ static final int FLAG_ABSTRACT = 0x40000;
+ static final int FLAG_ATTRIBUTE_TYPE = 0x80000;
- static String typeflagsString(int flags)
- {
+ static String typeflagsString(int flags) {
StringBuilder result = new StringBuilder();
- if ((flags & FLAG_SIMPLE_TYPE) != 0) result.append("FLAG_SIMPLE_TYPE | ");
- if ((flags & FLAG_DOCUMENT_TYPE) != 0) result.append("FLAG_DOCUMENT_TYPE | ");
- if ((flags & FLAG_ATTRIBUTE_TYPE) != 0) result.append("FLAG_ATTRIBUTE_TYPE | ");
- if ((flags & FLAG_ORDERED) != 0) result.append("FLAG_ORDERED | ");
- if ((flags & FLAG_BOUNDED) != 0) result.append("FLAG_BOUNDED | ");
- if ((flags & FLAG_FINITE) != 0) result.append("FLAG_FINITE | ");
- if ((flags & FLAG_NUMERIC) != 0) result.append("FLAG_NUMERIC | ");
- if ((flags & FLAG_STRINGENUM) != 0) result.append("FLAG_STRINGENUM | ");
- if ((flags & FLAG_UNION_OF_LISTS) != 0) result.append("FLAG_UNION_OF_LISTS | ");
- if ((flags & FLAG_HAS_PATTERN) != 0) result.append("FLAG_HAS_PATTERN | ");
- if ((flags & FLAG_TOTAL_ORDER) != 0) result.append("FLAG_TOTAL_ORDER | ");
- if ((flags & FLAG_COMPILED) != 0) result.append("FLAG_COMPILED | ");
- if ((flags & FLAG_BLOCK_EXT) != 0) result.append("FLAG_BLOCK_EXT | ");
- if ((flags & FLAG_BLOCK_REST) != 0) result.append("FLAG_BLOCK_REST | ");
- if ((flags & FLAG_FINAL_EXT) != 0) result.append("FLAG_FINAL_EXT | ");
- if ((flags & FLAG_FINAL_REST) != 0) result.append("FLAG_FINAL_REST | ");
- if ((flags & FLAG_FINAL_UNION) != 0) result.append("FLAG_FINAL_UNION | ");
- if ((flags & FLAG_FINAL_LIST) != 0) result.append("FLAG_FINAL_LIST | ");
- if ((flags & FLAG_ABSTRACT) != 0) result.append("FLAG_ABSTRACT | ");
- if (result.length() == 0) result.append("0 | ");
+ if ((flags & FLAG_SIMPLE_TYPE) != 0) {
+ result.append("FLAG_SIMPLE_TYPE | ");
+ }
+ if ((flags & FLAG_DOCUMENT_TYPE) != 0) {
+ result.append("FLAG_DOCUMENT_TYPE | ");
+ }
+ if ((flags & FLAG_ATTRIBUTE_TYPE) != 0) {
+ result.append("FLAG_ATTRIBUTE_TYPE | ");
+ }
+ if ((flags & FLAG_ORDERED) != 0) {
+ result.append("FLAG_ORDERED | ");
+ }
+ if ((flags & FLAG_BOUNDED) != 0) {
+ result.append("FLAG_BOUNDED | ");
+ }
+ if ((flags & FLAG_FINITE) != 0) {
+ result.append("FLAG_FINITE | ");
+ }
+ if ((flags & FLAG_NUMERIC) != 0) {
+ result.append("FLAG_NUMERIC | ");
+ }
+ if ((flags & FLAG_STRINGENUM) != 0) {
+ result.append("FLAG_STRINGENUM | ");
+ }
+ if ((flags & FLAG_UNION_OF_LISTS) != 0) {
+ result.append("FLAG_UNION_OF_LISTS | ");
+ }
+ if ((flags & FLAG_HAS_PATTERN) != 0) {
+ result.append("FLAG_HAS_PATTERN | ");
+ }
+ if ((flags & FLAG_TOTAL_ORDER) != 0) {
+ result.append("FLAG_TOTAL_ORDER | ");
+ }
+ if ((flags & FLAG_COMPILED) != 0) {
+ result.append("FLAG_COMPILED | ");
+ }
+ if ((flags & FLAG_BLOCK_EXT) != 0) {
+ result.append("FLAG_BLOCK_EXT | ");
+ }
+ if ((flags & FLAG_BLOCK_REST) != 0) {
+ result.append("FLAG_BLOCK_REST | ");
+ }
+ if ((flags & FLAG_FINAL_EXT) != 0) {
+ result.append("FLAG_FINAL_EXT | ");
+ }
+ if ((flags & FLAG_FINAL_REST) != 0) {
+ result.append("FLAG_FINAL_REST | ");
+ }
+ if ((flags & FLAG_FINAL_UNION) != 0) {
+ result.append("FLAG_FINAL_UNION | ");
+ }
+ if ((flags & FLAG_FINAL_LIST) != 0) {
+ result.append("FLAG_FINAL_LIST | ");
+ }
+ if ((flags & FLAG_ABSTRACT) != 0) {
+ result.append("FLAG_ABSTRACT | ");
+ }
+ if (result.length() == 0) {
+ result.append("0 | ");
+ }
return result.substring(0, result.length() - 3);
}
- void dumpAll()
- {
+ void dumpAll() {
int filetype = dumpHeader();
- switch (filetype)
- {
+ switch (filetype) {
case FILETYPE_SCHEMAINDEX:
dumpIndexData();
return;
@@ -318,33 +389,30 @@ public class XsbDumper
readEnd();
}
- static String hex32String(int i)
- {
+ static String hex32String(int i) {
return Integer.toHexString(i);
}
- protected int dumpHeader()
- {
+ protected int dumpHeader() {
int magic = readInt();
emit("Magic cookie: " + hex32String(magic));
- if (magic != DATA_BABE)
- {
+ if (magic != DATA_BABE) {
emit("Wrong magic cookie.");
return 0;
}
_majorver = readShort();
_minorver = readShort();
- if (atLeast(2, 18, 0))
+ if (atLeast(2, 18, 0)) {
_releaseno = readShort();
+ }
emit("Major version: " + _majorver);
emit("Minor version: " + _minorver);
emit("Release number: " + _releaseno);
- if (_majorver != MAJOR_VERSION || _minorver > MINOR_VERSION)
- {
+ if (_majorver != MAJOR_VERSION || _minorver > MINOR_VERSION) {
emit("Incompatible version.");
return 0;
}
@@ -358,19 +426,16 @@ public class XsbDumper
return actualfiletype;
}
- void dumpPointerData()
- {
+ void dumpPointerData() {
emit("Type system: " + readString());
}
- protected void dumpIndexData()
- {
+ protected void dumpIndexData() {
// has a handle pool (count, handle/type, handle/type...)
int size = readShort();
emit("Handle pool (" + size + "):");
indent();
- for (int i = 0; i < size; i++)
- {
+ for (int i = 0; i < size; i++) {
String handle = readString();
int code = readShort();
emit(handle + " (" + filetypeString(code) + ")");
@@ -404,45 +469,42 @@ public class XsbDumper
dumpStringArray("Defined namespaces");
// version 15 stuff for redefines
- if (atLeast(2, 15, 0))
- {
+ if (atLeast(2, 15, 0)) {
dumpQNameMap("Redefined global types");
dumpQNameMap("Redfined model groups");
dumpQNameMap("Redfined attribute groups");
}
// version 19 annotations
- if (atLeast(2, 19, 0))
+ if (atLeast(2, 19, 0)) {
dumpAnnotations();
+ }
readEnd();
}
- class StringPool
- {
+ class StringPool {
private List intsToStrings = new ArrayList();
private Map stringsToInts = new HashMap();
- StringPool()
- {
+ StringPool() {
intsToStrings.add(null);
}
- String stringForCode(int code)
- {
- if (code == 0)
+ String stringForCode(int code) {
+ if (code == 0) {
return null;
- return (String)intsToStrings.get(code);
+ }
+ return (String) intsToStrings.get(code);
}
- int codeForString(String str)
- {
- if (str == null)
+ int codeForString(String str) {
+ if (str == null) {
return 0;
- Integer result = (Integer)stringsToInts.get(str);
- if (result == null)
- {
+ }
+ Integer result = (Integer) stringsToInts.get(str);
+ if (result == null) {
result = new Integer(intsToStrings.size());
intsToStrings.add(str);
stringsToInts.put(str, result);
@@ -450,28 +512,25 @@ public class XsbDumper
return result.intValue();
}
- void readFrom(DataInputStream input)
- {
- if (intsToStrings.size() != 1 || stringsToInts.size() != 0)
+ void readFrom(DataInputStream input) {
+ if (intsToStrings.size() != 1 || stringsToInts.size() != 0) {
throw new IllegalStateException();
+ }
- try
- {
+ try {
int size = input.readShort();
emit("String pool (" + size + "):");
indent();
- for (int i = 1; i < size; i++)
- {
+ for (int i = 1; i < size; i++) {
String str = input.readUTF();
int code = codeForString(str);
- if (code != i)
+ if (code != i) {
throw new IllegalStateException();
+ }
emit(code + " = \"" + str + "\"");
}
outdent();
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
emit(e.toString());
}
}
@@ -481,237 +540,218 @@ public class XsbDumper
DataInputStream _input;
StringPool _stringPool;
- int readShort()
- {
- try
- {
+ int readShort() {
+ try {
return _input.readUnsignedShort();
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
error(e);
return 0;
}
}
- int readInt()
- {
- try
- {
+ int readInt() {
+ try {
return _input.readInt();
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
error(e);
return 0;
}
}
- String readString()
- {
+ String readString() {
return _stringPool.stringForCode(readShort());
}
- QName readQName()
- {
+ QName readQName() {
String namespace = readString();
String localname = readString();
- if (localname == null)
+ if (localname == null) {
return null;
+ }
return new QName(namespace, localname);
}
- String readHandle()
- {
+ String readHandle() {
return readString();
}
- String readType()
- {
+ String readType() {
return readHandle();
}
- static String qnameString(QName qname)
- {
- if (qname == null)
+ static String qnameString(QName qname) {
+ if (qname == null) {
return "(null)";
- if (qname.getNamespaceURI() != null)
+ }
+ if (qname.getNamespaceURI() != null) {
return qname.getLocalPart() + "@" + qname.getNamespaceURI();
- else
+ } else {
return qname.getLocalPart();
+ }
}
- static String qnameSetString(QNameSet set)
- {
+ static String qnameSetString(QNameSet set) {
return set.toString();
}
- void dumpQNameMap(String fieldname)
- {
+ void dumpQNameMap(String fieldname) {
int size = readShort();
emit(fieldname + " (" + size + "):");
indent();
- for (int i = 0; i < size; i++)
- {
+ for (int i = 0; i < size; i++) {
emit(qnameString(readQName()) + " = " + readHandle());
}
outdent();
}
- void dumpTypeArray(String fieldname)
- {
+ void dumpTypeArray(String fieldname) {
int size = readShort();
emit(fieldname + " (" + size + "):");
indent();
- for (int i = 0; i < size; i++)
- {
+ for (int i = 0; i < size; i++) {
emit(i + " = " + readType());
}
outdent();
}
- void dumpClassnameIndex(String fieldname)
- {
+ void dumpClassnameIndex(String fieldname) {
int size = readShort();
emit(fieldname + " (" + size + "):");
indent();
- for (int i = 0; i < size; i++)
- {
+ for (int i = 0; i < size; i++) {
emit(readString() + " = " + readType());
}
outdent();
}
- void dumpStringArray(String fieldname)
- {
+ void dumpStringArray(String fieldname) {
int size = readShort();
emit(fieldname + " (" + size + "):");
indent();
- for (int i = 0; i < size; i++)
- {
+ for (int i = 0; i < size; i++) {
emit(readString());
}
outdent();
}
- void readEnd()
- {
- try
- {
+ void readEnd() {
+ try {
_input.close();
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
// oh, well.
}
_input = null;
_stringPool = null;
}
- static String particleTypeString(int spt)
- {
- switch (spt)
- {
- case SchemaParticle.ALL: return "ALL";
- case SchemaParticle.CHOICE: return "CHOICE";
- case SchemaParticle.ELEMENT: return "ELEMENT";
- case SchemaParticle.SEQUENCE: return "SEQUENCE";
- case SchemaParticle.WILDCARD: return "WILDCARD";
+ static String particleTypeString(int spt) {
+ switch (spt) {
+ case SchemaParticle.ALL:
+ return "ALL";
+ case SchemaParticle.CHOICE:
+ return "CHOICE";
+ case SchemaParticle.ELEMENT:
+ return "ELEMENT";
+ case SchemaParticle.SEQUENCE:
+ return "SEQUENCE";
+ case SchemaParticle.WILDCARD:
+ return "WILDCARD";
default:
return "Unknown particle type (" + spt + ")";
}
}
- static String bigIntegerString(BigInteger bigint)
- {
- if (bigint == null)
+ static String bigIntegerString(BigInteger bigint) {
+ if (bigint == null) {
return "(null)";
+ }
return bigint.toString();
}
- static String wcprocessString(int code)
- {
- switch (code)
- {
- case SchemaParticle.STRICT: return "STRICT";
- case SchemaParticle.SKIP: return "SKIP";
- case SchemaParticle.LAX: return "LAX";
- case 0: return "NOT_WILDCARD";
+ static String wcprocessString(int code) {
+ switch (code) {
+ case SchemaParticle.STRICT:
+ return "STRICT";
+ case SchemaParticle.SKIP:
+ return "SKIP";
+ case SchemaParticle.LAX:
+ return "LAX";
+ case 0:
+ return "NOT_WILDCARD";
default:
return "Unknown process type (" + code + ")";
}
}
- void dumpAnnotation()
- {
- if (!atLeast(2, 19, 0))
+ void dumpAnnotation() {
+ if (!atLeast(2, 19, 0)) {
return; // no annotations in this version of the file
+ }
int n = readInt();
- if (n == -1)
+ if (n == -1) {
return; // no annotation present
+ }
emit("Annotation");
boolean empty = true;
indent();
- if (n > 0)
- {
+ if (n > 0) {
emit("Attributes (" + n + "):");
indent();
- for (int i = 0; i < n; i++)
- {
- if (atLeast(2, 24, 0))
+ for (int i = 0; i < n; i++) {
+ if (atLeast(2, 24, 0)) {
emit("Name: " + qnameString(readQName()) +
- ", Value: " + readString() +
- ", ValueURI: " + readString());
- else
+ ", Value: " + readString() +
+ ", ValueURI: " + readString());
+ } else {
emit("Name: " + qnameString(readQName()) +
- ", Value: " + readString());
+ ", Value: " + readString());
+ }
}
outdent();
empty = false;
}
n = readInt();
- if (n > 0)
- {
+ if (n > 0) {
emit("Documentation elements (" + n + "):");
indent();
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
emit(readString());
+ }
outdent();
empty = false;
}
n = readInt();
- if (n > 0)
- {
+ if (n > 0) {
emit("Appinfo elements (" + n + "):");
indent();
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
emit(readString());
+ }
outdent();
empty = false;
}
- if (empty)
+ if (empty) {
emit("<empty>");
+ }
outdent();
}
- void dumpAnnotations()
- {
+ void dumpAnnotations() {
int n = readInt();
- if (n > 0)
- {
+ if (n > 0) {
emit("Top-level annotations (" + n + "):");
indent();
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
dumpAnnotation();
+ }
outdent();
}
}
- void dumpParticleData(boolean global)
- {
+ void dumpParticleData(boolean global) {
int particleType = readShort();
emit(particleTypeString(particleType) + ":");
indent();
@@ -723,8 +763,7 @@ public class XsbDumper
emit("Transition: " + qnameSetString(readQNameSet()));
- switch (particleType)
- {
+ switch (particleType) {
case SchemaParticle.WILDCARD:
emit("Wildcard set: " + qnameSetString(readQNameSet()));
emit("Wildcard process: " + wcprocessString(readShort()));
@@ -734,19 +773,19 @@ public class XsbDumper
emit("Name: " + qnameString(readQName()));
emit("Type: " + readType());
emit("Default: " + readString());
- if (atLeast(2, 16, 0))
+ if (atLeast(2, 16, 0)) {
emit("Default value: " + readXmlValueObject());
+ }
emit("WsdlArrayType: " + SOAPArrayTypeString(readSOAPArrayType()));
dumpAnnotation();
- if (global)
- {
- if (atLeast(2, 17, 0))
+ if (global) {
+ if (atLeast(2, 17, 0)) {
emit("Substitution group ref: " + readHandle());
+ }
int substGroupCount = readShort();
emit("Substitution group members (" + substGroupCount + ")");
indent();
- for (int i = 0; i < substGroupCount; i++)
- {
+ for (int i = 0; i < substGroupCount; i++) {
emit(qnameString(readQName()));
}
outdent();
@@ -754,13 +793,13 @@ public class XsbDumper
int count = readShort();
emit("Identity constraints (" + count + "):");
indent();
- for (int i = 0; i < count; i++)
- {
+ for (int i = 0; i < count; i++) {
emit(readHandle());
}
outdent();
- if (global)
+ if (global) {
emit("Filename: " + readString());
+ }
break;
case SchemaParticle.ALL:
@@ -775,86 +814,98 @@ public class XsbDumper
outdent();
}
- void dumpParticleArray(String fieldname)
- {
+ void dumpParticleArray(String fieldname) {
int count = readShort();
emit(fieldname + "(" + count + "):");
indent();
- for (int i = 0; i < count; i++)
+ for (int i = 0; i < count; i++) {
dumpParticleData(false);
+ }
outdent();
}
- static String complexVarietyString(int code)
- {
- switch (code)
- {
- case SchemaType.EMPTY_CONTENT: return "EMPTY_CONTENT";
- case SchemaType.SIMPLE_CONTENT: return "SIMPLE_CONTENT";
- case SchemaType.ELEMENT_CONTENT: return "ELEMENT_CONTENT";
- case SchemaType.MIXED_CONTENT: return "MIXED_CONTENT";
+ static String complexVarietyString(int code) {
+ switch (code) {
+ case SchemaType.EMPTY_CONTENT:
+ return "EMPTY_CONTENT";
+ case SchemaType.SIMPLE_CONTENT:
+ return "SIMPLE_CONTENT";
+ case SchemaType.ELEMENT_CONTENT:
+ return "ELEMENT_CONTENT";
+ case SchemaType.MIXED_CONTENT:
+ return "MIXED_CONTENT";
default:
return "Unknown complex variety (" + code + ")";
}
}
- static String simpleVarietyString(int code)
- {
- switch (code)
- {
- case SchemaType.ATOMIC: return "ATOMIC";
- case SchemaType.LIST: return "LIST";
- case SchemaType.UNION: return "UNION";
+ static String simpleVarietyString(int code) {
+ switch (code) {
+ case SchemaType.ATOMIC:
+ return "ATOMIC";
+ case SchemaType.LIST:
+ return "LIST";
+ case SchemaType.UNION:
+ return "UNION";
default:
return "Unknown simple variety (" + code + ")";
}
}
- String facetCodeString(int code)
- {
- switch (code)
- {
- case SchemaType.FACET_LENGTH: return "FACET_LENGTH";
- case SchemaType.FACET_MIN_LENGTH: return "FACET_MIN_LENGTH";
- case SchemaType.FACET_MAX_LENGTH: return "FACET_MAX_LENGTH";
- case SchemaType.FACET_MIN_EXCLUSIVE: return "FACET_MIN_EXCLUSIVE";
- case SchemaType.FACET_MIN_INCLUSIVE: return "FACET_MIN_INCLUSIVE";
- case SchemaType.FACET_MAX_INCLUSIVE: return "FACET_MAX_INCLUSIVE";
- case SchemaType.FACET_MAX_EXCLUSIVE: return "FACET_MAX_EXCLUSIVE";
- case SchemaType.FACET_TOTAL_DIGITS: return "FACET_TOTAL_DIGITS";
- case SchemaType.FACET_FRACTION_DIGITS: return "FACET_FRACTION_DIGITS";
+ String facetCodeString(int code) {
+ switch (code) {
+ case SchemaType.FACET_LENGTH:
+ return "FACET_LENGTH";
+ case SchemaType.FACET_MIN_LENGTH:
+ return "FACET_MIN_LENGTH";
+ case SchemaType.FACET_MAX_LENGTH:
+ return "FACET_MAX_LENGTH";
+ case SchemaType.FACET_MIN_EXCLUSIVE:
+ return "FACET_MIN_EXCLUSIVE";
+ case SchemaType.FACET_MIN_INCLUSIVE:
+ return "FACET_MIN_INCLUSIVE";
+ case SchemaType.FACET_MAX_INCLUSIVE:
+ return "FACET_MAX_INCLUSIVE";
+ case SchemaType.FACET_MAX_EXCLUSIVE:
+ return "FACET_MAX_EXCLUSIVE";
+ case SchemaType.FACET_TOTAL_DIGITS:
+ return "FACET_TOTAL_DIGITS";
+ case SchemaType.FACET_FRACTION_DIGITS:
+ return "FACET_FRACTION_DIGITS";
default:
return "Unknown facet code (" + code + ")";
}
}
- String whitespaceCodeString(int code)
- {
- switch (code)
- {
- case SchemaType.WS_COLLAPSE: return "WS_COLLAPSE";
- case SchemaType.WS_PRESERVE: return "WS_PRESERVE";
- case SchemaType.WS_REPLACE: return "WS_REPLACE";
- case SchemaType.WS_UNSPECIFIED: return "WS_UNSPECIFIED";
+ String whitespaceCodeString(int code) {
+ switch (code) {
+ case SchemaType.WS_COLLAPSE:
+ return "WS_COLLAPSE";
+ case SchemaType.WS_PRESERVE:
+ return "WS_PRESERVE";
+ case SchemaType.WS_REPLACE:
+ return "WS_REPLACE";
+ case SchemaType.WS_UNSPECIFIED:
+ return "WS_UNSPECIFIED";
default:
return "Unknown whitespace code (" + code + ")";
}
}
- String derivationTypeString(int code)
- {
- switch (code)
- {
- case SchemaType.DT_NOT_DERIVED: return "DT_NOT_DERIVED";
- case SchemaType.DT_RESTRICTION: return "DT_RESTRICTION";
- case SchemaType.DT_EXTENSION: return "DT_EXTENSION";
+ String derivationTypeString(int code) {
+ switch (code) {
+ case SchemaType.DT_NOT_DERIVED:
+ return "DT_NOT_DERIVED";
+ case SchemaType.DT_RESTRICTION:
+ return "DT_RESTRICTION";
+ case SchemaType.DT_EXTENSION:
+ return "DT_EXTENSION";
default:
return "Unknown derivation code (" + code + ")";
}
}
- void dumpTypeFileData()
- {
+ void dumpTypeFileData() {
emit("Name: " + qnameString(readQName()));
emit("Outer type: " + readType());
emit("Depth: " + readShort());
@@ -866,8 +917,7 @@ public class XsbDumper
indent();
int containerfieldtype = readShort();
emit("Reftype: " + containerfieldTypeString(containerfieldtype));
- switch (containerfieldtype)
- {
+ switch (containerfieldtype) {
case FIELD_GLOBAL:
emit("Handle: " + readHandle());
break;
@@ -892,19 +942,20 @@ public class XsbDumper
boolean isComplexType = ((flags & FLAG_SIMPLE_TYPE) == 0);
int complexVariety = SchemaType.NOT_COMPLEX_TYPE;
- if (isComplexType)
- {
+ if (isComplexType) {
complexVariety = readShort();
emit("Complex variety: " + complexVarietyString(complexVariety));
- if (atLeast(2, 23, 0))
+ if (atLeast(2, 23, 0)) {
emit("Content based on type: " + readType());
+ }
int attrCount = readShort();
emit("Attribute model (" + attrCount + "):");
indent();
- for (int i = 0; i < attrCount; i++)
+ for (int i = 0; i < attrCount; i++) {
dumpAttributeData(false);
+ }
emit("Wildcard set: " + qnameSetString(readQNameSet()));
emit("Wildcard process: " + wcprocessString(readShort()));
@@ -914,14 +965,12 @@ public class XsbDumper
int attrPropCount = readShort();
emit("Attribute properties (" + attrPropCount + "):");
indent();
- for (int i = 0; i < attrPropCount; i++)
- {
+ for (int i = 0; i < attrPropCount; i++) {
dumpPropertyData();
}
outdent();
- if (complexVariety == SchemaType.ELEMENT_CONTENT || complexVariety == SchemaType.MIXED_CONTENT)
- {
+ if (complexVariety == SchemaType.ELEMENT_CONTENT || complexVariety == SchemaType.MIXED_CONTENT) {
emit("IsAll: " + readShort());
// Content model tree
@@ -931,16 +980,14 @@ public class XsbDumper
int elemPropCount = readShort();
emit("Element properties (" + elemPropCount + "):");
indent();
- for (int i = 0; i < elemPropCount; i++)
- {
+ for (int i = 0; i < elemPropCount; i++) {
dumpPropertyData();
}
outdent();
}
}
- if (!isComplexType || complexVariety == SchemaType.SIMPLE_CONTENT)
- {
+ if (!isComplexType || complexVariety == SchemaType.SIMPLE_CONTENT) {
int simpleVariety = readShort();
emit("Simple type variety: " + simpleVarietyString(simpleVariety));
@@ -949,8 +996,7 @@ public class XsbDumper
int facetCount = readShort();
emit("Facets (" + facetCount + "):");
indent();
- for (int i = 0; i < facetCount; i++)
- {
+ for (int i = 0; i < facetCount; i++) {
emit(facetCodeString(readShort()));
emit("Value: " + readXmlValueObject());
emit("Fixed: " + readShort());
@@ -962,8 +1008,7 @@ public class XsbDumper
int patternCount = readShort();
emit("Patterns (" + patternCount + "):");
indent();
- for (int i = 0; i < patternCount; i++)
- {
+ for (int i = 0; i < patternCount; i++) {
emit(readString());
}
outdent();
@@ -971,27 +1016,23 @@ public class XsbDumper
int enumCount = readShort();
emit("Enumeration values (" + enumCount + "):");
indent();
- for (int i = 0; i < enumCount; i++)
- {
+ for (int i = 0; i < enumCount; i++) {
emit(readXmlValueObject());
}
outdent();
emit("Base enum type: " + readType());
- if (isStringEnum)
- {
+ if (isStringEnum) {
int seCount = readShort();
emit("String enum entries (" + seCount + "):");
indent();
- for (int i = 0; i < seCount; i++)
- {
+ for (int i = 0; i < seCount; i++) {
emit("\"" + readString() + "\" -> " + readShort() + " = " + readString());
}
outdent();
}
- switch (simpleVariety)
- {
+ switch (simpleVariety) {
case SchemaType.ATOMIC:
emit("Primitive type: " + readType());
emit("Decimal size: " + readInt());
@@ -1013,130 +1054,151 @@ public class XsbDumper
emit("Filename: " + readString());
}
- static String attruseCodeString(int code)
- {
- switch (code)
- {
- case SchemaLocalAttribute.OPTIONAL: return "OPTIONAL";
- case SchemaLocalAttribute.REQUIRED: return "REQUIRED";
- case SchemaLocalAttribute.PROHIBITED: return "PROHIBITED";
+ static String attruseCodeString(int code) {
+ switch (code) {
+ case SchemaLocalAttribute.OPTIONAL:
+ return "OPTIONAL";
+ case SchemaLocalAttribute.REQUIRED:
+ return "REQUIRED";
+ case SchemaLocalAttribute.PROHIBITED:
+ return "PROHIBITED";
default:
return "Unknown use code (" + code + ")";
}
}
- void dumpAttributeData(boolean global)
- {
+ void dumpAttributeData(boolean global) {
emit("Name: " + qnameString(readQName()));
emit("Type: " + readType());
emit("Use: " + attruseCodeString(readShort()));
emit("Default: " + readString());
- if (atLeast(2, 16, 0))
+ if (atLeast(2, 16, 0)) {
emit("Default value: " + readXmlValueObject());
+ }
emit("Fixed: " + readShort());
emit("WsdlArrayType: " + SOAPArrayTypeString(readSOAPArrayType()));
dumpAnnotation();
- if (global)
+ if (global) {
emit("Filename: " + readString());
+ }
}
private static final XmlOptions prettyOptions =
new XmlOptions().setSavePrettyPrint();
- void dumpXml()
- {
+ void dumpXml() {
String xml = readString();
- try
- {
- emit( XmlObject.Factory.parse( xml ).xmlText( prettyOptions ) );
- }
- catch ( XmlException x )
- {
- emit( "!!!!!! BAD XML !!!!!" );
- emit( xml );
+ try {
+ emit(XmlObject.Factory.parse(xml).xmlText(prettyOptions));
+ } catch (XmlException x) {
+ emit("!!!!!! BAD XML !!!!!");
+ emit(xml);
}
}
- void dumpModelGroupData()
- {
+ void dumpModelGroupData() {
emit("Name: " + qnameString(readQName()));
emit("Target namespace: " + readString());
emit("Chameleon: " + readShort());
- if (atLeast(2, 22, 0))
+ if (atLeast(2, 22, 0)) {
emit("Element form default: " + readString());
- if (atLeast(2, 22, 0))
+ }
+ if (atLeast(2, 22, 0)) {
emit("Attribute form default: " + readString());
- if (atLeast(2, 15, 0))
+ }
+ if (atLeast(2, 15, 0)) {
emit("Redefine: " + readShort());
+ }
emit("Model Group Xml: ");
dumpXml();
dumpAnnotation();
- if (atLeast(2, 21, 0))
+ if (atLeast(2, 21, 0)) {
emit("Filename: " + readString());
+ }
}
- void dumpAttributeGroupData()
- {
+ void dumpAttributeGroupData() {
emit("Name: " + qnameString(readQName()));
emit("Target namespace: " + readString());
emit("Chameleon: " + readShort());
- if (atLeast(2, 22, 0))
+ if (atLeast(2, 22, 0)) {
emit("Form default: " + readString());
- if (atLeast(2, 15, 0))
+ }
+ if (atLeast(2, 15, 0)) {
emit("Redefine: " + readShort());
+ }
emit("Attribute Group Xml: ");
dumpXml();
dumpAnnotation();
- if (atLeast(2, 21, 0))
+ if (atLeast(2, 21, 0)) {
emit("Filename: " + readString());
+ }
}
- static String alwaysString(int code)
- {
- switch (code)
- {
- case SchemaProperty.CONSISTENTLY: return "CONSISTENTLY";
- case SchemaProperty.NEVER: return "NEVER";
- case SchemaProperty.VARIABLE: return "VARIABLE";
+ static String alwaysString(int code) {
+ switch (code) {
+ case SchemaProperty.CONSISTENTLY:
+ return "CONSISTENTLY";
+ case SchemaProperty.NEVER:
+ return "NEVER";
+ case SchemaProperty.VARIABLE:
+ return "VARIABLE";
default:
return "Unknown frequency code (" + code + ")";
}
}
- static String jtcString(int code)
- {
- switch (code)
- {
- case SchemaProperty.XML_OBJECT: return "XML_OBJECT";
- case SchemaProperty.JAVA_BOOLEAN: return "JAVA_BOOLEAN";
- case SchemaProperty.JAVA_FLOAT: return "JAVA_FLOAT";
- case SchemaProperty.JAVA_DOUBLE: return "JAVA_DOUBLE";
- case SchemaProperty.JAVA_BYTE: return "JAVA_BYTE";
- case SchemaProperty.JAVA_SHORT: return "JAVA_SHORT";
- case SchemaProperty.JAVA_INT: return "JAVA_INT";
- case SchemaProperty.JAVA_LONG: return "JAVA_LONG";
-
- case SchemaProperty.JAVA_BIG_DECIMAL: return "JAVA_BIG_DECIMAL";
- case SchemaProperty.JAVA_BIG_INTEGER: return "JAVA_BIG_INTEGER";
- case SchemaProperty.JAVA_STRING: return "JAVA_STRING";
- case SchemaProperty.JAVA_BYTE_ARRAY: return "JAVA_BYTE_ARRAY";
- case SchemaProperty.JAVA_GDATE: return "JAVA_GDATE";
- case SchemaProperty.JAVA_GDURATION: return "JAVA_GDURATION";
- case SchemaProperty.JAVA_DATE: return "JAVA_DATE";
- case SchemaProperty.JAVA_QNAME: return "JAVA_QNAME";
- case SchemaProperty.JAVA_CALENDAR: return "JAVA_CALENDAR";
- case SchemaProperty.JAVA_LIST: return "JAVA_LIST";
-
- case SchemaProperty.JAVA_ENUM: return "JAVA_ENUM";
- case SchemaProperty.JAVA_OBJECT: return "JAVA_OBJECT";
+ static String jtcString(int code) {
+ switch (code) {
+ case SchemaProperty.XML_OBJECT:
+ return "XML_OBJECT";
+ case SchemaProperty.JAVA_BOOLEAN:
+ return "JAVA_BOOLEAN";
+ case SchemaProperty.JAVA_FLOAT:
+ return "JAVA_FLOAT";
+ case SchemaProperty.JAVA_DOUBLE:
+ return "JAVA_DOUBLE";
+ case SchemaProperty.JAVA_BYTE:
+ return "JAVA_BYTE";
+ case SchemaProperty.JAVA_SHORT:
+ return "JAVA_SHORT";
+ case SchemaProperty.JAVA_INT:
+ return "JAVA_INT";
+ case SchemaProperty.JAVA_LONG:
+ return "JAVA_LONG";
+
+ case SchemaProperty.JAVA_BIG_DECIMAL:
+ return "JAVA_BIG_DECIMAL";
+ case SchemaProperty.JAVA_BIG_INTEGER:
+ return "JAVA_BIG_INTEGER";
+ case SchemaProperty.JAVA_STRING:
+ return "JAVA_STRING";
+ case SchemaProperty.JAVA_BYTE_ARRAY:
+ return "JAVA_BYTE_ARRAY";
+ case SchemaProperty.JAVA_GDATE:
+ return "JAVA_GDATE";
+ case SchemaProperty.JAVA_GDURATION:
+ return "JAVA_GDURATION";
+ case SchemaProperty.JAVA_DATE:
+ return "JAVA_DATE";
+ case SchemaProperty.JAVA_QNAME:
+ return "JAVA_QNAME";
+ case SchemaProperty.JAVA_CALENDAR:
+ return "JAVA_CALENDAR";
+ case SchemaProperty.JAVA_LIST:
+ return "JAVA_LIST";
+
+ case SchemaProperty.JAVA_ENUM:
+ return "JAVA_ENUM";
+ case SchemaProperty.JAVA_OBJECT:
+ return "JAVA_OBJECT";
default:
return "Unknown java type code (" + code + ")";
}
}
- void dumpPropertyData()
- {
+ void dumpPropertyData() {
emit("Property");
indent();
emit("Name: " + qnameString(readQName()));
@@ -1153,32 +1215,33 @@ public class XsbDumper
emit("Java prop name: " + readString());
emit("Java type code: " + jtcString(readShort()));
emit("Type for java signature: " + readType());
- if (atMost(2, 19, 0))
+ if (atMost(2, 19, 0)) {
emit("Java setter delimiter: " + qnameSetString(readQNameSet()));
- if (atLeast(2, 16, 0))
+ }
+ if (atLeast(2, 16, 0)) {
emit("Default value: " + readXmlValueObject());
- if (((propflags & FLAG_PROP_ISATTR) == 0) && atLeast(2, 17, 0))
- {
+ }
+ if (((propflags & FLAG_PROP_ISATTR) == 0) && atLeast(2, 17, 0)) {
int size = readShort();
emit("Accepted substitutions (" + size + "):");
- for (int i = 0 ; i < size ; i++)
+ for (int i = 0; i < size; i++) {
emit(" Accepted name " + readQName());
+ }
}
outdent();
}
- String readXmlValueObject()
- {
+ String readXmlValueObject() {
String type = readType();
- if (type == null)
+ if (type == null) {
return "null";
+ }
int btc = readShort();
String value;
- switch (btc)
- {
+ switch (btc) {
default:
- assert(false);
+ assert (false);
case 0:
value = "nil";
break;
@@ -1201,13 +1264,13 @@ public class XsbDumper
break;
case SchemaType.BTC_BASE_64_BINARY:
- case SchemaType.BTC_HEX_BINARY:
- {
- value = new String(HexBin.encode(readByteArray()));
- if (value.length() > 19)
- value = value.subSequence(0, 16) + "...";
- break;
+ case SchemaType.BTC_HEX_BINARY: {
+ value = new String(HexBin.encode(readByteArray()), StandardCharsets.ISO_8859_1);
+ if (value.length() > 19) {
+ value = value.subSequence(0, 16) + "...";
}
+ break;
+ }
case SchemaType.BTC_QNAME:
case SchemaType.BTC_NOTATION:
@@ -1219,121 +1282,124 @@ public class XsbDumper
value = Double.toString(readDouble());
break;
}
- return value + " (" + type + ": " + btc +")";
+ return value + " (" + type + ": " + btc + ")";
}
- double readDouble()
- {
- try
- {
+ double readDouble() {
+ try {
return _input.readDouble();
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
error(e);
return 0.0;
}
}
- String SOAPArrayTypeString(SOAPArrayType t)
- {
- if (t == null)
+ String SOAPArrayTypeString(SOAPArrayType t) {
+ if (t == null) {
return "null";
+ }
return QNameHelper.pretty(t.getQName()) + t.soap11DimensionString();
}
- SOAPArrayType readSOAPArrayType()
- {
+ SOAPArrayType readSOAPArrayType() {
QName qName = readQName();
String dimensions = readString();
- if (qName == null)
+ if (qName == null) {
return null;
+ }
return new SOAPArrayType(qName, dimensions);
}
- QNameSet readQNameSet()
- {
+ QNameSet readQNameSet() {
int flag = readShort();
Set uriSet = new HashSet();
int uriCount = readShort();
- for (int i = 0; i < uriCount; i++)
+ for (int i = 0; i < uriCount; i++) {
uriSet.add(readString());
+ }
Set qnameSet1 = new HashSet();
int qncount1 = readShort();
- for (int i = 0; i < qncount1; i++)
+ for (int i = 0; i < qncount1; i++) {
qnameSet1.add(readQName());
+ }
Set qnameSet2 = new HashSet();
int qncount2 = readShort();
- for (int i = 0; i < qncount2; i++)
+ for (int i = 0; i < qncount2; i++) {
qnameSet2.add(readQName());
+ }
- if (flag == 1)
+ if (flag == 1) {
return QNameSet.forSets(uriSet, null, qnameSet1, qnameSet2);
- else
+ } else {
return QNameSet.forSets(null, uriSet, qnameSet2, qnameSet1);
+ }
}
- byte[] readByteArray()
- {
- try
- {
+ byte[] readByteArray() {
+ try {
int len = _input.readShort();
byte[] result = new byte[len];
_input.readFully(result);
return result;
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
error(e);
return null;
}
}
- BigInteger readBigInteger()
- {
+ BigInteger readBigInteger() {
byte[] result = readByteArray();
- if (result.length == 0)
+ if (result.length == 0) {
return null;
- if (result.length == 1 && result[0] == 0)
+ }
+ if (result.length == 1 && result[0] == 0) {
return BigInteger.ZERO;
- if (result.length == 1 && result[0] == 1)
+ }
+ if (result.length == 1 && result[0] == 1) {
return BigInteger.ONE;
+ }
return new BigInteger(result);
}
- static final byte[] SINGLE_ZERO_BYTE = new byte[] { (byte)0 };
+ static final byte[] SINGLE_ZERO_BYTE = new byte[]{(byte) 0};
private int _majorver;
private int _minorver;
private int _releaseno;
- protected boolean atLeast(int majorver, int minorver, int releaseno)
- {
- if (_majorver > majorver)
+ protected boolean atLeast(int majorver, int minorver, int releaseno) {
+ if (_majorver > majorver) {
return true;
- if (_majorver < majorver)
+ }
+ if (_majorver < majorver) {
return false;
- if (_minorver > minorver)
+ }
+ if (_minorver > minorver) {
return true;
- if (_minorver < minorver)
+ }
+ if (_minorver < minorver) {
return false;
+ }
return (_releaseno >= releaseno);
}
- protected boolean atMost(int majorver, int minorver, int releaseno)
- {
- if (_majorver > majorver)
+ protected boolean atMost(int majorver, int minorver, int releaseno) {
+ if (_majorver > majorver) {
return false;
- if (_majorver < majorver)
+ }
+ if (_majorver < majorver) {
return true;
- if (_minorver > minorver)
+ }
+ if (_minorver > minorver) {
return false;
- if (_minorver < minorver)
+ }
+ if (_minorver < minorver) {
return true;
+ }
return (_releaseno <= releaseno);
}
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/HexBin.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/HexBin.java?rev=1881117&r1=1881116&r2=1881117&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/HexBin.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/HexBin.java Sun Aug 23 20:16:45 2020
@@ -15,39 +15,40 @@
package org.apache.xmlbeans.impl.util;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+
/**
* format validation
- *
+ * <p>
* This class encodes/decodes hexadecimal data
- * @author Jeffrey Rodriguez
- * @version $Id$
*/
-public final class HexBin {
- static private final int BASELENGTH = 255;
- static private final int LOOKUPLENGTH = 16;
- static private byte [] hexNumberTable = new byte[BASELENGTH];
- static private byte [] lookUpHexAlphabet = new byte[LOOKUPLENGTH];
+public final class HexBin {
+ static private final int BASELENGTH = 255;
+ static private final int LOOKUPLENGTH = 16;
+ static private byte[] hexNumberTable = new byte[BASELENGTH];
+ static private byte[] lookUpHexAlphabet = new byte[LOOKUPLENGTH];
static {
- for (int i = 0; i<BASELENGTH; i++ ) {
+ for (int i = 0; i < BASELENGTH; i++) {
hexNumberTable[i] = -1;
}
- for ( int i = '9'; i >= '0'; i--) {
- hexNumberTable[i] = (byte) (i-'0');
+ for (int i = '9'; i >= '0'; i--) {
+ hexNumberTable[i] = (byte) (i - '0');
}
- for ( int i = 'F'; i>= 'A'; i--) {
- hexNumberTable[i] = (byte) ( i-'A' + 10 );
+ for (int i = 'F'; i >= 'A'; i--) {
+ hexNumberTable[i] = (byte) (i - 'A' + 10);
}
- for ( int i = 'f'; i>= 'a'; i--) {
- hexNumberTable[i] = (byte) ( i-'a' + 10 );
+ for (int i = 'f'; i >= 'a'; i--) {
+ hexNumberTable[i] = (byte) (i - 'a' + 10);
}
- for(int i = 0; i<10; i++ )
- lookUpHexAlphabet[i] = (byte) ('0'+i );
- for(int i = 10; i<=15; i++ )
- lookUpHexAlphabet[i] = (byte) ('A'+i -10);
+ for (int i = 0; i < 10; i++) {
+ lookUpHexAlphabet[i] = (byte) ('0' + i);
+ }
+ for (int i = 10; i <= 15; i++) {
+ lookUpHexAlphabet[i] = (byte) ('A' + i - 10);
+ }
}
/**
@@ -63,19 +64,18 @@ public final class HexBin {
/**
* Converts bytes to a hex string
*/
- static public String bytesToString(byte[] binaryData)
- {
- if (binaryData == null)
+ static public String bytesToString(byte[] binaryData) {
+ if (binaryData == null) {
return null;
- return new String(encode(binaryData));
+ }
+ return new String(encode(binaryData), StandardCharsets.ISO_8859_1);
}
/**
* Converts a hex string to a byte array.
*/
- static public byte[] stringToBytes(String hexEncoded)
- {
- return decode(hexEncoded.getBytes());
+ static public byte[] stringToBytes(String hexEncoded) {
+ return decode(hexEncoded.getBytes(StandardCharsets.ISO_8859_1));
}
/**
@@ -85,32 +85,35 @@ public final class HexBin {
* @return return encode binary array
*/
static public byte[] encode(byte[] binaryData) {
- if (binaryData == null)
+ if (binaryData == null) {
return null;
- int lengthData = binaryData.length;
+ }
+ int lengthData = binaryData.length;
int lengthEncode = lengthData * 2;
byte[] encodedData = new byte[lengthEncode];
- for( int i = 0; i<lengthData; i++ ){
- encodedData[i*2] = lookUpHexAlphabet[(binaryData[i] >> 4) & 0xf];
- encodedData[i*2+1] = lookUpHexAlphabet[ binaryData[i] & 0xf];
+ for (int i = 0; i < lengthData; i++) {
+ encodedData[i * 2] = lookUpHexAlphabet[(binaryData[i] >> 4) & 0xf];
+ encodedData[i * 2 + 1] = lookUpHexAlphabet[binaryData[i] & 0xf];
}
return encodedData;
}
static public byte[] decode(byte[] binaryData) {
- if (binaryData == null)
+ if (binaryData == null) {
return null;
- int lengthData = binaryData.length;
- if (lengthData % 2 != 0)
+ }
+ int lengthData = binaryData.length;
+ if (lengthData % 2 != 0) {
return null;
+ }
int lengthDecode = lengthData / 2;
byte[] decodedData = new byte[lengthDecode];
- for( int i = 0; i<lengthDecode; i++ ){
- if (!isHex(binaryData[i*2]) || !isHex(binaryData[i*2+1])) {
+ for (int i = 0; i < lengthDecode; i++) {
+ if (!isHex(binaryData[i * 2]) || !isHex(binaryData[i * 2 + 1])) {
return null;
}
- decodedData[i] = (byte)((hexNumberTable[binaryData[i*2]] << 4) | hexNumberTable[binaryData[i*2+1]]);
+ decodedData[i] = (byte) ((hexNumberTable[binaryData[i * 2]] << 4) | hexNumberTable[binaryData[i * 2 + 1]]);
}
return decodedData;
}
@@ -122,16 +125,12 @@ public final class HexBin {
* @return string containing decoded data.
*/
public static String decode(String binaryData) {
- if (binaryData == null)
+ if (binaryData == null) {
return null;
-
- byte[] decoded = null;
- try {
- decoded = decode(binaryData.getBytes("utf-8"));
- }
- catch(UnsupportedEncodingException e) {
}
- return decoded == null ? null : new String(decoded);
+
+ byte[] decoded = decode(binaryData.getBytes(StandardCharsets.ISO_8859_1));
+ return decoded == null ? null : new String(decoded, StandardCharsets.UTF_8);
}
/**
@@ -141,15 +140,12 @@ public final class HexBin {
* @return string containing decoded data.
*/
public static String encode(String binaryData) {
- if (binaryData == null)
+ if (binaryData == null) {
return null;
-
- byte[] encoded = null;
- try {
- encoded = encode(binaryData.getBytes("utf-8"));
}
- catch(UnsupportedEncodingException e) {}
- return encoded == null ? null : new String(encoded);
+
+ byte[] encoded = encode(binaryData.getBytes(StandardCharsets.UTF_8));
+ return encoded == null ? null : new String(encoded, StandardCharsets.ISO_8859_1);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org