1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.mindcrimeilab.xsanalyzer.xsext;
19
20 import java.security.MessageDigest;
21 import java.security.NoSuchAlgorithmException;
22
23 import org.apache.xerces.xs.XSComplexTypeDefinition;
24 import org.apache.xerces.xs.XSSimpleTypeDefinition;
25 import org.apache.xerces.xs.XSTypeDefinition;
26
27
28
29
30
31
32
33 public class TypeDescriptionFactory {
34
35 private final MessageDigest messageDigest;
36
37 public TypeDescriptionFactory() throws NoSuchAlgorithmException {
38 messageDigest = MessageDigest.getInstance("MD5");
39 }
40
41 public TypeDescriptionFactory(String algorithm) throws NoSuchAlgorithmException {
42 messageDigest = MessageDigest.getInstance(algorithm);
43 }
44
45 public String generateTypeDescriptionSignature(XSTypeDefinition typedef) {
46 final String signature;
47 switch (typedef.getTypeCategory()) {
48 case XSTypeDefinition.SIMPLE_TYPE:
49 signature = SimpleTypeDescription.getSignatureDigest((XSSimpleTypeDefinition) typedef, messageDigest);
50 break;
51 case XSTypeDefinition.COMPLEX_TYPE:
52 signature = ComplexTypeDescription.getSignatureDigest((XSComplexTypeDefinition) typedef, messageDigest);
53 break;
54
55 default:
56 throw new RuntimeException("Unexpected type category [" + typedef.getTypeCategory() + "]");
57 }
58 return signature;
59 }
60 }