further improvements to module loader, implemented sysadmin module install page

This commit is contained in:
Eric J. Bowersox
2003-06-19 08:43:17 +00:00
parent f1ceac134c
commit 0f0f4a4a4e
14 changed files with 603 additions and 23 deletions

View File

@@ -0,0 +1,42 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.dynamo.iface;
public interface DynamoLog
{
public void debug(Object message);
public void debug(Object message, Throwable t);
public void error(Object message);
public void error(Object message, Throwable t);
public void fatal(Object message);
public void fatal(Object message, Throwable t);
public void info(Object message);
public void info(Object message, Throwable t);
public void warn(Object message);
public void warn(Object message, Throwable t);
} // end interface DynamoLog

View File

@@ -26,9 +26,9 @@ public interface Module
{
public QualifiedNameKey getModuleID();
public void install(Principal installer) throws DatabaseException, ModuleException;
public void install(Principal installer, DynamoLog log) throws DatabaseException, ModuleException;
public void uninstall(Principal uninstaller) throws DatabaseException, ModuleException;
public void uninstall(Principal uninstaller, DynamoLog log) throws DatabaseException, ModuleException;
public DynamicObject getProvidedObject(String namespace, String name) throws ModuleException;

View File

@@ -33,9 +33,11 @@ public interface ModuleFunctions
public boolean canInstall(ServiceProvider services, Principal installer);
public void install(ModuleSite site, ServiceProvider services, Principal installer) throws ModuleException;
public void install(ModuleSite site, ServiceProvider services, Principal installer, DynamoLog log)
throws ModuleException;
public void uninstall(ModuleSite site, ServiceProvider services, Principal uninstaller) throws ModuleException;
public void uninstall(ModuleSite site, ServiceProvider services, Principal uninstaller, DynamoLog log)
throws ModuleException;
public DynamicObject getProvidedObject(String namespace, String name) throws ModuleException;

View File

@@ -284,7 +284,7 @@ class ModuleLoader extends URLClassLoader implements Module
} // end getModuleID
public synchronized void install(Principal installer) throws DatabaseException, ModuleException
public synchronized void install(Principal installer, DynamoLog log) throws DatabaseException, ModuleException
{
if (m_ops.isModuleInstalled(m_filename))
return; // already installed
@@ -305,8 +305,11 @@ class ModuleLoader extends URLClassLoader implements Module
} // end if
if (log==null)
log = NullLog.get();
ModuleSite s = new Site();
m_modfuncs.install(s,m_install_svcs,installer);
m_modfuncs.install(s,m_install_svcs,installer,log);
QualifiedNameKey name = m_modfuncs.getModuleID();
m_ops.markInstalled(m_filename,m_nscache.namespaceNameToId(name.getNamespace()),name.getName());
m_modfuncs.initialize(s,m_install_svcs);
@@ -314,7 +317,7 @@ class ModuleLoader extends URLClassLoader implements Module
} // end install
public synchronized void uninstall(Principal uninstaller) throws DatabaseException, ModuleException
public synchronized void uninstall(Principal uninstaller, DynamoLog log) throws DatabaseException, ModuleException
{
if (!(m_ops.isModuleInstalled(m_filename)))
return; // already uninstalled
@@ -334,7 +337,10 @@ class ModuleLoader extends URLClassLoader implements Module
} // end if
m_modfuncs.uninstall(new Site(),m_install_svcs,uninstaller);
if (log==null)
log = NullLog.get();
m_modfuncs.uninstall(new Site(),m_install_svcs,uninstaller,log);
m_ops.unmarkInstalled(m_filename);
} // end uninstall

View File

