예제 #1
0
  /**
   * Create an {@link Element } with type {@link RegexpType#LAMBDA } with proper constraints and
   * metadata containing sentinel info. This kind of element is used when it was defined previously
   * and it is unnecessary to build a rule subtree for it again (it is either a reference, or a leaf
   * in recursion).
   *
   * @param domElem Node in the DOM tree from which the sentinel is made.
   * @param context Context of the node in the rule tree.
   * @param useAsName Name of the attribute to be used as a name of the new <code>Element</code>.
   * @return Sentinel element.
   * @throws XSDException Raise exception when schema contains errors.
   * @see IGGUtils#METADATA_SENTINEL
   */
  public static Element createSentinel(
      final org.w3c.dom.Element domElem, final List<String> context, final XSDAttribute useAsName)
      throws XSDException {
    final Element sentinel = Element.getMutable();
    if (XSDAttribute.NAME.equals(useAsName) || XSDAttribute.REF.equals(useAsName)) {
      sentinel.setName(domElem.getAttribute(useAsName.toString()));
    } else {
      throw new XSDException(
          NbBundle.getMessage(
              DOMHelper.class,
              "Error.SentinelWrongAttribute",
              useAsName.toString(),
              domElem.getTagName()));
    }

    if (BaseUtils.isEmpty(sentinel.getName())) {
      throw new XSDException(NbBundle.getMessage(DOMHelper.class, "Error.SentinelNoName"));
    }
    if (XSDImportSettings.isVerbose()) {
      LOG.debug(
          NbBundle.getMessage(
              DOMHelper.class, "Debug.CreatingSentinel", useAsName.toString(), sentinel.getName()));
    }
    sentinel.getContext().addAll(context);
    sentinel.getMetadata().putAll(IGGUtils.METADATA_SENTINEL);
    sentinel.getMetadata().putAll(IGGUtils.ATTR_FROM_SCHEMA);
    sentinel.getSubnodes().setType(RegexpType.LAMBDA);
    sentinel.setImmutable();
    return sentinel;
  }
예제 #2
0
 /**
  * Extract value of <i>name</i> or <i>ref</i> from an <i>attribute</i> tag.
  *
  * @param child Node containing the <i>attribute</i> tag.
  * @return Value of tag attribute <i>name</i> or <i>ref</i> or empty string.
  */
 public static String getAttributeName(final org.w3c.dom.Element child) {
   final String name = child.getAttribute(XSDAttribute.NAME.toString());
   final String ref = child.getAttribute(XSDAttribute.REF.toString());
   if (!BaseUtils.isEmpty(name)) {
     if (!BaseUtils.isEmpty(ref)) {
       LOG.error(NbBundle.getMessage(DOMHelper.class, "Error.NameAndRef", name, ref));
     }
     return name;
   } else if (!BaseUtils.isEmpty(ref)) {
     return ref;
   } else {
     return "";
   }
 }