Search in sources :

Example 11 with StringRefAddr

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;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) SystemComponentReference(org.apache.openejb.core.ivm.naming.SystemComponentReference) Reference(javax.naming.Reference) AtomicReference(java.util.concurrent.atomic.AtomicReference) ResourceRef(org.apache.naming.ResourceRef) ResourceEnvRef(org.apache.naming.ResourceEnvRef) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 12 with StringRefAddr

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();
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with StringRefAddr

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;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) Reference(javax.naming.Reference) Stack(java.util.Stack) StartElement(javax.xml.stream.events.StartElement) Entry(java.util.Map.Entry) StringRefAddr(javax.naming.StringRefAddr) XMLEvent(javax.xml.stream.events.XMLEvent) Iterator(java.util.Iterator) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 14 with StringRefAddr

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);
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr)

Example 15 with StringRefAddr

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);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Aggregations

StringRefAddr (javax.naming.StringRefAddr)67 Reference (javax.naming.Reference)51 NamingException (javax.naming.NamingException)18 RefAddr (javax.naming.RefAddr)9 Test (org.junit.Test)8 Name (javax.naming.Name)7 Properties (java.util.Properties)6 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 CompositeName (javax.naming.CompositeName)5 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)5 ObjectFactory (javax.naming.spi.ObjectFactory)5 MalformedURLException (java.net.MalformedURLException)4 Enumeration (java.util.Enumeration)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 Context (javax.naming.Context)4 NameNotFoundException (javax.naming.NameNotFoundException)3 Context (org.apache.catalina.Context)3 NamingContext (org.apache.naming.NamingContext)3