예제 #1
0
 // Serialize the bean using the specified namespace prefix & uri
 public String serialize(Object bean) throws IntrospectionException, IllegalAccessException {
   // Use the class name as the name of the root element
   String className = bean.getClass().getName();
   String rootElementName = null;
   if (bean.getClass().isAnnotationPresent(ObjectXmlAlias.class)) {
     AnnotatedElement annotatedElement = bean.getClass();
     ObjectXmlAlias aliasAnnotation = annotatedElement.getAnnotation(ObjectXmlAlias.class);
     rootElementName = aliasAnnotation.value();
   }
   // Use the package name as the namespace URI
   Package pkg = bean.getClass().getPackage();
   nsURI = pkg.getName();
   // Remove a trailing semi-colon (;) if present (i.e. if the bean is an array)
   className = StringUtils.deleteTrailingChar(className, ';');
   StringBuffer sb = new StringBuffer(className);
   String objectName = sb.delete(0, sb.lastIndexOf(".") + 1).toString();
   domDocument = createDomDocument(objectName);
   document = domDocument.getDocument();
   Element root = document.getDocumentElement();
   // Parse the bean elements
   getBeanElements(root, rootElementName, className, bean);
   StringBuffer xml = new StringBuffer();
   if (prettyPrint)
     xml.append(domDocument.serialize(lineSeperator, indentChars, includeXmlProlog));
   else xml.append(domDocument.serialize(includeXmlProlog));
   if (!includeTypeInfo) {
     int index = xml.indexOf(root.getNodeName());
     xml.delete(index - 1, index + root.getNodeName().length() + 2);
     xml.delete(xml.length() - root.getNodeName().length() - 4, xml.length());
   }
   return xml.toString();
 }
예제 #2
0
 static String javaSignature(Class<?> type) {
   if (!type.isArray()) {
     return type.getName();
   } else {
     int arrayDimension = 0;
     do {
       ++arrayDimension;
       type = type.getComponentType();
     } while (type.isArray());
     String name = type.getName();
     String suffix = "[]";
     if (arrayDimension == 1) {
       return name.concat(suffix);
     } else {
       int length = name.length() + arrayDimension * suffix.length();
       StringBuffer sb = new StringBuffer(length);
       sb.append(name);
       while (arrayDimension != 0) {
         --arrayDimension;
         sb.append(suffix);
       }
       return sb.toString();
     }
   }
 }
 public String toString() {
   StringBuffer s = new StringBuffer();
   s.append("ed:");
   for (int i = 0; i < count; i++) s.append(" " + args[i]);
   if (size != null) s.append(" (" + size + ")");
   return s.toString();
 }
예제 #4
0
 /** Converts a byte array into the unknown RR format. */
 protected static String unknownToString(byte[] data) {
   StringBuffer sb = new StringBuffer();
   sb.append("\\# ");
   sb.append(data.length);
   sb.append(" ");
   sb.append(base16.toString(data));
   return sb.toString();
 }
예제 #5
0
 public String toString() {
   StringBuffer buf = new StringBuffer();
   buf.append("(Struct: ");
   for (InferredType it : structTypes) {
     buf.append(it.toString() + ", ");
   }
   buf.append(") ");
   return buf.toString();
 }
    /**
     * Print this EmitterSet readably.
     *
     * @return a string describing this EmitterSet
     */
    public String toString() {
      StringBuffer s = new StringBuffer();
      s.append("Emitter Set of:\n");
      Iterator<EmitterDescriptor> i = emitters.iterator();
      while (i.hasNext()) s.append(i.next().toString() + "\n");

      s.append("-------------\n");
      return s.toString();
    }
예제 #7
0
 public String toString() {
   StringBuffer buf = new StringBuffer();
   buf.append("(Union (" + unionTypes.size() + "): ");
   for (InferredType it : unionTypes) {
     buf.append(it.toString() + ", ");
   }
   buf.append(") ");
   return buf.toString();
 }
 private String buildInternalSignature() {
   StringBuffer buf = new StringBuffer();
   buf.append("(");
   for (int i = 0; i < parameterTypes.length; i++) {
     buf.append(getClassName(parameterTypes[i], true));
   }
   buf.append(")");
   buf.append(getClassName(returnType, true));
   return buf.toString();
 }
예제 #9
0
 public String toString(Object v) {
   StringBuffer sb = new StringBuffer();
   if (this.isHelp()) {
     sb.append("# --- ").append(this.getHelp());
   } else {
     sb.append(this.getKey()).append("=");
     sb.append((v != null) ? v : NULL_VALUE);
   }
   return sb.toString();
 }
