/*
* Copyright (C) 2004 Roman Krylov
* rkrylov@mail.ru
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.JWrapper;
import java.util.*;
public abstract class JDynamicCompositeWrapper extends JCompositeWrapper
{
public JDynamicCompositeWrapper(String _name)
{ super(_name); }
public boolean isRegular() {return true;}
public boolean isCreateAllowed() {return CREATE_ALLOWED;}
public boolean isDeleteAllowed() {return DELETE_ALLOWED;}
public final JWrapper createChild() throws Exception
{
java.util.List list = createChildren();
if(list.size()>1) { throw new Exception("Only one element possible!"); }
if(list.size()==0) { return null; }
JWrapper wrp = list.get(0);
if(wrp==null) {return null;}
wrp.parent=this;
childAdded.Op(wrp);
return wrp;
}
public java.util.List createChildren() throws Exception
{
if(!isCreateAllowed()) { throw new Exception("Addition prohibited!"); }
synchronized(this)
{
List wrps = create_children();
for(JWrapper wrp : wrps)
{
if(wrp==null) {continue;}
wrp.parent=this;
childAdded.Op(wrp);
}
return wrps;
}
}
public final void removeChild(JWrapper wrp) throws Exception
{
if(!isDeleteAllowed()) { throw new Exception("Removal prohibited!"); }
synchronized(this)
{
remove_child(wrp);
childRemoved.Op(wrp);
}
}
public boolean edit(JWrapper wrp) throws Exception
{ /*by default do nothing*/return true; }
protected boolean CREATE_ALLOWED = true;
public void setCreateAllowed(boolean allowed)// is it too bad?
{ CREATE_ALLOWED = allowed; }
protected boolean DELETE_ALLOWED = true;
public void setDeleteAllowed(boolean allowed)
{ DELETE_ALLOWED = allowed; }
// public abstract JWrapper getChildPrototype() throws Exception;
//"Template Method"(GoF):
@Deprecated
protected final JWrapper create_child() throws Exception
{ throw new Exception("not supported"); }
protected abstract java.util.List create_children() throws Exception;
protected abstract void remove_child(JWrapper wrp) throws Exception;
}
|