KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > wsdlmodelext > AlgoSuiteModelHelper


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.wsitconf.wsdlmodelext;
21
22 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants;
23 import org.netbeans.modules.websvc.wsitmodelext.policy.Policy;
24 import org.netbeans.modules.websvc.wsitmodelext.policy.PolicyQName;
25 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.AlgorithmSuite;
26 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.AlgorithmSuiteQName;
27 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic128;
28 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic192;
29 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic256;
30 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic256Sha256;
31 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic256Sha256Rsa15;
32 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.TripleDes;
33 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.TripleDesRsa15;
34 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.TripleDesSha256;
35 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.TripleDesSha256Rsa15;
36 import org.netbeans.modules.xml.wsdl.model.*;
37
38 import javax.xml.namespace.QName JavaDoc;
39 import java.util.List JavaDoc;
40 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic128Rsa15;
41 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic128Sha256;
42 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic128Sha256Rsa15;
43 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic192Rsa15;
44 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic192Sha256;
45 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic192Sha256Rsa15;
46 import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.Basic256Rsa15;
47
48 /**
49  *
50  * @author Martin Grebac
51  */

52 public class AlgoSuiteModelHelper {
53     
54     /**
55      * Creates a new instance of AlgoSuiteModelHelper
56      */

57     public AlgoSuiteModelHelper() {
58     }
59     
60     public static String JavaDoc getAlgorithmSuite(WSDLComponent comp) {
61         WSDLComponent layout = getAlgorithmSuiteElement(comp);
62         if (layout != null) {
63             if (layout instanceof Basic128) return ComboConstants.BASIC128;
64             if (layout instanceof Basic192) return ComboConstants.BASIC192;
65             if (layout instanceof Basic256) return ComboConstants.BASIC256;
66             if (layout instanceof TripleDes) return ComboConstants.TRIPLEDES;
67             if (layout instanceof Basic256Rsa15) return ComboConstants.BASIC256RSA15;
68             if (layout instanceof Basic192Rsa15) return ComboConstants.BASIC192RSA15;
69             if (layout instanceof Basic128Rsa15) return ComboConstants.BASIC128RSA15;
70             if (layout instanceof TripleDesRsa15) return ComboConstants.TRIPLEDESRSA15;
71             if (layout instanceof Basic256Sha256) return ComboConstants.BASIC256SHA256;
72             if (layout instanceof Basic192Sha256) return ComboConstants.BASIC192SHA256;
73             if (layout instanceof Basic128Sha256) return ComboConstants.BASIC128SHA256;
74             if (layout instanceof TripleDesSha256) return ComboConstants.TRIPLEDESSHA256;
75             if (layout instanceof Basic256Sha256Rsa15) return ComboConstants.BASIC256SHA256RSA15;
76             if (layout instanceof Basic192Sha256Rsa15) return ComboConstants.BASIC192SHA256RSA15;
77             if (layout instanceof Basic128Sha256Rsa15) return ComboConstants.BASIC128SHA256RSA15;
78             if (layout instanceof TripleDesSha256Rsa15) return ComboConstants.TRIPLEDESSHA256RSA15;
79         }
80         return null;
81     }
82     
83     public static WSDLComponent getAlgorithmSuiteElement(WSDLComponent comp) {
84         if ((comp instanceof Binding) || (comp instanceof BindingOperation)) {
85             comp = SecurityPolicyModelHelper.getSecurityBindingTypeElement(comp);
86         }
87         if (comp == null) return null;
88         Policy p = PolicyModelHelper.getTopLevelElement(comp, Policy.class);
89         AlgorithmSuite as = PolicyModelHelper.getTopLevelElement(p, AlgorithmSuite.class);
90         p = PolicyModelHelper.getTopLevelElement(as, Policy.class);
91         if (p != null) {
92             List JavaDoc<ExtensibilityElement> elements = p.getExtensibilityElements();
93             if ((elements != null) && !(elements.isEmpty())) {
94                 ExtensibilityElement e = elements.get(0);
95                 return e;
96             }
97         }
98         return null;
99     }
100  
101     public static void setAlgorithmSuite(WSDLComponent c, String JavaDoc algoSuite) {
102         WSDLModel model = c.getModel();
103         WSDLComponentFactory wcf = model.getFactory();
104         
105         WSDLComponent topElem = c;
106         
107         boolean isTransaction = model.isIntransaction();
108         if (!isTransaction) {
109             model.startTransaction();
110         }
111
112         try {
113             QName qnameToCreate = null;
114
115             if (ComboConstants.BASIC128.equals(algoSuite)) {
116                 qnameToCreate = AlgorithmSuiteQName.BASIC128.getQName();
117             } else if (ComboConstants.BASIC192.equals(algoSuite)) {
118                 qnameToCreate = AlgorithmSuiteQName.BASIC192.getQName();
119             } else if (ComboConstants.BASIC256.equals(algoSuite)) {
120                 qnameToCreate = AlgorithmSuiteQName.BASIC256.getQName();
121             } else if (ComboConstants.TRIPLEDES.equals(algoSuite)) {
122                 qnameToCreate = AlgorithmSuiteQName.TRIPLEDES.getQName();
123             } else if (ComboConstants.BASIC128RSA15.equals(algoSuite)) {
124                 qnameToCreate = AlgorithmSuiteQName.BASIC128RSA15.getQName();
125             } else if (ComboConstants.BASIC192RSA15.equals(algoSuite)) {
126                 qnameToCreate = AlgorithmSuiteQName.BASIC192RSA15.getQName();
127             } else if (ComboConstants.BASIC256RSA15.equals(algoSuite)) {
128                 qnameToCreate = AlgorithmSuiteQName.BASIC256RSA15.getQName();
129             } else if (ComboConstants.TRIPLEDESRSA15.equals(algoSuite)) {
130                 qnameToCreate = AlgorithmSuiteQName.TRIPLEDESRSA15.getQName();
131             } else if (ComboConstants.BASIC128SHA256.equals(algoSuite)) {
132                 qnameToCreate = AlgorithmSuiteQName.BASIC128SHA256.getQName();
133             } else if (ComboConstants.BASIC192SHA256.equals(algoSuite)) {
134                 qnameToCreate = AlgorithmSuiteQName.BASIC192SHA256.getQName();
135             } else if (ComboConstants.BASIC256SHA256.equals(algoSuite)) {
136                 qnameToCreate = AlgorithmSuiteQName.BASIC256SHA256.getQName();
137             } else if (ComboConstants.TRIPLEDESSHA256.equals(algoSuite)) {
138                 qnameToCreate = AlgorithmSuiteQName.TRIPLEDESSHA256.getQName();
139             } else if (ComboConstants.BASIC128SHA256RSA15.equals(algoSuite)) {
140                 qnameToCreate = AlgorithmSuiteQName.BASIC128SHA256RSA15.getQName();
141             } else if (ComboConstants.BASIC192SHA256RSA15.equals(algoSuite)) {
142                 qnameToCreate = AlgorithmSuiteQName.BASIC192SHA256RSA15.getQName();
143             } else if (ComboConstants.BASIC256SHA256RSA15.equals(algoSuite)) {
144                 qnameToCreate = AlgorithmSuiteQName.BASIC256SHA256RSA15.getQName();
145             } else if (ComboConstants.TRIPLEDESSHA256RSA15.equals(algoSuite)) {
146                 qnameToCreate = AlgorithmSuiteQName.TRIPLEDESSHA256RSA15.getQName();
147             }
148
149             AlgorithmSuite suite = PolicyModelHelper.createElement(topElem,
150                     AlgorithmSuiteQName.ALGORITHMSUITE.getQName(),
151                     AlgorithmSuite.class,
152                     !(topElem instanceof Policy));
153
154             List JavaDoc<Policy> policies = suite.getExtensibilityElements(Policy.class);
155             if ((policies != null) && (!policies.isEmpty())) {
156                 for (Policy pol : policies) {
157                     suite.removeExtensibilityElement(pol);
158                 }
159             }
160             Policy p = PolicyModelHelper.createElement(suite, PolicyQName.POLICY.getQName(), Policy.class, false);
161             ExtensibilityElement e = (ExtensibilityElement) wcf.create(p, qnameToCreate);
162             p.addExtensibilityElement(e);
163         } finally {
164             if (!isTransaction) {
165                 model.endTransaction();
166             }
167         }
168     }
169     
170 }
Popular Tags