159 lines
5.3 KiB
Java
159 lines
5.3 KiB
Java
/*
|
|
* 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) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
|
*
|
|
* Contributor(s):
|
|
*/
|
|
package com.silverwrist.venice.script;
|
|
|
|
import com.silverwrist.dynamo.Namespaces;
|
|
import com.silverwrist.dynamo.except.*;
|
|
import com.silverwrist.dynamo.iface.*;
|
|
import com.silverwrist.venice.app.AdvancedUserService;
|
|
import com.silverwrist.venice.community.CategoryService;
|
|
import com.silverwrist.venice.community.CommunityService;
|
|
import com.silverwrist.venice.iface.*;
|
|
import com.silverwrist.venice.sidebox.SideboxDescriptor;
|
|
import com.silverwrist.venice.sidebox.SideboxService;
|
|
|
|
public class LibraryVeniceCast
|
|
{
|
|
/*--------------------------------------------------------------------------------
|
|
* Constructor
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
public LibraryVeniceCast()
|
|
{ // do nothing
|
|
} // end constructor
|
|
|
|
/*--------------------------------------------------------------------------------
|
|
* Internal operations
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
private final Object query(Object obj, Class klass)
|
|
{
|
|
if (klass.isInstance(obj))
|
|
return obj;
|
|
if (obj instanceof ServiceProvider)
|
|
{ // try using ServiceProvider
|
|
try
|
|
{ // query for this object as a service
|
|
return ((ServiceProvider)obj).queryService(klass);
|
|
|
|
} // end try
|
|
catch (NoSuchServiceException e)
|
|
{ // do nothing with this exception
|
|
} // end catch
|
|
|
|
} // end if
|
|
|
|
throw new ClassCastException("object is not an instance of " + klass.getName());
|
|
|
|
} // end query
|
|
|
|
/*--------------------------------------------------------------------------------
|
|
* External operations
|
|
*--------------------------------------------------------------------------------
|
|
*/
|
|
|
|
public final SecureObjectStore getGlobalBlocksStore(Request r)
|
|
{
|
|
ObjectProvider op = (ObjectProvider)(r.queryService(ObjectProvider.class));
|
|
ServiceProvider sp = (ServiceProvider)(op.getObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"globals"));
|
|
return (SecureObjectStore)(sp.queryService(SecureObjectStore.class,"blocks"));
|
|
|
|
} // end getGlobalPropertiesStore
|
|
|
|
public final SecureObjectStore getGlobalPropertiesStore(Request r)
|
|
{
|
|
ObjectProvider op = (ObjectProvider)(r.queryService(ObjectProvider.class));
|
|
ServiceProvider sp = (ServiceProvider)(op.getObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"globals"));
|
|
return (SecureObjectStore)(sp.queryService(SecureObjectStore.class,"properties"));
|
|
|
|
} // end getGlobalPropertiesStore
|
|
|
|
public final AdvancedUserService queryAdvancedUserService(Object obj)
|
|
{
|
|
return (AdvancedUserService)query(obj,AdvancedUserService.class);
|
|
|
|
} // end queryUserManagement
|
|
|
|
public final ButtonProvider queryButtonProvider(Object obj)
|
|
{
|
|
return (ButtonProvider)query(obj,ButtonProvider.class);
|
|
|
|
} // end queryButtonProvider
|
|
|
|
public final CategoryService queryCategoryService(Object obj)
|
|
{
|
|
return (CategoryService)query(obj,CategoryService.class);
|
|
|
|
} // end queryCategoryService
|
|
|
|
public final CommunityService queryCommunityService(Object obj)
|
|
{
|
|
return (CommunityService)query(obj,CommunityService.class);
|
|
|
|
} // end queryCategoryService
|
|
|
|
public final ContentBlockProvider queryContentBlockProvider(Object obj)
|
|
{
|
|
return (ContentBlockProvider)query(obj,ContentBlockProvider.class);
|
|
|
|
} // end queryContentBlockProvider
|
|
|
|
public final MenuProvider queryMenuProvider(Object obj)
|
|
{
|
|
return (MenuProvider)query(obj,MenuProvider.class);
|
|
|
|
} // end queryMenuProvider
|
|
|
|
public final RenderImage queryRenderImage(Object obj)
|
|
{
|
|
return (RenderImage)query(obj,RenderImage.class);
|
|
|
|
} // end queryRenderImage
|
|
|
|
public final SideboxService querySideboxService(Object obj)
|
|
{
|
|
return (SideboxService)query(obj,SideboxService.class);
|
|
|
|
} // end querySideboxService
|
|
|
|
public final UserDefaultPropertyNamespace queryUserDefaultPropertyNamespace(Object obj)
|
|
{
|
|
return (UserDefaultPropertyNamespace)query(obj,UserDefaultPropertyNamespace.class);
|
|
|
|
} // end queryUserDefaultPropertyNamespace
|
|
|
|
public final SideboxDescriptor toSideboxDescriptor(Object obj)
|
|
{
|
|
if (obj instanceof SideboxDescriptor)
|
|
return (SideboxDescriptor)obj;
|
|
throw new ClassCastException("LibraryVeniceCast.toSideboxDescriptor: invalid cast");
|
|
|
|
} // end toSideboxDescriptor
|
|
|
|
public final VeniceCommunity toVeniceCommunity(Object obj)
|
|
{
|
|
if (obj instanceof VeniceCommunity)
|
|
return (VeniceCommunity)obj;
|
|
throw new ClassCastException("LibraryVeniceCast.toVeniceCommunity: invalid cast");
|
|
|
|
} // end toVeniceCommunity
|
|
|
|
} // end class LibraryVeniceCast
|