Package org.destecs.tools.jprotocolgenerator.ast

Examples of org.destecs.tools.jprotocolgenerator.ast.Type


    Method toMapMethod = new Method();
    toMapMethod.name = "toMap";
    toMapMethod.returnType = new FreeTextType("Map<String,? extends Object>");// new Type( new MapType(new
    // Type(String.class), new
    // Type(Object.class));
    stryctInterface.imports.add(new Type(Map.class));
    stryctInterface.definitions.add(toMapMethod);

    StringBuffer sb = new StringBuffer();
    this.packageName = intf.packageName;
    this.structPackageName = this.packageName + ".structs";
    GenerateProxy.outputFolder = outputFolder;
    sb.append("package " + intf.packageName + ";");

    sb.append("\n");

    for (ITypeNode c : intf.imports)
    {
      sb.append("\nimport " + c.getName() + ";");
    }
    sb.append("\nimport " + new Type(Hashtable.class).getName() + ";");
    sb.append("\nimport " + new Type(Vector.class).getName() + ";");
    sb.append("\nimport " + structPackageName + ".*;");

    sb.append("\n");
    String name = "Proxy" + intf.getName();
    sb.append("\n");
View Full Code Here


    if (m.returnType instanceof MapType)
    {
      returnClass = new ClassDefinition();
      returnClass.setName(m.name + "Struct");
      returnClass.packageName = structPackageName;
      returnClass.imports.add(new Type(Map.class));
      returnClass.imports.add(new Type(List.class));
      returnClass.implemented.add(stryctInterface);
      sb.append(returnClass.getName());
    } else
    {

      sb.append(m.returnType.toSource());
    }
    sb.append(" ");
    sb.append(m.name);
    sb.append("(");

    Parameter p1 = m.parameters.get(0);

    MapType type = (MapType) p1.type;

    Map<String, ClassDefinition> structs = new Hashtable<String, ClassDefinition>();

    for (String key : type.possibleEntries.keySet())
    {
      ITypeNode t = type.possibleEntries.get(key);
      if ((t instanceof ListType
          && ((ListType) t).type instanceof MapType || t instanceof MapType))
      {

        ClassDefinition pClass = new ClassDefinition();
        pClass.setName(m.name + key + "StructParam");
        pClass.packageName = structPackageName;
        pClass.imports.add(new Type(Map.class));
        pClass.imports.add(new Type(List.class));
        pClass.implemented.add(stryctInterface);
        defs.add(pClass);
        structs.put(key, pClass);
        MapType mType = null;
        if (t instanceof ListType)
        {
          mType = (MapType) ((ListType) t).type;
        } else
        {
          mType = (MapType) t;
        }
        defs.addAll(generateStructs(pClass, structPackageName, mType));

        if (t instanceof ListType)
        {
          sb.append("List<" + pClass.getName() + ">");
        } else
        {

          sb.append(pClass.getName());
        }
      } else
      {

        sb.append(type.possibleEntries.get(key).toSource());
      }
      sb.append(" ");
      sb.append(key);
      sb.append(",");
    }
    if (type.possibleEntries.size() > 0)
    {
      sb.deleteCharAt(sb.length() - 1);
    }

    sb.append(")");

    if (!m.throwsTypes.isEmpty())
    {
      sb.append(m.getThrowsSourceSegment());
    }

    sb.append("\n\t{");

    sb.append("\n\t\t" + p1.type.toSource() + " data = new "
        + p1.type.toSource().replaceFirst("Map", "Hashtable") + "();");

    Integer pCount = 0;
    for (String key : type.possibleEntries.keySet())
    {

      if (structs.containsKey(key))
      {
        ITypeNode t = ((MapType) p1.type).valueType;
        if (t.getName().contains(Object.class.getSimpleName()))
        {
          t = new ListType(new Type(Object.class));
        }

        MapType mapt = ((MapType) p1.type);
        if (mapt.valueType instanceof ListType)
        {
View Full Code Here

        {
          swa.warnings.add(WarningTypes.unchecked);
          ClassDefinition newRet = new ClassDefinition();
          newRet.setName(m.name + p + appendName);
          newRet.packageName = packageName2;
          newRet.imports.add(new Type(Map.class));
          newRet.imports.add(new Type(List.class));
          newRet.implemented.add(stryctInterface);
          returnClass.imports.add(new Type(Vector.class));

          defs.addAll(generateStructs(newRet, packageName2, (MapType) ((ListType) type).type, isParameter));
          defs.add(newRet);
          f.type = new ListType(newRet);
          m.body += f.type.getName() + " tmp" + count
              + " = new Vector<" + newRet.getName()
              + ">();\n\t\t";

          m.body += "if( value.keySet().contains(\"" + f.getName()
              + "\" ))\n\t\t";
          m.body += "{\n\t\t\t";

          if (map.valueType instanceof List
              || map.valueType instanceof ListType)
          {
            m.body += "Object tmpL" + count + " = value.get(\""
                + f.getName() + "\");\n\t\t\t";
            m.body += "for( Object m : (Object[])tmpL" + count
                + ")\n\t\t\t";

          } else
          {
            m.body += "for( Object m : (Object[])value.get(\""
                + f.getName() + "\"))\n\t\t\t";
          }

          m.body += "{\n\t\t\t\t";

          m.body += "tmp" + count + ".add( new " + newRet.getName()
              + "( (" + ((ListType) type).type + ") m)";
          m.body += ");\n\t\t\t";

          m.body += "}\n\t\t";

          m.body += "}\n\t\t";

          m.body += "this." + f.getName() + " = tmp" + count
              + ";\n\n\n\t\t\t";

        } else
        {
          f.type = map.possibleEntries.get(p);
          // m.body += "this." + f.getName() + " = (" + f.type.getName()
          // + ") value.get(value.keySet().toArray()[" + count
          // + "]);\n\t\t";
          m.body += "if( value.keySet().contains(\"" + f.getName()
              + "\" ))\n\t\t";
          m.body += "{\n\t\t\t";

          if (map.valueType instanceof List
              || map.valueType instanceof ListType)
          {
            m.body += "Object tmpL" + count + " = value.get(\""
                + f.getName() + "\");\n\t\t\t";
            m.body += "for( Object m : (Object[])tmpL" + count
                + ")\n\t\t\t";

          } else
          {
            m.body += "for( Object m : (Object[])value.get(\""
                + f.getName() + "\"))\n\t\t\t";
          }

          m.body += "{\n\t\t\t\t";

          m.body += "this." + f.getName() + ".add(("
              + ((ListType) type).type + ") m";
          m.body += ");\n\t\t\t";

          m.body += "}\n\t\t";

          m.body += "}\n\t\t";

        }
      } else if (type instanceof MapType)
      {
        ClassDefinition newRet = new ClassDefinition();
        newRet.setName(m.name + p + appendName);
        newRet.packageName = packageName2;
        newRet.imports.add(new Type(Map.class));
        newRet.imports.add(new Type(List.class));
        newRet.implemented.add(stryctInterface);

        defs.addAll(generateStructs(newRet, packageName2, (MapType) type, isParameter));
        defs.add(newRet);
        f.type = newRet;
View Full Code Here

      // {
      ClassDefinition returnClass = null;
      returnClass = new ClassDefinition();
      returnClass.setName(m.name + "Struct");
      returnClass.packageName = structPackageName;
      returnClass.imports.add(new Type(Map.class));
      returnClass.imports.add(new Type(List.class));
      returnClass.implemented.add(stryctInterface);
      newM.returnType = returnClass;

      sb.append("new " + returnClass.getName() + "(");
      List<ClassDefinition> defs = generateStructs(returnClass, structPackageName, (MapType) m.returnType);
View Full Code Here

      interfaceNode.packageName = packageName;
      sb.append("package " + packageName + ";");

      sb.append("\n");

      interfaceNode.imports.add(new Type(Map.class));
      interfaceNode.imports.add(new Type(List.class));
      interfaceNode.imports.add(new RpcMethodType());

      sb.append("\nimport " + Map.class.getName() + ";");
      sb.append("\nimport " + List.class.getName() + ";");
      sb.append("\n");
View Full Code Here

    List<Parameter> parameters = new Vector<Parameter>();
    // Element paramsNode = (Element) element.getElementsByTagName(TAG_PARAMS).item(0);

    if (!paramsNode.hasChildNodes())
    {
      parameters.add(new Parameter(new Type(Void.class)));
    } else
    {

      for (Element param : getElements(paramsNode.getElementsByTagName(TAG_PARAM)))
      {
View Full Code Here

      System.err.println("Invalid param value node: " + value);
    }

    if (!value.hasChildNodes())
    {
      return new Parameter(new Type(String.class), getValidJavaName(name));

    } else
    {

      Element typeNode = getFirstChildElement(value);
View Full Code Here

        if (rangeType == null)
        {
          rangeType = getType(nextedTypeElement);
        } else if (!rangeType.equals(getType(nextedTypeElement)))
        {
          rangeType = new Type(Object.class);
          break;
        }
      }
    }
View Full Code Here

            {
              rangeType = possibleType;

            } else if (!rangeType.equals(possibleType))
            {
              rangeType = new Type(Object.class);
              break;
            }
          } else if (value.getNodeName().equals(TAG_NAME))
          {
            if (value.hasChildNodes())
            {
              possibleName = value.getFirstChild().getNodeValue();
            } else
            {
              possibleName = "";
            }
          }
        }
        if (possibleName != null
            && !mapType.possibleEntries.containsKey(possibleName))
        {
          mapType.possibleEntries.put(possibleName, possibleType);
        }
      }
    }

    if (rangeType == null)
    {
      System.err.println("Error at node: " + getNodePath(typeNode));
      rangeType = TYPE_ERROR;
    }

    sb.append(rangeType);
    sb.append(">");

    mapType.keyType = new Type(String.class);
    mapType.valueType = rangeType;

    return mapType; // new MapType(new Type(String.class),rangeType); //sb.toString();
  }
View Full Code Here

  private static ITypeNode getBasicType(Element typeElement)
  {
    if (typeElement.getNodeName().equals(TAG_BOOLEAN))
    {
      return new Type(Boolean.class);
    } else if (typeElement.getNodeName().equals(TAG_STRING))
    {
      return new Type(String.class);
    } else if (typeElement.getNodeName().equals(TAG_INT))
    {
      return new Type(Integer.class);
    } else if (typeElement.getNodeName().equals(TAG_DOUBLE))
    {
      return new Type(Double.class);
    }

    return null;
  }
View Full Code Here

TOP

Related Classes of org.destecs.tools.jprotocolgenerator.ast.Type

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.