Esempio n. 1
0
  private Collection<Permission> getPermissions(cfSession _session, cfStructData cc)
      throws cfmRunTimeException {
    List<Permission> permissions = new LinkedList<Permission>();

    if (!cc.containsKey("permissions")) return permissions;

    cfArrayData arr = (cfArrayData) cc.getData("permissions");

    for (int x = 0; x < arr.size(); x++) {
      cfStructData cs = (cfStructData) arr.getData(x + 1);

      Permission p = new Permission();

      p.setGranteeType(cs.getData("granteetype").getString());
      p.setGrantee(cs.getData("grantee").getString());

      cfArrayData access = (cfArrayData) cs.getData("access");
      List<String> accessList = new LinkedList<String>();

      for (int a = 0; a < access.size(); a++) {
        accessList.add(access.getData(a + 1).getString());
      }
      p.setAccess(accessList);

      permissions.add(p);
    }

    return permissions;
  }
  public Permission unmarshall(JsonUnmarshallerContext context) throws Exception {
    Permission permission = new Permission();

    int originalDepth = context.getCurrentDepth();
    String currentParentElement = context.getCurrentParentElement();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.getCurrentToken();
    if (token == null) token = context.nextToken();
    if (token == VALUE_NULL) return null;

    while (true) {
      if (token == null) break;

      if (token == FIELD_NAME || token == START_OBJECT) {
        if (context.testExpression("GranteeType", targetDepth)) {
          context.nextToken();
          permission.setGranteeType(context.getUnmarshaller(String.class).unmarshall(context));
        }
        if (context.testExpression("Grantee", targetDepth)) {
          context.nextToken();
          permission.setGrantee(context.getUnmarshaller(String.class).unmarshall(context));
        }
        if (context.testExpression("Access", targetDepth)) {
          context.nextToken();
          permission.setAccess(
              new ListUnmarshaller<String>(context.getUnmarshaller(String.class))
                  .unmarshall(context));
        }
      } else if (token == END_ARRAY || token == END_OBJECT) {
        if (context.getLastParsedParentElement() == null
            || context.getLastParsedParentElement().equals(currentParentElement)) {
          if (context.getCurrentDepth() <= originalDepth) break;
        }
      }
      token = context.nextToken();
    }

    return permission;
  }
Esempio n. 3
0
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof Permission == false) return false;
    Permission other = (Permission) obj;
    if (other.getGranteeType() == null ^ this.getGranteeType() == null) return false;
    if (other.getGranteeType() != null
        && other.getGranteeType().equals(this.getGranteeType()) == false) return false;
    if (other.getGrantee() == null ^ this.getGrantee() == null) return false;
    if (other.getGrantee() != null && other.getGrantee().equals(this.getGrantee()) == false)
      return false;
    if (other.getAccess() == null ^ this.getAccess() == null) return false;
    if (other.getAccess() != null && other.getAccess().equals(this.getAccess()) == false)
      return false;
    return true;
  }