Package org.jboss.util

Examples of org.jboss.util.JBossStringBuilder


      {
         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 uninstallMethod;
   }

   public String toShortString()
   {
      JBossStringBuilder buffer = new JBossStringBuilder();
      toShortString(buffer);
      return buffer.toString();
   }
View Full Code Here

               if (ctx.getState().equals(ControllerState.ERROR))
                  errors.add(ctx);
               else
                  incomplete.add(ctx);
            }
            JBossStringBuilder buffer = new JBossStringBuilder();
            buffer.append("Incompletely deployed:\n");
            if (errors.size() != 0)
            {
               buffer.append("\n*** DEPLOYMENTS IN ERROR: Name -> Error\n");
               for (Iterator i = errors.iterator(); i.hasNext(); )
               {
                  KernelControllerContext ctx = (KernelControllerContext) i.next();
                  buffer.append(ctx.getName()).append(" -> ").append(ctx.getError().toString()).append('\n');
               }
            }
            if (incomplete.size() != 0)
            {
               buffer.append("\n*** DEPLOYMENTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}\n");
               for (Iterator i = incomplete.iterator(); i.hasNext();)
               {
                  KernelControllerContext ctx = (KernelControllerContext) i.next();
                  buffer.append(ctx.getName()).append(" -> ");
                  DependencyInfo dependsInfo = ctx.getDependencyInfo();
                  Set depends = dependsInfo.getIDependOn(null);
                  for (Iterator j = depends.iterator(); j.hasNext();)
                  {
                     DependencyItem item = (DependencyItem) j.next();
                     buffer.append(item.getIDependOn()).append('{').append(item.getWhenRequired().getStateString());
                     buffer.append(':');
                     Object iDependOn = item.getIDependOn();
                     if (iDependOn == null)
                     {
                        // FIXME needs to print something better than item.toString()
                        buffer.append("** UNRESOLVED " + item + " **");
                     }
                     else
                     {
                        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(", ");
                  }
                  buffer.append('\n');
               }
            }
            throw new IllegalStateException(buffer.toString());
         }
      }
   }
View Full Code Here

    */
   protected void internalValidateContext(ControllerContext ctx, Set<String> errors, Map<Object, String> incomplete)
   {
      if (ctx.getState().equals(ControllerState.ERROR))
      {
         JBossStringBuilder builder = new JBossStringBuilder();
         builder.append("Profile: ").append(ctx.getName());
         builder.append(" in error due to ").append(ctx.getError().toString());
         errors.add(builder.toString());
      }
      else
      {
         Object name = ctx.getName();
         if(incomplete.containsKey(name))
            return;
        
         DependencyInfo dependsInfo = ctx.getDependencyInfo();
         Set<DependencyItem> depends = dependsInfo.getIDependOn(null);
         for (DependencyItem item : depends)
         {
            ControllerState dependentState = item.getDependentState();
            if (dependentState == null)
               dependentState = ControllerState.INSTALLED;
           
            ControllerState otherState = null;
            ControllerContext other = null;
            Object iDependOn = item.getIDependOn();

            if (name.equals(iDependOn) == false)
            {
               if (iDependOn != null)
               {
                  other = controller.getContext(iDependOn, null);
                  if (other != null)
                     otherState = other.getState();
               }

               boolean print = true;
               if (otherState != null && otherState.equals(ControllerState.ERROR) == false)
               {
                  ControllerStateModel states = controller.getStates();
                  if (states.isBeforeState(otherState, dependentState) == false)
                     print = false;
               }

               if (print)
               {
                  JBossStringBuilder buffer = new JBossStringBuilder();
                  buffer.append(name).append(" is missing following dependencies: ");

                  buffer.append(iDependOn).append('{').append(dependentState.getStateString());
                  buffer.append(':');
                  if (iDependOn == null)
                  {
                     buffer.append("** UNRESOLVED " + item.toHumanReadableString() + " **");
                  }
                  else
                  {
                     if (other == null)
                        buffer.append("** NOT FOUND **");
                     else
                        buffer.append(otherState.getStateString());
                  }
                  buffer.append('}');

                  // Add Error message and check other context.
                  incomplete.put(name, buffer.toString());
                  if(other!= null && incomplete.containsKey(other) == false)
                  {
                     internalValidateContext(other, errors, incomplete);
                  }
               }
View Full Code Here

   protected void logErrors(Set<String> errors, Collection<String> incomplete) throws Exception
   {
      if(errors.isEmpty() && incomplete.isEmpty())
         return;

      JBossStringBuilder buffer = new JBossStringBuilder();
      buffer.append("Incompletely deployed:\n");
     
      // Append errors
      if(errors.size() != 0)
      {
         buffer.append("\n*** PROFILES IN ERROR: Name -> Error\n");
         for(String error : errors)
            buffer.append(error).append('\n');
      }
     
      // Append missing dependencies
      if(incomplete.size() != 0)
      {
         buffer.append("\n*** PROFILES MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}\n");
         for(String missing : incomplete)
            buffer.append(missing).append('\n');
      }
     
      // Fail
      throw new IllegalStateException(buffer.toString());
   }
View Full Code Here

      Locator locator = delegateHandler.getDocumentLocator();
      if (locator == null)
         return fileName;
      else
      {
         JBossStringBuilder buffer = new JBossStringBuilder();
         String id = locator.getSystemId();
         if (id == null)
            id = locator.getPublicId();
         buffer.append(id).append('@');
         buffer.append(locator.getLineNumber());
         buffer.append(',');
         buffer.append(locator.getColumnNumber());
         return buffer.toString();
      }
   }
View Full Code Here

   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

   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

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.