KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xml > mbeanserver > AppConfigurationEntryHolder


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.xml.mbeanserver;
23
24 import java.util.HashMap JavaDoc;
25 import javax.security.auth.login.AppConfigurationEntry JavaDoc;
26 import javax.xml.namespace.QName JavaDoc;
27
28 import org.jboss.xb.binding.GenericValueContainer;
29
30 /**
31  * @author Scott.Stark@jboss.org
32  * @version $Revision: 42074 $
33  */

34 public class AppConfigurationEntryHolder
35    implements GenericValueContainer
36 {
37    String JavaDoc code;
38    AppConfigurationEntry.LoginModuleControlFlag JavaDoc controlFlag;
39    HashMap JavaDoc options = new HashMap JavaDoc();
40
41    // GenericValueContainer should have default ctor
42
public AppConfigurationEntryHolder()
43    {
44    }
45
46    AppConfigurationEntryHolder(String JavaDoc code, String JavaDoc flag)
47    {
48       this.code = code;
49       controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
50       if (flag != null)
51       {
52          // Lower case is what is used by the jdk1.4.1 implementation
53
flag = flag.toLowerCase();
54          if (AppConfigurationEntry.LoginModuleControlFlag.REQUIRED.toString().indexOf(flag) > 0)
55             controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
56          else if (AppConfigurationEntry.LoginModuleControlFlag.REQUISITE.toString().indexOf(flag) > 0)
57             controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;
58          else if (AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT.toString().indexOf(flag) > 0)
59             controlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;
60          else if (AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL.toString().indexOf(flag) > 0)
61             controlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;
62       }
63    }
64
65    public AppConfigurationEntry JavaDoc getEntry()
66    {
67       AppConfigurationEntry JavaDoc entry = new AppConfigurationEntry JavaDoc(code, controlFlag, options);
68       return entry;
69    }
70
71    public void addOption(ModuleOption option)
72    {
73       options.put(option.name, option.value);
74    }
75
76    // GenericValueContainer impl
77

78    public void addChild(QName JavaDoc name, Object JavaDoc value)
79    {
80       if("code".equals(name.getLocalPart()))
81       {
82          this.code = (String JavaDoc)value;
83       }
84       else if("flag".equals(name.getLocalPart()))
85       {
86          // Lower case is what is used by the jdk1.4.1 implementation
87
String JavaDoc flag = ((String JavaDoc)value).toLowerCase();
88          if (AppConfigurationEntry.LoginModuleControlFlag.REQUIRED.toString().indexOf(flag) > 0)
89             controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
90          else if (AppConfigurationEntry.LoginModuleControlFlag.REQUISITE.toString().indexOf(flag) > 0)
91             controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;
92          else if (AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT.toString().indexOf(flag) > 0)
93             controlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;
94          else if (AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL.toString().indexOf(flag) > 0)
95             controlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;
96       }
97       else if("module-option".equals(name.getLocalPart()))
98       {
99          addOption((ModuleOption)value);
100       }
101    }
102
103    public Object JavaDoc instantiate()
104    {
105       return new AppConfigurationEntry JavaDoc(code, controlFlag, options);
106    }
107
108    public Class JavaDoc getTargetClass()
109    {
110       return AppConfigurationEntry JavaDoc.class;
111    }
112 }
113
Popular Tags