Package org.jboss.util

Examples of org.jboss.util.JBossStringBuilder


   protected String convertName(CtClass clazz)
   {
      CtClass temp = clazz;
      if (temp.isArray())
      {
         JBossStringBuilder buffer = new JBossStringBuilder();
         try
         {
            while (temp.isArray())
            {
               buffer.append('[');
               temp = temp.getComponentType();
            }
            if (temp.isPrimitive())
            {
               CtPrimitiveType primitive = (CtPrimitiveType) temp;
               buffer.append(Character.toString(primitive.getDescriptor()));
            }
            else
            {
               buffer.append('L');
               buffer.append(temp.getName());
               buffer.append(';');
            }
            return buffer.toString();
         }
         catch (NotFoundException e)
         {
            throw raiseClassNotFound(clazz.getName(), e);
         }
View Full Code Here


      constructor.setBody("super();");
      result.addConstructor(constructor);
     
      CtClass object = pool.get(Object.class.getName());
     
      JBossStringBuilder buffer = new JBossStringBuilder();
     
      // Signature
      buffer.append("public Object invoke(Object target, Object[] args) throws Throwable {");

      boolean isInstanceMethod = Modifier.isStatic(ctMethod.getModifiers()) == false;

      // Check for null target
      if (check && isInstanceMethod)
      {
         buffer.append("if (target == null) throw new IllegalArgumentException(\"Null target for ");
         buffer.append(ctMethod.getName()).append(ctMethod.getSignature()).append("\");");
      }

      // Check the target
      CtClass declaring = ctMethod.getDeclaringClass();
      boolean needsCast = isInstanceMethod && object.equals(declaring) == false;
      if (check && needsCast)
      {
         buffer.append("if (target instanceof ").append(declaring.getName()).append(" == false) ");
         buffer.append("throw new IllegalArgumentException(\"Target \" + target + \"");
         buffer.append(" is not an instance of ").append(declaring.getName());
         buffer.append(" for ").append(ctMethod.getName()).append(ctMethod.getSignature()).append("\");");
      }

      // Check the parameters
      CtClass[] params = ctMethod.getParameterTypes();
      if (check)
      {
         // Wrong number of args?
         if (params.length != 0)
         {
            buffer.append("if (args == null || args.length != ").append(params.length).append(") ");
            buffer.append("throw new IllegalArgumentException(\"Expected ").append(params.length).append(" parameter(s)");
            buffer.append(" for ").append(ctMethod.getName()).append(ctMethod.getSignature()).append("\");");
         }
         else
         {
            // Didn't expect args
            buffer.append("if (args != null && args.length != 0)");
            buffer.append("throw new IllegalArgumentException(\"Expected no parameters");
            buffer.append(" for ").append(ctMethod.getName()).append(ctMethod.getSignature()).append("\");");
         }
         for (int i = 0; i < params.length; ++i)
         {
            if (object.equals(params[i]) == false)
            {
               String paramType = getBoxedType(params[i]);
               // Primitives can't be null
               if (params[i].isPrimitive())
               {
                  buffer.append("if (args[").append(i).append("] == null) ");
                  buffer.append("throw new IllegalArgumentException(\"Parameter ").append(i);
                  buffer.append(" cannot be null for ").append(params[i].getName());
                  buffer.append(" for ").append(ctMethod.getName()).append(ctMethod.getSignature()).append("\");");
               }
               // Check the parameter types
               buffer.append("if (args[").append(i).append("] != null && ");
               buffer.append("args[").append(i).append("] instanceof ").append(paramType).append(" == false) ");
               buffer.append("throw new IllegalArgumentException(\"Parameter ").append(i).append(" \" + args[").append(i).append("] + \"");
               buffer.append(" is not an instance of ").append(paramType);
               buffer.append(" for ").append(ctMethod.getName()).append(ctMethod.getSignature()).append("\");");
            }
         }
      }
     
      // Add a return and box the return type if necessary
      CtClass returnType = ctMethod.getReturnType();
      boolean isVoid = CtClass.voidType.equals(returnType);
      boolean isPrimitive = returnType.isPrimitive();
      if (isVoid == false)
      {
         buffer.append("return ");
         if (isPrimitive)
            buffer.append("new ").append(getBoxedType(returnType)).append('(');
      }

      // Instance method
      if (isInstanceMethod)
      {
         buffer.append('(');
         if (needsCast)
            buffer.append("(").append(declaring.getName()).append(')');
        
         buffer.append("target).");
      }
      else
      {
         // Static method
         buffer.append(declaring.getName()).append('.');
      }

      // Add the method name
      buffer.append(ctMethod.getName()).append('(');

      // Add the parameters
      for (int i = 0; i < params.length; ++i)
      {
         buffer.append('(');
         // Cast the parameters
         if (object.equals(params[i]) == false)
             buffer.append("(").append(getBoxedType(params[i])).append(')');
         buffer.append("args[").append(i).append("])");
         // Unbox primitive parameters
         if (params[i].isPrimitive())
            unbox(buffer, params[i]);
        
         if (i < params.length - 1)
            buffer.append(", ");
      }
      buffer.append(')');

      // Complete the boxing of the return value
      if (isVoid == false && isPrimitive)
         buffer.append(')');
     
      buffer.append(';');
     
      // Add a return null if there is no return value
      if (isVoid)
         buffer.append("return null;");
      buffer.append('}');

      // Compile it
      String code = buffer.toString();
      try
      {
         CtMethod invoke = CtNewMethod.make(code, result);
         result.addMethod(invoke);
      }
View Full Code Here

      constructor.setBody("super();");
      result.addConstructor(constructor);
     
      CtClass object = pool.get(Object.class.getName());
     
      JBossStringBuilder buffer = new JBossStringBuilder();
     
      // Signature
      buffer.append("public Object newInstance(Object[] args) throws Throwable {");

      String declaring = ctConstructor.getDeclaringClass().getName();
     
      // Check the parameters
      CtClass[] params = ctConstructor.getParameterTypes();
      if (check)
      {
         // Wrong number of args?
         if (params.length != 0)
         {
            buffer.append("if (args == null || args.length != ").append(params.length).append(") ");
            buffer.append("throw new IllegalArgumentException(\"Expected ").append(params.length).append(" parameter(s)");
            buffer.append(" for ").append("new ").append(declaring).append(ctConstructor.getSignature()).append("\");");
         }
         else
         {
            // Didn't expect args
            buffer.append("if (args != null && args.length != 0)");
            buffer.append("throw new IllegalArgumentException(\"Expected no parameters");
            buffer.append(" for ").append("new ").append(declaring).append(ctConstructor.getSignature()).append("\");");
         }
         for (int i = 0; i < params.length; ++i)
         {
            if (object.equals(params[i]) == false)
            {
               String paramType = getBoxedType(params[i]);
               // Primitives can't be null
               if (params[i].isPrimitive())
               {
                  buffer.append("if (args[").append(i).append("] == null) ");
                  buffer.append("throw new IllegalArgumentException(\"Parameter ").append(i);
                  buffer.append(" cannot be null for ").append(params[i].getName());
                  buffer.append(" for ").append("new ").append(declaring).append(ctConstructor.getSignature()).append("\");");
               }
               // Check the parameter types
               buffer.append("if (args[").append(i).append("] != null && ");
               buffer.append("args[").append(i).append("] instanceof ").append(paramType).append(" == false) ");
               buffer.append("throw new IllegalArgumentException(\"Parameter ").append(i).append(" \" + args[").append(i).append("] + \"");
               buffer.append(" is not an instance of ").append(paramType);
               buffer.append(" for ").append("new ").append(declaring).append(ctConstructor.getSignature()).append("\");");
            }
         }
      }
     
      // Add the return new
      buffer.append("return new ").append(declaring).append('(');

      // Add the parameters
      for (int i = 0; i < params.length; ++i)
      {
         buffer.append('(');
         // Cast the parameters
         if (object.equals(params[i]) == false)
             buffer.append("(").append(getBoxedType(params[i])).append(')');
         buffer.append("args[").append(i).append("])");
         // Unbox primitive parameters
         if (params[i].isPrimitive())
            unbox(buffer, params[i]);
        
         if (i < params.length - 1)
            buffer.append(", ");
      }
      buffer.append(");}");

      // Compile it
      String code = buffer.toString();
      try
      {
         CtMethod newInstance = CtNewMethod.make(code, result);
         result.addMethod(newInstance);
      }
View Full Code Here

  
   public int hashCode()
   {
      if (cachedHashCode == Integer.MIN_VALUE)
      {
         JBossStringBuilder builder = new JBossStringBuilder();
         if (name != null)
            builder.append(name);
         if (params != null)
         {
            for (int i = 0; i < params.length; ++i)
               builder.append(params[i]);
         }
         cachedHashCode = builder.toString().hashCode();
      }
      return cachedHashCode;
   }
View Full Code Here

      result.addConstructor(constructor);
     
      CtClass object = pool.get(Object.class.getName());
     
      // GET
      JBossStringBuilder buffer = new JBossStringBuilder();
     
      // Signature
      buffer.append("public Object get(Object target) throws Throwable {");

      boolean isInstanceField= Modifier.isStatic(ctField.getModifiers()) == false;

      // Check for null target
      if (check && isInstanceField)
      {
         buffer.append("if (target == null) throw new IllegalArgumentException(\"Null target");
         buffer.append(" for ").append(ctField.getName()).append("\");");
      }

      // Check the target
      CtClass declaring = ctField.getDeclaringClass();
      boolean needsCast = isInstanceField && object.equals(declaring) == false;
      if (check && needsCast)
      {
         buffer.append("if (target instanceof ").append(declaring.getName()).append(" == false) ");
         buffer.append("throw new IllegalArgumentException(\"Target \" + target + \"");
         buffer.append(" is not an instance of ").append(declaring.getName());
         buffer.append(" for ").append(ctField.getName()).append("\");");
      }
     
      // Add a return and box the return type if necessary
      CtClass type = ctField.getType();
      boolean isPrimitive = type.isPrimitive();
      buffer.append("return ");
      if (isPrimitive)
         buffer.append("new ").append(getBoxedType(type)).append('(');

      // Instance field
      if (isInstanceField)
      {
         buffer.append('(');
         if (needsCast)
            buffer.append("(").append(declaring.getName()).append(')');
        
         buffer.append("target).");
      }
      else
      {
         // Static field
         buffer.append(declaring.getName()).append('.');
      }

      // Add the field name
      buffer.append(ctField.getName());

      // Complete the boxing of the return value
      if (isPrimitive)
         buffer.append(')');
     
      buffer.append(";}");

      // Compile it
      String code = buffer.toString();
      CtMethod get = CtNewMethod.make(code, result);
      try
      {
         result.addMethod(get);
      }
      catch (Exception e)
      {
         throw new RuntimeException("Cannot compile " + code, e);
      }
     
      // SET
      buffer = new JBossStringBuilder();
     
      // Signature
      buffer.append("public void set(Object target, Object value) throws Throwable {");

      // Check for null target
      if (check && isInstanceField)
      {
         buffer.append("if (target == null) throw new IllegalArgumentException(\"Null target");
         buffer.append(" for ").append(ctField.getName()).append("\");");
      }

      // Check the target
      if (check && needsCast)
      {
         buffer.append("if (target instanceof ").append(declaring.getName()).append(" == false) ");
         buffer.append("throw new IllegalArgumentException(\"Target \" + target + \"");
         buffer.append(" is not an instance of ").append(declaring.getName());
         buffer.append(" for ").append(ctField.getName()).append("\");");
      }

      // Check the parameter
      if (check)
      {
         if (object.equals(type) == false)
         {
            String paramType = getBoxedType(type);
            // Primitives can't be null
            if (type.isPrimitive())
            {
               buffer.append("if (type == null) ");
               buffer.append("throw new IllegalArgumentException(\"Value ");
               buffer.append(" cannot be null for ").append(type.getName());
               buffer.append(" for ").append(ctField.getName()).append("\");");
            }
            // Check the parameter types
            buffer.append("if (value != null && ");
            buffer.append("value instanceof ").append(paramType).append(" == false) ");
            buffer.append("throw new IllegalArgumentException(\"Value \" + value + \"");
            buffer.append(" is not an instance of ").append(paramType);
            buffer.append(" for ").append(ctField.getName()).append("\");");
         }
      }

      // Instance Field
      if (isInstanceField)
      {
         buffer.append('(');
         if (needsCast)
            buffer.append("(").append(declaring.getName()).append(')');
        
         buffer.append("target).");
      }
      else
      {
         // Static field
         buffer.append(declaring.getName()).append('.');
      }

      // Add the field name
      buffer.append(ctField.getName()).append("=");

      // Add the value
      buffer.append('(');
      // Cast the value
      if (object.equals(type) == false)
          buffer.append("(").append(getBoxedType(type)).append(')');
      buffer.append("value)");
      // Unbox primitive parameters
      if (type.isPrimitive())
         unbox(buffer, type);
     
      buffer.append(";}");

      // Compile it
      code = buffer.toString();
      try
      {
         CtMethod set = CtNewMethod.make(code, result);
         result.addMethod(set);
      }
View Full Code Here

      {
         if (Character.isUpperCase(name.charAt(1)))
            return name;
      }

      JBossStringBuilder buffer = new JBossStringBuilder(name.length());
      buffer.append(Character.toLowerCase(name.charAt(0)));
      if (name.length() > 1)
         buffer.append(name.substring(1));
      return buffer.toString();
   }
View Full Code Here

      return annotations == null || annotations.length == 0;
   }

   public String toString()
   {
      JBossStringBuilder buffer = new JBossStringBuilder();
      Strings.defaultToString(buffer, this);
      buffer.append("[");
      buffer.append(annotated);
      buffer.append("]");
      return buffer.toString();
   }
