Methods Summary |
---|
private static java.lang.String | getIdToCompare(Resource res)
final AttributeList attrs = res.getAttributes();
final String type = res.getType();
String id;
if (Resource.JDBC_CONNECTION_POOL.equals(type) ||
Resource.CONNECTOR_CONNECTION_POOL.equals(type)){
id = getNamedAttributeValue(attrs, CONNECTION_POOL_NAME); // this should come from refactored stuff TBD
}
else if (Resource.CONNECTOR_SECURITY_MAP.equals(type)) {
id = getNamedAttributeValue(attrs, SECURITY_MAP_NAME); // this should come from refactored stuff TBD
}
else if (Resource.RESOURCE_ADAPTER_CONFIG.equals(type)) {
id = getNamedAttributeValue(attrs, RESOURCE_ADAPTER_CONFIG_NAME); // this should come from refactored stuff TBD
}
else {
//it is OK to assume that this Resource will one of the *RESOURCEs?
id = getNamedAttributeValue(attrs, JNDI_NAME); // this should come from refactored stuff TBD
}
return ( id );
|
private static java.lang.String | getNamedAttributeValue(javax.management.AttributeList attrs, java.lang.String aName)
String value = null;
for (final Object obj : attrs) {
if (obj instanceof Attribute) {
final Attribute a = (Attribute) obj;
if (aName.equals(a.getName())) {
value = a.getValue().toString();
}
}
}
return ( value );
|
public static java.util.Set | getResourceConfigConflicts(java.util.Set resSet, com.sun.enterprise.config.ConfigContext cc)Checks if any of the Resource in the given set has a conflict with
resource definitions in the domain.xml. A conflict is defined
based on the type of the resource. For example, a JDBC Resource has "jndi-name"
that is the identifying key where as for a JDBC Connection Pool, it is
the "name" that must be unique.
final Set<Resource> conflicts = new HashSet<Resource>();
if (resSet != null) {
for (final Resource res : resSet) {
final String id = getIdToCompare(res);
final ConfigBean sb = ResourceHelper.findResource(cc, id);
if (sb != null) {
conflicts.add(res);
}
}
}
return ( conflicts );
|
public static void | getResourceConflictsWithDomainXML(java.util.List resList, com.sun.enterprise.config.ConfigContext configContext)Checks if any of the Resource in the given set has a conflict with
resource definitions in the domain.xml. A conflict is defined
based on the type of the resource. For example, a JDBC Resource has "jndi-name"
that is the identifying key where as for a JDBC Connection Pool, it is
the "name" that must be unique.
if (resList != null) {
Iterator<Resource> iterRes = resList.iterator();
StringBuffer conflictingResources = new StringBuffer();
while (iterRes.hasNext()) {
Resource res = iterRes.next();
final String id = getIdToCompare(res);
final ConfigBean sb = ResourceHelper.findResource(configContext, id);
if (sb != null) {
conflictingResources.append("\n");
String message = localStrings.getString(
"conflict.resource.with.domain.xml",
getIdToCompare(res));
conflictingResources.append(message);
_logger.warning(message);
if(_logger.isLoggable(Level.FINE))
logAttributes(res);
}
}
if(conflictingResources.toString().length() > 0){
throw new ResourceConflictException(conflictingResources.toString());
}
}
|
private static void | logAttributes(Resource res)
StringBuffer message = new StringBuffer();
Iterator<Attribute> attributeIter = res.getAttributes().iterator();
while(attributeIter.hasNext()){
Attribute attribute = attributeIter.next();
message.append(attribute.getName());
message.append("=");
message.append(attribute.getValue());
message.append(" ");
}
_logger.fine(localStrings.getString("resource.attributes",
message.toString()));
|
public static java.util.Set | resolveResourceDuplicatesConflictsWithinArchive(java.util.List sunResList)Resolves all duplicates and conflicts within an archive and returns a set
of resources that needs to be created for the archive being deployed. The
deployment backend would then use these set of resources to check for
conflicts with resources existing in domain.xml and then continue
with deployment.
All resource duplicates within an archive found are flagged with a
WARNING and only one resource is added in the final Resource
Set returned.
We currently do not handle any resource conflicts found within the archive
and the method throws an exception when this condition is detected.
boolean conflictExist = false;
StringBuffer conflictingResources = new StringBuffer();
Set<Resource> resourceSet = new HashSet<Resource>();
Iterator<SunResourcesXML> sunResourcesXMLIter = sunResList.iterator();
while(sunResourcesXMLIter.hasNext()){
//get list of resources from one sun-resources.xml file
SunResourcesXML sunResXML = sunResourcesXMLIter.next();
List<Resource> resources = sunResXML.getResourcesList();
Iterator<Resource> resourcesIter = resources.iterator();
//for each resource mentioned
while(resourcesIter.hasNext()){
Resource res = resourcesIter.next();
Iterator<Resource> resSetIter = resourceSet.iterator();
boolean addResource = true;
//check if a duplicate has already been added
while(resSetIter.hasNext()){
Resource existingRes = resSetIter.next();
if(existingRes.equals(res)){
//duplicate within an archive
addResource = false;
_logger.warning(localStrings.getString(
"duplicate.resource.sun.resource.xml",
getIdToCompare(res),
sunResXML.getXMLPath()));
break;
}
//check if another existing resource conflicts with the
//resource being added
if(existingRes.isAConflict(res)){
//conflict within an archive
addResource = false;
conflictingResources.append("\n");
String message = localStrings.getString(
"conflict.resource.sun.resource.xml",
getIdToCompare(res),
sunResXML.getXMLPath());
conflictingResources.append(message);
_logger.warning(message);
if(_logger.isLoggable(Level.FINE))
logAttributes(res);
}
}
if(addResource)
resourceSet.add(res);
}
}
if(conflictingResources.toString().length() > 0){
throw new ResourceConflictException(conflictingResources.toString());
}
return resourceSet;
|