View Javadoc

1   /*
2    * ====================
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4    * 
5    * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.     
6    * 
7    * The contents of this file are subject to the terms of the Common Development 
8    * and Distribution License("CDDL") (the "License").  You may not use this file 
9    * except in compliance with the License.
10   * 
11   * You can obtain a copy of the License at 
12   * http://IdentityConnectors.dev.java.net/legal/license.txt
13   * See the License for the specific language governing permissions and limitations 
14   * under the License. 
15   * 
16   * When distributing the Covered Code, include this CDDL Header Notice in each file
17   * and include the License file at identityconnectors/legal/license.txt.
18   * If applicable, add the following below this CDDL Header, with the fields 
19   * enclosed by brackets [] replaced by your own identifying information: 
20   * "Portions Copyrighted [year] [name of copyright owner]"
21   * ====================
22   */
23  package org.identityconnectors.framework.impl.api;
24  
25  import java.util.HashMap;
26  import java.util.Map;
27  import java.util.Set;
28  
29  import org.identityconnectors.common.CollectionUtil;
30  import org.identityconnectors.common.pooling.ObjectPoolConfiguration;
31  import org.identityconnectors.framework.api.APIConfiguration;
32  import org.identityconnectors.framework.api.ResultsHandlerConfiguration;
33  import org.identityconnectors.framework.api.operations.APIOperation;
34  
35  
36  public class APIConfigurationImpl implements APIConfiguration {
37  
38      // =======================================================================
39      // Fields
40      // =======================================================================
41      /**
42       * All configuration related to connector pooling.
43       */
44      private ObjectPoolConfiguration _connectorPoolConfiguration;
45  
46      private ResultsHandlerConfiguration _resultsHandlerConfiguration;
47      
48      private boolean _isConnectorPoolingSupported;
49      
50      private ConfigurationPropertiesImpl _configurationProperties;
51             
52      /**
53       * Default size of the buffer.
54       */
55      private int _bufferSize = 100;
56      
57      /**
58       * Map of timeout per operation.
59       */
60      private Map<Class<? extends APIOperation>, Integer> _timeoutMap 
61      = new HashMap<Class<? extends APIOperation>, Integer>();
62  
63      /**
64       * Set of supported operations;
65       */
66      private Set<Class<? extends APIOperation>> _supportedOperations; 
67      
68      
69      /**
70       * The connector info from which this was created. Not serialized in this 
71       * object. Set when returned from the parent
72       */
73      private transient AbstractConnectorInfo _connectorInfo;
74      
75      // =======================================================================
76      // Internal Methods
77      // =======================================================================
78     
79      
80      public AbstractConnectorInfo getConnectorInfo() {
81          return _connectorInfo;
82      }
83      
84      public void setConnectorInfo(AbstractConnectorInfo connectorInfo) {
85         _connectorInfo = connectorInfo;
86      }
87      
88      public void setConnectorPoolingSupported(boolean supported) {
89          _isConnectorPoolingSupported = supported;
90      }
91      
92      public void setConnectorPoolConfiguration(ObjectPoolConfiguration config) {
93          _connectorPoolConfiguration = config;
94      }
95      
96      public void setConfigurationProperties(ConfigurationPropertiesImpl properties) {
97          if (_configurationProperties != null) {
98              _configurationProperties.setParent(null);
99          }
100         _configurationProperties = properties;
101         if (_configurationProperties != null) {
102             _configurationProperties.setParent(this);
103         }        
104     }
105 
106     
107     public Map<Class<? extends APIOperation>, Integer> getTimeoutMap() {
108         return _timeoutMap;
109     }
110     
111     public void setTimeoutMap(Map<Class<? extends APIOperation>, Integer> map) {
112         _timeoutMap = map;
113     }
114     
115     public void setSupportedOperations(Set<Class<? extends APIOperation>> op) {
116         _supportedOperations = op;        
117     }
118     
119 
120     // =======================================================================
121     // Interface Methods
122     // =======================================================================
123 
124     /**
125      * {@inheritDoc}
126      */
127     public boolean isConnectorPoolingSupported() {
128         return _isConnectorPoolingSupported;
129     }
130 
131     /**
132      * {@inheritDoc}
133      */
134     public ObjectPoolConfiguration getConnectorPoolConfiguration() {
135         if (_connectorPoolConfiguration == null) {
136             _connectorPoolConfiguration = new ObjectPoolConfiguration();
137         }
138         return _connectorPoolConfiguration;
139     }
140 
141     /**
142      * {@inheritDoc}
143      */
144     public ConfigurationPropertiesImpl getConfigurationProperties() {
145         return _configurationProperties;
146     }    
147 
148     /**
149      * {@inheritDoc}
150      */
151     public int getTimeout(Class<? extends APIOperation> operation) {
152         Integer ret = this._timeoutMap.get(operation);
153         if (ret == null) {
154             // use the default..
155             ret = APIOperation.NO_TIMEOUT;
156         }
157         return ret;
158     }
159     
160     /**
161      * {@inheritDoc}
162      */
163     public Set<Class<? extends APIOperation>> getSupportedOperations() {
164         return CollectionUtil.newReadOnlySet(_supportedOperations);
165     }
166 
167     /**
168      * {@inheritDoc}
169      */
170     public void setTimeout(Class<? extends APIOperation> operation, 
171             int timeout) {
172         this._timeoutMap.put(operation, timeout);
173     }
174 
175     /**
176      * {@inheritDoc}
177      */
178     public void setProducerBufferSize(int size) {
179         this._bufferSize = size;
180     }
181 
182     /**
183      * {@inheritDoc}
184      */
185     public int getProducerBufferSize() {
186         return this._bufferSize;
187     }
188 
189     /**
190      * {@inheritDoc}
191      */
192     public ResultsHandlerConfiguration getResultsHandlerConfiguration() {
193         if (null == _resultsHandlerConfiguration) {
194             _resultsHandlerConfiguration = new ResultsHandlerConfiguration();
195         }
196         return _resultsHandlerConfiguration;
197     }
198 
199     public void setResultsHandlerConfiguration(ResultsHandlerConfiguration config) {
200         this._resultsHandlerConfiguration = config;
201     }
202 }