@@ -0,0 +1,98 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.dynamo.util;
import com.silverwrist.dynamo.iface.*;
public class NullLog implements DynamoLog
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static NullLog _self = null;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
private NullLog()
{ // do nothing
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface DynamoLog
*--------------------------------------------------------------------------------
*/
public void debug(Object message)
{ // no implementation
} // end debug
public void debug(Object message, Throwable t)
{ // no implementation
} // end debug
public void error(Object message)
{ // no implementation
} // end error
public void error(Object message, Throwable t)
{ // no implementation
} // end error
public void fatal(Object message)
{ // no implementation
} // end fatal
public void fatal(Object message, Throwable t)
{ // no implementation
} // end fatal
public void info(Object message)
{ // no implementation
} // end info
public void info(Object message, Throwable t)
{ // no implementation
} // end info
public void warn(Object message)
{ // no implementation
} // end warn
public void warn(Object message, Throwable t)
{ // no implementation
} // end warn
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------
*/
public static synchronized DynamoLog get()
{
if (_self==null)
_self = new NullLog();
return _self;
} // end get
} // end class NullLog

View File

@@ -0,0 +1,180 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.dynamo.util;
import java.io.*;
import java.text.*;
import java.util.*;
import com.silverwrist.util.*;
import com.silverwrist.dynamo.iface.*;
public class SimpleMemoryLog implements DynamoLog
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static DateFormat s_fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final String S_DEBUG = "DEBUG";
private static final String S_ERROR = "ERROR";
private static final String S_FATAL = "FATAL";
private static final String S_INFO = "INFO ";
private static final String S_WARN = "WARN ";
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private LinkedList m_scroll = new LinkedList();
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public SimpleMemoryLog()
{ // do nothing
} // end constructor
/*--------------------------------------------------------------------------------
* Internal operations
*--------------------------------------------------------------------------------
*/
private final void output(String s)
{
if (s==null)
return;
String[] lines = StringUtils.split(s,"\r\n");
for (int i=0; i<lines.length; i++)
m_scroll.addLast(lines[i]);
} // end output
private final void stackTrace(Throwable t)
{
if (t==null)
return;
StringWriter wr = new StringWriter();
PrintWriter pwr = new PrintWriter(wr);
t.printStackTrace(pwr);
pwr.flush();
output(wr.toString());
} // end stackTrace
private final void doMessage(String level, Object data)
{
StringBuffer buf = new StringBuffer(s_fmt.format(new java.util.Date()));
buf.append(" ").append(level).append(" ").append(data);
output(buf.toString());
} // end doMessage
/*--------------------------------------------------------------------------------
* Implementations from interface DynamoLog
*--------------------------------------------------------------------------------
*/
public void debug(Object message)
{
doMessage(S_DEBUG,message);
} // end debug
public void debug(Object message, Throwable t)
{
doMessage(S_DEBUG,message);
stackTrace(t);
} // end debug
public void error(Object message)
{
doMessage(S_ERROR,message);
} // end error
public void error(Object message, Throwable t)
{
doMessage(S_ERROR,message);
stackTrace(t);
} // end error
public void fatal(Object message)
{
doMessage(S_FATAL,message);
} // end fatal
public void fatal(Object message, Throwable t)
{
doMessage(S_FATAL,message);
stackTrace(t);
} // end fatal
public void info(Object message)
{
doMessage(S_INFO,message);
} // end info
public void info(Object message, Throwable t)
{
doMessage(S_INFO,message);
stackTrace(t);
} // end info
public void warn(Object message)
{
doMessage(S_WARN,message);
} // end warn
public void warn(Object message, Throwable t)
{
doMessage(S_WARN,message);
stackTrace(t);
} // end warn
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public List getLog()
{
ArrayList rc = new ArrayList(m_scroll);
return Collections.unmodifiableList(rc);
} // end getLog
public void clear()
{
m_scroll.clear();
} // end clear
} // end class SimpleMemoryLog

View File

@@ -88,12 +88,14 @@ public class Main implements ModuleFunctions
} // end canInstall
public void install(ModuleSite site, ServiceProvider services, Principal installer) throws ModuleException
public void install(ModuleSite site, ServiceProvider services, Principal installer, DynamoLog log)
throws ModuleException
{
// module does not need installation
} // end install
public void uninstall(ModuleSite site, ServiceProvider services, Principal uninstaller) throws ModuleException
public void uninstall(ModuleSite site, ServiceProvider services, Principal uninstaller, DynamoLog log)
throws ModuleException
{
// module does not need uninstallation
} // end uninstall