Example #1
0
  static void init() {
    TargetType.account.setInheritedByTargetTypes(new TargetType[] {TargetType.account});
    TargetType.calresource.setInheritedByTargetTypes(
        new TargetType[] {TargetType.account, TargetType.calresource});
    TargetType.dl.setInheritedByTargetTypes(
        new TargetType[] {TargetType.account, TargetType.calresource, TargetType.dl});
    TargetType.domain.setInheritedByTargetTypes(
        new TargetType[] {
          TargetType.account, TargetType.calresource, TargetType.dl, TargetType.domain
        });
    TargetType.cos.setInheritedByTargetTypes(new TargetType[] {TargetType.cos});
    TargetType.server.setInheritedByTargetTypes(new TargetType[] {TargetType.server});
    TargetType.xmppcomponent.setInheritedByTargetTypes(new TargetType[] {TargetType.xmppcomponent});
    TargetType.zimlet.setInheritedByTargetTypes(new TargetType[] {TargetType.zimlet});
    TargetType.config.setInheritedByTargetTypes(new TargetType[] {TargetType.config});
    TargetType.global.setInheritedByTargetTypes(
        new TargetType[] {
          TargetType.account,
          TargetType.calresource,
          TargetType.cos,
          TargetType.dl,
          domain,
          server,
          xmppcomponent,
          zimlet,
          config,
          global
        }); // inherited by all

    // compute mInheritFromTargetTypes and  mInheritedByOtherTargetTypes
    // from mInheritedByTargetTypes
    for (TargetType inheritFrom : TargetType.values()) {
      inheritFrom.mInheritFromTargetTypes = new HashSet<TargetType>();
      inheritFrom.mSubTargetTypes = new HashSet<TargetType>();

      for (TargetType inheritedBy : TargetType.values()) {
        if (inheritedBy.mInheritedByTargetTypes.contains(inheritFrom))
          inheritFrom.mInheritFromTargetTypes.add(inheritedBy);
      }

      for (TargetType tt : inheritFrom.mInheritedByTargetTypes) {
        // add this ugly check, see comments for mSubTargetTypes above
        if (inheritFrom == TargetType.calresource) {
          if (inheritFrom != tt && tt != TargetType.account) inheritFrom.mSubTargetTypes.add(tt);
        } else {
          if (inheritFrom != tt) inheritFrom.mSubTargetTypes.add(tt);
        }
      }
    }

    for (TargetType tt : TargetType.values()) {
      tt.mInheritedByTargetTypes = Collections.unmodifiableSet(tt.mInheritedByTargetTypes);
      tt.mInheritFromTargetTypes = Collections.unmodifiableSet(tt.mInheritFromTargetTypes);
      tt.mSubTargetTypes = Collections.unmodifiableSet(tt.mSubTargetTypes);
    }
  }