svnno****@sourc*****
svnno****@sourc*****
2008年 9月 25日 (木) 02:05:09 JST
Revision: 1962 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=jiemamy&view=rev&rev=1962 Author: daisuke_m Date: 2008-09-25 02:05:09 +0900 (Thu, 25 Sep 2008) Log Message: ----------- AbstractModel等、全実装共通の実装をJ-coreSpecに移動。 その他いろいろ。 Modified Paths: -------------- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/RootModelImpl.java artemis/trunk/org.jiemamy.view/src/main/java/org/jiemamy/core/model/presentation/DiagramPresentationModelImpl.java artemis/trunk/org.jiemamy.view/src/main/java/org/jiemamy/core/utils/processor/root/presentation/ResetBendpointProcessor.java zeus/trunk/org.jiemamy.spec.core/META-INF/MANIFEST.MF zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/spec/RootModelFactory.java Added Paths: ----------- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/JiemamyModelFactory.java zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/ zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/model/ zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/model/AbstractModel.java zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/model/ModelIdManager.java Removed Paths: ------------- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/event/ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/AbstractModel.java artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/ModelIdManager.java -------------- next part -------------- Deleted: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/AbstractModel.java =================================================================== --- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/AbstractModel.java 2008-09-24 16:46:21 UTC (rev 1961) +++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/AbstractModel.java 2008-09-24 17:05:09 UTC (rev 1962) @@ -1,161 +0,0 @@ -/* - * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/06/09 - * - * This file is part of Jiemamy-core. - * - * 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.core.model; - -import java.util.List; -import java.util.UUID; - -import org.apache.commons.collections15.list.UnmodifiableList; -import org.seasar.framework.util.tiger.CollectionsUtil; - -import org.jiemamy.spec.model.JiemamyModel; -import org.jiemamy.spec.util.Processor; - -/** - * Jiemamyが扱う、ユーザが定義するDB設計に関わるデータ(モデル)クラスの抽象クラス。 - * @author daisuke - */ -public abstract class AbstractModel implements JiemamyModel { - - /** - * モデルID - * - * <p>モデルIDは、このモデルのライフサイクル(生成から削除まで)を通して一貫している。</p> - */ - private UUID id; - - /** 適用可能なアダプタのリスト */ - private List<Object> adapters = CollectionsUtil.newArrayList(); - - - /** - * コンストラクタ。 - * @category instance creation - */ - public AbstractModel() { - ModelIdManager modelManager = ModelIdManager.getInstance(); - modelManager.register(this); - } - - /** - * {@inheritDoc} - */ - public void dispose() { - ModelIdManager modelIdManager = ModelIdManager.getInstance(); - modelIdManager.unregister(this); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AbstractModel other = (AbstractModel) obj; - if (id == null) { - if (other.id != null) { - return false; - } - } else if (!id.equals(other.id)) { - return false; - } - return true; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public <T>T getAdapter(Class<T> adapter) { - for (Object myAdapter : adapters) { - if (myAdapter.getClass().isAssignableFrom(adapter)) { - return (T) myAdapter; - } - } - return null; - } - - /** - * 適用可能なアダプタのリストを取得する。 - * @return 適用可能なアダプタのリスト - */ - public List<Object> getAdapters() { - return UnmodifiableList.decorate(adapters); - } - - /** - * {@inheritDoc} - */ - public UUID getId() { - return id; - } - - /** - * {@inheritDoc} - */ - public boolean hasAdapter(Class<?> adapter) { - for (Object myAdapter : adapters) { - if (myAdapter.getClass().isAssignableFrom(adapter)) { - return true; - } - } - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public <R, T extends JiemamyModel, E extends Exception>R process(Processor<T, R, E> processor) throws E { - return processor.process((T) this); - } - - /** - * モデルIDを設定する。 - * - * <p>モデルIDは、このモデルのライフサイクル(生成から削除まで)を通して一貫しているべきであり、通常このメソッドは - * 呼び出されるべきではない。deserialize時の現状復帰用として存在するメソッドである。</p> - * - * @param id モデルID - * @category accessing - */ - public void setId(UUID id) { - this.id = id; - } - - protected void addAdapter(Object adapter) { - adapters.add(adapter); - } - -} Added: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/JiemamyModelFactory.java =================================================================== --- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/JiemamyModelFactory.java (rev 0) +++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/JiemamyModelFactory.java 2008-09-24 17:05:09 UTC (rev 1962) @@ -0,0 +1,38 @@ +/* + * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. + * Created on 2008/09/25 + * + * 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.core.model; + +import org.jiemamy.spec.exception.JiemamyRuntimeException; +import org.jiemamy.spec.model.JiemamyModel; +import org.jiemamy.spec.model.RootModel; + +/** + * TODO for daisuke + * @author daisuke + */ +public class JiemamyModelFactory { + + static <T extends JiemamyModel>T createNewInstance(RootModel rootModel, Class<T> clazz) { + try { + return clazz.newInstance(); + } catch (Exception e) { + throw new JiemamyRuntimeException(e); + } + } +} Property changes on: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/JiemamyModelFactory.java ___________________________________________________________________ Name: svn:mime-type + text/plain Deleted: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/ModelIdManager.java =================================================================== --- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/ModelIdManager.java 2008-09-24 16:46:21 UTC (rev 1961) +++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/ModelIdManager.java 2008-09-24 17:05:09 UTC (rev 1962) @@ -1,106 +0,0 @@ -/* - * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. - * Created on 2008/06/27 - * - * 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.core.model; - -import java.util.Map; -import java.util.UUID; - -import org.seasar.framework.util.tiger.CollectionsUtil; - -import org.jiemamy.spec.model.JiemamyModel; - -/** - * モデルIDを管理するマネージャクラス。 - * @author j5ik2o - */ -public final class ModelIdManager { - - /** シングルトンインスタンス */ - private static ModelIdManager instance; - - - /** - * シングルトンのインスタンスを取得する。 - * <p>THINK パフォーマンスを改善する余地があるなら,instanceのnullチェック以降にsynchronizedを設けてみる。</p> - * @return ModelManagerのインスタンス - */ - public synchronized static ModelIdManager getInstance() { - if (instance == null) { - instance = (new ModelIdManager()); - } - return instance; - } - - - /** モデル管理マップ */ - private Map<UUID, JiemamyModel> modelMap = CollectionsUtil.newHashMap(); - - - /** - * コンストラクタ。 - * @category instance creation - */ - protected ModelIdManager() { - } - - /** - * モデルIDからモデルを検索する。 - * - * <p>該当するモデルが見つからなかった時は、<code>null</code>を返す。</p> - * - * @param <T> モデルの型 - * @param id モデルID - * @return AbstractModel モデル - */ - @SuppressWarnings("unchecked") - public <T extends JiemamyModel>T findModel(UUID id) { - T result = (T) modelMap.get(id); - return result; - } - - /** - * モデルIDを生成して返す。 - * @return モデルID - */ - synchronized UUID generateModelId() { - UUID id = UUID.randomUUID(); - return id; - } - - /** - * モデルに新しいモデルIDを設定し,モデル管理マップに登録する。 - * @param model モデル - */ - synchronized void register(JiemamyModel model) { - UUID id = UUID.randomUUID(); - ((AbstractModel) model).setId(id); - modelMap.put(id, model); - } - - /** - * モデルIDを消去する。 - * <p>モデルIDに関連づくオブジェクトも破棄されます</p> - * @param model モデル - */ - synchronized void unregister(JiemamyModel model) { - modelMap.remove(model.getId()); - ((AbstractModel) model).setId(null); - } - -} Modified: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/RootModelImpl.java =================================================================== --- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/RootModelImpl.java 2008-09-24 16:46:21 UTC (rev 1961) +++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/core/model/RootModelImpl.java 2008-09-24 17:05:09 UTC (rev 1962) @@ -88,8 +88,7 @@ * {@inheritDoc} */ public <T extends JiemamyModel>T createJiemamyModel(Class<T> clazz) { - // TODO Auto-generated method stub - return null; + return JiemamyModelFactory.createNewInstance(this, clazz); } /** Modified: artemis/trunk/org.jiemamy.view/src/main/java/org/jiemamy/core/model/presentation/DiagramPresentationModelImpl.java =================================================================== --- artemis/trunk/org.jiemamy.view/src/main/java/org/jiemamy/core/model/presentation/DiagramPresentationModelImpl.java 2008-09-24 16:46:21 UTC (rev 1961) +++ artemis/trunk/org.jiemamy.view/src/main/java/org/jiemamy/core/model/presentation/DiagramPresentationModelImpl.java 2008-09-24 17:05:09 UTC (rev 1962) @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Set; +import org.jiemamy.core.model.AbstractModel; import org.jiemamy.spec.geometory.JmColor; import org.jiemamy.spec.geometory.JmPoint; import org.jiemamy.spec.geometory.JmRectangle; Modified: artemis/trunk/org.jiemamy.view/src/main/java/org/jiemamy/core/utils/processor/root/presentation/ResetBendpointProcessor.java =================================================================== --- artemis/trunk/org.jiemamy.view/src/main/java/org/jiemamy/core/utils/processor/root/presentation/ResetBendpointProcessor.java 2008-09-24 16:46:21 UTC (rev 1961) +++ artemis/trunk/org.jiemamy.view/src/main/java/org/jiemamy/core/utils/processor/root/presentation/ResetBendpointProcessor.java 2008-09-24 17:05:09 UTC (rev 1962) @@ -57,12 +57,12 @@ * {@inheritDoc} */ public Void process(RootModel rootModel) { - List<JmPoint> list = + List<JmPoint> bendpoints = rootModel.getAdapter(DiagramPresentations.class).get(index).getConnectionLayouts().get(connection); - if (list == null) { + if (bendpoints == null) { throw new IllegalStateException("表示されていないレイアウトをリセットしようとしました。"); } - list.clear(); + bendpoints.clear(); if (connection.isSelfConnection()) { // 自己コネクション時の、bendpoint自動作成 Modified: zeus/trunk/org.jiemamy.spec.core/META-INF/MANIFEST.MF =================================================================== --- zeus/trunk/org.jiemamy.spec.core/META-INF/MANIFEST.MF 2008-09-24 16:46:21 UTC (rev 1961) +++ zeus/trunk/org.jiemamy.spec.core/META-INF/MANIFEST.MF 2008-09-24 17:05:09 UTC (rev 1962) @@ -7,7 +7,8 @@ Bundle-Vendor: Jiemamy Project Eclipse-BuddyPolicy: registered Eclipse-LazyStart: false -Export-Package: org.jiemamy.spec, +Export-Package: org.jiemamy.core.model, + org.jiemamy.spec, org.jiemamy.spec.adapter, org.jiemamy.spec.exception, org.jiemamy.spec.extension, Added: zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/model/AbstractModel.java =================================================================== --- zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/model/AbstractModel.java (rev 0) +++ zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/model/AbstractModel.java 2008-09-24 17:05:09 UTC (rev 1962) @@ -0,0 +1,158 @@ +/* + * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. Created on 2008/06/09 + * + * This file is part of Jiemamy-core. + * + * 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.core.model; + +import java.util.List; +import java.util.UUID; + +import org.jiemamy.spec.model.JiemamyModel; +import org.jiemamy.spec.util.Processor; + +/** + * Jiemamyが扱う、ユーザが定義するDB設計に関わるデータ(モデル)クラスの抽象クラス。 + * @author daisuke + */ +public abstract class AbstractModel implements JiemamyModel { + + /** + * モデルID + * + * <p>モデルIDは、このモデルのライフサイクル(生成から削除まで)を通して一貫している。</p> + */ + private UUID id; + + /** 適用可能なアダプタのリスト */ + private List<Object> adapters; + + + /** + * コンストラクタ。 + * @category instance creation + */ + public AbstractModel() { + ModelIdManager modelManager = ModelIdManager.getInstance(); + modelManager.register(this); + } + + /** + * {@inheritDoc} + */ + public void dispose() { + ModelIdManager modelIdManager = ModelIdManager.getInstance(); + modelIdManager.unregister(this); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final AbstractModel other = (AbstractModel) obj; + if (id == null) { + if (other.id != null) { + return false; + } + } else if (!id.equals(other.id)) { + return false; + } + return true; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public <T>T getAdapter(Class<T> adapter) { + for (Object myAdapter : adapters) { + if (myAdapter.getClass().isAssignableFrom(adapter)) { + return (T) myAdapter; + } + } + return null; + } + + /** + * 適用可能なアダプタのリストを取得する。 + * @return 適用可能なアダプタのリスト + */ + public List<Object> getAdapters() { + return adapters; + } + + /** + * {@inheritDoc} + */ + public UUID getId() { + return id; + } + + /** + * {@inheritDoc} + */ + public boolean hasAdapter(Class<?> adapter) { + for (Object myAdapter : adapters) { + if (myAdapter.getClass().isAssignableFrom(adapter)) { + return true; + } + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public <R, T extends JiemamyModel, E extends Exception>R process(Processor<T, R, E> processor) throws E { + return processor.process((T) this); + } + + /** + * モデルIDを設定する。 + * + * <p>モデルIDは、このモデルのライフサイクル(生成から削除まで)を通して一貫しているべきであり、通常このメソッドは + * 呼び出されるべきではない。deserialize時の現状復帰用として存在するメソッドである。</p> + * + * @param id モデルID + * @category accessing + */ + public void setId(UUID id) { + this.id = id; + } + + protected void addAdapter(Object adapter) { + adapters.add(adapter); + } + +} Added: zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/model/ModelIdManager.java =================================================================== --- zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/model/ModelIdManager.java (rev 0) +++ zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/core/model/ModelIdManager.java 2008-09-24 17:05:09 UTC (rev 1962) @@ -0,0 +1,105 @@ +/* + * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. + * Created on 2008/06/27 + * + * 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.core.model; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.jiemamy.spec.model.JiemamyModel; + +/** + * モデルIDを管理するマネージャクラス。 + * @author j5ik2o + */ +public final class ModelIdManager { + + /** シングルトンインスタンス */ + private static ModelIdManager instance; + + + /** + * シングルトンのインスタンスを取得する。 + * <p>THINK パフォーマンスを改善する余地があるなら,instanceのnullチェック以降にsynchronizedを設けてみる。</p> + * @return ModelManagerのインスタンス + */ + public synchronized static ModelIdManager getInstance() { + if (instance == null) { + instance = (new ModelIdManager()); + } + return instance; + } + + + /** モデル管理マップ */ + private Map<UUID, JiemamyModel> modelMap = new HashMap<UUID, JiemamyModel>(); + + + /** + * コンストラクタ。 + * @category instance creation + */ + protected ModelIdManager() { + } + + /** + * モデルIDからモデルを検索する。 + * + * <p>該当するモデルが見つからなかった時は、<code>null</code>を返す。</p> + * + * @param <T> モデルの型 + * @param id モデルID + * @return AbstractModel モデル + */ + @SuppressWarnings("unchecked") + public <T extends JiemamyModel>T findModel(UUID id) { + T result = (T) modelMap.get(id); + return result; + } + + /** + * モデルIDを生成して返す。 + * @return モデルID + */ + synchronized UUID generateModelId() { + UUID id = UUID.randomUUID(); + return id; + } + + /** + * モデルに新しいモデルIDを設定し,モデル管理マップに登録する。 + * @param model モデル + */ + synchronized void register(JiemamyModel model) { + UUID id = UUID.randomUUID(); + ((AbstractModel) model).setId(id); + modelMap.put(id, model); + } + + /** + * モデルIDを消去する。 + * <p>モデルIDに関連づくオブジェクトも破棄されます</p> + * @param model モデル + */ + synchronized void unregister(JiemamyModel model) { + modelMap.remove(model.getId()); + ((AbstractModel) model).setId(null); + } + +} Modified: zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/spec/RootModelFactory.java =================================================================== --- zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/spec/RootModelFactory.java 2008-09-24 16:46:21 UTC (rev 1961) +++ zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/spec/RootModelFactory.java 2008-09-24 17:05:09 UTC (rev 1962) @@ -22,14 +22,14 @@ import org.jiemamy.spec.model.RootModel; /** - * TODO for daisuke + * 新しい {@link RootModel}を生成するためのファクトリ。 * @author daisuke */ public class RootModelFactory { /** - * TODO for daisuke - * @return + * 新しい {@link RootModel} のインスタンスを取得する。 + * @return {@link RootModel}のインスタンス。 */ public static RootModel createInstance() { try { @@ -39,4 +39,11 @@ throw new JiemamyRuntimeException(e); } } + + /** + * privateコンストラクタ。 + * @category instance creation + */ + private RootModelFactory() { + } }