KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > property > OperationInputOutputFaultPropertyAdapter


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 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.view.property;
21
22 import javax.xml.namespace.QName JavaDoc;
23
24 import org.netbeans.modules.xml.wsdl.model.Message;
25 import org.netbeans.modules.xml.wsdl.model.Operation;
26 import org.netbeans.modules.xml.wsdl.model.OperationParameter;
27 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
28 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter;
29 import org.netbeans.modules.xml.wsdl.ui.commands.NamedPropertyAdapter;
30 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
31 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
32 import org.openide.ErrorManager;
33
34 /**
35  *
36  * @author radval
37  *
38  */

39 public class OperationInputOutputFaultPropertyAdapter extends ConstraintNamedPropertyAdapter implements NamedPropertyAdapter {
40     
41     private OperationParameter mOParameter;
42     
43     public OperationInputOutputFaultPropertyAdapter(WSDLComponent wsdlComponent) {
44         super(wsdlComponent);
45         this.mOParameter = (OperationParameter) wsdlComponent;
46     }
47      
48      public String JavaDoc getMessage() {
49          NamedComponentReference message = mOParameter.getMessage();
50          if(message == null) {
51              return "";
52          }
53          QName JavaDoc messageQName = message.getQName();
54          return Utility.fromQNameToString(messageQName);
55      }
56      
57      public void setMessage(String JavaDoc message) {
58          if(message != null) {
59              try {
60                  org.netbeans.modules.xml.wsdl.ui.common.QName messageQName = org.netbeans.modules.xml.wsdl.ui.common.QName.getQNameFromString(message);
61                  if(messageQName == null) {
62                      mOParameter.getModel().startTransaction();
63                      mOParameter.setMessage(null);
64                      mOParameter.getModel().endTransaction();
65                  } else {
66                      
67                      String JavaDoc ns = messageQName.getNamespaceURI();
68                      String JavaDoc prefix = messageQName.getPrefix();
69                      if(ns == null || ns.trim().equals("")) {
70                          ns = Utility.getNamespaceURI(prefix, mOParameter.getModel());
71                      }
72                      
73                      QName JavaDoc qname = null;
74                      if (ns != null) {
75                          qname = new QName JavaDoc(ns, messageQName.getLocalName());
76                      }
77                      
78                      if(qname != null) {
79                          Message msg = mOParameter.getModel().findComponentByName(qname, Message.class);
80                          if (msg == null) {
81                              ErrorManager.getDefault().notify(ErrorManager.ERROR, new Exception JavaDoc ("Not a valid type"));
82                          } else {
83                              mOParameter.getModel().startTransaction();
84                              mOParameter.setMessage(mOParameter.createReferenceTo(msg, Message.class));
85                              
86                              mOParameter.getModel().endTransaction();
87                          }
88                      }
89                  }
90              } catch (Exception JavaDoc e) {
91                  ErrorManager.getDefault().notify(e);
92              }
93          }
94      }
95
96     @Override JavaDoc
97     public boolean isNameExists(String JavaDoc name) {
98         boolean exists = false;
99         Operation operation = (Operation) mOParameter.getParent();
100         if (operation.getInput() != null) {
101             exists = operation.getInput().getName().equals(name);
102         }
103         
104         if (operation.getOutput() != null) {
105             exists = operation.getOutput().getName().equals(name);
106         }
107         
108         return exists;
109     }
110
111 }
112
Popular Tags