use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class ActivityDef method getBuiltInCollectionResource.
protected DescriptionObject[] getBuiltInCollectionResource(BuiltInCollections collection) throws ObjectNotFoundException, InvalidDataException {
ArrayList<DescriptionObject> retArr = new ArrayList<DescriptionObject>();
if (itemPath == null) {
Logger.warning("ActivityDef.getBuiltInCollectionResource(actName:" + getName() + ", collection:" + collection + ") - itemPath is null! CANNOT resolve data in ClusterStorage");
return retArr.toArray(new DescriptionObject[0]);
// throw new InvalidDataException("actName:"+getName()+", collection:"+collection+" - itemPath is null! CANNOT resolve data in ClusterStorage");
}
Logger.msg(5, "ActivityDef.getBuiltInCollectionResource(actName:" + getName() + ") - Loading from collection:" + collection);
Dependency resColl;
try {
String clusterPath = ClusterType.COLLECTION + "/" + collection + "/" + ((mVersion == null || mVersion == -1) ? "last" : String.valueOf(mVersion));
String[] contents = Gateway.getStorage().getClusterContents(itemPath, clusterPath);
if (contents != null && contents.length > 0)
resColl = (Dependency) Gateway.getStorage().get(itemPath, clusterPath, null);
else
return retArr.toArray(new DescriptionObject[retArr.size()]);
} catch (PersistencyException e) {
Logger.error(e);
throw new InvalidDataException("Error loading description collection " + collection);
}
for (DependencyMember resMem : resColl.getMembers().list) {
String resUUID = resMem.getChildUUID();
Integer resVer = deriveVersionNumber(resMem.getBuiltInProperty(VERSION));
if (resVer == null) {
throw new InvalidDataException("Version is null for Item:" + itemPath + ", Collection:" + collection + ", DependencyMember:" + resUUID);
}
if (collection != ACTIVITY && retArr.size() > 0) {
throw new InvalidDataException("actName:" + getName() + " has an invalid dependency:" + collection);
}
switch(collection) {
case SCHEMA:
retArr.add(LocalObjectLoader.getSchema(resUUID, resVer));
break;
case SCRIPT:
retArr.add(LocalObjectLoader.getScript(resUUID, resVer));
break;
case QUERY:
retArr.add(LocalObjectLoader.getQuery(resUUID, resVer));
break;
case STATE_MACHINE:
retArr.add(LocalObjectLoader.getStateMachine(resUUID, resVer));
break;
case ACTIVITY:
retArr.add(LocalObjectLoader.getActDef(resUUID, resVer));
break;
default:
throw new InvalidDataException("");
}
}
return retArr.toArray(new DescriptionObject[retArr.size()]);
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class ActivityDef method export.
@Override
public void export(Writer imports, File dir) throws InvalidDataException, ObjectNotFoundException, IOException {
String actXML;
String tc = ELEM_ACT_DESC_RESOURCE.getTypeCode();
exportCollections(imports, dir);
try {
actXML = Gateway.getMarshaller().marshall(this);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Couldn't marshall activity def " + getActName());
}
FileStringUtility.string2File(new File(new File(dir, tc), getActName() + (getVersion() == null ? "" : "_" + getVersion()) + ".xml"), actXML);
if (imports != null) {
imports.write("<Activity " + getExportAttributes(tc) + ">" + getExportCollections() + "</Activity>\n");
}
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Bootstrap method verifyPathAndModuleProperty.
/**
* Verify module property and location
*
* @param ns
* @param itemType
* @param itemName
* @param itemPath
* @param modDomPath
* @param path
* @return the ItemProxy either create or initialised for existing
* @throws Exception
*/
private static ItemProxy verifyPathAndModuleProperty(String ns, String itemType, String itemName, ItemPath itemPath, DomainPath modDomPath, DomainPath path) throws Exception {
LookupManager lookupManager = Gateway.getLookupManager();
ItemProxy thisProxy = Gateway.getProxyManager().getProxy(path);
if (itemPath != null && !path.getItemPath().equals(itemPath)) {
Logger.warning("Resource " + itemType + "/" + itemName + " should have path " + itemPath + " but was found with path " + path.getItemPath());
itemPath = path.getItemPath();
}
if (itemPath == null)
itemPath = path.getItemPath();
String moduleName = (ns == null ? "kernel" : ns);
String itemModule;
try {
itemModule = thisProxy.getProperty("Module");
if (itemModule != null && !itemModule.equals("") && !itemModule.equals("null") && !moduleName.equals(itemModule)) {
String error = "Module clash! Resource '" + itemName + "' included in module " + moduleName + " but is assigned to '" + itemModule + "'.";
Logger.error(error);
throw new InvalidDataException(error);
}
} catch (ObjectNotFoundException ex) {
itemModule = "";
}
if (!modDomPath.equals(path)) {
// move item to module subtree
Logger.msg("Module item " + itemName + " found with path " + path.toString() + ". Moving to " + modDomPath.toString());
modDomPath.setItemPath(itemPath);
if (!modDomPath.exists())
lookupManager.add(modDomPath);
lookupManager.delete(path);
}
return thisProxy;
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Gateway method connect.
/**
* Log in with the given username and password, and initialises the {@link Lookup}, {@link TransactionManager} and {@link ProxyManager}.
* It shall be uses in client processes only.
*
* @param agentName - username
* @param agentPassword - password
* @return an AgentProxy on the requested user
*
* @throws InvalidDataException - bad params
* @throws PersistencyException - error starting storages
* @throws ObjectNotFoundException - object not found
*/
public static AgentProxy connect(String agentName, String agentPassword, String resource) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
Authenticator auth = getAuthenticator();
if (!auth.authenticate(agentName, agentPassword, resource))
throw new InvalidDataException("Login failed");
try {
if (mLookup != null)
mLookup.close();
mLookup = (Lookup) mC2KProps.getInstance("Lookup");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
Logger.error(ex);
throw new InvalidDataException("Lookup " + mC2KProps.getString("Lookup") + " could not be instantiated");
}
mLookup.open(auth);
mStorage = new TransactionManager(auth);
mProxyManager = new ProxyManager();
// find agent proxy
AgentPath agentPath = mLookup.getAgentPath(agentName);
AgentProxy agent = (AgentProxy) mProxyManager.getProxy(agentPath);
agent.setAuthObj(auth);
ScriptConsole.setUser(agent);
// Run module startup scripts. Server does this during bootstrap
mModules.setUser(agent);
mModules.runScripts("startup");
Logger.msg("Gateway.connect(agent) - DONE.");
return agent;
}
use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.
the class Gateway method startServer.
/**
* Makes this process capable of creating and managing server entities. Runs the
* Creates the LookupManager, ProxyServer, initialises the ORB and CORBAServer
*/
public static void startServer() throws InvalidDataException, CannotManageException {
try {
// check top level directory contexts
if (mLookup instanceof LookupManager) {
mLookupManager = (LookupManager) mLookup;
mLookupManager.initializeDirectory();
} else {
throw new CannotManageException("Lookup implementation is not a LookupManager. Cannot write to directory");
}
// start entity proxy server
mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name"));
// Init ORB - set various config
String serverName = mC2KProps.getProperty("ItemServer.name");
// TODO: externalize this (or replace corba completely)
if (serverName != null)
mC2KProps.put("com.sun.CORBA.ORBServerHost", serverName);
String serverPort = mC2KProps.getProperty("ItemServer.iiop", "1500");
mC2KProps.put("com.sun.CORBA.ORBServerPort", serverPort);
mC2KProps.put("com.sun.CORBA.POA.ORBServerId", "1");
mC2KProps.put("com.sun.CORBA.POA.ORBPersistentServerPort", serverPort);
// need to force UTF-8 in the Sun ORB
mC2KProps.put("com.sun.CORBA.codeset.charsets", "0x05010001, 0x00010109");
mC2KProps.put("com.sun.CORBA.codeset.wcharsets", "0x00010109, 0x05010001");
// Standard initialisation of the ORB
orbDestroyed = false;
mORB = org.omg.CORBA.ORB.init(new String[0], mC2KProps);
Logger.msg("Gateway.startServer() - ORB initialised. ORB class:'" + mORB.getClass().getName() + "'");
// start corba server components
mCorbaServer = new CorbaServer();
Logger.msg("Gateway.startServer() - Server '" + serverName + "' STARTED.");
} catch (Exception ex) {
Logger.error(ex);
Logger.die("Exception starting server components. Shutting down.");
}
}
Aggregations