1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.client;
36
37 import java.text.MessageFormat;
38
39 import javax.security.auth.login.LoginContext;
40
41 import org.apache.log4j.Logger;
42 import org.ogf.graap.wsag.api.WsagConstants;
43 import org.ogf.graap.wsag.api.client.AgreementFactoryRegistryClient;
44 import org.ogf.graap.wsag.api.configuration.WSAG4JConfiguration;
45 import org.ogf.graap.wsag.client.impl.AgreementFactoryRegistryBuilder;
46 import org.ogf.graap.wsag.client.impl.DefaultAgreementFactoryRegistryBuilder;
47 import org.w3.x2005.x08.addressing.EndpointReferenceType;
48
49
50
51
52
53
54
55
56
57
58
59 public class AgreementFactoryRegistryLocator
60 {
61
62 private static AgreementFactoryRegistryBuilder creator = null;
63
64 private static final Logger LOG = Logger.getLogger( AgreementFactoryRegistryLocator.class );
65
66
67
68
69 public static final String REGISTRY_LOCATOR = "org.ogf.graap.wsag.client.AgreementFactoryRegistryLocator";
70
71
72
73
74
75
76
77
78
79
80
81
82
83 public static final synchronized AgreementFactoryRegistryClient getFactoryRegistry( EndpointReferenceType epr )
84 throws Exception
85 {
86 return getFactoryRegistry( epr, (LoginContext) null );
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 public static final synchronized AgreementFactoryRegistryClient getFactoryRegistry( EndpointReferenceType epr,
105 LoginContext context )
106 throws Exception
107 {
108 if ( creator == null )
109 {
110
111
112
113
114 if ( System.getProperties().containsKey( REGISTRY_LOCATOR ) )
115 {
116 String implClass = System.getProperties().getProperty( REGISTRY_LOCATOR );
117 try
118 {
119 if ( LOG.isDebugEnabled() )
120 {
121 LOG.debug( "AgreementFactoryRegistryLocator implementation (" + implClass
122 + ") specified in system properties." );
123 }
124
125 @SuppressWarnings( "unchecked" )
126 Class<AgreementFactoryRegistryBuilder> clazz =
127 (Class<AgreementFactoryRegistryBuilder>) Class.forName( implClass );
128 creator = (AgreementFactoryRegistryBuilder) clazz.newInstance();
129 }
130 catch ( ClassNotFoundException e )
131 {
132 String message =
133 "AgreementFactoryRegistryBuilder implementation ({0}) not found. "
134 + "Load implementation specified in {1}.";
135 LOG.warn( MessageFormat.format( message, new Object[] { implClass,
136 WsagConstants.WSAG4J_CLIENT_CONFIG_FILE } ) );
137 }
138 catch ( ClassCastException e )
139 {
140 String message =
141 "AgreementFactoryRegistryBuilder implementation ({0}) does not implement the interface {1}. "
142 + "Implementation was specified in {2}.";
143 LOG.warn( MessageFormat.format( message, new Object[] { implClass,
144 AgreementFactoryRegistryBuilder.class.getName(),
145 WsagConstants.WSAG4J_CLIENT_CONFIG_FILE } ) );
146 }
147
148 }
149
150
151
152
153 if ( creator == null )
154 {
155 Class<AgreementFactoryRegistryBuilder> interfaceDef = AgreementFactoryRegistryBuilder.class;
156 String wsag4jClientConfigFile = WsagConstants.WSAG4J_CLIENT_CONFIG_FILE;
157 String defaultImpl = DefaultAgreementFactoryRegistryBuilder.class.getName();
158
159 creator =
160 (AgreementFactoryRegistryBuilder) WSAG4JConfiguration.findImplementation( interfaceDef,
161 wsag4jClientConfigFile,
162 defaultImpl );
163 }
164 }
165 return creator.newInstance( epr, context );
166 }
167 }