com.ca.jcs.meta
Class MetaConnectorFactory

java.lang.Object
  extended by com.ca.jcs.meta.MetaConnectorFactory
All Implemented Interfaces:
ConnectorFactory

public class MetaConnectorFactory
extends Object
implements ConnectorFactory

Factory driven by metadata contained in attributes of ConnectorType objects (aka Endpoint Type, formerly Namespace). It's functions include:

  1. Indexing information about connector implementations hosted by a JCS (via ImplBundle objects constructed from connectors' /conf/connector.xml files via Spring XML), and matching them to the LDAP requests they are designed to process.
  2. Creating and deleting concrete ConnectorType objects using ImplBundle information and provided metadata.
  3. Creating and deleting concrete Connector objects using ImplBundle information and provided metadata.
  4. Converting metadata from text into Java objects.
  5. Configuring special loggers for connectors at the time they are created.
  6. Providing support for creating Java proxy wrappers around the various styles of processors a connector may choose to implement.


Field Summary
static String ATTR_NAMESPACE_FAMILY
          Attribute name for a namespace family (used by ConnXp to determine dynamic connectors)
static String ATTR_OBJECT_CLASS
          Attribute name for the object class
static String CUSTOM_METADATA_ATTR
          connectorMapTo= value for sparse metadata to be merged over the top of static metadata, see ImplBundle.getCustomMetadataFile().
static String IMPL_BUNDLE_TAG
           
static String LOG_DEST_ATTR
           
static String SKIP_PERSISTER_DELETE_LDAP_ATTR
          Mapping for BaseConnector.CONN_SKIP_PERSISTER_DELETE_ATTR on Connector Types/Connectors.
static String STR_VALUE_TAG
           
static String VALUE_NAMESPACE_FAMILY_DYNAMIC
          Namespace family value for dynamic connector types
static String VALUE_OBJECT_CLASS_DYN_NAMESPACE
          Object class value for a dynamic namespace
 
Constructor Summary
MetaConnectorFactory()
           
 
Method Summary
 ImplBundle addConnectorTypeStaticAttributes(String connTypeName, Attributes attrs)
          Adds the static attributes (metadata, op bindings) of a connector type to an existing group of attributes.
 void addImplBundle(ImplBundle implBundle, boolean replaceExisting)
          Add a single implBundle, replacing any old bundle with the same name
 void clearMetadataAttributesValues(Attributes attrs, ModificationItem[] items)
          When modifying the metadata and opbinding metadata attributes, sometimes the clients like JX sends down the multi-valued modification form (in Add mode) to JCS, hence JCS adds the replaced attribute value at the end of the existing values.
 DataModel convertMetadata(String connTypeName, Attributes attrs)
           
protected  DataModel convertMetadata(String connTypeName, String metaData, String customMetaData)
           
 Opbindings convertOpBindingMetadata(String connTypeName, String metadata)
          Convert XML opbindings containing at least one of method-style and script-style bindings for operations.
 Connector createConnector(ConnectorType connType, String namingAttr, String name, LdapDN suffix, Attributes attrs)
          Create a connector based on parent type's metadata, the provided attrs and the default connector config stored on parent connType.
 ConnectorType createConnectorType(String connTypeName, Attributes attrs)
          Creates a MetaConnectorType capable of broadcasting metadata changes to contained connectors.
 ImplBundle createImplBundle(String connectorXML)
          Dynamically create a bundle from connector.xml content and register it for use
 ImplBundle createImplBundle(String connTypeName, DataModel model)
          Dynamically create a bundle for an endpoint type from connector.xml content in metadata if present
 Logger createLogger(String connTypeName, String connName)
          Create logger for connector, which also means creating an appender for it which uses the connector's connName.
 void destroyConnectorType(String connTypeName)
          Destroys a MetaConnectorType instance identified by name.
 void destroyLogger(Logger connLog)
           
 ImplBundle findImplBundle(String connTypeName, Attributes attrs)
          Attempt to find a suitable ImplBundle amongst statically registered ones
 List<String> getAcceptedUnknownAttrIds()
           
 String getConfDirectory()
           
 String getConnectorFilePath(String connTypeName, String connName)
           
 ConnectorPersister getConnectorPersister()
           
 String getConnectorTypeFilePath(String connTypeName)
           
 ConverterManager getConverterManager()
           
 DataModel getDataModel(String connTypeName, Attributes attrs)
          Get the datamodel representation of any metadata set in the connectorType's attributes
 String getDynamicConnectorXML(DataModel datamodel)
          Given DataModel instance for the metadata on endpointType, string representation of any embedded connectorXML metadata
 ImplBundle getImplBundleFromConnectorTypeName(String connTypeName)
           
 ImplBundle getImplBundleFromName(String name)
           
 ImplBundle getImplBundleFromObjectClass(Attribute objClassAttr)
           
 ImplBundle getImplBundleFromObjectClass(String connTypeObjClass)
           
 ImplBundle getImplBundleFromString(String connectorXML)
          Given a string representing connectorXML file content, return the corresponding implBundle bean
 String[] getImplBundleNames()
          Get all names for currently installed JCS connectors.
 List<ImplBundle> getImplBundles()
          List[ImplBundle].
protected  void getImplBundleStaticOpbindingsMetadata(ImplBundle implBundle, Attributes attrs)
           
 String getLogLevelAttr()
           
 org.springframework.context.MessageSource getMessageSource()
           
 String getMetadata(Attributes attrs)
           
 String getMetaDataAttr()
           
 String getMetaDataTimestampAttr()
           
 String getOpBindingMetadata(Attributes attrs)
           
 String getOpBindingMetaDataAttr()
           
 String getOpBindingMetaDataTimestampAttr()
           
 ValidatorManager getValidatorManager()
           
 boolean isAllowMetadataModify(ImplBundle implBundle)
          To determine if the metadata files (eTMetadata and eTOpbindingMetadata) are allowed to modify based on the settings in isAllowMetadataModifyGlobally defined in server_jcs.xml and isAllowMetadataModify in connector.xml.
 boolean isAllowMetadataModifyGlobally()
           
static boolean isDynamicConnectorType(Attributes attrs)
          Method to check if a connector type is dynamic based on it's attributes alone.
 boolean isDynamicConnectorType(LdapDN connTypeDn)
          Method to check if a connector type is dynamic based on it's DN.
 boolean isMetadataChange(Attributes currAttrs, Attributes newAttrs, String attrId, String tsAttrId)
          Compare modification times for metadata in current and new attributes to see if it has changed, return true if either doesn't have a timestamp or if an error occurs trying to access it.
 void proxyAttributeStyleOpProcessorProxy(MetaConnector conn, AttributeStyleOpProcessor proc)
          Queue any required proxy handler classes to conn's proxy chain to be interposed when the chain is activated.
 MethodStyleOpProcessor proxyMethodStyleOpProcessor(MetaConnector conn, MethodStyleOpProcessor proc)
          Return a proxy for one of the given connector's processors if: The connector's implementation bundle has a resilientProxyClass class defined AND The connector's configuration has resilientDelay > 0
 ScriptStyleOpProcessor proxyScriptStyleOpProcessor(MetaConnector conn, ScriptStyleOpProcessor proc)
          Return a proxy for one of the given connector's processors if: The connector's implementation bundle has a resilientProxyClass class defined AND The connector's configuration has resilientDelay > 0
 void setAcceptedUnknownAttrIds(List<String> acceptedUnknownAttrIds)
          When ConnectorConfig.isFailOnUnknownAttrIds() is true then this list can be used to define global attribute ids which aren't mapped, but shouldn't cause an add() or modify() operation to fail when they are mentioned (individual connector configs can add their own ones too if they wish).
 void setAllowMetadataModifyGlobally(boolean allowMetadataModifyGlobally)
           
 void setConfDirectory(String confDirectory)
           
 void setConnectorPersister(ConnectorPersister persister)
          Accessed internally as passed down to created ConnectorTypes and Connectors for use when they are changed.
 void setConverterManager(ConverterManager converterManager)
           
 void setImplBundles(List<ImplBundle> implBundles)
           
 void setLogLevel(ConnectorType connType, Logger logger, Attributes attrs)
          Set logging level on a connector's logger using metadata (and possibly static configuration) combined with values contained in attrs, or do nothing if no logging related attributes are present in attrs.
 void setLogLevelAttr(String logLevelAttr)
           
 void setMessageSource(org.springframework.context.MessageSource msgSrc)
           
 void setMetaDataAttr(String metaDataAttr)
           
 void setMetaDataTimestampAttr(String metaDataTimestampAttr)
           
 void setOpBindingMetaDataAttr(String opBindingMetaDataAttr)
           
 void setOpBindingMetaDataTimestampAttr(String opBindingMetaDataTimestampAttr)
           
 void setValidatorManager(ValidatorManager validatorManager)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STR_VALUE_TAG

public static final String STR_VALUE_TAG
See Also:
Constant Field Values

IMPL_BUNDLE_TAG

public static final String IMPL_BUNDLE_TAG
See Also:
Constant Field Values

CUSTOM_METADATA_ATTR

public static String CUSTOM_METADATA_ATTR
connectorMapTo= value for sparse metadata to be merged over the top of static metadata, see ImplBundle.getCustomMetadataFile().


LOG_DEST_ATTR

public static final String LOG_DEST_ATTR
See Also:
Constant Field Values

ATTR_OBJECT_CLASS

public static final String ATTR_OBJECT_CLASS
Attribute name for the object class

See Also:
Constant Field Values

ATTR_NAMESPACE_FAMILY

public static final String ATTR_NAMESPACE_FAMILY
Attribute name for a namespace family (used by ConnXp to determine dynamic connectors)

See Also:
Constant Field Values

VALUE_OBJECT_CLASS_DYN_NAMESPACE

public static final String VALUE_OBJECT_CLASS_DYN_NAMESPACE
Object class value for a dynamic namespace

See Also:
Constant Field Values

VALUE_NAMESPACE_FAMILY_DYNAMIC

public static final String VALUE_NAMESPACE_FAMILY_DYNAMIC
Namespace family value for dynamic connector types

See Also:
Constant Field Values

SKIP_PERSISTER_DELETE_LDAP_ATTR

public static final String SKIP_PERSISTER_DELETE_LDAP_ATTR
Mapping for BaseConnector.CONN_SKIP_PERSISTER_DELETE_ATTR on Connector Types/Connectors.

See Also:
Constant Field Values
Constructor Detail

MetaConnectorFactory

public MetaConnectorFactory()
Method Detail

getConfDirectory

public String getConfDirectory()
Specified by:
getConfDirectory in interface ConnectorFactory

setConfDirectory

public void setConfDirectory(String confDirectory)
Specified by:
setConfDirectory in interface ConnectorFactory

getAcceptedUnknownAttrIds

public List<String> getAcceptedUnknownAttrIds()

setAcceptedUnknownAttrIds

public void setAcceptedUnknownAttrIds(List<String> acceptedUnknownAttrIds)
When ConnectorConfig.isFailOnUnknownAttrIds() is true then this list can be used to define global attribute ids which aren't mapped, but shouldn't cause an add() or modify() operation to fail when they are mentioned (individual connector configs can add their own ones too if they wish).

Parameters:
acceptedUnknownAttrIds - List of legal, but never-the-less unmapped, LDAP attribute ids.

getValidatorManager

public ValidatorManager getValidatorManager()

setValidatorManager

public void setValidatorManager(ValidatorManager validatorManager)

getConverterManager

public ConverterManager getConverterManager()

setConverterManager

public void setConverterManager(ConverterManager converterManager)

getConnectorPersister

public ConnectorPersister getConnectorPersister()
Specified by:
getConnectorPersister in interface ConnectorFactory

getMessageSource

public org.springframework.context.MessageSource getMessageSource()
Specified by:
getMessageSource in interface ConnectorFactory

setMessageSource

public void setMessageSource(org.springframework.context.MessageSource msgSrc)
Specified by:
setMessageSource in interface ConnectorFactory

setConnectorPersister

public void setConnectorPersister(ConnectorPersister persister)
Description copied from interface: ConnectorFactory
Accessed internally as passed down to created ConnectorTypes and Connectors for use when they are changed.

Specified by:
setConnectorPersister in interface ConnectorFactory

getImplBundles

public List<ImplBundle> getImplBundles()
List[ImplBundle].

Specified by:
getImplBundles in interface ConnectorFactory

getImplBundleNames

public String[] getImplBundleNames()
Get all names for currently installed JCS connectors. "-JAVA" will be appended to each implBundle name. The primary reason is that currently ConXp lacks enough information to ensure the choice of managing CS for a namespace is sane (e.g. can't route to a C++ SA for a DYN namespace). If it could get a live connection to a CS it could determine whether it was a SA or CS by querying its supported controls.

Specified by:
getImplBundleNames in interface ConnectorFactory
Returns:
the array containing all current installed implBundle names

getImplBundleFromName

public ImplBundle getImplBundleFromName(String name)
Specified by:
getImplBundleFromName in interface ConnectorFactory

getImplBundleFromConnectorTypeName

public ImplBundle getImplBundleFromConnectorTypeName(String connTypeName)
Specified by:
getImplBundleFromConnectorTypeName in interface ConnectorFactory

getImplBundleFromObjectClass

public ImplBundle getImplBundleFromObjectClass(String connTypeObjClass)
Specified by:
getImplBundleFromObjectClass in interface ConnectorFactory

getImplBundleFromObjectClass

public ImplBundle getImplBundleFromObjectClass(Attribute objClassAttr)

addImplBundle

public void addImplBundle(ImplBundle implBundle,
                          boolean replaceExisting)
Add a single implBundle, replacing any old bundle with the same name


setImplBundles

public void setImplBundles(List<ImplBundle> implBundles)

getMetaDataAttr

public String getMetaDataAttr()

setMetaDataAttr

public void setMetaDataAttr(String metaDataAttr)

getMetaDataTimestampAttr

public String getMetaDataTimestampAttr()

setMetaDataTimestampAttr

public void setMetaDataTimestampAttr(String metaDataTimestampAttr)

getOpBindingMetaDataAttr

public String getOpBindingMetaDataAttr()

setOpBindingMetaDataAttr

public void setOpBindingMetaDataAttr(String opBindingMetaDataAttr)

getOpBindingMetaDataTimestampAttr

public String getOpBindingMetaDataTimestampAttr()

setOpBindingMetaDataTimestampAttr

public void setOpBindingMetaDataTimestampAttr(String opBindingMetaDataTimestampAttr)

getLogLevelAttr

public String getLogLevelAttr()

setLogLevelAttr

public void setLogLevelAttr(String logLevelAttr)

getConnectorFilePath

public String getConnectorFilePath(String connTypeName,
                                   String connName)
Specified by:
getConnectorFilePath in interface ConnectorFactory

getConnectorTypeFilePath

public String getConnectorTypeFilePath(String connTypeName)
Specified by:
getConnectorTypeFilePath in interface ConnectorFactory

isMetadataChange

public boolean isMetadataChange(Attributes currAttrs,
                                Attributes newAttrs,
                                String attrId,
                                String tsAttrId)
Compare modification times for metadata in current and new attributes to see if it has changed, return true if either doesn't have a timestamp or if an error occurs trying to access it.

Parameters:
currAttrs - Currently stored attributes.
newAttrs - New attributes to be assigned.
Returns:
True if moving to new metadata;

clearMetadataAttributesValues

public void clearMetadataAttributesValues(Attributes attrs,
                                          ModificationItem[] items)
When modifying the metadata and opbinding metadata attributes, sometimes the clients like JX sends down the multi-valued modification form (in Add mode) to JCS, hence JCS adds the replaced attribute value at the end of the existing values. Hence the new replaced value will never be used as the first value of the attribute always be retrieved in the subsequence code. So the solution is to clear the previous values if these metadata attributes are contained in the modification items. On the other hand, if the attributes are not contained in the mod items, don't clear the values otherwise it will cause problem later on as the attributes will be on value and fails the checkAttrsValid.

Parameters:
attrs -
items -

getMetadata

public String getMetadata(Attributes attrs)

getOpBindingMetadata

public String getOpBindingMetadata(Attributes attrs)

isAllowMetadataModify

public boolean isAllowMetadataModify(ImplBundle implBundle)
Description copied from interface: ConnectorFactory
To determine if the metadata files (eTMetadata and eTOpbindingMetadata) are allowed to modify based on the settings in isAllowMetadataModifyGlobally defined in server_jcs.xml and isAllowMetadataModify in connector.xml.

Specified by:
isAllowMetadataModify in interface ConnectorFactory
Parameters:
implBundle -
Returns:
return per-implBundle flag in connector.xml if one has been set, otherwise default to global setting in server_jcs.properties.

createConnectorType

public ConnectorType createConnectorType(String connTypeName,
                                         Attributes attrs)
                                  throws LdapConfigurationException
Creates a MetaConnectorType capable of broadcasting metadata changes to contained connectors.

Specified by:
createConnectorType in interface ConnectorFactory
Parameters:
connTypeName - Name of connector type.
attrs - Attributes passed in through the LDAP front-end, possibly written over the top of attrs persisted previously if there are any.
Returns:
New empty connector type.
Throws:
LdapConfigurationException

addConnectorTypeStaticAttributes

public ImplBundle addConnectorTypeStaticAttributes(String connTypeName,
                                                   Attributes attrs)
                                            throws NamingException
Adds the static attributes (metadata, op bindings) of a connector type to an existing group of attributes.

Parameters:
connTypeName - the connector type name.
attrs - the connector type attributes.
Returns:
the ImplBundle representing the connector type.
Throws:
NamingException

destroyConnectorType

public void destroyConnectorType(String connTypeName)
                          throws LdapConfigurationException
Destroys a MetaConnectorType instance identified by name.

Specified by:
destroyConnectorType in interface ConnectorFactory
Parameters:
connTypeName - Name of connector type.
Throws:
LdapConfigurationException

getDynamicConnectorXML

public String getDynamicConnectorXML(DataModel datamodel)
Given DataModel instance for the metadata on endpointType, string representation of any embedded connectorXML metadata


getImplBundleFromString

public ImplBundle getImplBundleFromString(String connectorXML)
Given a string representing connectorXML file content, return the corresponding implBundle bean


getDataModel

public DataModel getDataModel(String connTypeName,
                              Attributes attrs)
Get the datamodel representation of any metadata set in the connectorType's attributes


createImplBundle

public ImplBundle createImplBundle(String connTypeName,
                                   DataModel model)
Dynamically create a bundle for an endpoint type from connector.xml content in metadata if present

Parameters:
connTypeName -
model -
Returns:

createImplBundle

public ImplBundle createImplBundle(String connectorXML)
Dynamically create a bundle from connector.xml content and register it for use


findImplBundle

public ImplBundle findImplBundle(String connTypeName,
                                 Attributes attrs)
Attempt to find a suitable ImplBundle amongst statically registered ones


setLogLevel

public void setLogLevel(ConnectorType connType,
                        Logger logger,
                        Attributes attrs)
Description copied from interface: ConnectorFactory
Set logging level on a connector's logger using metadata (and possibly static configuration) combined with values contained in attrs, or do nothing if no logging related attributes are present in attrs. Note the signature of this method may seem a little odd, but this is to handle the usescase where logger must be configured for a connector prior to it actually being created so that any problems encountered during its creation also end up in its dedicated log file.

Specified by:
setLogLevel in interface ConnectorFactory
Parameters:
connType - Parent type for connector which owns (or will later be made to own) the provided logger which is to be configured.
logger - Logger on which level should be updated.
attrs - Attributes containing attribute associated with logging (either it has MetaDataDefs.MD_CONN_MAP_TO=MetaConnector.CONN_LOG_SEVERITY_ATTR or it's name was statically assigned via setLogLevelAttr(String)) from which new level will be taken (other attributes also come into play in this case).

createLogger

public Logger createLogger(String connTypeName,
                           String connName)
Create logger for connector, which also means creating an appender for it which uses the connector's connName. Note that filenames are written using the exact connName provided (which may include special and multi-byte characters in the expectation that setting of LANG / LOCALE / font etc has been done correctly before the JCS is started) except that each non-alphanumeric character is replaced by an underscore. Due to this sanitization, in very rare cases logging file names may clash, in which case the logger written at the start of each line will have to be used to determine which log messages relate to which connector.

Note that the logger and appender are created by cloning the log4j.properties file and getting the NLOG4J library to create the actual objects (this was the only way to get it to work as each appender must have its own Layout instance or log messages are corrupted).

Specified by:
createLogger in interface ConnectorFactory

destroyLogger

public void destroyLogger(Logger connLog)

proxyAttributeStyleOpProcessorProxy

public void proxyAttributeStyleOpProcessorProxy(MetaConnector conn,
                                                AttributeStyleOpProcessor proc)
Queue any required proxy handler classes to conn's proxy chain to be interposed when the chain is activated.


proxyMethodStyleOpProcessor

public MethodStyleOpProcessor proxyMethodStyleOpProcessor(MetaConnector conn,
                                                          MethodStyleOpProcessor proc)
Return a proxy for one of the given connector's processors if:
  1. The connector's implementation bundle has a resilientProxyClass class defined AND
  2. The connector's configuration has resilientDelay > 0

Parameters:
conn - Connector, which might be proxied.
Returns:
Proxy for connector's MethodStyleOpProcessor if conditions described above are true, otherwise null.

proxyScriptStyleOpProcessor

public ScriptStyleOpProcessor proxyScriptStyleOpProcessor(MetaConnector conn,
                                                          ScriptStyleOpProcessor proc)
Return a proxy for one of the given connector's processors if:
  1. The connector's implementation bundle has a resilientProxyClass class defined AND
  2. The connector's configuration has resilientDelay > 0

Parameters:
conn - Connector, which might be proxied.
Returns:
Proxy for connector's MethodStyleOpProcessor if conditions described above are true, otherwise null.

createConnector

public Connector createConnector(ConnectorType connType,
                                 String namingAttr,
                                 String name,
                                 LdapDN suffix,
                                 Attributes attrs)
                          throws LdapConfigurationException
Create a connector based on parent type's metadata, the provided attrs and the default connector config stored on parent connType. This includes optionally interposing proxies and registering a cache manager, if required,

Specified by:
createConnector in interface ConnectorFactory
Parameters:
connType - Parent connector type grouping all connector instances implemented by a common custom option, or sharing a common dynamic configuration.
namingAttr - Passed in so a sanity check can be done against the implementation bundle on the original DN.
name - Name specified for connector by end-user.
attrs - Attributes for this connector.
Returns:
New connector which has been registered with its parent type.
Throws:
LdapConfigurationException

convertMetadata

@Nullable
public DataModel convertMetadata(@NotNull
                                          String connTypeName,
                                          @NotNull
                                          Attributes attrs)
                          throws NamingException
Throws:
NamingException

convertMetadata

@NotNull
protected DataModel convertMetadata(@NotNull
                                            String connTypeName,
                                            @NotNull
                                            String metaData,
                                            @Nullable
                                            String customMetaData)
                             throws LdapConfigurationException
Throws:
LdapConfigurationException

convertOpBindingMetadata

public Opbindings convertOpBindingMetadata(String connTypeName,
                                           String metadata)
                                    throws javax.xml.bind.JAXBException
Convert XML opbindings containing at least one of method-style and script-style bindings for operations.

Parameters:
connTypeName - Target connectorType name
metadata - XML text to be converted.
Returns:
Java bindings matching XML metadata.
Throws:
javax.xml.bind.JAXBException

isAllowMetadataModifyGlobally

public boolean isAllowMetadataModifyGlobally()

setAllowMetadataModifyGlobally

public void setAllowMetadataModifyGlobally(boolean allowMetadataModifyGlobally)

getImplBundleStaticOpbindingsMetadata

protected void getImplBundleStaticOpbindingsMetadata(ImplBundle implBundle,
                                                     Attributes attrs)

isDynamicConnectorType

public static boolean isDynamicConnectorType(Attributes attrs)
Method to check if a connector type is dynamic based on it's attributes alone.

Note: Static connectors that use a DYN schema appear dynamic based on attributes alone.

Parameters:
attrs - the attributes of the connector type.
Returns:
true if dynamic.

isDynamicConnectorType

public boolean isDynamicConnectorType(LdapDN connTypeDn)
Method to check if a connector type is dynamic based on it's DN.

This method uses information from the connector type ImplBundle.

Specified by:
isDynamicConnectorType in interface ConnectorFactory
Parameters:
connTypeDn - the connector type DN.
Returns:
true if dynamic.


Created 2011-07-14 13:27 EST