예제 #1
0
  /**
   * Construct compiled definitions
   *
   * @param model model definition
   * @param namespaceDAO namespace DAO
   */
  private void constructDefinitions(M2Model model, NamespaceDAO namespaceDAO) {
    NamespacePrefixResolver localPrefixes = createLocalPrefixResolver(model, namespaceDAO);

    // Construct Model Definition
    modelDefinition = new M2ModelDefinition(model, localPrefixes);

    // Construct Property Types
    for (M2DataType propType : model.getPropertyTypes()) {
      M2DataTypeDefinition def = new M2DataTypeDefinition(modelDefinition, propType, localPrefixes);
      if (dataTypes.containsKey(def.getName())) {
        throw new DictionaryException(
            "Found duplicate property type definition " + propType.getName());
      }
      dataTypes.put(def.getName(), def);
    }

    // Construct Type Definitions
    for (M2Type type : model.getTypes()) {
      M2TypeDefinition def =
          new M2TypeDefinition(modelDefinition, type, localPrefixes, properties, associations);
      if (classes.containsKey(def.getName())) {
        throw new DictionaryException(
            "Found duplicate class definition " + type.getName() + " (a type)");
      }
      classes.put(def.getName(), def);
      types.put(def.getName(), def);
    }

    // Construct Aspect Definitions
    for (M2Aspect aspect : model.getAspects()) {
      M2AspectDefinition def =
          new M2AspectDefinition(modelDefinition, aspect, localPrefixes, properties, associations);
      if (classes.containsKey(def.getName())) {
        throw new DictionaryException(
            "Found duplicate class definition " + aspect.getName() + " (an aspect)");
      }
      classes.put(def.getName(), def);
      aspects.put(def.getName(), def);
    }

    // Construct Constraint Definitions
    for (M2Constraint constraint : model.getConstraints()) {
      M2ConstraintDefinition def =
          new M2ConstraintDefinition(modelDefinition, null, constraint, localPrefixes);
      QName qname = def.getName();
      if (constraints.containsKey(qname)) {
        throw new DictionaryException(
            "Found duplicate constraint definition " + constraint.getName() + " (an aspect)");
      }
      constraints.put(qname, def);
    }
  }
예제 #2
0
  /**
   * Construct
   *
   * @param model model definition
   * @param dictionaryDAO dictionary DAO
   * @param namespaceDAO namespace DAO
   */
  /*package*/ CompiledModel(M2Model model, DictionaryDAO dictionaryDAO, NamespaceDAO namespaceDAO) {
    try {
      // Phase 1: Construct model definitions from model entries
      //          resolving qualified names
      this.model = model;
      constructDefinitions(model, namespaceDAO);

      // Phase 2: Resolve dependencies between model definitions
      ModelQuery query = new DelegateModelQuery(this, dictionaryDAO);
      resolveDependencies(query, namespaceDAO);

      // Phase 3: Resolve inheritance of values within class hierachy
      NamespacePrefixResolver localPrefixes = createLocalPrefixResolver(model, namespaceDAO);
      resolveInheritance(query, localPrefixes, constraints);

      // Phase 4: Resolve constraint dependencies
      for (ConstraintDefinition def : constraints.values()) {
        ((M2ConstraintDefinition) def).resolveDependencies(query);
      }
    } catch (Exception e) {
      throw new DictionaryException("Failed to compile model " + model.getName(), e);
    }
  }