use of javax.naming.StringRefAddr in project tomee by apache.
the class TomcatWebAppBuilder method createReference.
private static Reference createReference(final ResourceBase resource) {
final Reference ref;
if (resource instanceof ContextResource) {
final ContextResource cr = (ContextResource) resource;
ref = new ResourceRef(resource.getType(), resource.getDescription(), cr.getScope(), cr.getAuth(), cr.getSingleton());
} else {
ref = new ResourceEnvRef(resource.getType());
}
final Iterator<String> params = resource.listProperties();
while (params.hasNext()) {
final String paramName = params.next();
final String paramValue = (String) resource.getProperty(paramName);
final StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
ref.add(refAddr);
}
return ref;
}
use of javax.naming.StringRefAddr in project kernel by exoplatform.
the class InitialContextBinder method bind.
/**
* Constructs references from params, binds in initial contexts and persists list of all binded
* references into file.
*
* @param bindName
* bind name
* @param className
* class name
* @param factory
* factory name
* @param factoryLocation
* factory location
* @param refAddr
* map of references's properties
*
* @throws NamingException
* if error occurs due to binding
* @throws XMLStreamException
* @throws FileNotFoundException
*/
public void bind(String bindName, String className, String factory, String factoryLocation, Map<String, String> refAddr) throws NamingException, FileNotFoundException, XMLStreamException {
Reference reference = new Reference(className, factory, factoryLocation);
for (Map.Entry<String, String> entry : refAddr.entrySet()) {
reference.add(new StringRefAddr(entry.getKey(), entry.getValue()));
}
bindInternally(bindName, reference);
saveBindings();
}
use of javax.naming.StringRefAddr in project kernel by exoplatform.
the class InitialContextBinder method readBindings.
/**
* Import references from xml-file.
*
* @return map with bind name - references
*
* @throws XMLStreamException
* if errors occurs during import
* @throws FileNotFoundException
* if can't open input stream from file
*/
protected Map<String, Reference> readBindings() throws FileNotFoundException, XMLStreamException {
Stack<RefEntity> stack = new Stack<RefEntity>();
Map<String, Reference> importedRefs = new HashMap<String, Reference>();
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader reader = factory.createXMLEventReader(PrivilegedFileHelper.fileInputStream(bindingsStorePath), "UTF-8");
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
switch(event.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
StartElement startElement = event.asStartElement();
Map<String, String> attr = new HashMap<String, String>();
Iterator attributes = startElement.getAttributes();
while (attributes.hasNext()) {
Attribute attribute = (Attribute) attributes.next();
attr.put(attribute.getName().getLocalPart(), attribute.getValue());
}
String localName = startElement.getName().getLocalPart();
if (localName.equals(REFERENCE_ELEMENT)) {
String bindName = attr.get(BIND_NAME_ATTR);
String className = attr.get(CLASS_NAME_ATTR);
String factoryName = attr.get(FACTORY_ATTR);
String factoryLocation = attr.get(FACTORY_LOCATION_ATTR);
Reference reference = new Reference(className, factoryName, factoryLocation);
stack.push(new RefEntity(bindName, reference));
} else if (localName.equals(PROPERTY_ELEMENT)) {
RefEntity refEntity = stack.pop();
Reference reference = refEntity.getValue();
for (Entry<String, String> entry : attr.entrySet()) {
reference.add(new StringRefAddr(entry.getKey(), entry.getValue()));
}
refEntity.setValue(reference);
stack.push(refEntity);
}
break;
case XMLStreamConstants.END_ELEMENT:
EndElement endElement = event.asEndElement();
localName = endElement.getName().getLocalPart();
if (localName.equals(REFERENCE_ELEMENT)) {
RefEntity refEntity = stack.pop();
importedRefs.put(refEntity.getKey(), refEntity.getValue());
}
break;
default:
break;
}
}
return importedRefs;
}
use of javax.naming.StringRefAddr in project Payara by payara.
the class NamingContextListener method addAdditionalParameters.
/**
* Add additional parameters to the reference.
*/
private void addAdditionalParameters(NamingResources resources, Reference ref, String name) {
if (resources == null) {
resources = namingResources;
}
ResourceParams resourceParameters = resources.findResourceParams(name);
if (debug >= 2)
log(" Resource parameters for " + name + " = " + resourceParameters);
if (resourceParameters == null)
return;
Hashtable<String, String> params = resourceParameters.getParameters();
Enumeration<String> enumeration = params.keys();
while (enumeration.hasMoreElements()) {
String paramName = enumeration.nextElement();
String paramValue = params.get(paramName);
StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
ref.add(refAddr);
}
}
use of javax.naming.StringRefAddr in project Payara by payara.
the class GlassfishNamingManagerImpl method publishCosNamingObject.
@Override
public void publishCosNamingObject(String name, Object obj, boolean rebind) throws NamingException {
Name nameObj = new CompositeName(name);
// Create any COS naming sub-contexts in name
// that don't already exist.
createSubContexts(nameObj, getCosContext());
if (rebind) {
getCosContext().rebind(name, obj);
} else {
getCosContext().bind(name, obj);
}
// Bind a reference to it in the SerialContext using
// the same name. This is needed to allow standalone clients
// to lookup the object using the same JNDI name.
// It is also used from bindObjects while populating ejb-refs in
// the java:comp namespace.
Object serialObj = new Reference("reference", new StringRefAddr("url", name), IIOPOBJECT_FACTORY, null);
publishObject(name, serialObj, rebind);
}
Aggregations