View Javadoc
1   /**
2    * Copyright (C) 2014-2017 Philip Helger (www.helger.com)
3    * philip[at]helger[dot]com
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *         http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package com.helger.schematron.pure.model;
18  
19  import java.io.Serializable;
20  
21  import javax.annotation.Nonnull;
22  import javax.annotation.Nullable;
23  import javax.annotation.concurrent.NotThreadSafe;
24  
25  import com.helger.commons.lang.ICloneable;
26  import com.helger.commons.string.ToStringGenerator;
27  import com.helger.schematron.CSchematronXML;
28  import com.helger.xml.microdom.IMicroElement;
29  
30  /**
31   * A single "linkable" group
32   *
33   * @author Philip Helger
34   */
35  @NotThreadSafe
36  public class PSLinkableGroup implements ICloneable <PSLinkableGroup>, Serializable
37  {
38    private String m_sRole;
39    private String m_sSubject;
40  
41    public PSLinkableGroup ()
42    {}
43  
44    public void setRole (@Nullable final String sRole)
45    {
46      m_sRole = sRole;
47    }
48  
49    /**
50     * A name describing the function of the assertion or context node in the
51     * pattern. If the assertion has a subject attribute, then the role labels the
52     * arc between the context node and any nodes which match the path expression
53     * given by the subject attribute.<br>
54     * An implementation is not required to make use of this attribute.
55     *
56     * @return The role value
57     */
58    @Nullable
59    public String getRole ()
60    {
61      return m_sRole;
62    }
63  
64    public void setSubject (@Nullable final String sSubject)
65    {
66      m_sSubject = sSubject;
67    }
68  
69    /**
70     * A path allowing more precise specification of nodes. The path expression is
71     * evaluated in the context of the context node of the current rule. If no
72     * subject attribute is specified, the current subject node may be used.<br>
73     * NOTE: The subject attribute is required because the rule context may have
74     * been selected for reasons of convenience or performance, in association
75     * with the particular assertion tests. In such cases, the rule context may
76     * not be useful to identify the subject, and the nodes located by the subject
77     * attribute may be more useful. Similarly, it may not be possible to
78     * determine from an assertion test which nodes the assertion test has tested.
79     * In such a case, the nodes located by the subject attribute may be more
80     * useful.<br>
81     * An implementation is not required to make use of this element.
82     *
83     * @return The subject value
84     */
85    @Nullable
86    public String getSubject ()
87    {
88      return m_sSubject;
89    }
90  
91    public static boolean isLinkableAttribute (@Nullable final String sAttrName)
92    {
93      return CSchematronXML.ATTR_ROLE.equals (sAttrName) || CSchematronXML.ATTR_SUBJECT.equals (sAttrName);
94    }
95  
96    public void fillMicroElement (@Nonnull final IMicroElement aElement)
97    {
98      aElement.setAttribute (CSchematronXML.ATTR_ROLE, m_sRole);
99      aElement.setAttribute (CSchematronXML.ATTR_SUBJECT, m_sSubject);
100   }
101 
102   @Nonnull
103   public PSLinkableGroup getClone ()
104   {
105     final PSLinkableGroup ret = new PSLinkableGroup ();
106     ret.setRole (m_sRole);
107     ret.setSubject (m_sSubject);
108     return ret;
109   }
110 
111   @Override
112   public String toString ()
113   {
114     return new ToStringGenerator (this).appendIfNotNull ("role", m_sRole)
115                                        .appendIfNotNull ("subject", m_sSubject)
116                                        .getToString ();
117   }
118 }