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  
18  package org.apache.juddi.validation;
19  
20  
21  import java.util.logging.Level;
22  import java.util.logging.Logger;
23  import javax.persistence.EntityManager;
24  import org.apache.commons.configuration.ConfigurationException;
25  import org.apache.juddi.config.AppConfig;
26  import org.apache.juddi.config.Property;
27  
28  import org.apache.juddi.model.Subscription;
29  import org.apache.juddi.model.UddiEntity;
30  import org.apache.juddi.model.UddiEntityPublisher;
31  import org.apache.juddi.v3.error.ErrorMessage;
32  import org.apache.juddi.v3.error.UnsupportedException;
33  import org.uddi.v3_service.DispositionReportFaultMessage;
34  
35  /**
36   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
37   */
38  public abstract class ValidateUDDIApi {
39  
40  	protected UddiEntityPublisher publisher;
41     protected String nodeID=null;
42  		
43     /**
44      * This is used only during the install process to prevent infinite loops
45      * @param publisher
46      * @param nodeid 
47      */
48  	public ValidateUDDIApi(UddiEntityPublisher publisher, String nodeid) {
49  		this.publisher = publisher;
50        this.nodeID = nodeid;
51  	}
52     
53     public ValidateUDDIApi(UddiEntityPublisher publisher) {
54  		this.publisher = publisher;
55        try {
56           this.nodeID = AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID);
57        } catch (ConfigurationException ex) {
58           Logger.getLogger(ValidateUDDIApi.class.getName()).log(Level.SEVERE, "unable to get the current node id, this may cause access control problems"
59                   + " and must be fixed. set " + Property.JUDDI_NODE_ID + " in juddiv3.xml", ex);
60        }
61  	}
62  
63  	public UddiEntityPublisher getPublisher() {
64  		return publisher;
65  	}
66  
67  	public void setPublisher(UddiEntityPublisher publisher) {
68  		this.publisher = publisher;
69  	}
70  	
71  	public static void unsupportedAPICall() throws DispositionReportFaultMessage {
72  		throw new UnsupportedException(new ErrorMessage("errors.Unsupported"));
73  	}
74  	
75  	public static boolean isUniqueKey(EntityManager em, String entityKey) {
76  		Object obj = em.find(UddiEntity.class, entityKey);
77  		if (obj != null)
78  			return false;
79  		
80  		obj = em.find(Subscription.class, entityKey);
81  		if (obj != null)
82  			return false;
83  		
84  		return true;
85  	}
86  }