示例#1
0
  /** @throws OvalException */
  public static boolean addElement(
      final OvalDefinitions oval_defs, final DefinitionsElement element) {
    if (oval_defs == null || element == null) {
      throw new IllegalArgumentException("empty OVAL Definitions or element");
    }

    ElementType element_type = element.ovalGetType();

    boolean added = false;
    if (element_type == ElementType.DEFINITION) {
      DefinitionsType definitions = oval_defs.getDefinitions();
      if (definitions == null) {
        definitions = new DefinitionsType();
        oval_defs.setDefinitions(definitions);
      }
      added = definitions.add(asDefinition(element));

    } else if (element_type == ElementType.TEST) {
      TestsType tests = oval_defs.getTests();
      if (tests == null) {
        tests = new TestsType();
        oval_defs.setTests(tests);
      }
      added = tests.add(asTest(element));

    } else if (element_type == ElementType.OBJECT) {
      SystemObjectsType objects = oval_defs.getObjects();
      if (objects == null) {
        objects = new SystemObjectsType();
        oval_defs.setObjects(objects);
      }
      added = objects.add(asObject(element));

    } else if (element_type == ElementType.STATE) {
      StatesType states = oval_defs.getStates();
      if (states == null) {
        states = new StatesType();
        oval_defs.setStates(states);
      }
      added = states.add(asState(element));

    } else if (element_type == ElementType.VARIABLE) {
      VariablesType variables = oval_defs.getVariables();
      if (variables == null) {
        variables = new VariablesType();
        oval_defs.setVariables(variables);
      }
      added = variables.add(asVariable(element));
    }

    return added;
  }