Package org.stringtemplate.v4.misc

Examples of org.stringtemplate.v4.misc.ObjectModelAdaptor


    EvalTemplateEvent e = ((Wrapper)parent).event;
    return e.scope.childEvalTemplateEvents.size();
  }

  public int getIndexOfChild(Object parent, Object child) {
    EvalTemplateEvent p = ((Wrapper)parent).event;
    EvalTemplateEvent c = ((Wrapper)parent).event;
        int i = 0;
        for (EvalTemplateEvent e : p.scope.childEvalTemplateEvents) {
            if ( e.scope.st == c.scope.st ) {
//        System.out.println(i);
//        System.out.println("found "+e.self+" as child of "+parentST);
View Full Code Here


        viewFrame.trace.setText(Misc.join(trace.iterator(), "\n"));

        CaretListener caretListenerLabel = new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                int dot = e.getDot();
                InterpEvent de = findEventAtOutputLocation(allEvents, dot);
                if ( de==null ) currentScope = tmodel.root.event.scope;
        else currentScope = de.scope;

        // update tree view of template hierarchy
        // compute path from root to currentST, create TreePath for tree widget
View Full Code Here

      new Interpreter(groupThatCreatedThisInstance, locale, true);
    interp.exec(wr, this); // render and track events
    List<InterpEvent> events = interp.getEvents();
    EvalTemplateEvent overallTemplateEval =
      (EvalTemplateEvent)events.get(events.size()-1);
    STViz viz = new STViz(errMgr, overallTemplateEval, out.toString(), interp,
                interp.getExecutionTrace(), errors.errors);
    viz.open();
    return viz;
  }
View Full Code Here

    gen.writeVocabFile();
  }

  protected void writeRecognizer(ST template, CodeGenerator gen) {
    if ( g.tool.launch_ST_inspector ) {
      STViz viz = template.inspect();
      if (g.tool.ST_inspector_wait_for_close) {
        try {
          viz.waitForClose();
        }
        catch (InterruptedException ex) {
          g.tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, ex);
        }
      }
View Full Code Here

    {
      boolean can_break = false;
      Object tok = tokens.get(i);
      if( tok instanceof Aggregate )
      {
        Aggregate atok = (Aggregate) tok;
        for (Map.Entry<String, Object> pairs : atok.properties.entrySet()) {
          if( pairs.getValue().equals("EOF") )
          {
            tokens.remove(i);
            can_break = true;
View Full Code Here

        return entity.getTypeName();
      }
    });

    group.registerModelAdaptor(EntityDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {

            EntityDescription entity = (EntityDescription) o;
            if ("docString".equals(propertyName)) {
              return jsDocString(entity.getDocString());
            }

            else if ("canonicalName".equals(propertyName)) {
              return getPackageName(entity) + "." + upcase(entity.getTypeName());
            }

            else if ("supertype".equals(propertyName)) {
              EntityDescription supertype = entity.getSupertype();
              if (supertype == null) {
                supertype = baseHasUuid;
              }
              return supertype;
            }

            else if ("properties".equals(propertyName)) {

              Map<String, Property> propertyMap = new HashMap<String, Property>();
              for (Property p : entity.getProperties()) {
                propertyMap.put(p.getName(), p);
              }

              List<Property> sortedProperties = new ArrayList<Property>();
              sortedProperties.addAll(propertyMap.values());
              Collections.sort(sortedProperties, new Comparator<Property>() {
                @Override
                public int compare(Property p1, Property p2) {
                  return p1.getName().compareTo(p2.getName());
                }
              });

              return sortedProperties;
            }

            else if ("collectionProperties".equals(propertyName)) {
              return getSortedCollectionProperties(entity);
            }

            else if ("uniqueTypeCollectionListProperties".equals(propertyName)) {
              List<Property> props = getSortedCollectionProperties(entity);
              Iterator<Property> iter = props.iterator();

              Set<String> seen = new HashSet<String>();
              while (iter.hasNext()) {
                Property prop = iter.next();
                String name = collectionNameForProperty(prop);
                if (!seen.contains(name)) {
                  seen.add(name);
                }
                else {
                  iter.remove();
                }
              }
              return props;
            }

            else if ("validations".equals(propertyName)) {
              Map<String, List<String>> map = new HashMap<String, List<String>>();

              for (Property p : entity.getProperties()) {
                List<String> validations = new ArrayList<String>();

                List<Annotation> docAnnotations = p.getDocAnnotations();
                if (docAnnotations != null) {
                  for (Annotation a : docAnnotations) {
                    String name = a.annotationType().getName();

                    String validation = validationMap.get(name);
                    if (validation != null) {
                      validation = "new " + validation + "(";
                      validation += getValidationParameters(a);
                      validation += ")";
                      validations.add(validation);
                    }
                  }
                }

                if (!validations.isEmpty()) {
                  map.put(p.getName(), validations);
                }
              }
              return map;
            }

            else if ("validationRequires".equals(propertyName)) {
              Set<String> requires = new HashSet<String>();

              for (Property p : entity.getProperties()) {
                List<Annotation> docAnnotations = p.getDocAnnotations();
                if (docAnnotations != null) {
                  for (Annotation a : docAnnotations) {
                    String name = a.annotationType().getName();
                    String require = validationMap.get(name);
                    if (require != null) {
                      requires.add(require);
                    }
                  }
                }
              }

              return requires;
            }

            return super.getProperty(interp, self, o, property, propertyName);
          }

        });

    group.registerModelAdaptor(Property.class, new ObjectModelAdaptor() {
      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {
        Property p = (Property) o;
        if ("docString".equals(propertyName)) {
          String docString = jsDocString(p.getDocString());

          List<String> enumValues = p.getType().getEnumValues();
          if (enumValues == null && p.getType().getListElement() != null &&
            p.getType().getListElement().getEnumValues() != null) {
            enumValues = p.getType().getListElement().getEnumValues();
          }
          if (enumValues != null) {
            docString = docString == null ? "" : docString;
            docString += "\n\nPossible values: ";
            for (int i = 0; i < enumValues.size(); i++) {
              docString += enumValues.get(i);
              if (i < enumValues.size() - 1) docString += ", ";
            }
          }

          return docString;

        }

        else if ("jsType".equals(propertyName)) {
          return jsTypeForType(p.getType());
        }

        else if ("listElementEnum".equals(propertyName)) {
          if (p.getType() != null && p.getType().getListElement() != null &&
            p.getType().getListElement().getEnumValues() != null) {
            String enumVals = "";
            int idx = 0;
            for (String val : p.getType().getListElement().getEnumValues()) {
              if (idx != 0) {
                enumVals += ", ";
              }
              enumVals += val;
              idx++;
            }
            return enumVals;
          }
        }

        else if ("listElementKind".equals(propertyName)) {
          if (p.getType().getListElement() != null &&
            p.getType().getListElement().getName() != null) {
            return (packageName + "." + upcase(p.getType().getListElement().toString()));
          }
        }

        else if ("collectionName".equals(propertyName)) {
          return collectionNameForProperty(p);
        }

        else if ("canonicalListElementKind".equals(propertyName)) {
          if (p.getType().getListElement() != null) {

            String collectionModelType = jsTypeForType(p.getType().getListElement());
            Property implied = p.getImpliedProperty();
            if (implied != null) {
              return "function(attrs, options) {\n" +
                "      return new " + collectionModelType + "(\n" +
                "        _(attrs).extend({ " + implied.getName()
                + " : self }), options);\n" +
                "    }";
            }
            else {
              return collectionModelType;
            }
          }
        }

        else if ("defaultValue".equals(propertyName)) {
          String defaultVal = "undefined";
          if (p.isEmbedded()) {
            defaultVal = "new " + jsTypeForType(p.getType()) + "()";
          }
          if (p.getType().getJsonKind().equals(JsonKind.LIST) &&
            jsTypeForType(p.getType().getListElement()).equals("String")) {
            defaultVal = "[]";
            jsTypeForType(p.getType());
          }
          else if (p.getType().getJsonKind().equals(JsonKind.LIST) &&
            p.getType().getListElement().getName() != null) {
            defaultVal = "new " + collectionNameForProperty(p) + "()";
          }
          else if (p.getType().getJsonKind().equals(JsonKind.MAP)) {
            return "{}";
          }
          return defaultVal;
        }

        return super.getProperty(interp, self, o, property, propertyName);
      }
    });

    group.registerModelAdaptor(String.class, new ObjectModelAdaptor() {

      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {
        final String string = (String) o;
        if ("chunks".equals(propertyName)) {
          /*
           * Split a string into individual chunks that can be reflowed. This implementation is
           * pretty simplistic, but helps make the generated documentation at least somewhat more
           * readable.
           */
          return new Iterator<CharSequence>() {
            int index;
            int length = string.length();
            CharSequence next;

            {
              advance();
            }

            @Override
            public boolean hasNext() {
              return next != null;
            }

            @Override
            public CharSequence next() {
              CharSequence toReturn = next;
              advance();
              return toReturn;
            }

            @Override
            public void remove() {
              throw new UnsupportedOperationException();
            }

            private void advance() {
              int start = advance(false);
              int end = advance(true);
              if (start == end) {
                next = null;
              } else {
                next = string.subSequence(start, end);
              }
            }

            /**
             * Advance to next non-whitespace character.
             */
            private int advance(boolean whitespace) {
              while (index < length
                && (whitespace ^ Character.isWhitespace(string.charAt(index)))) {
                index++;
              }
              return index;
            }
          };
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }
    });

    group.registerModelAdaptor(ApiDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            ApiDescription apiDescription = (ApiDescription) o;
            if ("endpoints".equals(propertyName)) {
              Set<EndpointDescription> uniqueEndpoints =
                  new HashSet<EndpointDescription>(apiDescription.getEndpoints());
              List<EndpointDescription> sortedEndpoints = new ArrayList<EndpointDescription>(
                  uniqueEndpoints);
              Collections.sort(sortedEndpoints, new Comparator<EndpointDescription>() {
                @Override
                public int compare(EndpointDescription e1, EndpointDescription e2) {
                  return e1.getPath().compareTo(e2.getPath());
                }
              });
              Iterator<EndpointDescription> iter = sortedEndpoints.iterator();
              while (iter.hasNext()) {
                EndpointDescription ed = iter.next();
                if (ed.getPath() != null && ed.getPath().contains("{path:.*}")) {
                  iter.remove();
                }
              }
              return sortedEndpoints;
            }
            else if ("flatpackEndpoints".equals(propertyName)) {
              List<EndpointDescription> sortedEndpoints = new ArrayList<EndpointDescription>(
                  apiDescription.getEndpoints());
              Collections.sort(sortedEndpoints, new Comparator<EndpointDescription>() {
                @Override
                public int compare(EndpointDescription e1, EndpointDescription e2) {
                  return e1.getPath().compareTo(e2.getPath());
                }
              });
              Iterator<EndpointDescription> iter = sortedEndpoints.iterator();
              while (iter.hasNext()) {
                if (!hasCustomRequestBuilderClass(iter.next())) {
                  iter.remove();
                }
              }
              return sortedEndpoints;
            }
            else if ("requireNames".equals(propertyName)) {
              return entityRequires;
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(EndpointDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            EndpointDescription end = (EndpointDescription) o;
            if ("docString".equals(propertyName)) {
              return jsDocString(end.getDocString());
            }
            if ("methodName".equals(propertyName)) {

              String path = end.getPath();
              String[] parts = path.split(Pattern.quote("/"));
              StringBuilder sb = new StringBuilder();
              sb.append(end.getMethod().toLowerCase());
              for (int i = 3, j = parts.length; i < j; i++) {
                String part = parts[i];
                if (part.length() == 0) continue;
                if (!part.startsWith("{") && !part.endsWith("}")) {
                  if (part.contains(".")) {
                    String[] dotPart = part.split(Pattern.quote("."));
                    for (String dot : dotPart) {
                      sb.append(upcase(dot));
                    }
                  }
                  else {
                    sb.append(upcase(part));
                  }
                }
                else {
                  sb.append(upcase(part.substring(1, part.length() - 1)));
                }
              }

              return sb.toString();
            }

            else if ("methodParameterList".equals(propertyName)) {
              String path = end.getPath();
              String[] parts = path.split(Pattern.quote("/"));
              StringBuilder sb = new StringBuilder();
              int paramCount = 0;
              for (int i = 3, j = parts.length; i < j; i++) {
                String part = parts[i];
                if (part.length() == 0) continue;

                if (part.startsWith("{") && part.endsWith("}")) {
                  String name = part.substring(1, part.length() - 1);
                  sb.append(name);
                  paramCount++;
                  if (end.getPathParameters() != null
                    && paramCount < end.getPathParameters().size()) {
                    sb.append(", ");
                  }
                }
              }
              if (end.getEntity() != null) {
                if (paramCount > 0) {
                  sb.append(", ");
                }
                sb.append(getNameForType(end.getEntity()));
              }

              return sb.toString();
            }
            else if ("entityName".equals(propertyName)) {
              return getNameForType(end.getEntity());
            }
            else if ("requestBuilderClassName".equals(propertyName)) {

              if (hasCustomRequestBuilderClass(end)) {
                return getBuilderReturnType(end);
              }
              else {
                return "com.getperka.flatpack.client.JsonRequest";
              }
            }

            else if ("requestBuilderBlockName".equals(propertyName)) {
              return getBuilderReturnType(end) + "Block";
            }

            else if ("pathDecoded".equals(propertyName)) {
              // URL-decode the path in the endpoint description
              try {
                String decoded = URLDecoder.decode(end.getPath(), "UTF8");
                return decoded;
              } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
              }
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }

        });

    group.registerModelAdaptor(ParameterDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            ParameterDescription param = (ParameterDescription) o;
View Full Code Here

        return entity.getTypeName();
      }
    });

    group.registerModelAdaptor(ApiDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            ApiDescription apiDescription = (ApiDescription) o;
            if ("endpoints".equals(propertyName)) {
              List<EndpointDescription> sortedEndpoints = new ArrayList<EndpointDescription>(
                  apiDescription.getEndpoints());
              Collections.sort(sortedEndpoints, new Comparator<EndpointDescription>() {
                @Override
                public int compare(EndpointDescription e1, EndpointDescription e2) {
                  return e1.getPath().compareTo(e2.getPath());
                }
              });
              return sortedEndpoints;
            }
            else if ("importNames".equals(propertyName)) {
              Set<String> imports = new HashSet<String>();
              for (EndpointDescription e : apiDescription.getEndpoints()) {
                if (e.getEntity() != null) {
                  String type = objcTypeForType(e.getEntity());
                  if (isRequiredImport(type)) {
                    imports.add(type);
                  }
                }
                if (e.getReturnType() != null) {
                  String type = objcTypeForType(e.getReturnType());
                  if (isRequiredImport(type)) {
                    imports.add(type);
                  }
                }
              }
              List<String> sortedImports = new ArrayList<String>(imports);
              Collections.sort(sortedImports);
              return sortedImports;
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(EndpointDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            EndpointDescription end = (EndpointDescription) o;
            if ("docString".equals(propertyName)) {
              return doxygenDocString(end.getDocString());
            }
            else if ("methodName".equals(propertyName)) {
              StringBuilder sb = new StringBuilder();

              sb.append("- (" + getBuilderReturnType(end) + " *)");

              sb.append(getMethodizedPath(end));

              if (end.getEntity() != null) {
                if (end.getPathParameters() != null && end.getPathParameters().size() > 0) {
                  sb.append(" entity");
                }
                String type = objcTypeForType(end.getEntity());
                sb.append(":(" + type + " *)");
                String paramName = type;
                if (type.startsWith(classPrefix)) {
                  paramName = downcase(type.substring(classPrefix.length()));
                }
                sb.append(paramName);
              }

              return sb.toString();
            }

            else if ("requestBuilderClassName".equals(propertyName)) {
              return getBuilderReturnType(end);
            }

            else if ("requestBuilderBlockName".equals(propertyName)) {
              return getBuilderReturnType(end) + "Block";
            }

            else if ("entityReturnType".equals(propertyName)) {
              String type = objcFlatpackReturnType(end.getReturnType());
              return type.equals("void") ? null : type;
            }

            else if ("entityReturnName".equals(propertyName)) {
              if (end.getReturnType() == null) return null;

              String name = "result";
              if (end.getReturnType().getName() != null) {
                name = end.getReturnType().getName();
              }

              if (end.getReturnType().getListElement() != null) {
                if (end.getReturnType().getListElement().getName() != null) {
                  name = end.getReturnType().getListElement().getName();
                }
                name = pluralOf(name);
              }

              return name;
            }

            else if ("pathDecoded".equals(propertyName)) {
              // URL-decode the path in the endpoint description
              try {
                String decoded = URLDecoder.decode(end.getPath(), "UTF8");
                return decoded;
              } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
              }
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(EntityDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {

            EntityDescription entity = (EntityDescription) o;
            if ("importNames".equals(propertyName)) {
              Set<String> imports = new HashSet<String>();
              String type = requireNameForType(entity.getTypeName());
              if (isRequiredImport(type)) {
                imports.add(type);
              }
              for (Property p : entity.getProperties()) {
                String name = null;
                if (p.getType().getListElement() != null) {
                  name = objcTypeForType(p.getType().getListElement());
                }
                else {
                  name = objcTypeForProperty(p);
                }
                if (name != null && isRequiredImport(name)) {
                  imports.add(name);
                }
              }
              List<String> sortedImports = new ArrayList<String>(imports);
              Collections.sort(sortedImports);
              return sortedImports;
            }
            if ("docString".equals(propertyName)) {
              return doxygenDocString(entity.getDocString());
            }
            else if ("payloadName".equals(propertyName)) {
              return entity.getTypeName();
            }

            else if ("supertype".equals(propertyName)) {
              EntityDescription supertype = entity.getSupertype();
              if (supertype == null) {
                supertype = baseHasUuid;
              }
              return supertype;
            }

            else if ("requireName".equals(propertyName)) {
              return requireNameForType(entity.getTypeName());
            }

            else if ("properties".equals(propertyName)) {

              Map<String, Property> propertyMap = new HashMap<String, Property>();
              for (Property p : entity.getProperties()) {
                propertyMap.put(p.getName(), p);
              }

              List<Property> sortedProperties = new ArrayList<Property>();
              sortedProperties.addAll(propertyMap.values());
              Collections.sort(sortedProperties, new Comparator<Property>() {
                @Override
                public int compare(Property p1, Property p2) {
                  return p1.getName().compareTo(p2.getName());
                }
              });

              return sortedProperties;
            }

            else if ("entityProperties".equals(propertyName)) {

              Map<String, Property> propertyMap = new HashMap<String, Property>();
              for (Property p : entity.getProperties()) {

                // TODO if we decide to encode enum types, we'll want to remove the second condition
                if (p.getType().getName() != null) {
                  propertyMap.put(p.getName(), p);
                }
              }

              List<Property> sortedProperties = new ArrayList<Property>();
              sortedProperties.addAll(propertyMap.values());
              Collections.sort(sortedProperties, new Comparator<Property>() {
                @Override
                public int compare(Property p1, Property p2) {
                  return p1.getName().compareTo(p2.getName());
                }
              });

              return sortedProperties;
            }

            else if ("collectionProperties".equals(propertyName)) {
              List<Property> properties = new ArrayList<Property>();
              for (Property p : entity.getProperties()) {
                if (p.getType().getJsonKind().equals(JsonKind.LIST)) {
                  properties.add(p);
                }
              }
              List<Property> sortedProperties = new ArrayList<Property>();
              sortedProperties.addAll(properties);
              Collections.sort(sortedProperties, new Comparator<Property>() {
                @Override
                public int compare(Property p1, Property p2) {
                  return p1.getName().compareTo(p2.getName());
                }
              });
              return sortedProperties;
            }

            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(ParameterDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            ParameterDescription param = (ParameterDescription) o;
            if ("requireName".equals(propertyName)) {
              return upcase(param.getName());
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(Property.class, new ObjectModelAdaptor() {
      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {
        Property p = (Property) o;
        if ("docString".equals(propertyName)) {
          String docString = p.getDocString();

          List<String> enumValues = p.getType().getEnumValues();
          if (enumValues != null) {
            docString = docString == null ? "" : docString;
            docString += "\n\nPossible values: ";
            for (int i = 0; i < enumValues.size(); i++) {
              docString += enumValues.get(i);
              if (i < enumValues.size() - 1) docString += ", ";
            }
          }
          return doxygenDocString(docString);
        }
        else if ("requireName".equals(propertyName)) {
          return requireNameForType(p.getType().getName());
        }
        else if ("objcType".equals(propertyName)) {
          return objcTypeForProperty(p);
        }
        else if ("modifiers".equals(propertyName)) {
          List<String> modifiers = new ArrayList<String>();
          String safeName = getSafeName(p.getName());
          if (p.getImpliedProperty() != null
            && p.getImpliedProperty().getType().getJsonKind().equals(JsonKind.LIST)) {
            modifiers.add("weak");
          }
          else {
            modifiers.add("strong");
          }
          if (p.getType().getJsonKind().equals(JsonKind.BOOLEAN)) {
            modifiers.add("getter=is" + upcase(safeName));
          }
          // http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html
          if (p.getName().startsWith("new")) {
            modifiers.add("getter=a" + upcase(safeName));
          }
          return modifiers;
        }
        else if ("safeName".equals(propertyName)) {
          return getSafeName(p.getName());
        }
        else if ("upcaseName".equals(propertyName)) {
          return upcase(getSafeName(p.getName()));
        }
        else if ("listElementObjcType".equals(propertyName)) {
          return objcTypeForType(p.getType().getListElement());
        }
        else if ("singularUpcaseName".equals(propertyName)) {
          if (p.getType().getListElement() != null) {
            String type = objcTypeForType(p.getType().getListElement());
            return type.substring(2);
          }
          return upcase(p.getName());
        }

        return super.getProperty(interp, self, o, property, propertyName);
      }
    });

    group.registerModelAdaptor(Type.class, new ObjectModelAdaptor() {

      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {

        if (propertyName.equals("name")) {
          return ((Type) o).getName();
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }
    });

    group.registerModelAdaptor(String.class, new ObjectModelAdaptor() {

      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {
View Full Code Here

        return upcase(entity.getTypeName());
      }
    });

    group.registerModelAdaptor(EndpointDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            EndpointDescription end = (EndpointDescription) o;
            if ("className".equals(propertyName) || "methodName".equals(propertyName)) {
              // Convert a path like /api/2/foo/bar/{}/baz to FooBarBazMethod
              String path = end.getPath();
              String[] parts = path.split(Pattern.quote("/"));
              StringBuilder sb = new StringBuilder();
              for (int i = 3, j = parts.length; i < j; i++) {
                try {
                  String part = parts[i];
                  if (part.length() == 0) {
                    continue;
                  }
                  StringBuilder decodedPart = new StringBuilder(URLDecoder
                      .decode(part, "UTF8"));
                  // Trim characters that aren't legal
                  for (int k = decodedPart.length() - 1; k >= 0; k--) {
                    if (!Character.isJavaIdentifierPart(decodedPart.charAt(k))) {
                      decodedPart.deleteCharAt(k);
                    }
                  }
                  // Append the new name part, using camel-cased names
                  String newPart = decodedPart.toString();
                  if (sb.length() > 0) {
                    newPart = upcase(newPart);
                  }
                  sb.append(newPart);
                } catch (UnsupportedEncodingException e) {
                  throw new RuntimeException(e);
                }
              }
              sb.append(upcase(end.getMethod().toLowerCase()));
              String name = sb.toString();

              return "className".equals(propertyName) ? upcase(name) : camelCaseToUnderscore(name);
            } else if ("pathDecoded".equals(propertyName)) {
              // URL-decode the path in the endpoint description
              try {
                String decoded = URLDecoder.decode(end.getPath(), "UTF8");
                return decoded;
              } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
              }
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(EntityDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {

            EntityDescription entity = (EntityDescription) o;
            if ("payloadName".equals(propertyName)) {
              return entity.getTypeName();
            }

            else if ("supertype".equals(propertyName)) {
              EntityDescription supertype = entity.getSupertype();
              if (supertype == null) {
                supertype = baseHasUuid;
              }
              return supertype;
            }

            else if ("simpleName".equals(propertyName)) {
              if (entity.getTypeName().equals("baseHasUuid")) {
                return "Flatpack::Core::" + BaseHasUuid.class.getSimpleName();
              }
              return upcase(entity.getTypeName());
            }

            else if ("requireName".equals(propertyName)) {
              return requireNameForType(entity.getTypeName());
            }

            else if ("properties".equals(propertyName)) {
              List<Property> properties = new ArrayList<Property>();
              for (Property p : entity.getProperties()) {
                if (!p.isEmbedded()) {
                  properties.add(p);
                }
              }
              return properties;
            }

            else if ("entityProperties".equals(propertyName)) {

              Map<String, Property> propertyMap = new HashMap<String, Property>();
              for (Property p : entity.getProperties()) {

                // TODO if we decide to encode enum types, we'll want to remove the second condition
                if (p.getType().getName() != null && p.getType().getEnumValues() == null) {
                  propertyMap.put(p.getName(), p);
                }
              }

              return propertyMap.values();
            }

            else if ("embeddedEntityProperties".equals(propertyName)) {
              Map<String, Property> propertyMap = new HashMap<String, Property>();
              for (Property p : entity.getProperties()) {
                if (p.getType().getName() != null &&
                  p.getType().getEnumValues() == null && p.isEmbedded()) {

                  propertyMap.put(p.getName(), p);
                }
              }
              return propertyMap.values();
            }

            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(ParameterDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            ParameterDescription param = (ParameterDescription) o;
            if ("underscoreName".equals(propertyName)) {
              return camelCaseToUnderscore(param.getName());
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(Property.class, new ObjectModelAdaptor() {
      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {
        Property p = (Property) o;
        if ("attrName".equals(propertyName)) {
          return camelCaseToUnderscore(p.getName());
        }

        else if ("requireName".equals(propertyName)) {
          return requireNameForType(p.getType().getName());
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }
    });

    group.registerModelAdaptor(Type.class, new ObjectModelAdaptor() {

      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {

        if (propertyName.equals("name")) {
          return moduleName + "::" + modelModuleName + "::" + upcase(((Type) o).getName());
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }
    });

    group.registerModelAdaptor(String.class, new ObjectModelAdaptor() {

      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {
View Full Code Here

        }
        throw new UnsupportedOperationException("Unknown JsonKind " + type.getJsonKind());
      }
    });
    group.registerModelAdaptor(ApiDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            ApiDescription apiDescription = (ApiDescription) o;
            if ("endpoints".equals(propertyName)) {
              Set<EndpointDescription> uniqueEndpoints =
                  new HashSet<EndpointDescription>(apiDescription.getEndpoints());
              List<EndpointDescription> sortedEndpoints = new ArrayList<EndpointDescription>(
                  uniqueEndpoints);
              Collections.sort(sortedEndpoints, new Comparator<EndpointDescription>() {
                @Override
                public int compare(EndpointDescription e1, EndpointDescription e2) {
                  return e1.getPath().compareTo(e2.getPath());
                }
              });
              return sortedEndpoints;
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(EndpointDescription.class, new ObjectModelAdaptor() {
      @Override
      public Object getProperty(Interpreter interp, ST self, Object o, Object property,
          String propertyName) throws STNoSuchPropertyException {
        EndpointDescription end = (EndpointDescription) o;
        if ("combinedArgs".equals(propertyName)) {
          // Return the path and query parameters together
          List<ParameterDescription> toReturn = new ArrayList<ParameterDescription>();
          if (end.getPathParameters() != null) {
            toReturn.addAll(end.getPathParameters());
          }
          if (end.getQueryParameters() != null) {
            toReturn.addAll(end.getQueryParameters());
          }
          return toReturn;
        } else if ("javaName".equals(propertyName) || "javaNameUpcase".equals(propertyName)) {
          // Convert a path like /api/2/foo/bar/{}/baz to fooBarBazMethod
          String path = end.getPath();
          String[] parts = path.split(Pattern.quote("/"));
          StringBuilder sb = new StringBuilder();
          for (int i = stripPathSegments, j = parts.length; i < j; i++) {
            try {
              String part = parts[i];
              if (part.length() == 0) {
                continue;
              }
              StringBuilder decodedPart = new StringBuilder(URLDecoder.decode(part, "UTF8"));
              // Trim characters that aren't legal
              for (int k = decodedPart.length() - 1; k >= 0; k--) {
                if (!Character.isJavaIdentifierPart(decodedPart.charAt(k))) {
                  decodedPart.deleteCharAt(k);
                }
              }
              // Append the new name part, using camel-cased names
              String newPart = decodedPart.toString();
              if (sb.length() > 0) {
                newPart = upcase(newPart);
              }
              sb.append(newPart);
            } catch (UnsupportedEncodingException e) {
              throw new RuntimeException(e);
            }
          }
          sb.append(upcase(end.getMethod().toLowerCase()));
          String javaName = sb.toString();
          if ("javaNameUpcase".equals(propertyName)) {
            javaName = upcase(javaName);
          }
          return javaName;
        } else if ("pathDecoded".equals(propertyName)) {
          // URL-decode the path in the endpoint description
          try {
            String decoded = URLDecoder.decode(end.getPath(), "UTF8");
            return decoded;
          } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
          }
        } else if ("hasPayload".equals(propertyName)) {
          return end.getEntity() != null;
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }
    });
    group.registerModelAdaptor(EntityDescription.class, new ObjectModelAdaptor() {
      @Override
      public Object getProperty(Interpreter interp, ST self, Object o, Object property,
          String propertyName) throws STNoSuchPropertyException {
        EntityDescription entity = (EntityDescription) o;
        if ("baseType".equals(propertyName)) {
          return baseTypes.contains(entity.getTypeName());
        } else if ("payloadName".equals(propertyName)) {
          return entity.getTypeName();
        } else if ("supertype".equals(propertyName)) {
          EntityDescription supertype = entity.getSupertype();
          if (supertype == null) {
            return entity.isPersistent() ? BasePersistenceAware.class.getCanonicalName()
                : BaseHasUuid.class.getCanonicalName();
          } else {
            return supertype;
          }
        } else if ("simpleName".equals(propertyName)) {
          return typePrefix + upcase(entity.getTypeName());
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }
    });
    group.registerModelAdaptor(ParameterDescription.class, new ObjectModelAdaptor() {
      @Override
      public Object getProperty(Interpreter interp, ST self, Object o, Object property,
          String propertyName) throws STNoSuchPropertyException {
        ParameterDescription param = (ParameterDescription) o;
        if ("javaNameUpcase".equals(propertyName)) {
          return upcase(param.getName());
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }
    });
    group.registerModelAdaptor(Property.class, new ObjectModelAdaptor() {
      @Override
      public Object getProperty(Interpreter interp, ST self, Object o, Object property,
          String propertyName) throws STNoSuchPropertyException {
        Property p = (Property) o;
        if ("getterName".equals(propertyName)) {
          return upcase(p.getName());
        } else if ("needsImplied".equals(propertyName)) {
          // Returns true if the property has @Implies / @OneToMany and is a list
          return p.getImpliedProperty() != null && p.getType().getListElement() != null;
        } else if ("needsAdder".equals(propertyName)) {
          return JsonKind.LIST.equals(p.getType().getJsonKind());
        } else if ("needsPutter".equals(propertyName)) {
          return JsonKind.MAP.equals(p.getType().getJsonKind());
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }
    });
    group.registerModelAdaptor(Type.class, new ObjectModelAdaptor() {

      @Override
      public Object getProperty(Interpreter interp, ST self, Object o, Object property,
          String propertyName) throws STNoSuchPropertyException {
        Type type = (Type) o;
        if ("flatTypes".equals(propertyName)) {
          return flatten(type);
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }

      private List<String> flatten(Type type) {
        switch (type.getJsonKind()) {
          case ANY:
            return Collections.singletonList(Object.class.getCanonicalName());
          case BOOLEAN:
            return Collections.singletonList(Boolean.class.getCanonicalName());
          case DOUBLE:
            return Collections.singletonList(Double.class.getCanonicalName());
          case INTEGER:
            return Collections.singletonList(Integer.class.getCanonicalName());
          case LIST: {
            List<String> toReturn = new ArrayList<String>();
            toReturn.add(List.class.getCanonicalName());
            toReturn.addAll(flatten(type.getListElement()));
            return toReturn;
          }
          case MAP: {
            List<String> toReturn = new ArrayList<String>();
            toReturn.add(Map.class.getCanonicalName());
            toReturn.addAll(flatten(type.getMapKey()));
            toReturn.addAll(flatten(type.getMapValue()));
            return toReturn;
          }
          case NULL:
            return Collections.singletonList(Void.class.getCanonicalName());
          case STRING: {
            if (type.getName() != null) {
              return Collections.singletonList(typePrefix + upcase(type.getName()));
            } else if (type.getTypeHint() != null) {
              return Collections.singletonList(type.getTypeHint().getValue());
            } else {
              return Collections.singletonList(String.class.getCanonicalName());
            }
          }
        }
        throw new UnsupportedOperationException("Unknown JsonKind " + type.getJsonKind());
      }
    });
    group.registerModelAdaptor(String.class, new ObjectModelAdaptor() {

      @Override
      public Object getProperty(Interpreter interp, ST self, Object o, Object property,
          String propertyName) throws STNoSuchPropertyException {
        final String string = (String) o;
View Full Code Here

        return entity.getTypeName();
      }
    });

    group.registerModelAdaptor(ApiDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            ApiDescription apiDescription = (ApiDescription) o;
            if ("endpoints".equals(propertyName)) {
              List<EndpointDescription> sortedEndpoints = new ArrayList<EndpointDescription>(
                  apiDescription.getEndpoints());
              Collections.sort(sortedEndpoints, new Comparator<EndpointDescription>() {
                @Override
                public int compare(EndpointDescription e1, EndpointDescription e2) {
                  return e1.getPath().compareTo(e2.getPath());
                }
              });
              return sortedEndpoints;
            }
            else if ("importNames".equals(propertyName)) {
              Set<String> imports = new HashSet<String>();
              for (EndpointDescription e : apiDescription.getEndpoints()) {
                if (e.getEntity() != null) {
                  String type = phpTypeForType(e.getEntity());
                  if (isRequiredImport(type)) {
                    imports.add(type);
                  }
                }
                if (e.getReturnType() != null) {
                  String type = phpTypeForType(e.getReturnType());
                  if (isRequiredImport(type)) {
                    imports.add(type);
                  }
                }
              }
              List<String> sortedImports = new ArrayList<String>(imports);
              Collections.sort(sortedImports);
              return sortedImports;
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(EndpointDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            EndpointDescription end = (EndpointDescription) o;
            if ("docString".equals(propertyName)) {
              return doxygenDocString(end.getDocString());
            }
            else if ("methodName".equals(propertyName)) {
              StringBuilder sb = new StringBuilder();

              sb.append("public function " + getMethodizedPath(end));

              if (end.getEntity() != null) {
                if (end.getPathParameters() != null && end.getPathParameters().size() > 0) {
                  sb.append(" entity");
                }
                String type = phpTypeForType(end.getEntity());
                String paramName = type;
                if (type.startsWith(classPrefix)) {
                  paramName = downcase(type.substring(classPrefix.length()));
                }
                sb.append("($" + paramName + ")");
              }

              /*
               * if (end.getEntity() != null) { if (end.getPathParameters() != null &&
               * end.getPathParameters().size() > 0) { sb.append(" entity"); } String type =
               * phpTypeForType(end.getEntity()); sb.append(":(" + type + " *)"); String paramName =
               * type; if (type.startsWith(classPrefix)) { paramName =
               * downcase(type.substring(classPrefix.length())); } sb.append(paramName); }
               */

              return sb.toString();
            }

            else if ("requestBuilderClassName".equals(propertyName)) {
              return getBuilderReturnType(end);
            }

            else if ("requestBuilderBlockName".equals(propertyName)) {
              return getBuilderReturnType(end) + "Block";
            }

            else if ("entityReturnType".equals(propertyName)) {
              String type = phpFlatpackReturnType(end.getReturnType());
              return type.equals("void") ? null : type;
            }

            else if ("entityReturnName".equals(propertyName)) {
              if (end.getReturnType() == null) return null;

              String name = "result";
              if (end.getReturnType().getName() != null) {
                name = end.getReturnType().getName();
              }

              if (end.getReturnType().getListElement() != null) {
                if (end.getReturnType().getListElement().getName() != null) {
                  name = end.getReturnType().getListElement().getName();
                }
                name = pluralOf(name);
              }

              return name;
            }

            else if ("pathDecoded".equals(propertyName)) {
              // URL-decode the path in the endpoint description
              try {
                String decoded = URLDecoder.decode(end.getPath(), "UTF8");
                return decoded;
              } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
              }
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(EntityDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {

            EntityDescription entity = (EntityDescription) o;
            if ("importNames".equals(propertyName)) {
              Set<String> imports = new HashSet<String>();
              String type = requireNameForType(entity.getTypeName());
              if (isRequiredImport(type)) {
                imports.add(type);
              }
              for (Property p : entity.getProperties()) {
                String name = null;
                if (p.getType().getListElement() != null) {
                  name = phpTypeForType(p.getType().getListElement());
                }
                else {
                  name = phpTypeForProperty(p);
                }
                if (name != null && isRequiredImport(name)) {
                  imports.add(name);
                }
              }
              List<String> sortedImports = new ArrayList<String>(imports);
              Collections.sort(sortedImports);
              return sortedImports;
            }
            if ("docString".equals(propertyName)) {
              return doxygenDocString(entity.getDocString());
            }
            else if ("payloadName".equals(propertyName)) {
              return entity.getTypeName();
            }

            else if ("supertype".equals(propertyName)) {
              EntityDescription supertype = entity.getSupertype();
              if (supertype == null) {
                supertype = baseHasUuid;
              }
              return supertype;
            }

            else if ("requireName".equals(propertyName)) {
              return requireNameForType(entity.getTypeName());
            }

            else if ("properties".equals(propertyName)) {

              Map<String, Property> propertyMap = new HashMap<String, Property>();
              for (Property p : entity.getProperties()) {
                propertyMap.put(p.getName(), p);
              }

              List<Property> sortedProperties = new ArrayList<Property>();
              sortedProperties.addAll(propertyMap.values());
              Collections.sort(sortedProperties, new Comparator<Property>() {
                @Override
                public int compare(Property p1, Property p2) {
                  return p1.getName().compareTo(p2.getName());
                }
              });

              return sortedProperties;
            }

            else if ("entityProperties".equals(propertyName)) {

              Map<String, Property> propertyMap = new HashMap<String, Property>();
              for (Property p : entity.getProperties()) {

                // TODO if we decide to encode enum types, we'll want to remove the second condition
                if (p.getType().getName() != null) {
                  propertyMap.put(p.getName(), p);
                }
              }

              List<Property> sortedProperties = new ArrayList<Property>();
              sortedProperties.addAll(propertyMap.values());
              Collections.sort(sortedProperties, new Comparator<Property>() {
                @Override
                public int compare(Property p1, Property p2) {
                  return p1.getName().compareTo(p2.getName());
                }
              });

              return sortedProperties;
            }

            else if ("collectionProperties".equals(propertyName)) {
              List<Property> properties = new ArrayList<Property>();
              for (Property p : entity.getProperties()) {
                if (p.getType().getJsonKind().equals(JsonKind.LIST)) {
                  properties.add(p);
                }
              }
              List<Property> sortedProperties = new ArrayList<Property>();
              sortedProperties.addAll(properties);
              Collections.sort(sortedProperties, new Comparator<Property>() {
                @Override
                public int compare(Property p1, Property p2) {
                  return p1.getName().compareTo(p2.getName());
                }
              });
              return sortedProperties;
            }

            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(ParameterDescription.class,
        new ObjectModelAdaptor() {
          @Override
          public Object getProperty(Interpreter interp, ST self, Object o,
              Object property, String propertyName)
              throws STNoSuchPropertyException {
            ParameterDescription param = (ParameterDescription) o;
            if ("requireName".equals(propertyName)) {
              return upcase(param.getName());
            }
            return super.getProperty(interp, self, o, property, propertyName);
          }
        });

    group.registerModelAdaptor(Property.class, new ObjectModelAdaptor() {
      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {
        Property p = (Property) o;
        if ("docString".equals(propertyName)) {
          String docString = p.getDocString();

          List<String> enumValues = p.getType().getEnumValues();
          if (enumValues != null) {
            docString = docString == null ? "" : docString;
            docString += "\n\nPossible values: ";
            for (int i = 0; i < enumValues.size(); i++) {
              docString += enumValues.get(i);
              if (i < enumValues.size() - 1) docString += ", ";
            }
          }
          return doxygenDocString(docString);
        }
        else if ("requireName".equals(propertyName)) {
          return requireNameForType(p.getType().getName());
        }
        else if ("phpType".equals(propertyName)) {
          return phpTypeForProperty(p);
        }
        else if ("modifiers".equals(propertyName)) {
          List<String> modifiers = new ArrayList<String>();
          String safeName = getSafeName(p.getName());
          if (p.getImpliedProperty() != null
            && p.getImpliedProperty().getType().getJsonKind().equals(JsonKind.LIST)) {
            modifiers.add("weak");
          }
          else {
            modifiers.add("strong");
          }
          if (p.getType().getJsonKind().equals(JsonKind.BOOLEAN)) {
            modifiers.add("getter=is" + upcase(safeName));
          }
          // http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html
          if (p.getName().startsWith("new")) {
            modifiers.add("getter=a" + upcase(safeName));
          }
          return modifiers;
        }
        else if ("safeName".equals(propertyName)) {
          return getSafeName(p.getName());
        }
        else if ("upcaseName".equals(propertyName)) {
          return upcase(getSafeName(p.getName()));
        }
        else if ("listElementphpType".equals(propertyName)) {
          return phpTypeForType(p.getType().getListElement());
        }
        else if ("singularUpcaseName".equals(propertyName)) {
          if (p.getType().getListElement() != null) {
            String type = phpTypeForType(p.getType().getListElement());
            return type.substring(2);
          }
          return upcase(p.getName());
        }

        return super.getProperty(interp, self, o, property, propertyName);
      }
    });

    group.registerModelAdaptor(Type.class, new ObjectModelAdaptor() {

      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {

        if (propertyName.equals("name")) {
          return ((Type) o).getName();
        }
        return super.getProperty(interp, self, o, property, propertyName);
      }
    });

    group.registerModelAdaptor(String.class, new ObjectModelAdaptor() {

      @Override
      public Object getProperty(Interpreter interp, ST self, Object o,
          Object property, String propertyName)
          throws STNoSuchPropertyException {
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.misc.ObjectModelAdaptor

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.