Package com.getperka.flatpack.ext

Examples of com.getperka.flatpack.ext.Property


    if (stack.isEmpty()) {
      return true;
    }

    State state = stack.peek();
    Property prop = state.property;
    if (prop.isEmbedded()) {
      // Embedded properties should immediately traverse into the related entity
      return true;
    }

    // Write the value of the property, optionally suppressing default values
    if (prop.isSuppressDefaultValue() && codex.isDefaultValue(value)) {
      return false;
    }

    // Write the name and defer to the codex to write the JSON value
    try {
      context.getWriter().name(prop.getName() + codex.getPropertySuffix());
    } catch (IOException e) {
      context.fail(e);
    }
    codex.write(value, context);
View Full Code Here


        if (!checkAccess(entity, prop, value, context)) {
          return;
        }

        // Perhaps set the other side of a OneToMany relationship
        Property impliedProperty = prop.getImpliedProperty();
        if (impliedProperty != null && value != null) {
          // Ensure that any linked property is also mutable
          if (!checkAccess(value, impliedProperty, entity, context)) {
            context.addWarning(entity,
                "Ignoring property %s because the inverse relationship (%s) may not be set",
                prop.getName(), impliedProperty.getName());
            return;
          }
          ImpliedPropertySetter setter = impliedPropertySetters.get();
          setter.setLater(impliedProperty, value, entity);
          context.addPostWork(setter);
View Full Code Here

      return;
    }

    allEntities.put(typeName, entity);
    for (Iterator<Property> it = entity.getProperties().iterator(); it.hasNext();) {
      Property prop = it.next();
      if ("uuid".equals(prop.getName())) {
        // Crop the UUID property
        it.remove();
      } else if (!prop.getEnclosingType().equals(entity)) {
        // Remove properties not declared in the current type
        it.remove();
      }
    }
View Full Code Here

              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;
View Full Code Here

  public boolean visit(AllowBlock x) {
    Ident<Property> inheritFrom = x.getInheritFrom();
    if (inheritFrom == null) {
      return true;
    }
    Property p = ensureReferent(inheritFrom);
    TypePolicy policy = p == null ? null : findTypePolicy(p);
    if (policy == null || hasUnroselvedInherits(policy)) {
      // Skip for the second pass
      unresolved.add(inheritFrom);
      return false;
View Full Code Here

  public boolean visit(GroupBlock x) {
    Ident<Property> inheritFrom = x.getInheritFrom();
    if (inheritFrom == null) {
      return true;
    }
    Property p = ensureReferent(inheritFrom);
    TypePolicy policy = p == null ? null : findTypePolicy(p);
    if (policy == null || hasUnroselvedInherits(policy)) {
      // Skip for the second pass
      unresolved.add(inheritFrom);
      return false;
View Full Code Here

   * Ensure that a Property is not mentioned in more than one policy block.
   */
  @Override
  public void endVisit(PropertyList x) {
    for (Ident<Property> ident : x.getPropertyNames()) {
      Property seen = ident.getReferent();
      if (seen == null) {
        // Reported earlier
        continue;
      }
      Integer previouslySeenOnLine = seenProperties.put(seen, ident.getLineNumber());
      if (previouslySeenOnLine != null) {
        error("Property " + seen.getName() + " was already given a policy on line "
          + previouslySeenOnLine);
      }
    }
  }
View Full Code Here

    Map<String, EntityDescription> allEntities = FlatPackCollections
        .mapForIteration();
    for (EntityDescription entity : api.getEntities()) {
      allEntities.put(entity.getTypeName(), entity);
      for (Iterator<Property> it = entity.getProperties().iterator(); it.hasNext();) {
        Property prop = it.next();
        // Remove the uuid property
        if ("uuid".equals(prop.getName())) {
          it.remove();
        }

        // and properties not declared in the current type
        else if (!prop.getEnclosingType().equals(entity)) {
          it.remove();
        }
      }
    }
    // Ensure that the "real" implementations are used
View Full Code Here

    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);
      }
    });
View Full Code Here

      visitors.visit(new AcyclicVisitor() {
        @Override
        public <T> void endVisitValue(T value, Codex<T> codex, VisitorContext<T> ctx) {
          boolean keep;
          if (value instanceof Property) {
            Property p = (Property) value;
            keep = shouldKeep(p.getGroupPermissions());

            /*
             * If the implied property should be kept, also keep this one. This allows collection
             * properties in parent types to be generated if only the child's parent-referencing
             * property is visible.
             */
            if (!keep && p.getImpliedProperty() != null) {
              keep = shouldKeep(p.getImpliedProperty().getGroupPermissions());
            }
          } else if (value instanceof EntityDescription) {
            EntityDescription e = (EntityDescription) value;
            if (e.getProperties().isEmpty()) {
              keep = false;
View Full Code Here

TOP

Related Classes of com.getperka.flatpack.ext.Property

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.