Initial commit from SVN.

This commit is contained in:
wcrisman
2014-05-30 10:31:51 -07:00
commit b45e56b890
1968 changed files with 370949 additions and 0 deletions

View File

@@ -0,0 +1,293 @@
/*
* Copyright (c) 2005,2009 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.foundation.application;
import java.io.File;
import java.io.InputStream;
import com.common.thread.ThreadService;
import com.common.util.*;
import com.common.debug.*;
import com.foundation.controller.DecorationManager;
import com.foundation.event.EventNotifier;
import com.foundation.metadata.MetadataService;
import com.foundation.transaction.TransactionService;
import com.foundation.view.resource.*;
public abstract class Application extends com.foundation.controller.Controller implements IApplication {
public static final File DEFAULT_RESOURCES_PATH = new File("./");
public static final String PACKAGE_RESOURCES_FILE_NAME = "packages.res";
/** The service that provides metadata relating to the models, controllers, and the mappings between the models/controllers and the repositories. */
private MetadataService metadataService = null;
/** The transaction service provides transactional interaction with the repositories defined in the application metadata. */
private TransactionService transactionService = null;
/** The service that provides resources accessable by the application at runtime. */
private AbstractResourceService resourceService;
/** Tracks whether the application is in the process of shutting down. */
private boolean isShuttingDown = false;
/** Tracks whether the application has shutdown. */
private boolean isShutdown = false;
/**
* Application constructor.
*/
protected Application() {
super();
}//Application()//
/**
* Gets the application object that this object is running under. The application object provides the object various services that it will need.
* @return The application reference for the application this object is running under.
*/
public IApplication getApplication() {
return this;
}//getApplication()//
/* (non-Javadoc)
* @see com.foundation.application.IApplication#getDefaultRepositoryIdentifier()
*/
public abstract Object getDefaultRepositoryIdentifier();
/* (non-Javadoc)
* @see com.foundation.application.IApplication#getDefaultRepositoryIdentifier(java.lang.Class)
*/
public Object getDefaultRepositoryIdentifier(Class type) {
return getDefaultRepositoryIdentifier();
}//getDefaultRepositoryIdentifier()//
/* (non-Javadoc)
* @see com.foundation.application.IApplication#getDatabaseUrl(java.lang.Object)
*/
public String getDatabaseUrl(Object id) {
return null;
}//getDatabaseUrl()//
/* (non-Javadoc)
* @see com.foundation.application.IApplication#getDatabaseUser(java.lang.Object)
*/
public String getDatabaseUser(Object id) {
return null;
}//getDatabaseUser()//
/* (non-Javadoc)
* @see com.foundation.application.IApplication#getDatabasePassword(java.lang.Object)
*/
public String getDatabasePassword(Object id) {
return null;
}//getDatabasePassword()//
/**
* Gets the location of the metadata file for this application.
* @return The java.lang.String, java.io.File, or java.net.URL location for the metadata file. If a string or file then a relative path may be specified.
*/
public abstract Object getMetadataLocation();
/**
* Gets the contents of the metadata file. This is an alternative to the getMetadataLocation() method in the event that the application cannot provide the metadata as a file reference.
* <p>Note: This does not currently support binary metadata.</p>
* @return The contents of the application's metadata file, or null if no metadata is provided.
*/
public InputStream getMetadataContents() {
return null;
}//getMetadataContents()//
/* (non-Javadoc)
* @see com.foundation.application.IApplication#getMetadataService()
*/
public MetadataService getMetadataService() {
return metadataService;
}//getMetadataService()//
/* (non-Javadoc)
* @see com.foundation.application.IApplication#getResourceService()
*/
public AbstractResourceService getResourceService() {
return resourceService;
}//getResourceService()//
/**
* Gets the path for the resources file that contains the package and code metadata.
* @return The path to the package and code metadata file.
*/
public File getResourcesPath() {
return DEFAULT_RESOURCES_PATH;
}//getResourcePath()//
/* (non-Javadoc)
* @see com.foundation.common.Entity#getTransactionService()
*/
public TransactionService getTransactionService() {
return transactionService;
}//getTransactionService()//
/**
* This method performs the actual shutdown.
* <p>Subclasses should override this method to add funcationality. They <b>must</b> call their super class' internalShutdown method when overriding the super class.
*/
protected void internalShutdown() {
if(transactionService != null) {
transactionService.shutdown();
}//if//
EventNotifier.getSingleton().stop();
ThreadService.shutdown();
}//internalShutdown()//
/**
* Loads the property file into a new hash map of key value pairs.
* @param propertyFilePath The absolute or relative path to the property file.
* @return The map of key value pairs found in the property file.
*/
protected LiteHashMap loadProperties(File propertyFile) {
LiteHashMap map = null;
if(propertyFile.exists()) {
try {
java.io.BufferedReader bufferedReader = new java.io.BufferedReader(new java.io.FileReader(propertyFile));
map = new LiteHashMap(10);
while(bufferedReader.ready()) {
String line = bufferedReader.readLine();
int equalsIndex = line.indexOf('=');
if(equalsIndex >= 0) {
String key = line.substring(0, equalsIndex).trim();
String value = line.substring(equalsIndex + 1).trim();
map.put(key, value);
}//if//
else {
Debug.log("Error: Invalid property file format found while loading the " + propertyFile.getAbsolutePath() + " property file.");
throw new RuntimeException("Property file format exception.");
}//else//
}//while//
}//try//
catch(java.io.FileNotFoundException e) {
Debug.log(e);
}//catch//
catch(java.io.IOException e) {
Debug.log(e);
}//catch//
}//if//
else {
Debug.log("Error: The specified property file does not exist: " + propertyFile.getAbsolutePath());
throw new RuntimeException("Property file does not exist.");
}//else//
return map;
}//setupMetadataService()//
/**
* Loads the property file into a new hash map of key value pairs.
* @param propertyFilePath The absolute or relative path to the property file.
* @return The map of key value pairs found in the property file.
*/
protected LiteHashMap loadProperties(String propertyFilePath) {
LiteHashMap map = null;
if((propertyFilePath != null) && ((propertyFilePath = propertyFilePath.trim()).length() != 0)) {
map = loadProperties(new File(propertyFilePath));
}//if//
else {
Debug.log("Error: Unable to load a property file using a null or empty path string.");
throw new RuntimeException("Null or empty path string is invalid. Unable to load the property file.");
}//else//
return map;
}//setupMetadataService()//
/**
* Initializes the metadata service for this application.
*/
protected boolean setupMetadataService() {
boolean retVal = true;
metadataService = MetadataService.getSingleton();
try {
metadataService.loadMetadata(this);
}//try//
catch(Throwable e) {
Debug.log(e);
retVal = false;
}//catch//
return retVal;
}//setupMetadataService()//
/**
* Initializes the transaction service for this application.
*/
protected void setupTransactionService() {
transactionService = new TransactionService();
}//setupTransactionService()//
/**
* Initializes the resource service for this application.
*/
protected void setupResourceService() {
try {
//Debug.log("Setting up resource service.");
ResourceService service = new ResourceService(getResourcesPath(), null);
//Debug.log("Created resource service: " + service);
setResourceService(service);
getResourceService().setCurrentCategories(new String[] {});
}//try//
catch(Throwable e) {
Debug.log(e);
}//catch//
}//setupResourceService()//
/**
* Sets the resource service for this application.
* <p>Warning: The service may only be set once. All all calls will be ignored.</p>
* @param resourceService The application's resource service.
*/
protected void setResourceService(AbstractResourceService resourceService) {
if(this.resourceService == null) {
//Debug.log("Setting resource service: " + resourceService);
this.resourceService = resourceService;
}//if//
}//setResourceService()//
/**
* Shuts down the application.
* Applications should provide customized shutdown code by overriding the internalShutdown method.
* @see #internalShutdown()
*/
public final synchronized void shutdown() {
isShuttingDown = true;
internalShutdown();
isShutdown = true;
isShuttingDown = false;
notifyAll();
}//shutdown()//
/**
* Determines whether the application is in the process of being shutdown (false if already shutdown or not shutting down).
* @return Whether the application's shutdown method is running.
*/
public synchronized boolean isShuttingDown() {
return isShuttingDown;
}//isShuttingDown()//
/**
* Determines whether the application has been shutdown.
* @return Whether the application's shutdown method has completed.
*/
public synchronized boolean isShutdown() {
return isShutdown;
}//isShutdown()//
/**
* Pauses the thread until the application shuts down.
* <p>This method was added to support the mac osx which at the time of this writing doesn't like to have the main thread exit for any reason before the application is finished. Exiting the main thread on the mac causes the whole process to terminate immediately.</p>
*/
public final synchronized void waitForShutdown() {
while(!isShutdown) {
try {
wait();
}//try//
catch(Throwable e) {
Debug.handle(e);
}//catch//
}//while//
}//waitForShutdown()//
/**
* Starts the application by initializing the application services and then initializing the application.
* <p>TODO: Should provide some default startup code.</p>
*/
protected synchronized void startup() {
isShutdown = false;
}//startup()//
/* (non-Javadoc)
* @see com.foundation.controller.IController#getDecorationManager()
*/
public final DecorationManager getDecorationManager() {
//Never used.//
return null;
}//getDecorationManager()//
}//Application//