예제 #10
0
 /**
  * ** Returns the bean method name for the specified field ** @param prefix Either "get" or "set"
  * ** @param fieldName The field name ** @return The 'getter'/'setter' method name
  */
 protected static String _beanMethodName(String prefix, String fieldName) {
   if ((prefix != null) && (fieldName != null)) {
     StringBuffer sb = new StringBuffer(prefix);
     sb.append(fieldName.substring(0, 1).toUpperCase());
     sb.append(fieldName.substring(1));
     return sb.toString();
   } else {
     return "";
   }
 }
예제 #11
0
  public String getCompUniqueID() {
    UUID tempID = null;
    long longID = 0L;
    StringBuffer result = new StringBuffer();

    tempID = getId();

    result.append(Long.toHexString(tempID.getMostSignificantBits()));
    result.append(Long.toHexString(tempID.getLeastSignificantBits()));
    return result.toString();
  }
예제 #12
0
  /**
   * _more_
   *
   * @param properties _more_
   * @return _more_
   */
  public String makePropertiesString(Hashtable properties) {
    StringBuffer sb = new StringBuffer();
    for (java.util.Enumeration keys = properties.keys(); keys.hasMoreElements(); ) {
      Object key = keys.nextElement();
      sb.append(key);
      sb.append("=");
      sb.append(properties.get(key));
      sb.append("\n");
    }

    return sb.toString();
  }
예제 #13
0
  public String getCompUniqueID() {
    UUID tempID = null;
    long longID = 0L;
    StringBuffer result = new StringBuffer();

    tempID = getArg_id();

    if (IdAssigner.NULL_UUID.equals(tempID)) tempID = getArg_idCachedValue();
    result.append(Long.toHexString(tempID.getMostSignificantBits()));
    result.append(Long.toHexString(tempID.getLeastSignificantBits()));
    return result.toString();
  }
예제 #14
0
 public String getDocString() {
   StringBuffer buf = new StringBuffer();
   buf.append("Example data: ");
   for (Iterator<String> it = sampleStrs.iterator(); it.hasNext(); ) {
     String tokStr = it.next();
     buf.append("'" + tokStr + "'");
     if (it.hasNext()) {
       buf.append(", ");
     }
   }
   return buf.toString();
 }
예제 #15
0
 @Override
 public String toString() {
   StringBuffer sb = new StringBuffer();
   for (int i = 0, N = methods.length; i != N; ++i) {
     Method method = methods[i].method();
     sb.append(JavaMembers.javaSignature(method.getReturnType()));
     sb.append(' ');
     sb.append(method.getName());
     sb.append(JavaMembers.liveConnectSignature(methods[i].argTypes));
     sb.append('\n');
   }
   return sb.toString();
 }
예제 #16
0
 public static void setElement(Object[] oArr, Object value, int index) throws Throwable {
   StringBuffer tempMessage = new StringBuffer();
   tempMessage.append(
       "配列に値を代入。 インデックス: " + index + " " + "要素型: " + value.getClass().getName() + "\r\n");
   int size = oArr.length;
   if (index >= 0 && index < size) {
     oArr[index] = (Object) value;
   } else {
     tempMessage.append("インデックスが不正です\r\n");
   }
   message = tempMessage.toString();
   display.append(message);
 }
예제 #17
0
 private static String prepareExceptionMessage(Method method, Object[] args) {
   StringBuffer message =
       new StringBuffer("Illegal object type for the method '" + method.getName() + "'. \n ");
   message.append("Expected types: \n");
   for (Class<?> type : method.getParameterTypes()) {
     message.append(type.getName());
   }
   message.append("\n Actual types: \n");
   for (Object param : args) {
     message.append(param.getClass().getName());
   }
   return message.toString();
 }
예제 #18
0
 public static String toString(byte[] b) {
   if (b == null) {
     return "(null)";
   }
   StringBuffer sb = new StringBuffer(b.length * 3);
   for (int i = 0; i < b.length; i++) {
     int k = b[i] & 0xff;
     if (i != 0) {
       sb.append(':');
     }
     sb.append(hexDigits[k >>> 4]);
     sb.append(hexDigits[k & 0xf]);
   }
   return sb.toString();
 }
예제 #19
0
  /**
   * クラスのオブジェクトを取得する
   *
   * @param String name クラスの名前
   */
  public static Class<?> getClass(String name) {
    StringBuffer tempMessage = new StringBuffer();
    Class<?> cls = null;
    try {
      cls = Class.forName(name);
      tempMessage.append("以下のクラスオブジェクトを取得: " + name + "\r\n");

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      tempMessage.append("ClassNotFoundException\r\n");
    }
    message = tempMessage.toString();
    display.append(message);
    return cls;
  }
