View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.context;
17  
18  import org.seasar.uruma.context.impl.ApplicationContextImpl;
19  import org.seasar.uruma.context.impl.PartContextImpl;
20  import org.seasar.uruma.context.impl.WidgetHandleImpl;
21  import org.seasar.uruma.context.impl.WindowContextImpl;
22  import org.seasar.uruma.exception.DuplicateComponentIdException;
23  import org.seasar.uruma.util.AssertionUtil;
24  
25  /**
26   * 各種コンテキストを生成するためのファクトリクラスです。<br />
27   * 
28   * @author y-komori
29   */
30  public class ContextFactory {
31  
32      private ContextFactory() {
33  
34      }
35  
36      /**
37       * {@link ApplicationContext} オブジェクトを生成します。<br />
38       * 
39       * @return 生成した {@link ApplicationContext} オブジェクト
40       */
41      public static ApplicationContext createApplicationContext() {
42          return new ApplicationContextImpl();
43      }
44  
45      /**
46       * {@link WindowContext} オブジェクトを生成します。<br />
47       * 
48       * @param parent
49       *            親 {@link ApplicationContext} オブジェクト
50       * @param name
51       *            {@link WindowContext} の名称
52       * @return 生成した {@link WindowContext} オブジェクト
53       * @throws DuplicateComponentIdException
54       *             名称が重複している場合
55       */
56      public static WindowContext createWindowContext(
57              final ApplicationContext parent, final String name) {
58          AssertionUtil.assertNotNull("parent", parent);
59          AssertionUtil.assertNotNull("name", name);
60  
61          WindowContext context = new WindowContextImpl(name, parent);
62          ((ApplicationContextImpl) parent).addWindowContext(context);
63  
64          return context;
65      }
66  
67      /**
68       * {@link PartContext} オブジェクトを生成します。<br />
69       * 
70       * @param parent
71       *            親 {@link WindowContext} オブジェクト
72       * @param name
73       *            {@link PartContext} の名称
74       * @return 生成した {@link PartContext} オブジェクト
75       * @throws DuplicateComponentIdException
76       *             名称が重複している場合
77       */
78      public static PartContext createPartContext(final WindowContext parent,
79              final String name) {
80          AssertionUtil.assertNotNull("parent", parent);
81          AssertionUtil.assertNotNull("name", name);
82  
83          PartContext context = new PartContextImpl(name, parent);
84          ((WindowContextImpl) parent).addPartContext(context);
85  
86          return context;
87      }
88  
89      /**
90       * {@link WidgetHandle} オブジェクトを生成します。<br />
91       * 
92       * @param widget
93       *            {@link WidgetHandle} へ格納するオブジェクト
94       * @return 生成した {@link WidgetHandle} オブジェクト
95       */
96      public static WidgetHandle createWidgetHandle(final Object widget) {
97          return new WidgetHandleImpl(widget);
98      }
99  }