Пример #1
0
  public static XSDConstrainingFacet addOrSetFacetValue(
      XSDSimpleTypeDefinition type, String facetName, FacetValue fv) {
    XSDConstrainingFacet workFacet = fv.facet;
    // do we need to add?
    if (fv.facet == null || fv.facet.getContainer() != type) {
      // need to add to this type:
      boolean inclusiveness = false;
      if (fv.value instanceof InclusiveInteger) {
        inclusiveness = ((InclusiveInteger) fv.value).isInclusive;
      } // endif

      // remove any facets with opposite inclusiveness:
      if (facetName == FAKE_FACET_MAXIMUM || facetName == FAKE_FACET_MINIMUM) {
        // go ahead and remove:
        removeFacet(type, facetName);
      } // endif -- using fake facets?

      workFacet = createFacet(facetName, inclusiveness);

      try {
        ModelerCore.getModelEditor().addValue(type, workFacet, type.getFacetContents());
      } catch (ModelerCoreException err) {
        ModelerXsdUiConstants.Util.log(err);
      } // endtry
    } // endif

    // set main value:
    if (!FormUtil.safeEquals(fv.value, getMainFacetValue(workFacet))) {
      // only set if changed:
      workFacet = setMainFacetValue(type, workFacet, fv.value);
      // in case this is a bounds facet and we swapped them out:
      fv.facet = workFacet;
    } // endif

    // set description:
    String existingDesc = ModelObjectUtilities.getDescription(workFacet);
    if (fv.description != null) {
      // new not null:
      if (!fv.description.equals(existingDesc)) {
        // description changed to a nonnull value:
        ModelObjectUtilities.setDescription(workFacet, fv.description, type);
      } // endif -- different
    } else if (existingDesc != null && existingDesc.length() > 0) {
      // new null, old not null:
      ModelObjectUtilities.setDescription(workFacet, " ", type); // $NON-NLS-1$
    } // endif

    // Lastly, set fixed if applicable:
    setFixed(workFacet, fv.isFixedLocal);

    return workFacet;
  }
Пример #2
0
  public static FacetValue getFacetValue(XSDSimpleTypeDefinition type, XSDConstrainingFacet facet) {
    FacetValue fv = new FacetValue();
    fv.description = ModelObjectUtilities.getDescription(facet);
    fv.type = type;
    fv.facet = facet;
    Object mainVal = getMainFacetValue(facet);
    if (mainVal != null) {
      fv.value = mainVal;
    } else {
      fv.value = getDefaultMainFacetValue(facet.getFacetName());
    } // endif

    if (type == facet.getContainer()) {
      // this facet set in the specified type, so it is not default:
      fv.defaultValue =
          null; // getMainFacetValue(type.getBaseTypeDefinition(), facet.getFacetName());
    } else {
      // facet set by a parent, so it is default:
      fv.defaultValue = fv.value;
    } // endif
    fv.isFixedLocal = isFixed(facet);

    return fv;
  }