View Full Code Here

            log.error("Failed deployment: " + ctx.getName(), ctx.getError());
         }
      }
      if (incomplete.size() != 0)
      {
         JBossStringBuilder buffer = new JBossStringBuilder();
         buffer.append("\n*** DEPLOYMENTS MISSING DEPENDENCIES:\n");
         for (Iterator i = incomplete.iterator(); i.hasNext();)
         {
            KernelControllerContext ctx = (KernelControllerContext) i.next();
            buffer.append(ctx.getName()).append(" depends on: \n");
            DependencyInfo dependsInfo = ctx.getDependencyInfo();
            Set depends = dependsInfo.getIDependOn(null);
            for (Iterator j = depends.iterator(); j.hasNext();)
            {
               DependencyItem item = (DependencyItem) j.next();
               buffer.append("                     ").append(item.getIDependOn()).append("'{").append(item.getWhenRequired().getStateString());
               buffer.append(':');
               ControllerContext other = controller.getContext(item.getIDependOn(), null);
               if (other == null)
                  buffer.append("NOT FOUND");
               else
                  buffer.append(other.getState().getStateString());
               buffer.append('}');
               if (j.hasNext())
                  buffer.append("\n");
            }
            buffer.append('\n');
         }
         log.error(buffer.toString());
      }
      if (errors.size() > 0 || incomplete.size() > 0)
      {
         return false;
      }
