1 // $Id: TypeDescriptionFactory.java 165 2009-05-28 21:46:38Z agony $
2 /*
3 * xsAnalyzer - XML schema analyzing tool. Copyright (C) 2008 Michael Engelhardt
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7 * version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
13 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 * @author Michael Engelhardt<me@mindcrime-ilab.de>
29 * @author $Author: agony $
30 * @version $Revision: 165 $
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 // throw new RuntimeException("Not implemented yet (complex type)!");
55 default:
56 throw new RuntimeException("Unexpected type category [" + typedef.getTypeCategory() + "]");
57 }
58 return signature;
59 }
60 }