Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNPORTAL-2732 GateIn AS7 subsystem code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mstruk authored and bdaw committed Nov 23, 2012
1 parent 9163b8e commit b7c918d
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public enum Attribute {
UNKNOWN(null), NAME("name"), MAIN("main"), IMPORT_SERVICES(Constants.IMPORT_SERVICES);
UNKNOWN(null),
NAME("name"),
IMPORT_SERVICES(Constants.IMPORT_SERVICES);

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,12 @@
*/
interface Constants {
// xml parser constants
String DEPLOYMENT_ARCHIVES = "deployment-archives";
String PORTLET_WAR_DEPENDENCIES = "portlet-war-dependencies";
String ARCHIVE = "archive";
String DEPENDENCY = "dependency";
String MAIN = "main";
String IMPORT_SERVICES = "import-services";

String PORTAL = "portal";

// MDR operations constants
String DEPLOYMENT_ARCHIVE = "deployment-archive";
String PORTLET_WAR_DEPENDENCY = "portlet-war-dependency";
String TRUE = "true";

String PATH = "path";
String RELATIVE_TO = "relative-to";
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
*/
public enum Element {
// must be first
UNKNOWN(null), DEPLOYMENT_ARCHIVES(Constants.DEPLOYMENT_ARCHIVES), PORTLET_WAR_DEPENDENCIES(
Constants.PORTLET_WAR_DEPENDENCIES), ARCHIVE(Constants.ARCHIVE), DEPENDENCY(Constants.DEPENDENCY);
UNKNOWN(null),
PORTLET_WAR_DEPENDENCIES(Constants.PORTLET_WAR_DEPENDENCIES),
DEPENDENCY(Constants.DEPENDENCY);

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class GateInExtension implements Extension {

public static final String SUBSYSTEM_NAME = "gatein";

protected static final String DEFAULT_PORTAL_NAME = "default";

private static final String RESOURCE_NAME = GateInExtension.class.getPackage().getName() + ".LocalDescriptions";

static ResourceDescriptionResolver getResourceDescriptionResolver(final String keyPrefix) {
Expand Down Expand Up @@ -93,7 +91,6 @@ public void initialize(ExtensionContext context) {
registration.registerOperationHandler(DESCRIBE, GenericSubsystemDescribeHandler.INSTANCE,
GenericSubsystemDescribeHandler.INSTANCE, false, OperationEntry.EntryType.PRIVATE);

registration.registerSubModel(new DeploymentArchiveDefinition(config));
registration.registerSubModel(new PortletWarDependencyDefinition(config));

// Register portal resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,13 @@ public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingCon
context.startSubsystemElement(GateInExtension.NAMESPACE, false);

ModelNode node = context.getModelNode();
if (node.hasDefined(Constants.DEPLOYMENT_ARCHIVE)) {
writeDeploymentArchives(writer, node.get(Constants.DEPLOYMENT_ARCHIVE));
}

if (node.hasDefined(Constants.PORTLET_WAR_DEPENDENCY)) {
writePortletWarDependencies(writer, node.get(Constants.PORTLET_WAR_DEPENDENCY));
}
writer.writeEndElement();
}

private void writeDeploymentArchives(XMLExtendedStreamWriter writer, ModelNode deployArchives) throws XMLStreamException {
if (deployArchives.isDefined() && deployArchives.asInt() > 0) {
writer.writeStartElement(Element.DEPLOYMENT_ARCHIVES.getLocalName());
for (Property archive : deployArchives.asPropertyList()) {
writer.writeStartElement(Element.ARCHIVE.getLocalName());
writer.writeAttribute(Attribute.NAME.getLocalName(), archive.getName());
ModelNode model = archive.getValue();
DeploymentArchiveDefinition.MAIN.marshallAsAttribute(model, false, writer);
writer.writeEndElement();
}
writer.writeEndElement();
}
}

private void writePortletWarDependencies(XMLExtendedStreamWriter writer, ModelNode warDependencies)
throws XMLStreamException {
if (warDependencies.isDefined() && warDependencies.asInt() > 0) {
Expand Down Expand Up @@ -131,11 +115,6 @@ public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) th
if (GateInExtension.NAMESPACE.equals(reader.getNamespaceURI())) {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case DEPLOYMENT_ARCHIVES: {
parseDeploymentArchives(reader, address, list);
hasArchives = true;
break;
}
case PORTLET_WAR_DEPENDENCIES: {
parsePortletWarDependencies(reader, address, list);
hasDependencies = true;
Expand All @@ -150,89 +129,10 @@ public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) th
}
}

if (!hasArchives)
addDefaultDeploymentArchivesOperations(reader, address, list);

if (!hasDependencies)
addDefaultPortletWarDependencies(reader, address, list);
}

static void parseDeploymentArchives(XMLExtendedStreamReader reader, ModelNode parent, List<ModelNode> operations)
throws XMLStreamException {
// no attributes
requireNoAttributes(reader);

boolean gotArchives = false;

// elements
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case ARCHIVE: {
parseArchive(reader, parent, operations);
gotArchives = true;
break;
}
default:
throw unexpectedElement(reader);
}
}

if (!gotArchives)
addDefaultDeploymentArchivesOperations(reader, parent, operations);
}

private static void addDefaultDeploymentArchivesOperations(XMLExtendedStreamReader reader, ModelNode parent,
List<ModelNode> operations) throws XMLStreamException {
ModelNode model = new ModelNode();
DeploymentArchiveDefinition.MAIN.parseAndSetParameter(Constants.TRUE, model, reader);
addDeploymentArchiveOperation(parent, model, "gatein.ear", operations);
}

static void parseArchive(XMLExtendedStreamReader reader, ModelNode parent, List<ModelNode> operations)
throws XMLStreamException {
ModelNode model = new ModelNode();

final int count = reader.getAttributeCount();

String name = null;
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
name = value;
break;
}
case MAIN: {
DeploymentArchiveDefinition.MAIN.parseAndSetParameter(value, model, reader);
break;
}
default:
throw unexpectedAttribute(reader, i);
}
}

