Skip to content
This repository was archived by the owner on Mar 9, 2024. It is now read-only.

Commit d1621d6

Browse files
Added javadoc
1 parent a7292ae commit d1621d6

File tree

4 files changed

+123
-92
lines changed

4 files changed

+123
-92
lines changed
Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1-
package org.fugerit.java.ee.naming.provider;
2-
3-
import java.io.Serializable;
4-
import java.util.Properties;
5-
6-
public class Config implements Serializable {
7-
8-
private static final long serialVersionUID = -178829411555556356L;
9-
10-
private Properties props;
11-
12-
public Config() {
13-
this.props = new Properties();
14-
}
15-
16-
protected void setAttribute(String key, String value) {
17-
props.put(key, value);
18-
}
19-
20-
public Object getAttribute(String key) {
21-
return props.get(key);
22-
}
23-
1+
package org.fugerit.java.ee.naming.provider;
2+
3+
import java.io.Serializable;
4+
import java.util.Properties;
5+
6+
/**
7+
* Simple configuration wrapper
8+
*
9+
* @author fugerit
10+
*
11+
*/
12+
public class Config implements Serializable {
13+
14+
private static final long serialVersionUID = -178829411555556356L;
15+
16+
private Properties props;
17+
18+
public Config() {
19+
this.props = new Properties();
20+
}
21+
22+
protected void setAttribute(String key, String value) {
23+
props.put(key, value);
24+
}
25+
26+
public Object getAttribute(String key) {
27+
return props.get(key);
28+
}
29+
30+
public Properties unwrapProperties() {
31+
return this.props;
32+
}
33+
2434
}
Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
1-
package org.fugerit.java.ee.naming.provider;
2-
3-
import java.io.Serializable;
4-
import java.util.Enumeration;
5-
import java.util.Hashtable;
6-
7-
import javax.naming.Context;
8-
import javax.naming.Name;
9-
import javax.naming.RefAddr;
10-
import javax.naming.Reference;
11-
import javax.naming.spi.ObjectFactory;
12-
13-
public class ConfigProvider implements ObjectFactory, Serializable {
14-
15-
private static final long serialVersionUID = 6199621162425L;
16-
17-
@Override
18-
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
19-
Config conf = new Config();
20-
Reference ref = (Reference) obj;
21-
Enumeration<RefAddr> addrs = ref.getAll();
22-
RefAddr addr = null;
23-
String entryName = null;
24-
String value = null;
25-
while (addrs.hasMoreElements()) {
26-
addr = (RefAddr) addrs.nextElement();
27-
entryName = addr.getType();
28-
value = (String) addr.getContent();
29-
conf.setAttribute( entryName , value );
30-
}
31-
return conf;
32-
}
33-
34-
}
1+
package org.fugerit.java.ee.naming.provider;
2+
3+
import java.io.Serializable;
4+
import java.util.Enumeration;
5+
import java.util.Hashtable;
6+
7+
import javax.naming.Context;
8+
import javax.naming.Name;
9+
import javax.naming.RefAddr;
10+
import javax.naming.Reference;
11+
import javax.naming.spi.ObjectFactory;
12+
13+
/**
14+
* Simple ObjectFactory based on {@link Config} to return all configuration entries
15+
*
16+
* @see Config
17+
*
18+
* @author fugerit
19+
*
20+
*/
21+
public class ConfigProvider implements ObjectFactory, Serializable {
22+
23+
private static final long serialVersionUID = 6199621162425L;
24+
25+
@Override
26+
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
27+
Config conf = new Config();
28+
Reference ref = (Reference) obj;
29+
Enumeration<RefAddr> addrs = ref.getAll();
30+
RefAddr addr = null;
31+
String entryName = null;
32+
String value = null;
33+
while (addrs.hasMoreElements()) {
34+
addr = (RefAddr) addrs.nextElement();
35+
entryName = addr.getType();
36+
value = (String) addr.getContent();
37+
conf.setAttribute( entryName , value );
38+
}
39+
return conf;
40+
}
41+
42+
}
Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
1-
package org.fugerit.java.ee.naming.provider;
2-
3-
import java.io.Serializable;
4-
import java.util.Enumeration;
5-
import java.util.Hashtable;
6-
import java.util.Properties;
7-
8-
import javax.naming.Context;
9-
import javax.naming.Name;
10-
import javax.naming.RefAddr;
11-
import javax.naming.Reference;
12-
import javax.naming.spi.ObjectFactory;
13-
14-
public class PropertyProvider implements ObjectFactory, Serializable {
15-
16-
private static final long serialVersionUID = 6199452144621162425L;
17-
18-
@Override
19-
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
20-
Properties props = new Properties();
21-
Reference ref = (Reference) obj;
22-
Enumeration<RefAddr> addrs = ref.getAll();
23-
RefAddr addr = null;
24-
String entryName = null;
25-
String value = null;
26-
while (addrs.hasMoreElements()) {
27-
addr = (RefAddr) addrs.nextElement();
28-
entryName = addr.getType();
29-
value = (String) addr.getContent();
30-
props.setProperty( entryName , value );
31-
}
32-
return props;
33-
}
34-
35-
}
1+
package org.fugerit.java.ee.naming.provider;
2+
3+
import java.io.Serializable;
4+
import java.util.Enumeration;
5+
import java.util.Hashtable;
6+
import java.util.Properties;
7+
8+
import javax.naming.Context;
9+
import javax.naming.Name;
10+
import javax.naming.RefAddr;
11+
import javax.naming.Reference;
12+
import javax.naming.spi.ObjectFactory;
13+
14+
/**
15+
* Simple ObjectFactory using a java.util.Properties to return all configuration entries
16+
*
17+
* @author fugerit
18+
*
19+
*/
20+
public class PropertyProvider implements ObjectFactory, Serializable {
21+
22+
private static final long serialVersionUID = 6199452144621162425L;
23+
24+
@Override
25+
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
26+
Properties props = new Properties();
27+
Reference ref = (Reference) obj;
28+
Enumeration<RefAddr> addrs = ref.getAll();
29+
RefAddr addr = null;
30+
String entryName = null;
31+
String value = null;
32+
while (addrs.hasMoreElements()) {
33+
addr = (RefAddr) addrs.nextElement();
34+
entryName = addr.getType();
35+
value = (String) addr.getContent();
36+
props.setProperty( entryName , value );
37+
}
38+
return props;
39+
}
40+
41+
}

src/main/java/org/fugerit/java/ee/naming/provider/StringProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
import javax.naming.Reference;
1111
import javax.naming.spi.ObjectFactory;
1212

13+
/**
14+
* Simple ObjectFactory using a java.util.String to return only one configuration entry
15+
* (if more configuration entries are set, result may be unpredictable).
16+
*
17+
* @author fugerit
18+
*
19+
*/
1320
public class StringProvider implements ObjectFactory, Serializable {
1421

1522
private static final long serialVersionUID = 6199452144621162425L;

0 commit comments

Comments
 (0)