|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.schema2beans; import java.text.*; import java.util.ResourceBundle; import java.util.Locale; import java.util.MissingResourceException; /** * This class contains the schema2beans constants and helper methods. */ public class Common { // Constants static public final int NONE = 0x00000; static public final int MASK_USER = 0xFFFF; static public int USE_DEFAULT_VALUES = 0x0001; static public int NO_DEFAULT_VALUES = 0x0002; static public final int MASK_SEQUENCE = 0x0000F; static public final int SEQUENCE_AND = 0x00001; static public final int SEQUENCE_OR = 0x00002; static public final int MASK_INSTANCE = 0x000F0; static public final int TYPE_0_1 = 0x00010; static public final int TYPE_1 = 0x00020; static public final int TYPE_0_N = 0x00030; static public final int TYPE_1_N = 0x00040; static public final int MASK_TYPE = 0x0FF00; static public final int TYPE_STRING = 0x00100; static public final int TYPE_BEAN = 0x00200; static public final int TYPE_BOOLEAN = 0x00300; static public final int TYPE_BYTE = 0x00400; static public final int TYPE_CHAR = 0x00500; static public final int TYPE_SHORT = 0x00600; static public final int TYPE_INT = 0x00700; static public final int TYPE_LONG = 0x00800; static public final int TYPE_FLOAT = 0x00900; static public final int TYPE_DOUBLE = 0x00a00; static public final int TYPE_COMMENT = 0x00f00; static public final int MASK_PROP = 0xF0000; static public final int TYPE_KEY = 0x10000; static public final int TYPE_SHOULD_NOT_BE_EMPTY = 0x20000; static public final int TYPE_VETOABLE = 0x100000; static public final int COMMENT = 0x01; static public final int ELEMENT = 0x02; static public final int ATTLIST = 0x03; static public final String DTD_STRING = "#PCDATA"; // NOI18N static public final String DTD_EMPTY = "EMPTY"; // NOI18N static public final String CLASS_STRING = "String"; // NOI18N static public final String CLASS_BOOLEAN = "Boolean"; // NOI18N static public final String GENERATED_TAG = "Generated"; public static boolean isSequenceOr(int type) { return ((type & MASK_SEQUENCE) == SEQUENCE_OR); } public static boolean isArray(int type) { int t = type & MASK_INSTANCE; return (t == TYPE_0_N || t == TYPE_1_N); } public static boolean isBean(int type) { return ((type & MASK_TYPE) == TYPE_BEAN); } public static boolean isString(int type) { return ((type & MASK_TYPE) == TYPE_STRING); } public static boolean isBoolean(int type) { return ((type & MASK_TYPE) == TYPE_BOOLEAN); } /* public static boolean isInt(int type) { return ((type & MASK_TYPE) == TYPE_INT); } */ public static boolean isKey(int type) { return ((type & TYPE_KEY) == TYPE_KEY); } public static boolean shouldNotBeEmpty(int type) { return ((type & TYPE_SHOULD_NOT_BE_EMPTY) == TYPE_SHOULD_NOT_BE_EMPTY); } public static boolean isVetoable(int type) { return ((type & TYPE_VETOABLE) == TYPE_VETOABLE); } /** * Is it a Java primitive or not? */ public static boolean isScalar(int type) { switch(type & MASK_TYPE) { case TYPE_STRING: case TYPE_BEAN: case TYPE_COMMENT: return false; case TYPE_BOOLEAN: case TYPE_BYTE: case TYPE_CHAR: case TYPE_SHORT: case TYPE_INT: case TYPE_LONG: case TYPE_FLOAT: case TYPE_DOUBLE: return true; default: throw new IllegalArgumentException(Common.getMessage( "UnknownType_msg", new Integer(type))); } } public static String wrapperGetMethod(int type) { switch(type & MASK_TYPE) { case TYPE_BOOLEAN: return "booleanValue"; // NOI18N case TYPE_BYTE: return "byteValue"; // NOI18N case TYPE_CHAR: return "charValue"; // NOI18N case TYPE_SHORT: return "shortValue"; // NOI18N case TYPE_INT: return "intValue"; // NOI18N case TYPE_LONG: return "longValue"; // NOI18N case TYPE_FLOAT: return "floatValue"; // NOI18N case TYPE_DOUBLE: return "doubleValue"; // NOI18N default: throw new IllegalArgumentException(Common.getMessage( "UnknownType_msg", new Integer(type))); } } public static String wrapperClass(int type) { switch(type & MASK_TYPE) { case TYPE_BOOLEAN: return "Boolean"; // NOI18N case TYPE_BYTE: return "Byte"; // NOI18N case TYPE_CHAR: return "Character"; // NOI18N case TYPE_SHORT: return "Short"; // NOI18N case TYPE_INT: return "Integer"; // NOI18N case TYPE_LONG: return "Long"; // NOI18N case TYPE_FLOAT: return "Float"; // NOI18N case TYPE_DOUBLE: return "Double"; // NOI18N default: throw new IllegalArgumentException(Common.getMessage( "UnknownType_msg", new Integer(type))); } } public static int wrapperToType(String wrapper) { if (wrapper == null) return NONE; String s = wrapper.trim(); if (s.endsWith("boolean")) // NOI18N return TYPE_BOOLEAN; if (s.endsWith("byte")) // NOI18N return TYPE_BYTE; if (s.endsWith("char")) // NOI18N return TYPE_CHAR; if (s.endsWith("short")) // NOI18N return TYPE_SHORT; if (s.endsWith("int")) // NOI18N return TYPE_INT; if (s.endsWith("long")) // NOI18N return TYPE_LONG; if (s.endsWith("float")) // NOI18N return TYPE_FLOAT; if (s.endsWith("double")) // NOI18N return TYPE_DOUBLE; if (s.equals("String") || s.equals("java.lang.String")) return TYPE_STRING; //System.out.println("schema2beans Common.wrapperToType: couldn't find type for "+wrapper); return NONE; } public static String scalarType(int type) { switch(type & MASK_TYPE) { case TYPE_BOOLEAN: return "boolean"; // NOI18N case TYPE_BYTE: return "byte"; // NOI18N case TYPE_CHAR: return "char"; // NOI18N case TYPE_SHORT: return "short"; // NOI18N case TYPE_INT: return "int"; // NOI18N case TYPE_LONG: return "long"; // NOI18N case TYPE_FLOAT: return "float"; // NOI18N case TYPE_DOUBLE: return "double"; // NOI18N default: throw new IllegalArgumentException(Common.getMessage( "UnknownType_msg", new Integer(type))); } } public static String typeToString(int type) { switch(type & MASK_TYPE) { case TYPE_STRING: return "TYPE_STRING"; // NOI18N case TYPE_COMMENT: return "TYPE_COMMENT"; case TYPE_BEAN: return "TYPE_BEAN"; // NOI18N case TYPE_BOOLEAN: return "TYPE_BOOLEAN"; // NOI18N case TYPE_BYTE: return "TYPE_BYTE"; // NOI18N case TYPE_CHAR: return "TYPE_CHAR"; // NOI18N case TYPE_SHORT: return "TYPE_SHORT"; // NOI18N case TYPE_INT: return "TYPE_INT"; // NOI18N case TYPE_LONG: return "TYPE_LONG"; // NOI18N case TYPE_FLOAT: return "TYPE_FLOAT"; // NOI18N case TYPE_DOUBLE: return "TYPE_DOUBLE"; // NOI18N default: throw new IllegalArgumentException(Common.getMessage( "UnknownType_msg", new Integer(type))); } } public static String dumpHex(String v) { String s; if (v != null) { s = "hex[ "; // NOI18N byte[] b = v.getBytes(); for (int i=0; i |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.