Search in sources :

Example 6 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class ComponentManager method unregisterResource.

/**
 * Unregister a given component resource.
 * @param resource the object that contains the xml config file.
 * @param context key with which config file to be registered.
 * @param variation with which config file to be registered.
 * @throws JAXBException
 * @throws SAXException
 * @throws IOException for file opening or reading errors, or when an
 * attempt to create a ComponentDefinition throws a
 * ComponentDefinitionException
 */
@Override
public void unregisterResource(Resource resource, String context, String variation) throws JAXBException, SAXException, IOException {
    Components components = JAXBHelper.unmarshalConfigFile(Components.class, resource, COMPONENT_XSD);
    List<Component> componentList = components.getComponent();
    if (componentList != null) {
        for (final Component component : componentList) {
            ComponentDefinition definition = createComponentDefinition(component);
            ContextKey contextKey = new ContextKey(definition.getComponentName(), resource.getURI().toString(), variation, context);
            unregisterComponentDefinition(contextKey);
        }
    }
}
Also used : Components(org.jaffa.presentation.portlet.component.componentdomain.Components) ContextKey(org.jaffa.loader.ContextKey) Component(org.jaffa.presentation.portlet.component.componentdomain.Component) ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition)

Example 7 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class ComponentManager method registerResource.

/**
 * Unmarshall the contents of the configuration to create and register
 * ComponentDefinition, QueueInfo, TopicInfo, and/or MessageFilter objects.
 * @param resource the object that contains the xml config file.
 * @param context key with which config file to be registered.
 * @param variation with which config file to be registered.
 * @throws JAXBException
 * @throws SAXException
 * @throws IOException for file opening or reading errors, or when an
 * attempt to create a ComponentDefinition throws a
 * ComponentDefinitionException
 */
@Override
public void registerResource(Resource resource, String context, String variation) throws JAXBException, SAXException, IOException {
    Components components = JAXBHelper.unmarshalConfigFile(Components.class, resource, COMPONENT_XSD);
    List<Component> componentList = components.getComponent();
    if (componentList != null) {
        for (final Component component : componentList) {
            ComponentDefinition definition = createComponentDefinition(component);
            ContextKey contextKey = new ContextKey(definition.getComponentName(), resource.getURI().toString(), variation, context);
            registerComponentDefinition(contextKey, definition);
        }
    }
}
Also used : Components(org.jaffa.presentation.portlet.component.componentdomain.Components) ContextKey(org.jaffa.loader.ContextKey) Component(org.jaffa.presentation.portlet.component.componentdomain.Component) ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition)

Example 8 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class ComponentManagerTest method testReadDefinitions.

public void testReadDefinitions() {
    try {
        Map m = Loader.getComponentPool();
        assertNotNull("Loading Component Definitions", m);
        assertEquals("Got All Components", 6, m.size());
        // Simple Component
        ComponentDefinition cd1 = (ComponentDefinition) m.get("Unit.Test.Component1");
        assertNotNull("Reading Component1", cd1);
        // Component will type and description
        ComponentDefinition cd2 = (ComponentDefinition) m.get("Unit.Test.Component2");
        assertNotNull("Reading Component2", cd2);
        assertNotNull("Component2 has type", cd2.getComponentType());
        // Component with optional and mandatory functions
        ComponentDefinition cd3 = (ComponentDefinition) m.get("Unit.Test.Component3");
        assertNotNull("Reading Component3", cd3);
        assertEquals("Component3 Has 3 Mandatory Functions", 3, cd3.getMandatoryFunctions().length);
        assertEquals("Component3 Has 3 Optional Functions", 3, cd3.getMandatoryFunctions().length);
        String[] mand = new String[] { "Function1", "Function2", "Function3" };
        assertTrue("Check Component3 Mandatory Functions", Arrays.equals(mand, cd3.getMandatoryFunctions()));
        String[] opt = new String[] { "FunctionA", "FunctionB", "FunctionC" };
        assertTrue("Check Component3 Optional Functions", Arrays.equals(opt, cd3.getOptionalFunctions()));
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition)

Example 9 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class ComponentManagerTest method testGetName.

/**
 * Test the repository name retrieval function
 */
@Test
public void testGetName() throws Exception {
    // A componentDefinition must be registered first
    Component component = new Component();
    String name = "q1";
    component.setId(name);
    ComponentDefinition definition = new ComponentDefinition(component);
    ContextKey key = new ContextKey(name, "components.xml", "DEF", "0-PLATFORM");
    manager.registerComponentDefinition(key, definition);
    assertEquals("ComponentDefinition", manager.getComponentRepository().getName());
}
Also used : ContextKey(org.jaffa.loader.ContextKey) Component(org.jaffa.presentation.portlet.component.componentdomain.Component) ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition) Test(org.junit.Test)

Example 10 with ComponentDefinition

use of org.jaffa.presentation.portlet.component.ComponentDefinition in project jaffa-framework by jaffa-projects.

the class ComponentManagerTest method testRegisterComponentDefinition.

/**
 * Tests registration of ComponentDefinition objects
 * @throws Exception
 */
@Test
public void testRegisterComponentDefinition() throws Exception {
    Component component = new Component();
    String name = "q1";
    component.setId(name);
    ComponentDefinition definition = new ComponentDefinition(component);
    ContextKey key = new ContextKey(name, "components.xml", VariationContext.NULL_VARIATION, "0-PLATFORM");
    manager.registerComponentDefinition(key, definition);
    ComponentDefinition retrievedDefinition = manager.getComponentDefinition(name);
    assertEquals(definition, retrievedDefinition);
}
Also used : ContextKey(org.jaffa.loader.ContextKey) Component(org.jaffa.presentation.portlet.component.componentdomain.Component) ComponentDefinition(org.jaffa.presentation.portlet.component.ComponentDefinition) Test(org.junit.Test)

Aggregations

ComponentDefinition (org.jaffa.presentation.portlet.component.ComponentDefinition)10 ContextKey (org.jaffa.loader.ContextKey)6 Component (org.jaffa.presentation.portlet.component.componentdomain.Component)5 Test (org.junit.Test)4 Components (org.jaffa.presentation.portlet.component.componentdomain.Components)2 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JAXBException (javax.xml.bind.JAXBException)1 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)1 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 RelatedDomainObjectFoundException (org.jaffa.exceptions.RelatedDomainObjectFoundException)1