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.subscription;
18  
19  import java.util.Date;
20  import java.util.GregorianCalendar;
21  
22  import javax.xml.datatype.DatatypeConfigurationException;
23  import javax.xml.datatype.DatatypeFactory;
24  import javax.xml.datatype.Duration;
25  import javax.xml.datatype.XMLGregorianCalendar;
26  
27  import org.apache.juddi.v3.error.ErrorMessage;
28  import org.apache.juddi.v3.error.FatalErrorException;
29  import org.uddi.v3_service.DispositionReportFaultMessage;
30  /**
31   * 
32   */
33  public class TypeConvertor {
34  	public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(Date date) throws DispositionReportFaultMessage {
35  		XMLGregorianCalendar result = null;
36  		try { 
37  			if (date!=null) {
38  				GregorianCalendar gc = new GregorianCalendar();
39  				gc.setTimeInMillis(date.getTime());
40  				
41  				DatatypeFactory df = DatatypeFactory.newInstance();
42  				result = df.newXMLGregorianCalendar(gc);
43  			}
44  		}
45  		catch(DatatypeConfigurationException ce) { 
46  			throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
47  		}
48  		
49  		return result;
50  	}
51  	
52  	public static Duration convertStringToDuration(String duration) throws DispositionReportFaultMessage {
53  		if (duration==null) return null;
54  		Duration result = null;
55  		try { 
56  			
57  			DatatypeFactory df = DatatypeFactory.newInstance();
58  			result = df.newDuration(duration);
59  		}
60  		catch(DatatypeConfigurationException ce) { 
61  			throw new FatalErrorException(new ErrorMessage("errors.Unspecified"));
62  		}
63  
64  		return result;
65  	}
66  }