001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2007, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.wsrp.producer.config;
023:
024: import org.jboss.portal.registration.RegistrationPolicy;
025: import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
026: import org.jboss.portal.wsrp.WSRPUtils;
027: import org.jboss.portal.wsrp.producer.config.impl.ProducerConfigurationImpl;
028: import org.jboss.portal.wsrp.producer.config.impl.ProducerRegistrationRequirementsImpl;
029: import org.jboss.portal.wsrp.registration.LocalizedString;
030: import org.jboss.portal.wsrp.registration.RegistrationPropertyDescription;
031: import org.jboss.xb.binding.MarshallingContext;
032: import org.jboss.xb.binding.ObjectModelProvider;
033:
034: /**
035: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
036: * @version $Revision: 9156 $
037: * @since 2.6.3
038: */
039: public class ProducerConfigurationProvider implements
040: ObjectModelProvider {
041: public Object getRoot(Object o,
042: MarshallingContext marshallingContext, String s, String s1) {
043: return o;
044: }
045:
046: public Object getChildren(ProducerConfigurationImpl configuration,
047: String namespaceUri, String localName) {
048: if ("registration-configuration".equals(localName)) {
049: ProducerRegistrationRequirements registrationRequirements = configuration
050: .getRegistrationRequirements();
051: if (registrationRequirements != null
052: && registrationRequirements
053: .isRegistrationRequired()) {
054: return registrationRequirements;
055: }
056: } else if ("producer-configuration".equals(localName)) {
057: return configuration;
058: }
059:
060: return null;
061: }
062:
063: public Object getChildren(
064: ProducerRegistrationRequirementsImpl regReq,
065: String namespaceUri, String localName) {
066: if ("registration-property-description".equals(localName)) {
067: return regReq.getRegistrationProperties().values();
068: }
069:
070: return null;
071: }
072:
073: public Object getAttributeValue(
074: ProducerConfigurationImpl configuration,
075: String namespaceUri, String localName) {
076: if ("fullServiceDescriptionRequiresRegistration"
077: .equals(localName)) {
078: return configuration.getRegistrationRequirements()
079: .isRegistrationRequiredForFullDescription();
080: }
081:
082: return null;
083: }
084:
085: public Object getElementValue(
086: ProducerRegistrationRequirementsImpl regReq,
087: String namespaceUri, String localName) {
088: Object value = null;
089: if ("registration-policy".equals(localName)) {
090: RegistrationPolicy policy = regReq.getPolicy();
091: if (policy != null) {
092: value = policy.getClass().getName();
093: }
094: } else if ("registration-property-validator".equals(localName)) {
095: RegistrationPolicy policy = regReq.getPolicy();
096: if (policy instanceof DefaultRegistrationPolicy) {
097: DefaultRegistrationPolicy defaultRegistrationPolicy = (DefaultRegistrationPolicy) policy;
098: value = defaultRegistrationPolicy.getValidator()
099: .getClass().getName();
100: }
101: } else {
102: value = null;
103: }
104: return value;
105: }
106:
107: public Object getElementValue(
108: RegistrationPropertyDescription propertyDescription,
109: String namespaceUri, String localName) {
110: Object value = null;
111: if ("name".equals(localName)) {
112: value = propertyDescription.getName();
113: } else if ("type".equals(localName)) {
114: value = propertyDescription.getType();
115: } else if ("label".equals(localName)) {
116: value = getLocalizedStringOrNull(propertyDescription
117: .getLabel());
118: } else if ("hint".equals(localName)) {
119: value = getLocalizedStringOrNull(propertyDescription
120: .getHint());
121: }
122: return value;
123: }
124:
125: private LocalizedString getLocalizedStringOrNull(
126: LocalizedString string) {
127: if (string != null) {
128: String value = string.getValue();
129: if (value == null || value.length() == 0) {
130: return null;
131: } else {
132: return string;
133: }
134: } else {
135: return null;
136: }
137: }
138:
139: public Object getAttributeValue(LocalizedString localizedString,
140: String namespaceUri, String localName) {
141: Object value = null;
142: if ("lang".equals(localName)) {
143: value = WSRPUtils.toString(localizedString.getLocale());
144: } else if ("resourceName".equals(localName)) {
145: value = localizedString.getResourceName();
146: }
147: return value;
148: }
149:
150: public Object getElementValue(LocalizedString localizedString,
151: String namespaceUri, String localName) {
152: return localizedString.getValue();
153: }
154: }
|