View Javadoc

1   // $Id: AbstractTypeDescription.java 165 2009-05-28 21:46:38Z agony $
2   /**
3    * 
4    */
5   package de.mindcrimeilab.xsanalyzer.xsext;
6   
7   import java.security.MessageDigest;
8   
9   import org.apache.commons.logging.Log;
10  import org.apache.commons.logging.LogFactory;
11  import org.apache.xerces.xs.XSTypeDefinition;
12  
13  import de.mindcrimeilab.xsanalyzer.XSAnalyzerConstants;
14  import de.mindcrimeilab.xsanalyzer.util.XSModelHelper;
15  
16  /**
17   * @author Michael Engelhardt<me@mindcrime-ilab.de>
18   * @author $Author: agony $
19   * @version $Revision: 165 $
20   * 
21   */
22  public class AbstractTypeDescription {
23  
24      protected static final Log logger = LogFactory.getLog("xsAnalyzerApplicationLogger");
25  
26      protected static String getSignatureDigest(String signature, MessageDigest messageDigest) {
27  
28          byte[] digest = messageDigest.digest(signature.toString().getBytes());
29  
30          StringBuilder sb = new StringBuilder();
31          for (byte b : digest) {
32              sb.append(Integer.toHexString(b & 0xff));
33          }
34  
35          return sb.toString();
36      }
37  
38      /**
39       * @param signature
40       * @param baseType
41       */
42      protected static void appendBaseType(StringBuilder signature, XSTypeDefinition baseType) {
43          signature.append(baseType.getNamespace()).append(":");
44          signature.append(baseType.getName()).append(":");
45      }
46  
47      protected static XSTypeDefinition getBaseTypeRecursive(XSTypeDefinition type) {
48          // return if the current namespace is the xml schema namespace - no
49          // further type definitions needed
50          if (XSAnalyzerConstants.XML_SCHEMA_NAMESPACE.equals(type.getNamespace())) {
51              return type;
52          }
53          else {
54              XSTypeDefinition base = XSModelHelper.getBaseType(type);
55              return (null == base) ? type : AbstractTypeDescription.getBaseTypeRecursive(base);
56          }
57  
58      }
59  
60      public AbstractTypeDescription() {
61          super();
62      }
63  
64  }