svnno****@sourc*****
svnno****@sourc*****
2009年 2月 22日 (日) 15:15:41 JST
Revision: 2706 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2706 Author: daisuke_m Date: 2009-02-22 15:15:41 +0900 (Sun, 22 Feb 2009) Log Message: ----------- Command#execute()のthrows Exceptionを廃止。 / Facadeの実装開始。 Modified Paths: -------------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/EventBrokerImpl.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractAddToRootCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractDeleteFromRootCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddColumnCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddColumnToColumnRefListCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddForeignKeyCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddPrimaryKeyCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteColumnCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteColumnFromColumnRefListCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteForeignKeyCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeletePrimaryKeyCommand.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/ModifyModelPropertyCommand.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/EventBroker.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/editcommand/Command.java Added Paths: ----------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/JiemamyFacadeImpl.java -------------- next part -------------- Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/EventBrokerImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/EventBrokerImpl.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/EventBrokerImpl.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -28,12 +28,14 @@ import org.jiemamy.editcommand.Command; import org.jiemamy.editcommand.CommandListener; +import org.jiemamy.editcommand.CommandProcessor; import org.jiemamy.editcommand.CommandProcessorImpl; import org.jiemamy.model.JiemamyElement; import org.jiemamy.utils.CollectionsUtil; /** * コマンドの実行を監視し、登録されている{@link CommandListener}にイベントを通知する。 + * * <p>{@link Command}が実行されたタイミングで、{@link #listeners}として保持している{@link CommandListener}の中で, * {@link Command#getTarget()}を監視する必要があるものにイベントを通知する。</p> * <p>{@link CommandProcessorImpl}は{@link Command}を実行した時に、どこからかコイツを取得して @@ -43,14 +45,33 @@ */ public class EventBrokerImpl implements EventBroker { + private static class DefaultDispatchStrategy implements DispatchStrategy { + + public boolean needToDispatch(CommandListener listener, Command command) { + UUID uuid = command.getTarget().getId(); + JiemamyElement targetModel = listener.getTargetModel(); + return ReferenceResolverImpl.isDescendFromElement(targetModel, uuid); + } + } + + private static Logger logger = LoggerFactory.getLogger(EventBrokerImpl.class); private List<CommandListener> listeners = CollectionsUtil.newArrayList(); private DispatchStrategy strategy = new DefaultDispatchStrategy(); + private CommandProcessor commandProcessor; + /** + * インスタンスを生成する。 + */ + public EventBrokerImpl() { + commandProcessor = new CommandProcessorImpl(this); + } + + /** * {@inheritDoc} */ public void addListener(CommandListener listener) { @@ -78,6 +99,13 @@ /** * {@inheritDoc} */ + public CommandProcessor getCommandProcessor() { + return commandProcessor; + } + + /** + * {@inheritDoc} + */ public void removeListener(CommandListener listener) { listeners.remove(listener); logger.info("CommandListener is unregistered: " + listener.toString()); @@ -91,14 +119,4 @@ Validate.notNull(strategy); this.strategy = strategy; } - - - private static class DefaultDispatchStrategy implements DispatchStrategy { - - public boolean needToDispatch(CommandListener listener, Command command) { - UUID uuid = command.getTarget().getId(); - JiemamyElement targetModel = listener.getTargetModel(); - return ReferenceResolverImpl.isDescendFromElement(targetModel, uuid); - } - } } Added: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/JiemamyFacadeImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/JiemamyFacadeImpl.java (rev 0) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/JiemamyFacadeImpl.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -0,0 +1,84 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/22 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy; + +import java.util.Stack; + +import org.jiemamy.editcommand.Command; +import org.jiemamy.editcommand.CommandProcessor; +import org.jiemamy.editcommand.impl.AddEntityToRootCommand; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.entity.EntityModel; + +/** + * TODO for daisuke + * + * @author daisuke + */ +public class JiemamyFacadeImpl { + + private final Jiemamy jiemamy; + + private Stack<Command> undoStack = new Stack<Command>(); + + private Stack<Command> redoStack = new Stack<Command>(); + + private final CommandProcessor processor; + + + /** + * インスタンスを生成する。 + * + * @param jiemamy + */ + public JiemamyFacadeImpl(Jiemamy jiemamy) { + this.jiemamy = jiemamy; + processor = jiemamy.getEventBroker().getCommandProcessor(); + } + + public void addEntity(EntityModel entity) { + AddEntityToRootCommand command = new AddEntityToRootCommand(getRootModel(), entity); + command.execute(processor, undoStack); + } + + /** + * TODO for daisuke + * @return the jiemamy + */ + public Jiemamy getJiemamy() { + return jiemamy; + } + + /** + * TODO for daisuke + * + * @return + */ + public RootModel getRootModel() { + return jiemamy.getFactory().getRootModel(); + } + + public void undo() { + if (undoStack.isEmpty() == false) { + return; + } + Command command = undoStack.pop(); + command.execute(processor, redoStack); + } +} Property changes on: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/JiemamyFacadeImpl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractAddToRootCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractAddToRootCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractAddToRootCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -52,7 +52,9 @@ this.element = element; } - public Command execute(CommandProcessor processor) throws Exception { + abstract AbstractDeleteFromRootCommand<T> createDeleteFromRootCommand(RootModel root, T element); + + public Command execute(CommandProcessor processor) { processor.process(this); return createDeleteFromRootCommand(root, element); } @@ -81,6 +83,4 @@ * @return {@link RootModel}が保持する、{@link JiemamyElement}のリスト */ public abstract Collection<? super T> getTargetList(); - - abstract AbstractDeleteFromRootCommand<T> createDeleteFromRootCommand(RootModel root, T element); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -30,7 +30,7 @@ */ public abstract class AbstractCommand implements Command { - public void execute(CommandProcessor commandProcessor, Stack<Command> commandStack) throws Exception { + public void execute(CommandProcessor commandProcessor, Stack<Command> commandStack) { Command undo = execute(commandProcessor); commandStack.push(undo); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractDeleteFromRootCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractDeleteFromRootCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AbstractDeleteFromRootCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -52,7 +52,9 @@ this.element = element; } - public Command execute(CommandProcessor processor) throws Exception { + abstract AbstractAddToRootCommand<T> createAddToRootCommand(RootModel root, T element); + + public Command execute(CommandProcessor processor) { processor.process(this); return createAddToRootCommand(root, element); } @@ -81,6 +83,4 @@ * @return {@link RootModel}が保持する、{@link JiemamyElement}のリスト */ public abstract Collection<? super T> getTargetList(); - - abstract AbstractAddToRootCommand<T> createAddToRootCommand(RootModel root, T element); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddColumnCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddColumnCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddColumnCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -51,7 +51,7 @@ /** * {@inheritDoc} */ - public Command execute(CommandProcessor processor) throws Exception { + public Command execute(CommandProcessor processor) { processor.process(this); return new DeleteColumnCommand(table, column); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddColumnToColumnRefListCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddColumnToColumnRefListCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddColumnToColumnRefListCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -76,7 +76,7 @@ /** * {@inheritDoc} */ - public Command execute(CommandProcessor processor) throws Exception { + public Command execute(CommandProcessor processor) { processor.process(this); return new DeleteColumnFromColumnRefListCommand(target, columnRefList, column, index); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddForeignKeyCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddForeignKeyCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddForeignKeyCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -49,7 +49,7 @@ /** * {@inheritDoc} */ - public Command execute(CommandProcessor processor) throws Exception { + public Command execute(CommandProcessor processor) { processor.process(this); return new DeleteForeignKeyCommand(table, fk); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddPrimaryKeyCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddPrimaryKeyCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/AddPrimaryKeyCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -50,7 +50,7 @@ /** * {@inheritDoc} */ - public Command execute(CommandProcessor processor) throws Exception { + public Command execute(CommandProcessor processor) { processor.process(this); return new DeletePrimaryKeyCommand(table, primaryKey); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteColumnCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteColumnCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteColumnCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -51,7 +51,7 @@ /** * {@inheritDoc} */ - public Command execute(CommandProcessor processor) throws Exception { + public Command execute(CommandProcessor processor) { processor.process(this); return new AddColumnCommand(table, column); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteColumnFromColumnRefListCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteColumnFromColumnRefListCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteColumnFromColumnRefListCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -89,7 +89,7 @@ /** * {@inheritDoc} */ - public Command execute(CommandProcessor processor) throws Exception { + public Command execute(CommandProcessor processor) { processor.process(this); return new AddColumnToColumnRefListCommand(target, columnRefList, column, index); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteForeignKeyCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteForeignKeyCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeleteForeignKeyCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -50,7 +50,7 @@ /** * {@inheritDoc} */ - public Command execute(CommandProcessor processor) throws Exception { + public Command execute(CommandProcessor processor) { processor.process(this); return new AddForeignKeyCommand(table, fk); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeletePrimaryKeyCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeletePrimaryKeyCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/DeletePrimaryKeyCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -50,7 +50,7 @@ /** * {@inheritDoc} */ - public Command execute(CommandProcessor processor) throws Exception { + public Command execute(CommandProcessor processor) { processor.process(this); return new AddPrimaryKeyCommand(table, primaryKey); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/ModifyModelPropertyCommand.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/ModifyModelPropertyCommand.java 2009-02-22 05:42:13 UTC (rev 2705) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/impl/ModifyModelPropertyCommand.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -19,6 +19,7 @@ package org.jiemamy.editcommand.impl; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import org.apache.commons.beanutils.BeanUtils; @@ -59,12 +60,34 @@ /** * {@inheritDoc} */ - public Command execute(CommandProcessor processor) throws Exception { - Object oldValue = BeanUtils.getProperty(target, propertyName); - processor.process(this); - Constructor<? extends ModifyModelPropertyCommand> constructor = - getClass().getConstructor(JiemamyElement.class, String.class, Object.class); - return constructor.newInstance(target, propertyName, oldValue); + public Command execute(CommandProcessor processor) { + try { + Object oldValue = BeanUtils.getProperty(target, propertyName); + processor.process(this); + Constructor<? extends ModifyModelPropertyCommand> constructor = + getClass().getConstructor(JiemamyElement.class, String.class, Object.class); + return constructor.newInstance(target, propertyName, oldValue); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // TODO 適当null返し + return null; } /** Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/EventBroker.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/EventBroker.java 2009-02-22 05:42:13 UTC (rev 2705) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/EventBroker.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -20,6 +20,7 @@ import org.jiemamy.editcommand.Command; import org.jiemamy.editcommand.CommandListener; +import org.jiemamy.editcommand.CommandProcessor; /** * コマンドの実行を監視し、登録されている{@link CommandListener}にイベントを通知する。 @@ -43,6 +44,13 @@ void fireCommandProcess(Command command); /** + * TODO for daisuke + * + * @return + */ + CommandProcessor getCommandProcessor(); + + /** * リスなを削除する。 * * @param listener Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/editcommand/Command.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/editcommand/Command.java 2009-02-22 05:42:13 UTC (rev 2705) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/editcommand/Command.java 2009-02-22 06:15:41 UTC (rev 2706) @@ -35,9 +35,8 @@ * * @param processor コマンドプロセッサ * @return 逆操作を行うコマンド - * @throws Exception */ - Command execute(CommandProcessor processor) throws Exception; + Command execute(CommandProcessor processor); /** * コマンドを実行する。 @@ -46,9 +45,8 @@ * * @param commandProcessor コマンドプロセッサ * @param commandStack undoの為のコマンドスタック - * @throws Exception */ - void execute(CommandProcessor commandProcessor, Stack<Command> commandStack) throws Exception; + void execute(CommandProcessor commandProcessor, Stack<Command> commandStack); /** * 操作対象の{@link JiemamyElement}を返す。