コード例 #1
0
  /**
   * This is used to acquire the name of the element or attribute that is used by the class schema.
   * The name is determined by checking for an override within the annotation. If it contains a name
   * then that is used, if however the annotation does not specify a name the the field or method
   * name is used instead.
   *
   * @param context this is the context used to style the name
   * @return returns the name that is used for the XML property
   */
  public String getName(Context context) throws Exception {
    Style style = context.getStyle();

    if (attribute) {
      return style.getAttribute(name);
    }
    return style.getElement(name);
  }
コード例 #2
0
ファイル: PathParser.java プロジェクト: unisx/simplexml
  /**
   * This is used to acquire the element path using this XPath expression. The element path is
   * simply the fully qualified path for this expression with the provided name appended. If this is
   * an empty path, the provided name is returned.
   *
   * @param path this is the path expression to be used
   * @param name this is the name of the element to be used
   * @return a fully qualified path for the specified name
   */
  protected String getElementPath(String path, String name) {
    String element = style.getElement(name);

    if (isEmpty(element)) {
      return path;
    }
    if (isEmpty(path)) {
      return element;
    }
    return path + "/" + element + "[1]";
  }
コード例 #3
0
ファイル: PathParser.java プロジェクト: unisx/simplexml
  /**
   * This will insert the path segment provided. A path segment is represented by an optional
   * namespace prefix and an XML element name. If there is no prefix then a null is entered this
   * will ensure that the names and segments are kept aligned by index.
   *
   * @param segment this is the path segment to be inserted
   */
  private void element(String segment) {
    int index = segment.indexOf(':');
    String prefix = null;

    if (index > 0) {
      prefix = segment.substring(0, index);
      segment = segment.substring(index + 1);
    }
    String element = style.getElement(segment);

    prefixes.add(prefix);
    names.add(element);
  }
コード例 #4
0
ファイル: CompositeKey.java プロジェクト: unisx/simplexml
  /**
   * This method is used to read the key value from the node. The value read from the node is
   * resolved using the template filter. If the key value can not be found according to the
   * annotation attributes then null is assumed and the node is valid.
   *
   * @param node this is the node to read the key value from
   * @param key this is the name of the key wrapper XML element
   * @return this returns the value deserialized from the node
   */
  private boolean validate(InputNode node, String key) throws Exception {
    String name = style.getElement(key);
    InputNode next = node.getNext(name);
    Class expect = type.getType();

    if (next == null) {
      return true;
    }
    if (next.isEmpty()) {
      return true;
    }
    return root.validate(next, expect);
  }
コード例 #5
0
ファイル: CompositeKey.java プロジェクト: unisx/simplexml
  /**
   * This method is used to write the value to the specified node. The value written to the node
   * must be a composite object and if the element map annotation is configured to have a key
   * attribute then this method will throw an exception.
   *
   * @param node this is the node that the value is written to
   * @param item this is the item that is to be written
   */
  public void write(OutputNode node, Object item) throws Exception {
    Class expect = type.getType();
    String key = entry.getKey();

    if (entry.isAttribute()) {
      throw new ElementException("Can not have %s as an attribute for %s", expect, entry);
    }
    if (key == null) {
      key = context.getName(expect);
    }
    String name = style.getElement(key);

    root.write(node, item, expect, name);
  }
コード例 #6
0
ファイル: PathParser.java プロジェクト: unisx/simplexml
  /**
   * This is used to acquire the element path using this XPath expression. The element path is
   * simply the fully qualified path for this expression with the provided name appended. If this is
   * an empty path, the provided name is returned.
   *
   * @param name this is the name of the element to be used
   * @return a fully qualified path for the specified name
   */
  public String getElement(String name) {
    if (!isEmpty(location)) {
      String path = elements.fetch(name);

      if (path == null) {
        path = getElementPath(location, name);

        if (path != null) {
          elements.cache(name, path);
        }
      }
      return path;
    }
    return style.getElement(name);
  }
コード例 #7
0
ファイル: CompositeKey.java プロジェクト: unisx/simplexml
  /**
   * This method is used to read the key value from the node. The value read from the node is
   * resolved using the template filter. If the key value can not be found according to the
   * annotation attributes then null is assumed and returned.
   *
   * @param node this is the node to read the key value from
   * @param key this is the name of the key wrapper XML element
   * @return this returns the value deserialized from the node
   */
  private Object read(InputNode node, String key) throws Exception {
    String name = style.getElement(key);
    Class expect = type.getType();

    if (name != null) {
      node = node.getNext(name);
    }
    if (node == null) {
      return null;
    }
    if (node.isEmpty()) {
      return null;
    }
    return root.read(node, expect);
  }
コード例 #8
0
  /**
   * This is used to acquire the name of the element or attribute that is used by the class schema.
   * The name is determined by checking for an override within the annotation. If it contains a name
   * then that is used, if however the annotation does not specify a name the the field or method
   * name is used instead.
   *
   * @param context this is the context used to style the name
   * @return returns the name that is used for the XML property
   */
  public String getName(Context context) throws Exception {
    Style style = context.getStyle();
    String name = detail.getName();

    return style.getElement(name);
  }
コード例 #9
0
  /**
   * This is used to either provide the entry value provided within the annotation or compute a
   * entry value. If the entry string is not provided the the entry value is calculated as the type
   * of primitive the object is as a simplified class name.
   *
   * @param context this is the context used to style the entry
   * @return this returns the name of the XML entry element used
   */
  private String getEntry(Context context) throws Exception {
    Style style = context.getStyle();
    String entry = getEntry();

    return style.getElement(entry);
  }