001    /*
002     * Copyright (c) 2009 The openGion Project.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013     * either express or implied. See the License for the specific language
014     * governing permissions and limitations under the License.
015     */
016    package org.opengion.hayabusa.db;
017    
018    import java.util.Arrays;
019    import java.util.Comparator;
020    import java.util.HashMap;
021    import java.util.Map;
022    
023    /**
024     * ユーザーå�˜ä½�ã?エãƒ?‚£ãƒ?ƒˆè¨­å®šæƒ…報を管ç�?�™ã‚‹ã�Ÿã‚�ã?クラスã�§ã�™ã?
025     *
026     * ç”»é�¢ID+エãƒ?‚£ãƒ?ƒˆå��をキーã�¨ã�—ã�¦ã‚¨ãƒ?‚£ãƒ?ƒˆè¨­å®šã‚ªãƒ–ジェクトã?
027     * 追åŠ??削除ã€�å�‚照を行ã�„ã�¾ã�™ã?
028     *
029     * @og.rev 5.3.6.0 (2011/06/01) 新�追�
030     *
031     * @version  5.0
032     * @author   Hiroki Nakamura
033     * @since    JDK6.0,
034     */
035    public class DBEditConfigManager  {
036    
037            // エãƒ?‚£ãƒ?ƒˆè¨­å®šæƒ…å ±ã�®ç®¡ç�?‚ªãƒ–ジェクãƒ?ç”»é�¢ID+エãƒ?‚£ãƒ?ƒˆå��å�˜ä½�ã�§ç®¡ç�?
038            private final Map<String,Map<String,DBEditConfig>> editConfigMap = new HashMap<String,Map<String,DBEditConfig>>();
039    
040            /**
041             * ãƒ?ƒ•ォルトコンストラクターã�§ã�™ã?
042             */
043    //      public DBEditConfigManager() {
044    //      }
045    
046            /**
047             * エãƒ?‚£ãƒ?ƒˆè¨­å®šã‚ªãƒ–ジェクトを追åŠ?�—ã�¾ã�™ã?
048             *
049             * ã�“ã�“ã�§ã�®è¿½åŠ??ã�‚ã��ã�¾ã�§ãƒ¡ãƒ¢ãƒªä¸Šã�§ã�®ç™»éŒ²ã�«ã�ªã‚Šã�¾ã�™ã?
050             * 登録ã�—ã�Ÿå†?®¹ã‚’永続的ã�«ç™»éŒ²ã�™ã‚‹å ´å�ˆã?ã€�別途DBã�¸ã�®ç™»éŒ²ã�Œå¿?¦�ã�«ã�ªã‚Šã�¾ã�™ã?
051             *
052             * @param guikey 画�ID
053             * @param editName エãƒ?‚£ãƒ?ƒˆå�?
054             * @param config エãƒ?‚£ãƒ?ƒˆè¨­å®šã‚ªãƒ–ジェクãƒ?
055             */
056            public void addEditConfig( final String guikey, final String editName, final DBEditConfig config ) {
057                    if( guikey == null || guikey.length() == 0 ) { return; }
058                    if( editName == null || editName.length() == 0 ) { return; }
059                    if( config == null ) { return; }
060    
061                    synchronized( editConfigMap ) {
062                            Map<String,DBEditConfig> map = editConfigMap.get( guikey );
063                            if( map == null ) {
064                                    map = new HashMap<String, DBEditConfig>();
065                            }
066                            map.put( editName, config );
067    
068                            editConfigMap.put( guikey, map );
069                    }
070            }
071    
072            /**
073             * エãƒ?‚£ãƒ?ƒˆè¨­å®šã‚ªãƒ–ジェクトを削除ã�—ã�¾ã�™ã?
074             *
075             * ã�“ã�“ã�§ã�®è¿½åŠ??ã�‚ã��ã�¾ã�§ãƒ¡ãƒ¢ãƒªä¸Šã�§ã�®å‰Šé™¤ã�«ã�ªã‚Šã�¾ã�™ã?
076             * 登録ã�—ã�Ÿå†?®¹ã‚’永続的ã�«å‰Šé™¤ã�™ã‚‹å ´å�ˆã?ã€�別途DBã�¸ã�®ç™»éŒ²ã�Œå¿?¦�ã�«ã�ªã‚Šã�¾ã�™ã?
077             *
078             * @param guikey 画�ID
079             * @param editName エãƒ?‚£ãƒ?ƒˆå�?
080             *
081             * @return エãƒ?‚£ãƒ?ƒˆè¨­å®šã‚ªãƒ–ジェクãƒ?
082             */
083            public DBEditConfig deleteEditConfig( final String guikey, final String editName ) {
084                    if( guikey == null || guikey.length() == 0 ) { return null; }
085                    if( editName == null || editName.length() == 0 ) { return null; }
086    
087                    DBEditConfig config = null;
088                    synchronized( editConfigMap ) {
089                            Map<String,DBEditConfig> map = editConfigMap.get( guikey );
090                            if( map == null ) { return null; }
091                            config = map.remove( editName );
092                            editConfigMap.put( guikey, map );
093                    }
094                    return config;
095            }
096    
097            /**
098             * エãƒ?‚£ãƒ?ƒˆè¨­å®šã‚ªãƒ–ジェクトをå�–å¾—ã�—ã�¾ã�™ã?
099             *
100             * @param guikey 画�ID
101             * @param editName エãƒ?‚£ãƒ?ƒˆå�?
102             *
103             * @return エãƒ?‚£ãƒ?ƒˆè¨­å®šã‚ªãƒ–ジェクãƒ?
104             */
105            public DBEditConfig getEditConfig( final String guikey, final String editName ) {
106                    if( guikey == null || guikey.length() == 0 ) { return null; }
107                    if( editName == null || editName.length() == 0 ) { return null; }
108    
109                    synchronized( editConfigMap ) {
110                            Map<String,DBEditConfig> map = editConfigMap.get( guikey );
111                            if( map == null ) { return null; }
112                            return map.get( editName );
113                    }
114            }
115    
116            /**
117             * ç”»é�¢IDをキーã�«ã‚¨ãƒ?‚£ãƒ?ƒˆè¨­å®šã?ä¸?¦§(é…�å?)ã‚’è¿”ã�—ã�¾ã�™ã?
118             * è¿”ã�•れるé…�å?ã�¯ã€�エãƒ?‚£ãƒ?ƒˆå��é?ã�«ã‚½ãƒ¼ãƒˆã�•れã�ŸçŠ¶æ…‹ã�§è¿”ã�•れã�¾ã�™ã?
119             *
120             * @param guikey 画�ID
121             *
122             * @return エãƒ?‚£ãƒ?ƒˆè¨­å®šä¸?¦§(é…�å?)
123             */
124            public DBEditConfig[] getEditConfigs( final String guikey ) {
125                    if( guikey == null || guikey.length() == 0 ) { return null; }
126    
127                    Map<String,DBEditConfig> map = editConfigMap.get( guikey );
128                    if( map == null ) { return null; }
129    
130                    DBEditConfig[] configs = map.values().toArray( new DBEditConfig[0] );
131                    Arrays.sort( configs
132                                    , new Comparator<DBEditConfig> (){
133                                            public int compare( final DBEditConfig c1, final DBEditConfig c2 ) {
134                                                    return ( c1 == null ? -1 : c1.getEditName().compareTo( c2.getEditName() ) );
135                                            }
136                                    }
137                    );
138    
139                    return configs;
140            }
141    }