View Full Code Here

      }
   }
  
   public String toString()
   {
      JBossStringBuilder buffer = new JBossStringBuilder(100);
      buffer.append("WorkWrapper@").append(Integer.toHexString(System.identityHashCode(this)));
      buffer.append("[workManger=").append(workManager);
      buffer.append(" work=").append(work);
      buffer.append(" state=").append(getStateString());
      if (executionContext != null && executionContext.getXid() != null)
      {
         buffer.append(" xid=").append(executionContext.getXid());
         buffer.append(" txTimeout=").append(executionContext.getTransactionTimeout());
      }
      buffer.append(" waitType=");
      switch (waitType)
      {
         case WAIT_NONE:
         {
            buffer.append("WAIT_NONE");
            break;
         }
         case WAIT_FOR_START:
         {
            buffer.append("WAIT_FOR_START");
            break;
         }
         case WAIT_FOR_COMPLETE:
         {
            buffer.append("WAIT_FOR_COMPLETE");
            break;
         }
         default:
            buffer.append("???");
      }
      if (startTimeout != WorkManager.INDEFINITE)
         buffer.append(" startTimeout=").append(startTimeout);
      long completionTimeout = getCompletionTimeout();
      if (completionTimeout != -1)
         buffer.append(" completionTimeout=").append(completionTimeout);
      if (blockedTime != 0)
         buffer.append(" blockTime=").append(blockedTime);
      buffer.append(" elapsedTime=").append(getElapsedTime());
      if (workListener != null)
         buffer.append(" workListener=").append(workListener);
      if (exception != null)
         buffer.append(" exception=").append(exception);
      buffer.append("]");
      return buffer.toString();
   }
View Full Code Here

   }

   public String showPreparedTransactionsAsHTML()
   {
      List txs = txRepository.getPreparedTransactions();
      JBossStringBuilder buffer = new JBossStringBuilder();
      buffer.append("<table width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">");
      buffer.append("<tr><th>Xid</th></tr>");
      for (Iterator i = txs.iterator(); i.hasNext();)
      {
         Xid xid = (Xid)i.next();
         if (xid != null)
         {
            buffer.append("<tr><td>");
            buffer.append(xid);
            buffer.append("</td></tr>");
         }
      }
      buffer.append("</table>");
      return buffer.toString();
   }
View Full Code Here

TOP

Related Classes of org.jboss.util.JBossStringBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.