001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.xml.mbeanserver;
023:
024: import java.util.HashMap;
025: import javax.security.auth.login.AppConfigurationEntry;
026: import javax.xml.namespace.QName;
027:
028: import org.jboss.xb.binding.GenericValueContainer;
029:
030: /**
031: * @author Scott.Stark@jboss.org
032: * @version $Revision: 57211 $
033: */
034: public class AppConfigurationEntryHolder implements
035: GenericValueContainer {
036: String code;
037: AppConfigurationEntry.LoginModuleControlFlag controlFlag;
038: HashMap options = new HashMap();
039:
040: // GenericValueContainer should have default ctor
041: public AppConfigurationEntryHolder() {
042: }
043:
044: AppConfigurationEntryHolder(String code, String flag) {
045: this .code = code;
046: controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
047: if (flag != null) {
048: // Lower case is what is used by the jdk1.4.1 implementation
049: flag = flag.toLowerCase();
050: if (AppConfigurationEntry.LoginModuleControlFlag.REQUIRED
051: .toString().indexOf(flag) > 0)
052: controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
053: else if (AppConfigurationEntry.LoginModuleControlFlag.REQUISITE
054: .toString().indexOf(flag) > 0)
055: controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;
056: else if (AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT
057: .toString().indexOf(flag) > 0)
058: controlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;
059: else if (AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL
060: .toString().indexOf(flag) > 0)
061: controlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;
062: }
063: }
064:
065: public AppConfigurationEntry getEntry() {
066: AppConfigurationEntry entry = new AppConfigurationEntry(code,
067: controlFlag, options);
068: return entry;
069: }
070:
071: public void addOption(ModuleOption option) {
072: options.put(option.name, option.value);
073: }
074:
075: // GenericValueContainer impl
076:
077: public void addChild(QName name, Object value) {
078: if ("code".equals(name.getLocalPart())) {
079: this .code = (String) value;
080: } else if ("flag".equals(name.getLocalPart())) {
081: // Lower case is what is used by the jdk1.4.1 implementation
082: String flag = ((String) value).toLowerCase();
083: if (AppConfigurationEntry.LoginModuleControlFlag.REQUIRED
084: .toString().indexOf(flag) > 0)
085: controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
086: else if (AppConfigurationEntry.LoginModuleControlFlag.REQUISITE
087: .toString().indexOf(flag) > 0)
088: controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;
089: else if (AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT
090: .toString().indexOf(flag) > 0)
091: controlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;
092: else if (AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL
093: .toString().indexOf(flag) > 0)
094: controlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;
095: } else if ("module-option".equals(name.getLocalPart())) {
096: addOption((ModuleOption) value);
097: }
098: }
099:
100: public Object instantiate() {
101: return new AppConfigurationEntry(code, controlFlag, options);
102: }
103:
104: public Class getTargetClass() {
105: return AppConfigurationEntry.class;
106: }
107: }
|