KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > function > AbstractFunction


1 /*
2  * Copyright 2001-2004 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 package org.apache.juddi.function;
17
18 import org.apache.juddi.datastore.DataStore;
19 import org.apache.juddi.datatype.publisher.Publisher;
20 import org.apache.juddi.datatype.request.AuthInfo;
21 import org.apache.juddi.error.AuthTokenExpiredException;
22 import org.apache.juddi.error.AuthTokenRequiredException;
23 import org.apache.juddi.error.RegistryException;
24 import org.apache.juddi.registry.RegistryEngine;
25  
26 /**
27  * @author Steve Viens (sviens@apache.org)
28  */

29 public abstract class AbstractFunction implements IFunction
30 {
31   // protected reference to parent Registry instance
32
protected RegistryEngine registry = null;
33
34   /**
35    * @param registry
36    */

37   protected AbstractFunction(RegistryEngine registry)
38   {
39     this.registry = registry;
40   }
41   
42   /**
43    * @return RegistryEngine
44    */

45   public RegistryEngine getRegistry()
46   {
47     return this.registry;
48   }
49   
50   /**
51    * @param registry
52    */

53   public void setRegistry(RegistryEngine registry)
54   {
55     this.registry = registry;
56   }
57
58   /**
59    * Verify the authentication parameters.
60    */

61   protected Publisher getPublisher(AuthInfo authInfo,DataStore dataStore)
62     throws RegistryException
63   {
64     Publisher publisher = null;
65
66     if ((authInfo == null) || (authInfo.getValue() == null))
67       throw new AuthTokenRequiredException("authToken: null");
68
69     String JavaDoc authToken = authInfo.getValue();
70     if (authToken.trim().length() == 0)
71       throw new AuthTokenRequiredException("authToken: "+authToken);
72
73     publisher = dataStore.getAuthTokenPublisher(authToken);
74     if (publisher == null)
75       throw new AuthTokenRequiredException("authToken: "+authToken);
76
77     if (dataStore.isAuthTokenExpired(authToken))
78       throw new AuthTokenExpiredException("authToken: "+authToken);
79
80     // Token is valid so 'touch' so that it's
81
// internal 'expiration clock' is reset.
82
dataStore.touchAuthToken(authToken);
83
84     return publisher;
85   }
86 }
Popular Tags