001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.conf;
020:
021: import org.apache.commons.lang.StringUtils;
022: import org.apache.openjpa.event.RemoteCommitEventManager;
023: import org.apache.openjpa.event.RemoteCommitProvider;
024: import org.apache.openjpa.lib.conf.Configuration;
025: import org.apache.openjpa.lib.conf.Configurations;
026: import org.apache.openjpa.lib.conf.PluginValue;
027: import org.apache.openjpa.lib.util.Options;
028:
029: /**
030: * Value type used to represent a {@link RemoteCommitProvider}. This
031: * plugin allows users to specify whether to transmit the ids of added objects
032: * in the remote commit events distributed.
033: *
034: * @author Abe White
035: * @nojavadoc
036: */
037: public class RemoteCommitProviderValue extends PluginValue {
038:
039: private static final String[] ALIASES = new String[] { "sjvm",
040: "org.apache.openjpa.event.SingleJVMRemoteCommitProvider",
041: "jms", "org.apache.openjpa.event.JMSRemoteCommitProvider",
042: "tcp", "org.apache.openjpa.event.TCPRemoteCommitProvider", };
043:
044: private Options _opts = null;
045: private Boolean _transmitPersIds = null;
046:
047: public RemoteCommitProviderValue() {
048: super ("RemoteCommitProvider", true);
049: setAliases(ALIASES);
050: }
051:
052: public void setProperties(String props) {
053: super .setProperties(props);
054: _opts = null;
055: _transmitPersIds = null;
056: }
057:
058: public void setString(String str) {
059: super .setString(str);
060: _opts = null;
061: _transmitPersIds = null;
062: }
063:
064: /**
065: * The cached provider.
066: */
067: public RemoteCommitProvider getProvider() {
068: return (RemoteCommitProvider) get();
069: }
070:
071: /**
072: * The cached provider.
073: */
074: public void setProvider(RemoteCommitProvider provider) {
075: set(provider);
076: }
077:
078: /**
079: * Whether to transmit persisted object ids in remote commit events.
080: */
081: public boolean getTransmitPersistedObjectIds() {
082: return Boolean.TRUE.equals(_transmitPersIds);
083: }
084:
085: /**
086: * The cached decorators.
087: */
088: public void setTransmitPersistedObjectIds(boolean transmit) {
089: _transmitPersIds = (transmit) ? Boolean.TRUE : Boolean.FALSE;
090: }
091:
092: /**
093: * Instantiate the provider.
094: */
095: public RemoteCommitProvider instantiateProvider(Configuration conf) {
096: return instantiateProvider(conf, true);
097: }
098:
099: /**
100: * Instantiate the provider.
101: */
102: public RemoteCommitProvider instantiateProvider(Configuration conf,
103: boolean fatal) {
104: return (RemoteCommitProvider) instantiate(
105: RemoteCommitProvider.class, conf, fatal);
106: }
107:
108: /**
109: * Configure the remote event manager.
110: */
111: public void configureEventManager(RemoteCommitEventManager mgr) {
112: parseOptions();
113: if (_transmitPersIds != null)
114: mgr.setTransmitPersistedObjectIds(_transmitPersIds
115: .booleanValue());
116: }
117:
118: /**
119: * Override to keep decorators out of transport configuration.
120: */
121: public Object instantiate(Class type, Configuration conf,
122: boolean fatal) {
123: Object obj = newInstance(getClassName(), type, conf, fatal);
124: parseOptions();
125: Configurations.configureInstance(obj, conf, _opts,
126: getProperty());
127: set(obj, true);
128: return obj;
129: }
130:
131: private void parseOptions() {
132: if (_opts != null)
133: return;
134:
135: _opts = Configurations.parseProperties(getProperties());
136: String transmit = StringUtils.trimToNull(_opts.removeProperty(
137: "transmitPersistedObjectIds",
138: "TransmitPersistedObjectIds", null));
139: if (transmit != null)
140: _transmitPersIds = Boolean.valueOf(transmit);
141: }
142: }
|