Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…g.cgi?id=6987

Use of null instances of "provides" and "requires" were causing NPE
  • Loading branch information
pauloricardomg committed May 4, 2010
1 parent 555d15e commit 192577f
Showing 1 changed file with 82 additions and 71 deletions.
Expand Up @@ -30,7 +30,6 @@
import org.nimbustools.ctxbroker.ContextBrokerException;
import org.nimbustools.ctxbroker.generated.gt4_0.types.Node_Type;
import org.nimbustools.ctxbroker.generated.gt4_0.types.ContextualizationContext;
import org.nimbustools.ctxbroker.generated.gt4_0.types.MatchedRole_Type;
import org.nimbustools.ctxbroker.generated.gt4_0.description.*;
import org.nimbustools.ctxbroker.blackboard.*;
import org.globus.security.gridmap.GridMap;
Expand All @@ -40,7 +39,6 @@
import java.util.Calendar;
import java.util.List;
import java.util.ArrayList;
import java.util.Enumeration;

public class ContextBrokerResourceImpl implements ContextBrokerResource {

Expand Down Expand Up @@ -395,18 +393,12 @@ public void addWorkspace(Integer workspaceID,
"contextualization resource. workspaceID #" + workspaceID);
}

boolean allIdentitiesRequired;
final Requires_TypeIdentity[] givenID = requires.getIdentity();
if (givenID == null || givenID.length == 0) {

logger.trace("#" + workspaceID + " does not require all " +
"identities, no identity element in given requires " +
"section");
boolean allIdentitiesRequired = false;

allIdentitiesRequired = false;

} else {
if(requires != null){
final Requires_TypeIdentity[] givenID = requires.getIdentity();

if(givenID != null && givenID.length > 0){
// next two exceptions are for forwards compatibility where it
// may be possible to specify specific identities required
// (without going through role finding which will always place
Expand Down Expand Up @@ -435,7 +427,14 @@ public void addWorkspace(Integer workspaceID,
}

allIdentitiesRequired = true;
}
}
}

if(!allIdentitiesRequired){
logger.trace("#" + workspaceID + " does not require all " +
"identities, no identity element in given requires " +
"section");
}

this.getBlackboard().addWorkspace(
workspaceID,
Expand All @@ -450,75 +449,87 @@ public void addWorkspace(Integer workspaceID,
private ProvidedRoleDescription[] getProvidedRoleDescriptions(Integer workspaceID,
Provides_Type provides) {

Provides_TypeRole[] roles = provides.getRole();
if (roles == null || roles.length == 0) {
logger.trace("Provides section for #" + workspaceID + " has " +
"identities but has no role-provides elements. " +
"Allowing, perhaps this is only to get identity " +
"into contextualization context's all-identity " +
"list.");
return null;
}
if(provides != null){
Provides_TypeRole[] roles = provides.getRole();

ProvidedRoleDescription[] roleDescs =
new ProvidedRoleDescription[roles.length];

for (int i = 0; i < roles.length; i++) {
Provides_TypeRole role = roles[i];
roleDescs[i] = new ProvidedRoleDescription(
role.get_value(),
role.get_interface());
}
return roleDescs;
if (roles != null && roles.length > 0){
ProvidedRoleDescription[] roleDescs = new ProvidedRoleDescription[roles.length];

for (int i = 0; i < roles.length; i++) {
Provides_TypeRole role = roles[i];
roleDescs[i] = new ProvidedRoleDescription(role.get_value(), role.get_interface());
}

return roleDescs;
}
}

//If there are no provided roles specified

if (logger.isTraceEnabled()) {
logger.trace("Provides section for #" + workspaceID + " has " +
"identities but has no role-provides elements. " +
"Allowing, perhaps this is only to get identity " +
"into contextualization context's all-identity " +
"list.");
}

return null;
}

private RequiredRole[] getRequiredRoles(Integer workspaceID, Requires_Type requires)
throws ContextBrokerException {
final RequiredRole[] roles;
final Requires_TypeRole[] requiredRoles = requires.getRole();
if (requiredRoles != null && requiredRoles.length > 0) {
roles = new RequiredRole[requiredRoles.length];

for (int i = 0; i < requiredRoles.length; i++) {
Requires_TypeRole requiredRole = requiredRoles[i];
roles[i] = getRequiredRole(requiredRole);
}

} else {
roles = null;
if (logger.isTraceEnabled()) {
logger.trace("Requires section for #" + workspaceID + " has " +
"no role-required elements." +
" Allowing, perhaps the only thing required by " +
"this node is the contextualization context's " +
"all-identity list and/or just data elements.");
}
}
return roles;
if(requires != null){
final RequiredRole[] roles;
final Requires_TypeRole[] requiredRoles = requires.getRole();
if (requiredRoles != null && requiredRoles.length > 0) {
roles = new RequiredRole[requiredRoles.length];

for (int i = 0; i < requiredRoles.length; i++) {
Requires_TypeRole requiredRole = requiredRoles[i];
roles[i] = getRequiredRole(requiredRole);
}
return roles;
}
}

//If there are no required roles specified

if (logger.isTraceEnabled()) {
logger.trace("Requires section for #" + workspaceID + " has " +
"no role-required elements." +
" Allowing, perhaps the only thing required by " +
"this node is the contextualization context's " +
"all-identity list and/or just data elements.");
}

return null;
}

private DataPair[] getDataPairs(Requires_Type requires)
throws ContextBrokerException {

final DataPair[] dataPairs;
final Requires_TypeData[] datas = requires.getData();
if (datas != null) {
dataPairs = new DataPair[datas.length];
for (int i = 0; i < datas.length; i++) {
Requires_TypeData data = datas[i];
final String dataName = data.getName();

if (dataName == null || dataName.trim().length() == 0) {
// does not happen when object is created via XML (which is usual)
throw new ContextBrokerException("Empty data element name (?)");
}
dataPairs[i] = new DataPair(dataName, data.get_value());
}

} else {
dataPairs = null;
}
return dataPairs;
if(requires != null){
final DataPair[] dataPairs;
final Requires_TypeData[] datas = requires.getData();
if (datas != null) {
dataPairs = new DataPair[datas.length];
for (int i = 0; i < datas.length; i++) {
Requires_TypeData data = datas[i];
final String dataName = data.getName();

if (dataName == null || dataName.trim().length() == 0) {
// does not happen when object is created via XML (which is usual)
throw new ContextBrokerException("Empty data element name (?)");
}
dataPairs[i] = new DataPair(dataName, data.get_value());
}
return dataPairs;
}
}

return null;
}

private RequiredRole getRequiredRole(Requires_TypeRole typeRole) throws ContextBrokerException {
Expand Down

0 comments on commit 192577f

Please sign in to comment.