예제 #20
0
 static int appendMethodSignature(Class[] argTypes, Class returnType, StringBuffer sb) {
   sb.append('(');
   int firstLocal = 1 + argTypes.length; // includes this.
   for (int i = 0; i < argTypes.length; i++) {
     Class type = argTypes[i];
     appendTypeString(sb, type);
     if (type == Long.TYPE || type == Double.TYPE) {
       // adjust for duble slot
       ++firstLocal;
     }
   }
   sb.append(')');
   appendTypeString(sb, returnType);
   return firstLocal;
 }
    /** Given a line from an input file, generates appropriate check or add command. */
    private static void generateCheckOrAddCommand(String command, int lineNumber) {
      // remove the command
      String args = command.substring(command.indexOf(":") + 1);

      StringTokenizer tokens = new StringTokenizer(args, argDivider);
      if (tokens.countTokens() != types.length) {
        throw new RuntimeException(
            "Number of arguments to generate an add command on line: "
                + lineNumber
                + " is: "
                + tokens.countTokens()
                + " but should be: "
                + types.length);
      }
      Object[] params = getParams(tokens);
      assert !tokens.hasMoreTokens();
      InvariantStatus goalStatus = null;
      if (isCheckCommand(command)) {
        goalStatus = getCheckStatus(params);
      } else {
        goalStatus = getAddStatus(params);
      }
      String invariantFormat = getInvariantFormat();
      results.append(
          command
              + argDivider
              + " "
              + goalStatus.toString()
              + argDivider
              + " "
              + invariantFormat
              + lineSep);
    }
예제 #22
0
 static String liveConnectSignature(Class<?>[] argTypes) {
   int N = argTypes.length;
   if (N == 0) {
     return "()";
   }
   StringBuffer sb = new StringBuffer();
   sb.append('(');
   for (int i = 0; i != N; ++i) {
     if (i != 0) {
       sb.append(',');
     }
     sb.append(javaSignature(argTypes[i]));
   }
   sb.append(')');
   return sb.toString();
 }
예제 #23
0
 /** Receive notification of character data inside an element. */
 @Override
 public void characters(char ch[], int start, int len) {
   while (len > 0 && Character.isWhitespace(ch[start])) {
     ++start;
     --len;
   }
   while (len > 0 && Character.isWhitespace(ch[start + len - 1])) {
     --len;
   }
   if (len > 0) {
     if (_chars.length() > 0) {
       _chars.append(' ');
     }
     _chars.append(ch, start, len);
   }
 }
예제 #24
0
 /**
  * Gets the DTD for the specified doctype file name.
  *
  * @param doctype the doctype file name (e.g., "osp10.dtd")
  * @return the DTD as a string
  */
 public static String getDTD(String doctype) {
   if (dtdName != doctype) {
     // set to defaults in case doctype is not found
     dtdName = defaultName;
     try {
       String dtdPath = "/org/opensourcephysics/resources/controls/doctypes/"; // $NON-NLS-1$
       java.net.URL url = XML.class.getResource(dtdPath + doctype);
       if (url == null) {
         return dtd;
       }
       Object content = url.getContent();
       if (content instanceof InputStream) {
         BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) content));
         StringBuffer buffer = new StringBuffer(0);
         String line;
         while ((line = reader.readLine()) != null) {
           buffer.append(line + NEW_LINE);
         }
         dtd = buffer.toString();
         dtdName = doctype;
       }
     } catch (IOException ex) {
       ex.printStackTrace();
     }
   }
   return dtd;
 }
  /**
   * This function performs an individual formatting test after the input and output streams have
   * been created.
   *
   * @param commands the input that decides which tests to perform
   * @return a String holding the error messages for any failed tests or null if no tests are
   *     failed.
   */
  private static /*@Nullable*/ String performTest(LineNumberReader commands) {
    StringBuffer output = new StringBuffer();
    //  List invariantTestCases = new Vector();
    boolean noTestFailed = true;

    while (true) {
      // Create a new test case
      //  FormatTestCase currentCase = FormatTestCase.instantiate(commands, generateGoals);

      // if (currentCase == null)
      //  break;
      //  else {
      //  invariantTestCases.add(currentCase);
      String results = AddAndCheckTestCase.runTest(commands);
      if (results == null) break;
      if (!(results.length() == 0)) {
        //  output.print(currentCase.getDiffString());
        output.append(results);
        noTestFailed = false;
      }
    }
    if (noTestFailed) {
      return null;
    } else {
      return output.toString();
    }
  }
