View Javadoc
1   /*
2    * Copyright 2001-2008 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.validation;
18  
19  import java.util.List;
20  import java.util.logging.Logger;
21  
22  import javax.persistence.EntityManager;
23  
24  import org.apache.juddi.api_v3.Node;
25  import org.apache.juddi.model.UddiEntityPublisher;
26  import org.apache.juddi.v3.error.ErrorMessage;
27  import org.apache.juddi.v3.error.FatalErrorException;
28  import org.apache.juddi.v3.error.ValueNotAllowedException;
29  import org.uddi.v3_service.DispositionReportFaultMessage;
30  
31  /**
32   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
33   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
34   */
35  public class ValidateNode extends ValidateUDDIApi {
36  
37          public ValidateNode(UddiEntityPublisher publisher) {
38                  super(publisher);
39          }
40          private static final Logger logger = Logger.getLogger(ValidateNode.class.getCanonicalName());
41          /*-------------------------------------------------------------------
42           validateSaveNode functions are specific to jUDDI.
43           --------------------------------------------------------------------*/
44  
45          public void validateSaveNode(EntityManager em, org.apache.juddi.api_v3.SaveNode body) throws DispositionReportFaultMessage {
46  
47                  if (body == null) {
48                          throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
49                  }
50  
51                  // No null or empty list
52                  List<Node> nodes = body.getNode();
53                  if (nodes == null) {
54                          throw new ValueNotAllowedException(new ErrorMessage("errors.saveNodes.NoInput"));
55                  }
56  
57                  for (Node clerk : body.getNode()) {
58                          validateNode(clerk);
59                  }
60  
61          }
62  
63          public void validateNode(org.apache.juddi.api_v3.Node node) throws DispositionReportFaultMessage {
64  
65                  // No null input
66                  if (node == null) {
67                          throw new ValueNotAllowedException(new ErrorMessage("errors.node.NullInput"));
68                  }
69  
70                  String name = node.getName();
71                  if (name == null || name.length() == 0 || name.length()>255 || node.getClientName()==null|| node.getClientName().length() > 255) {
72                          throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoName"));
73                  }
74                  if (node.getDescription() == null || node.getDescription().length() == 0 || node.getDescription().length() > 255) {
75                          throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoDescription"));
76                  }
77                  if (node.getClientName() == null || node.getClientName().length() == 0 || node.getClientName().length() > 255) {
78                          throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoClientName"));
79                  }
80                  if (node.getCustodyTransferUrl() == null || node.getCustodyTransferUrl().length() == 0 || node.getClientName().length() > 255) {
81                          throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoNCT"));
82                  }
83                  if (node.getInquiryUrl() == null || node.getInquiryUrl().length() == 0 || node.getInquiryUrl().length() > 255) {
84                          throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoIN"));
85                  }
86                  if (node.getPublishUrl() == null || node.getPublishUrl().length() == 0 || node.getPublishUrl().length() > 255) {
87                          throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoPUB"));
88                  }
89                  if (node.getSubscriptionListenerUrl() == null || node.getSubscriptionListenerUrl().length() == 0 || node.getSubscriptionListenerUrl().length() > 255) {
90                  //        throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoSUBL"));
91                  }
92                  if (node.getReplicationUrl() == null || node.getReplicationUrl().length() == 0 || node.getReplicationUrl().length() > 255) {
93                          //throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoSUBL"));
94                          //logger.log(Level.WARNING, "No replication url on save node request!");
95                  }
96                  if (node.getSubscriptionUrl() == null || node.getSubscriptionUrl().length() == 0 || node.getSubscriptionUrl().length() > 255) {
97                          throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoSUB"));
98                  }
99                  if (node.getSecurityUrl()== null || node.getSecurityUrl().length() == 0 || node.getSecurityUrl().length() > 255) {
100                         throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoSec"));
101                 }
102                 if (node.getProxyTransport() == null || node.getProxyTransport().length() == 0 || node.getProxyTransport().length() > 255) {
103                         throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoProxy"));
104                 } else {
105                         try {
106                                 //validate that the class exists and that it is of type
107                                 //org.apache.juddi.v3.client.transport.Transport
108                                 Class<?> forName = Class.forName(node.getProxyTransport());
109                                 Object j = forName.newInstance();
110                                 if (!(j instanceof org.apache.juddi.v3.client.transport.Transport)) {
111                                         throw new ValueNotAllowedException(new ErrorMessage("errors.node.illegalProxyTransport"));
112                                 }
113                         } catch (Exception ex) {
114                                 throw new ValueNotAllowedException(new ErrorMessage("errors.node.illegalProxyTransport"));
115                         }
116                 }
117                 if (node.getProxyTransport().equalsIgnoreCase("org.apache.juddi.v3.client.transport.RMITransport")) {
118                         throw new ValueNotAllowedException(new ErrorMessage("errors.node.NoRMIData"));
119 
120                 }
121 
122         }
123 }