use of alma.ACSErrTypeCommon.wrappers.AcsJNullPointerEx in project ACS by ACS-Community.
the class ManagerImpl method getCollocatedComponent.
/**
* @see com.cosylab.acs.maci.Manager#getCollocatedComponent(int, com.cosylab.acs.maci.ComponentSpec, boolean, URI)
*/
/// @todo MF not supported
public ComponentInfo getCollocatedComponent(int id, ComponentSpec componentSpec, boolean markAsDefault, URI targetComponentURI) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx, AcsJIncompleteComponentSpecEx, AcsJInvalidComponentSpecEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
try {
// check if null
if (componentSpec == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec");
throw ex;
}
// check componentSpec components are null
if (componentSpec.getName() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Name");
throw ex;
}
if (componentSpec.getType() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Type");
throw ex;
}
if (componentSpec.getCode() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Code");
throw ex;
}
if (componentSpec.getContainer() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Container");
throw ex;
}
// check for empty componentSpec.name
if (componentSpec.getName().length() == 0) {
AcsJBadParameterEx ex = new AcsJBadParameterEx();
ex.setParameter("componentSpec.Name");
ex.setParameterValue("EMPTY");
ex.setReason("Non empty Component Name expected");
throw ex;
}
// check if null
if (targetComponentURI == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("targetComponentURI");
throw ex;
}
if (!componentSpec.getContainer().equals(ComponentSpec.COMPSPEC_ANY)) {
AcsJBadParameterEx ex = new AcsJBadParameterEx();
ex.setParameter("componentSpec.Container");
ex.setParameterValue(componentSpec.getContainer());
ex.setReason("COMPSPEC_ANY expected");
throw ex;
}
} catch (AcsJNullPointerEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
} catch (AcsJBadParameterEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
}
// check handle and NONE permissions
// Throws AcsJNoPermissionEx that is let flying up
securityCheck(id, AccessRights.NONE);
/****************************************************************/
/// @todo temporary quick implementation (does not look in the CDB if component is not activated)
String name = extractName(targetComponentURI);
int h = 0;
ComponentInfo targetComponentInfo = null;
componentsLock.lock();
try {
h = components.first();
while (h != 0) {
ComponentInfo componentInfo = (ComponentInfo) components.get(h);
if (componentInfo.getName().equals(name)) {
targetComponentInfo = componentInfo;
break;
}
h = components.next(h);
}
} finally {
componentsLock.unlock();
}
// if not found, check the CDB
if (targetComponentInfo == null) {
DAOProxy componentsDAO = getComponentsDAOProxy();
if (componentsDAO != null) {
// read container name
String containerName = readStringCharacteristics(componentsDAO, name + "/Container", true);
if (containerName != null)
componentSpec.setContainer(containerName);
}
} else
componentSpec.setContainer(targetComponentInfo.getContainerName());
// failed to detemine a target container
if (componentSpec.getContainer().equals(ComponentSpec.COMPSPEC_ANY)) {
AcsJIncompleteComponentSpecEx ex = new AcsJIncompleteComponentSpecEx();
ex.setCURL(name);
ex.setContainerName(componentSpec.getContainer());
throw ex;
}
// request for component
// same exceptions are let flying up.
ComponentInfo componentInfo = null;
try {
componentInfo = internalRequestDynamicComponent(id, componentSpec);
} catch (AcsJSyncLockFailedEx e) {
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(name);
ex.setReason("Failed to get Synchronisation lock");
throw ex;
}
// update default components table
if (componentInfo != null && markAsDefault) {
synchronized (defaultComponents) {
// !!! ACID 3
executeCommand(new DefaultComponentCommandPut(componentInfo.getType(), componentInfo));
//defaultComponents.put(componentInfo.getType(), componentInfo.getName());
}
logger.log(Level.INFO, "'" + componentInfo.getName() + "' has been marked as a default component of type '" + componentInfo.getType() + "'.");
}
if (componentInfo == null) {
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(name);
throw ex;
}
return componentInfo;
}
use of alma.ACSErrTypeCommon.wrappers.AcsJNullPointerEx in project ACS by ACS-Community.
the class ManagerImpl method getDynamicComponent.
/**
* @see com.cosylab.acs.maci.Manager#getDynamicComponent(int, com.cosylab.acs.maci.ComponentSpec, boolean)
*/
// TODO MF not supported
public ComponentInfo getDynamicComponent(int id, ComponentSpec componentSpec, boolean markAsDefault) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx, AcsJIncompleteComponentSpecEx, AcsJInvalidComponentSpecEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
try {
// check if null
if (componentSpec == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec");
throw ex;
}
// check componentSpec components are null
if (componentSpec.getName() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Name");
throw ex;
}
if (componentSpec.getType() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Type");
throw ex;
}
if (componentSpec.getCode() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Code");
throw ex;
}
if (componentSpec.getContainer() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Container");
throw ex;
}
// check for empty componentSpec.name
if (componentSpec.getName().length() == 0) {
AcsJBadParameterEx ex = new AcsJBadParameterEx();
ex.setParameter("componentSpec.Name");
ex.setParameterValue("EMPTY");
ex.setReason("Non empty Component Name expected");
throw ex;
}
} catch (AcsJNullPointerEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
} catch (AcsJBadParameterEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
}
// check handle and NONE permissions
// Throws AcsJNoPermissionEx that is let flying up
securityCheck(id, AccessRights.NONE);
/****************************************************************/
// Same exceptions fly up
ComponentInfo componentInfo = null;
try {
componentInfo = internalRequestDynamicComponent(id, componentSpec);
} catch (AcsJSyncLockFailedEx e) {
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(componentSpec.getName());
ex.setReason("Failed to get Synchronisation lock");
throw ex;
}
// update default components table
if (componentInfo != null && markAsDefault) {
synchronized (defaultComponents) {
// !!! ACID 3
executeCommand(new DefaultComponentCommandPut(componentInfo.getType(), componentInfo));
//defaultComponents.put(componentInfo.getType(), componentInfo.getName());
}
logger.log(Level.INFO, "'" + componentInfo.getName() + "' has been marked as a default component of type '" + componentInfo.getType() + "'.");
}
if (componentInfo == null) {
/**
* @todo Is it OK to get here? Always?
* This is a place where we have to check carefully.
*/
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(componentSpec.getName());
throw ex;
}
return componentInfo;
}
use of alma.ACSErrTypeCommon.wrappers.AcsJNullPointerEx in project ACS by ACS-Community.
the class ManagerImpl method getComponent.
/**
* @see #getComponent
*/
private Component getComponent(int id, URI curl, boolean activate, StatusHolder status, boolean allowServices) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx {
AcsJCannotGetComponentEx ex2 = null;
// extract name
String name = extractName(curl);
// check if null
try {
checkCURL(curl);
} catch (AcsJBadParameterEx e) {
e.setParameter("curl");
ex2 = new AcsJCannotGetComponentEx(e);
ex2.setCURL(name);
throw ex2;
}
if (status == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("status");
ex2 = new AcsJCannotGetComponentEx(ex);
ex2.setCURL(name);
throw ex2;
}
/****************************************************************/
// log info
String requestorName = null;
if (id != 0) {
requestorName = getRequestorName(id);
logger.log(Level.INFO, "'" + requestorName + "' requested component '" + curl + "'.");
} else
logger.log(Level.INFO, "Request for component '" + curl + "' issued.");
// no login required for predefined objects (services)
Component component = null;
// "Manager" is a special service Component
if (allowServices && name.equals("Manager")) {
if (managerComponentReference != null)
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
else
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
component = new ServiceComponent(managerComponentReference);
} else // "NameService" is also a special service Component
if (allowServices && name.equals("NameService")) {
if (remoteDirectoryComponentReference != null)
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
else
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
component = new ServiceComponent(remoteDirectoryComponentReference);
} else if (allowServices && !name.startsWith(CURL_URI_SCHEMA) && isServiceComponent(name)) {
Object obj = lookup(name, null);
// set status
if (obj != null)
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
else
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
component = new ServiceComponent(obj);
} else {
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
try {
component = internalRequestComponent(id, curl, status, activate);
} catch (Throwable ce) {
ex2 = new AcsJCannotGetComponentEx(ce);
}
}
// log info
if (component != null && component.getObject() != null) {
if (requestorName != null)
logger.log(Level.INFO, "Component '" + curl + "' provided to '" + requestorName + "'.");
else
logger.log(Level.INFO, "Component '" + curl + "' provided.");
} else if (ex2 == null && !activate && status.getStatus() == ComponentStatus.COMPONENT_NOT_ACTIVATED) {
if (requestorName != null)
logger.log(Level.INFO, "Request from '" + requestorName + "' for component '" + curl + "' completed sucessfully, but component not activated.");
else
logger.log(Level.INFO, "Request for component '" + curl + "' completed sucessfully, but component not activated.");
} else /**
* @todo GCH 2006.09.25
* This last case should never happen, because
* there should be and exception thrown instead.
*/
{
if (ex2 == null)
ex2 = new AcsJCannotGetComponentEx();
// it's clients responibility to handle the exception
if (requestorName != null) {
if (logger.isLoggable(Level.FINE))
logger.log(Level.WARNING, "Failed to provide component '" + curl + "' to '" + requestorName + "'.", ex2);
else
logger.log(Level.WARNING, "Failed to provide component '" + curl + "' to '" + requestorName + "'.");
} else {
if (logger.isLoggable(Level.FINE))
logger.log(Level.WARNING, "Failed to provide component '" + curl + "'.", ex2);
else
logger.log(Level.FINE, "Failed to provide component '" + curl + "'.");
}
}
if (ex2 != null) {
ex2.setCURL(name);
throw ex2;
}
return component;
}
Aggregations