예제 #26
0
 private String formatName(String name) {
   StringBuffer propertyName = new StringBuffer();
   if (lowerCase) propertyName.append(name.toLowerCase());
   else propertyName.append(name);
   char c = propertyName.charAt(0);
   if (firstLetterUpperCase) {
     if (c >= 'a' && c <= 'z') {
       c += 'A' - 'a';
     }
   } else {
     if (c >= 'A' && c <= 'Z') {
       c -= 'A' - 'a';
     }
   }
   propertyName.setCharAt(0, c);
   return propertyName.toString();
 }
    /**
     * Initializes the fields of this class based on the first two lines of a case which include the
     * class name and parameter types.
     *
     * @return true is end of file is reached.
     */
    private static boolean initFields(LineNumberReader commands, boolean generatingCommands) {

      results = new StringBuffer();

      String className = getNextRealLine(commands);

      // End of file reached
      if (className == null) return true;

      // Load the class from file
      Class<? extends Invariant> classToTest = asInvClass(getClass(className));

      try {
        classToTest.getField("dkconfig_enabled"); // Enable if needs to be done
        InvariantAddAndCheckTester.config.apply(className + ".enabled", "true");
      } catch (NoSuchFieldException e) { // Otherwise do nothing
      }

      if (generatingCommands) {
        results.append(className + lineSep);
      }

      // Instantiate variables to be used as the names in the
      // invariants, variables are labeled a,b,c and so on as they
      // appear
      String typeString = getNextRealLine(commands);

      types = getTypes(typeString);

      VarInfo[] vars = getVarInfos(classToTest, types);
      PptSlice sl = createSlice(vars, daikon.test.Common.makePptTopLevel("Test:::OBJECT", vars));

      // Create an actual instance of the class
      invariantToTest = instantiateClass(classToTest, sl);

      addModified = getAddModified(invariantToTest.getClass());
      checkModified = getCheckModified(invariantToTest.getClass());
      outputProducer = getOutputProducer(invariantToTest.getClass());

      assert getArity(invariantToTest.getClass()) == types.length;

      if (generatingCommands) {
        results.append(typeString + lineSep);
      }
      return false;
    }
  private static String generateCommands(LineNumberReader input) {
    StringBuffer output = new StringBuffer();

    while (true) {
      String commands = AddAndCheckTestCase.generateTest(input);
      if (commands == null) break;
      output.append(commands);
    }
    return output.toString();
  }
예제 #29
0
  /* We look for System property sun.jvm.hotspot.jdi.<vm version>.
   * This property should have the value of JDK HOME directory for
   * the given <vm version>.
   */
  private static String getSAClassPathForVM(String vmVersion) {
    final String prefix = "sun.jvm.hotspot.jdi.";
    // look for exact match of VM version
    String jvmHome = System.getProperty(prefix + vmVersion);
    if (DEBUG) {
      System.out.println("looking for System property " + prefix + vmVersion);
    }

    if (jvmHome == null) {
      // omit chars after first '-' in VM version and try
      // for example, in '1.5.0-b55' we take '1.5.0'
      int index = vmVersion.indexOf('-');
      if (index != -1) {
        vmVersion = vmVersion.substring(0, index);
        if (DEBUG) {
          System.out.println("looking for System property " + prefix + vmVersion);
        }
        jvmHome = System.getProperty(prefix + vmVersion);
      }

      if (jvmHome == null) {
        // System property is not set
        if (DEBUG) {
          System.out.println("can't locate JDK home for " + vmVersion);
        }
        return null;
      }
    }

    if (DEBUG) {
      System.out.println("JDK home for " + vmVersion + " is " + jvmHome);
    }

    // sa-jdi is in $JDK_HOME/lib directory
    StringBuffer buf = new StringBuffer();
    buf.append(jvmHome);
    buf.append(File.separatorChar);
    buf.append("lib");
    buf.append(File.separatorChar);
    buf.append("sa-jdi.jar");
    return buf.toString();
  }
예제 #30
0
 private static void printDebug(String msg, MemberBox member, Object[] args) {
   if (debug) {
     StringBuffer sb = new StringBuffer();
     sb.append(" ----- ");
     sb.append(msg);
     sb.append(member.getDeclaringClass().getName());
     sb.append('.');
     if (member.isMethod()) {
       sb.append(member.getName());
     }
     sb.append(JavaMembers.liveConnectSignature(member.argTypes));
     sb.append(" for arguments (");
     sb.append(scriptSignature(args));
     sb.append(')');
     System.out.println(sb);
   }
 }