1 57 58 package org.apache.wsif.base; 59 60 import java.util.ArrayList ; 61 import java.util.Iterator ; 62 import java.util.List ; 63 64 import org.apache.wsif.WSIFException; 65 import org.apache.wsif.WSIFConstants; 66 import org.apache.wsif.WSIFMessage; 67 import org.apache.wsif.WSIFPort; 68 import org.apache.wsif.logging.Trc; 69 70 80 public abstract class WSIFDefaultPort implements WSIFPort { 81 private static final long serialVersionUID = 1L; 82 83 private WSIFMessage context; 84 85 public void close() throws WSIFException { 86 Trc.entry(this); 87 Trc.exit(); 88 } 89 90 public void finalize() throws Throwable { 91 Trc.entry(this); 92 try { 93 close(); 94 } catch (WSIFException ex) { 95 Trc.ignoredException( ex ); 96 } 97 super.finalize(); 98 Trc.exit(); 99 } 100 101 104 protected String getKey(String name, String inputName, String outputName) { 105 Trc.entry(this, name, inputName, outputName); 106 String s = 107 name 108 + (inputName != null ? ":" + inputName : "") 109 + (outputName != null ? ":" + outputName : ""); 110 Trc.exit(s); 111 return s; 112 } 113 114 118 protected Object getExtElem(Object ctx, Class extType, List extElems) 119 throws WSIFException { 120 Trc.entry(this, ctx, extType, extElems); 121 122 Object found = null; 123 if (extElems != null) { 124 for (Iterator i = extElems.iterator(); i.hasNext();) { 125 Object o = i.next(); 127 if (extType.isAssignableFrom(o.getClass())) { 128 if (found != null) { 129 throw new WSIFException( 130 "duplicated extensibility element " 131 + extType.getClass().getName() 132 + " in " 133 + ctx); 134 } 135 found = o; 136 } 137 } 138 } 139 Trc.exit(found); 140 return found; 141 } 142 143 146 protected List getExtElems(Object ctx, Class extType, List extElems) 147 throws WSIFException { 148 Trc.entry(this, ctx, extType, extElems); 149 List found = new ArrayList (); 150 if (extElems != null) 151 for (Iterator i = extElems.iterator(); i.hasNext();) { 152 Object o = i.next(); 153 if (extType.isAssignableFrom(o.getClass())) 154 found.add(o); 155 } 156 if (found.size() == 0) 157 return null; 158 Trc.exit(found); 159 return found; 160 } 161 162 167 public boolean supportsSync() { 168 Trc.entry(this); 169 Trc.exit(true); 170 return true; 171 } 172 173 178 public boolean supportsAsync() { 179 Trc.entry(this); 180 Trc.exit(false); 181 return false; 182 } 183 184 188 public WSIFMessage getContext() throws WSIFException { 189 Trc.entry(this); 190 WSIFMessage contextCopy; 191 if (this.context == null) { 192 contextCopy = new WSIFDefaultMessage(); 196 } else { 197 try { 198 contextCopy = (WSIFMessage) this.context.clone(); 199 } catch (CloneNotSupportedException e) { 200 throw new WSIFException( 201 "CloneNotSupportedException cloning context", e); 202 } 203 } 204 Trc.exit(contextCopy); 205 return contextCopy; 206 } 207 208 212 public void setContext(WSIFMessage context) { 213 Trc.entry(this, context); 214 if (context == null) { 215 throw new IllegalArgumentException ("context must not be null"); 216 } 217 this.context = context; 218 Trc.exit(null); 219 } 220 221 } | Popular Tags |