View File

@@ -0,0 +1,8 @@
package com.foundation.application;
/**
* The interface implemented by the user of an Amaranthine Defic Algorithm server. Allows the server to send updates to distributed logical objects.
*/
public interface IAdaClient {
}//IAdaClient//

View File

@@ -0,0 +1,24 @@
package com.foundation.application;
/**
* The interface into the Amaranthine Defic Algorithm service that manages distributed locks and distribution of logical object change sets.
*/
public interface IAdaService {
public void register(IAdaClient client);
//TODO: Some way to register/unregister for notifications for certain types of logical object updates.
/**
*
* Never blocks? Returns an update ID so the locker knows to ensure that the latest updates are applied before alterations are made?
* @param type
* @param key
*/
public void lockLogicalObject(String type, Object key);
/**
*
* Blocks? How are failures handled?
* @param type
* @param key
* @param changeSet
*/
public void applyLogicalObjectChanges(String type, Object key, Object changeSet);
}//IAdaService//

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2005,2009 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.foundation.application;
import com.foundation.metadata.MetadataService;
import com.foundation.transaction.TransactionService;
import com.foundation.view.resource.AbstractResourceService;
public interface IApplication extends com.foundation.controller.IController {
/**
* Gets the repository identifier for the application's primary (default) repository connection.
* @return The repository identifier the application objects will use by default.
*/
public Object getDefaultRepositoryIdentifier();
/**
* Gets the repository identifier for the application's primary (default) repository connection for the given class.
* @param type The class whose default repository identifier is desired.
* @return The repository identifier the application objects of the given type will use by default.
*/
public Object getDefaultRepositoryIdentifier(Class type);
/**
* Gets the metadata service for this application.
* @return The metadata service object that will service this application's metadata needs.
*/
public MetadataService getMetadataService();
/**
* Gets the resource service for this application.
* @return The resource service object that will service this application's resource needs.
*/
public AbstractResourceService getResourceService();
/**
* Gets the transaction service for this application.
* @return The transaction service object that will service this application's transactional needs.
*/
public TransactionService getTransactionService();
/**
* Gets the URL to access the given database.
* @param id The database/repository identifier.
* @return The URL for the database, or null if the URL in the metadata should be used.
*/
public String getDatabaseUrl(Object id);
/**
* Gets the name of the user to connect to the database as.
* @param id The database/repository identifier.
* @return The database user name to use when connecting.
*/
public String getDatabaseUser(Object id);
/**
* Gets the password used to connect to the database.
* @param id The database/repository identifier.
* @return The database user password to use when connecting.
*/
public String getDatabasePassword(Object id);
}//IApplication//