001: /*
002: * $Id: SecurityHeaderBlockImpl.java,v 1.4 2007/01/08 09:28:44 ashutoshshahi Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025: */
026:
027: package com.sun.xml.wss.impl.misc;
028:
029: import java.lang.reflect.Constructor;
030: import java.util.Iterator;
031: import java.util.logging.Level;
032: import java.util.logging.Logger;
033:
034: import javax.xml.soap.Name;
035: import javax.xml.soap.SOAPFactory;
036: import javax.xml.soap.SOAPElement;
037: import javax.xml.soap.SOAPException;
038:
039: import org.w3c.dom.Attr;
040: import org.w3c.dom.Node;
041: import org.w3c.dom.Element;
042: import org.w3c.dom.Document;
043: import org.w3c.dom.NodeList;
044: import org.w3c.dom.TypeInfo;
045: import org.w3c.dom.NamedNodeMap;
046: import org.w3c.dom.DOMException;
047: import org.w3c.dom.UserDataHandler;
048:
049: import com.sun.xml.wss.impl.MessageConstants;
050: import com.sun.xml.wss.logging.LogDomainConstants;
051: import com.sun.xml.wss.XWSSecurityException;
052:
053: import com.sun.xml.wss.core.SecurityHeaderBlock;
054:
055: /**
056: * @author XWS-Security Development Team
057: */
058: public abstract class SecurityHeaderBlockImpl extends
059: SOAPElementExtension implements SecurityHeaderBlock {
060:
061: private static Logger log = Logger.getLogger(
062: LogDomainConstants.WSS_API_DOMAIN,
063: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
064:
065: private static final Name idAttributeName;
066: private static SOAPFactory soapFactory;
067:
068: protected SOAPElement delegateElement;
069:
070: private boolean bsp = false;
071:
072: static {
073: Name temp = null;
074: try {
075: soapFactory = SOAPFactory.newInstance();
076: temp = getSoapFactory().createName("Id", "wsu",
077: "http://schemas.xmlsoap.org/ws/2003/06/utility");
078: } catch (SOAPException e) {
079: log.log(Level.SEVERE, "WSS0654.soap.exception", e
080: .getMessage());
081: }
082:
083: idAttributeName = temp;
084: }
085:
086: protected SecurityHeaderBlockImpl() {
087: // we expect that you will call setSOAPElement later
088: }
089:
090: protected SecurityHeaderBlockImpl(SOAPElement delegateElement) {
091: setSOAPElement(delegateElement);
092: }
093:
094: protected void setSOAPElement(SOAPElement delegateElement) {
095: this .delegateElement = delegateElement;
096: }
097:
098: public String getId() {
099: return delegateElement.getAttributeValue(idAttributeName);
100: }
101:
102: protected void setWsuIdAttr(Element element, String wsuId) {
103: element.setAttributeNS(MessageConstants.NAMESPACES_NS, "xmlns:"
104: + MessageConstants.WSU_PREFIX, MessageConstants.WSU_NS);
105: element.setAttributeNS(MessageConstants.WSU_NS,
106: MessageConstants.WSU_ID_QNAME, wsuId);
107: }
108:
109: public static SecurityHeaderBlock fromSoapElement(
110: SOAPElement element, Class implClass)
111: throws XWSSecurityException {
112:
113: SecurityHeaderBlock block = null;
114:
115: try {
116: Constructor implConstructor = implClass
117: .getConstructor(new Class[] { SOAPElement.class });
118: block = (SecurityHeaderBlock) implConstructor
119: .newInstance(new Object[] { element });
120: } catch (Exception e) {
121: log.log(Level.SEVERE, "WSS0655.error.creating.headerblock");
122: throw new XWSSecurityException(e);
123: }
124:
125: return block;
126: }
127:
128: public SOAPElement getAsSoapElement() throws XWSSecurityException {
129: return delegateElement;
130: }
131:
132: // Generated delegate methods
133: public SOAPElement addAttribute(Name arg0, String arg1)
134: throws SOAPException {
135: return delegateElement.addAttribute(arg0, arg1);
136: }
137:
138: public SOAPElement addChildElement(String arg0)
139: throws SOAPException {
140: return delegateElement.addChildElement(arg0);
141: }
142:
143: public SOAPElement addChildElement(String arg0, String arg1)
144: throws SOAPException {
145: return delegateElement.addChildElement(arg0, arg1);
146: }
147:
148: public SOAPElement addChildElement(String arg0, String arg1,
149: String arg2) throws SOAPException {
150: return delegateElement.addChildElement(arg0, arg1, arg2);
151: }
152:
153: public SOAPElement addChildElement(Name arg0) throws SOAPException {
154: return delegateElement.addChildElement(arg0);
155: }
156:
157: public SOAPElement addChildElement(SOAPElement arg0)
158: throws SOAPException {
159: return delegateElement.addChildElement(arg0);
160: }
161:
162: public SOAPElement addNamespaceDeclaration(String arg0, String arg1)
163: throws SOAPException {
164: return delegateElement.addNamespaceDeclaration(arg0, arg1);
165: }
166:
167: public SOAPElement addTextNode(String arg0) throws SOAPException {
168: return delegateElement.addTextNode(arg0);
169: }
170:
171: public Node appendChild(Node arg0) throws DOMException {
172: return delegateElement.appendChild(arg0);
173: }
174:
175: public Node cloneNode(boolean arg0) {
176: return delegateElement.cloneNode(arg0);
177: }
178:
179: public void detachNode() {
180: delegateElement.detachNode();
181: }
182:
183: public boolean equals(Object obj) {
184: return delegateElement.equals(obj);
185: }
186:
187: public Iterator getAllAttributes() {
188: return delegateElement.getAllAttributes();
189: }
190:
191: public String getAttribute(String arg0) {
192: return delegateElement.getAttribute(arg0);
193: }
194:
195: public Attr getAttributeNode(String arg0) {
196: return delegateElement.getAttributeNode(arg0);
197: }
198:
199: public Attr getAttributeNodeNS(String arg0, String arg1) {
200: return delegateElement.getAttributeNodeNS(arg0, arg1);
201: }
202:
203: public String getAttributeNS(String arg0, String arg1) {
204: return delegateElement.getAttributeNS(arg0, arg1);
205: }
206:
207: public NamedNodeMap getAttributes() {
208: return delegateElement.getAttributes();
209: }
210:
211: public String getAttributeValue(Name arg0) {
212: return delegateElement.getAttributeValue(arg0);
213: }
214:
215: public Iterator getChildElements() {
216: return delegateElement.getChildElements();
217: }
218:
219: public Iterator getChildElements(Name arg0) {
220: return delegateElement.getChildElements(arg0);
221: }
222:
223: public NodeList getChildNodes() {
224: return delegateElement.getChildNodes();
225: }
226:
227: public Name getElementName() {
228: return delegateElement.getElementName();
229: }
230:
231: public NodeList getElementsByTagName(String arg0) {
232: return delegateElement.getElementsByTagName(arg0);
233: }
234:
235: public NodeList getElementsByTagNameNS(String arg0, String arg1) {
236: return delegateElement.getElementsByTagNameNS(arg0, arg1);
237: }
238:
239: public String getEncodingStyle() {
240: return delegateElement.getEncodingStyle();
241: }
242:
243: public Node getFirstChild() {
244: return delegateElement.getFirstChild();
245: }
246:
247: public Node getLastChild() {
248: return delegateElement.getLastChild();
249: }
250:
251: public String getLocalName() {
252: return delegateElement.getLocalName();
253: }
254:
255: public Iterator getNamespacePrefixes() {
256: return delegateElement.getNamespacePrefixes();
257: }
258:
259: public String getNamespaceURI() {
260: return delegateElement.getNamespaceURI();
261: }
262:
263: public String getNamespaceURI(String arg0) {
264: return delegateElement.getNamespaceURI(arg0);
265: }
266:
267: public Node getNextSibling() {
268: return delegateElement.getNextSibling();
269: }
270:
271: public String getNodeName() {
272: return delegateElement.getNodeName();
273: }
274:
275: public short getNodeType() {
276: return delegateElement.getNodeType();
277: }
278:
279: public String getNodeValue() throws DOMException {
280: return delegateElement.getNodeValue();
281: }
282:
283: public Document getOwnerDocument() {
284: return delegateElement.getOwnerDocument();
285: }
286:
287: public SOAPElement getParentElement() {
288: return delegateElement.getParentElement();
289: }
290:
291: public Node getParentNode() {
292: return delegateElement.getParentNode();
293: }
294:
295: public String getPrefix() {
296: return delegateElement.getPrefix();
297: }
298:
299: public Node getPreviousSibling() {
300: return delegateElement.getPreviousSibling();
301: }
302:
303: public String getTagName() {
304: return delegateElement.getTagName();
305: }
306:
307: public String getValue() {
308: return delegateElement.getValue();
309: }
310:
311: public Iterator getVisibleNamespacePrefixes() {
312: return delegateElement.getVisibleNamespacePrefixes();
313: }
314:
315: public boolean hasAttribute(String arg0) {
316: return delegateElement.hasAttribute(arg0);
317: }
318:
319: public boolean hasAttributeNS(String arg0, String arg1) {
320: return delegateElement.hasAttributeNS(arg0, arg1);
321: }
322:
323: public boolean hasAttributes() {
324: return delegateElement.hasAttributes();
325: }
326:
327: public boolean hasChildNodes() {
328: return delegateElement.hasChildNodes();
329: }
330:
331: /*public int hashCode() {
332: return delegateElement.hashCode();
333: }*/
334:
335: public Node insertBefore(Node arg0, Node arg1) throws DOMException {
336: return delegateElement.insertBefore(arg0, arg1);
337: }
338:
339: public boolean isSupported(String arg0, String arg1) {
340: return delegateElement.isSupported(arg0, arg1);
341: }
342:
343: public void normalize() {
344: delegateElement.normalize();
345: }
346:
347: public void recycleNode() {
348: delegateElement.recycleNode();
349: }
350:
351: public void removeAttribute(String arg0) throws DOMException {
352: delegateElement.removeAttribute(arg0);
353: }
354:
355: public boolean removeAttribute(Name arg0) {
356: return delegateElement.removeAttribute(arg0);
357: }
358:
359: public Attr removeAttributeNode(Attr arg0) throws DOMException {
360: return delegateElement.removeAttributeNode(arg0);
361: }
362:
363: public void removeAttributeNS(String arg0, String arg1)
364: throws DOMException {
365: delegateElement.removeAttributeNS(arg0, arg1);
366: }
367:
368: public Node removeChild(Node arg0) throws DOMException {
369: return delegateElement.removeChild(arg0);
370: }
371:
372: public void removeContents() {
373: delegateElement.removeContents();
374: }
375:
376: public boolean removeNamespaceDeclaration(String arg0) {
377: return delegateElement.removeNamespaceDeclaration(arg0);
378: }
379:
380: public Node replaceChild(Node arg0, Node arg1) throws DOMException {
381: return delegateElement.replaceChild(arg0, arg1);
382: }
383:
384: public void setAttribute(String arg0, String arg1)
385: throws DOMException {
386: delegateElement.setAttribute(arg0, arg1);
387: }
388:
389: public Attr setAttributeNode(Attr arg0) throws DOMException {
390: return delegateElement.setAttributeNode(arg0);
391: }
392:
393: public Attr setAttributeNodeNS(Attr arg0) throws DOMException {
394: return delegateElement.setAttributeNodeNS(arg0);
395: }
396:
397: public void setAttributeNS(String arg0, String arg1, String arg2)
398: throws DOMException {
399: delegateElement.setAttributeNS(arg0, arg1, arg2);
400: }
401:
402: public void setEncodingStyle(String arg0) throws SOAPException {
403: delegateElement.setEncodingStyle(arg0);
404: }
405:
406: public void setNodeValue(String arg0) throws DOMException {
407: delegateElement.setNodeValue(arg0);
408: }
409:
410: public void setParentElement(SOAPElement arg0) throws SOAPException {
411: delegateElement.setParentElement(arg0);
412: }
413:
414: public void setPrefix(String arg0) throws DOMException {
415: delegateElement.setPrefix(arg0);
416: }
417:
418: public void setValue(String arg0) {
419: delegateElement.setValue(arg0);
420: }
421:
422: /*public String toString() {
423: return delegateElement.toString();
424: }*/
425:
426: protected static SOAPFactory getSoapFactory() {
427: return soapFactory;
428: }
429:
430: // DOM L3 methods from org.w3c.dom.Node
431: public String getBaseURI() {
432: return delegateElement.getBaseURI();
433: }
434:
435: public short compareDocumentPosition(org.w3c.dom.Node other)
436: throws DOMException {
437: return delegateElement.compareDocumentPosition(other);
438: }
439:
440: public String getTextContent() throws DOMException {
441: return delegateElement.getTextContent();
442: }
443:
444: public void setTextContent(String textContent) throws DOMException {
445: delegateElement.setTextContent(textContent);
446: }
447:
448: public boolean isSameNode(org.w3c.dom.Node other) {
449: return delegateElement.isSameNode(other);
450: }
451:
452: public String lookupPrefix(String namespaceURI) {
453: return delegateElement.lookupPrefix(namespaceURI);
454: }
455:
456: public boolean isDefaultNamespace(String namespaceURI) {
457: return delegateElement.isDefaultNamespace(namespaceURI);
458: }
459:
460: public String lookupNamespaceURI(String prefix) {
461: return delegateElement.lookupNamespaceURI(prefix);
462: }
463:
464: public boolean isEqualNode(org.w3c.dom.Node arg) {
465: return delegateElement.isEqualNode(arg);
466: }
467:
468: public Object getFeature(String feature, String version) {
469: return delegateElement.getFeature(feature, version);
470: }
471:
472: public Object setUserData(String key, Object data,
473: UserDataHandler handler) {
474: return delegateElement.setUserData(key, data, handler);
475: }
476:
477: public Object getUserData(String key) {
478: return delegateElement.getUserData(key);
479: }
480:
481: // DOM L3 methods from org.w3c.dom.Element
482:
483: public void setIdAttribute(String name, boolean isId)
484: throws DOMException {
485: delegateElement.setIdAttribute(name, isId);
486: }
487:
488: public void setIdAttributeNode(Attr idAttr, boolean isId)
489: throws DOMException {
490: delegateElement.setIdAttributeNode(idAttr, isId);
491: }
492:
493: public void setIdAttributeNS(String namespaceURI, String localName,
494: boolean isId) throws DOMException {
495: delegateElement.setIdAttributeNS(namespaceURI, localName, isId);
496: }
497:
498: public TypeInfo getSchemaTypeInfo() {
499: return delegateElement.getSchemaTypeInfo();
500: }
501:
502: public void isBSP(boolean flag) {
503: bsp = flag;
504: }
505:
506: public boolean isBSP() {
507: return bsp;
508: }
509:
510: public Iterator getAllAttributesAsQNames() {
511: return delegateElement.getAllAttributesAsQNames();
512: }
513:
514: }
|