if (name == null) {
throw new RuntimeException("Attribute '" + Attribute.NAME.getLocalName() + "' of '"
+ Element.ARCHIVE.getLocalName() + "' element can not be null!");
}

addDeploymentArchiveOperation(parent, model, name, operations);

requireNoContent(reader);
}

private static void addDeploymentArchiveOperation(ModelNode parent, ModelNode model, String name, List<ModelNode> operations) {
ModelNode address = parent.clone();
address.add(Constants.DEPLOYMENT_ARCHIVE, name);

model.get(OP).set(ADD);
model.get(OP_ADDR).set(address);
operations.add(model);
}

static void parsePortletWarDependencies(XMLExtendedStreamReader reader, ModelNode parent, List<ModelNode> operations)
throws XMLStreamException {
// no attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class GateInExtKey {
public static AttachmentKey<GateInExtKey> KEY = AttachmentKey.create(GateInExtKey.class);
public static GateInExtKey INSTANCE = new GateInExtKey();
public static final AttachmentKey<GateInExtKey> KEY = AttachmentKey.create(GateInExtKey.class);
public static final GateInExtKey INSTANCE = new GateInExtKey();
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ private void processChildDeployment(DeploymentPhaseContext phaseContext) {
DeploymentUnit du = phaseContext.getDeploymentUnit();
DeploymentUnit parent = du.getParent();
if (GateInConfiguration.isGateInArchive(parent)) {
// if (DeploymentTypeMarker.isType(DeploymentType.WAR, du))
// {
// config.getChildWars().add(WebSubsystemServices.JBOSS_WEB.append(du.getName()));
// }
du.putAttachment(GateInConfigurationKey.KEY, config);
config.addChildSubUnit(Services.deploymentUnitName(parent.getName(), du.getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,19 @@
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
*/
public class SubsystemParsingTestCase extends AbstractSubsystemBaseTest {
private static final String SUBSYSTEM_XML = "<subsystem xmlns=\"" + GateInExtension.NAMESPACE + "\">\n"
+ " <deployment-archives>\n" + " <archive name=\"" + Archive.GATEIN.getLocalName() + "\" main=\"true\" />\n"
+ " <archive name=\"" + Archive.GATEIN_SAMPLE_EXTENSION.getLocalName() + "\" />\n" + " <archive name=\""
+ Archive.GATEIN_SAMPLE_PORTAL.getLocalName() + "\" />\n" + " <archive name=\""
+ Archive.GATEIN_SAMPLE_SKIN.getLocalName() + "\" />\n" + " </deployment-archives>\n"
+ " <portlet-war-dependencies>\n" + " <dependency name=\"" + Module.ORG_GATEIN_LIB.getLocalName()
+ "\" import-services=\"true\" />\n" + " <dependency name=\"" + Module.ORG_GATEIN_WCI.getLocalName()
+ "\" />\n" + " <dependency name=\"" + Module.JAVAX_PORTLET_API.getLocalName() + "\" />\n"
+ " </portlet-war-dependencies>\n" + "</subsystem>";

static enum Archive {
GATEIN("gatein.ear"), GATEIN_SAMPLE_EXTENSION("gatein-sample-extension.ear"), GATEIN_SAMPLE_PORTAL(
"gatein-sample-portal.ear"), GATEIN_SAMPLE_SKIN("gatein-sample-skin.war");

private String archive;

public String getLocalName() {
return archive;
}

private Archive(String name) {
archive = name;
}
}
private static final String SUBSYSTEM_XML =
"<subsystem xmlns=\"" + GateInExtension.NAMESPACE + "\">\n" +
" <portlet-war-dependencies>\n" +
" <dependency name=\"" + Module.ORG_GATEIN_LIB.getLocalName() + "\" import-services=\"true\" />\n" +
" <dependency name=\"" + Module.ORG_GATEIN_WCI.getLocalName() + "\" />\n" +
" <dependency name=\"" + Module.JAVAX_PORTLET_API.getLocalName() + "\" />\n" +
" </portlet-war-dependencies>\n" +
"</subsystem>";

static enum Module {
ORG_GATEIN_LIB("org.gatein.lib"), ORG_GATEIN_WCI("org.gatein.wci"), JAVAX_PORTLET_API("javax.portlet.api");
ORG_GATEIN_LIB("org.gatein.lib"),
ORG_GATEIN_WCI("org.gatein.wci"),
JAVAX_PORTLET_API("javax.portlet.api");

private String module;

Expand Down

0 comments on commit b7c918d

Please sign in to comment.