Commit 1bd25b1a authored by Rodrigo Carneiro Henrique's avatar Rodrigo Carneiro Henrique
Browse files

[SCS-307]: Modificar a forma como atualizamos uma faceta no ComponentContext


git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/scs/core/java/trunk@119659 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 87619f4c
......@@ -11,6 +11,8 @@ import org.omg.CORBA.UserException;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.Servant;
import scs.core.exception.FacetAlreadyExists;
import scs.core.exception.FacetDoesNotExist;
import scs.core.exception.SCSException;
/**
......@@ -87,11 +89,11 @@ public class ComponentContext {
}
private void addBasicFacets() throws SCSException {
putFacet(IComponent.class.getSimpleName(), IComponentHelper.id(),
addFacet(IComponent.class.getSimpleName(), IComponentHelper.id(),
new IComponentServant(this));
putFacet(IReceptacles.class.getSimpleName(), IReceptaclesHelper.id(),
addFacet(IReceptacles.class.getSimpleName(), IReceptaclesHelper.id(),
new IReceptaclesServant(this));
putFacet(IMetaInterface.class.getSimpleName(), IMetaInterfaceHelper.id(),
addFacet(IMetaInterface.class.getSimpleName(), IMetaInterfaceHelper.id(),
new IMetaInterfaceServant(this));
}
......@@ -158,14 +160,27 @@ public class ComponentContext {
* @param servant The facet implementation, not yet activated within the POA.
* @throws SCSException If an UserException is catched.
*/
public void putFacet(String name, String interfaceName, Servant servant)
public void addFacet(String name, String interfaceName, Servant servant)
throws SCSException {
checkForGetComponentMethod(servant);
Facet oldFacet = this.facets.get(name);
if (oldFacet != null) {
this.deactivateFacet(oldFacet);
//TODO: logar que uma faceta foi substituída
throw new FacetAlreadyExists(name);
}
this.deactivateFacet(oldFacet);
this.putFacet(name, interfaceName, servant);
}
public void updateFacet(String name, Servant servant) throws SCSException {
Facet facet = this.facets.get(name);
if (facet == null) {
throw new FacetDoesNotExist(name);
}
this.putFacet(name, facet.getInterfaceName(), servant);
}
private void putFacet(String name, String interfaceName, Servant servant)
throws SCSException {
try {
org.omg.CORBA.Object reference = poa.servant_to_reference(servant);
Facet facet = new Facet(name, interfaceName, reference, servant);
......
......@@ -189,7 +189,7 @@ public class XMLComponentBuilder {
Object servant =
c.getConstructor(ComponentContext.class).newInstance(context);
if (servant instanceof Servant) {
context.putFacet(name, interfaceName, (Servant) servant);
context.addFacet(name, interfaceName, (Servant) servant);
}
else {
throw new InvalidServantException();
......
/*
* $Id$
*/
package scs.core.exception;
/**
*
* @author Tecgraf/PUC-Rio
*/
public final class FacetAlreadyExists extends SCSException {
private String facet;
public FacetAlreadyExists(String facet) {
this.facet = facet;
}
}
/*
* $Id$
*/
package scs.core.exception;
/**
*
* @author Tecgraf/PUC-Rio
*/
public final class FacetDoesNotExist extends SCSException {
private String facet;
public FacetDoesNotExist(String facet) {
this.facet = facet;
}
}
......@@ -196,10 +196,10 @@ public final class ComponentContextTest {
}
@Test
public void putFacet() throws SCSException {
public void addFacet() throws SCSException {
String facetName = "nome";
ComponentContext component = new ComponentContext(orb, poa, componentId);
component.putFacet(facetName, IComponentHelper.id(), new IComponentServant(
component.addFacet(facetName, IComponentHelper.id(), new IComponentServant(
component));
Assert.assertNotNull(component.getFacetByName(facetName));
}
......@@ -208,7 +208,7 @@ public final class ComponentContextTest {
public void removeFacet() throws SCSException {
String facetName = "nome";
ComponentContext component = new ComponentContext(orb, poa, componentId);
component.putFacet(facetName, IComponentHelper.id(), new IComponentServant(
component.addFacet(facetName, IComponentHelper.id(), new IComponentServant(
component));
Assert.assertNotNull(component.getFacetByName(facetName));
component.removeFacet(facetName);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment