Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source.
  * Copyright 2013, Red Hat Middleware LLC, and individual contributors
  * as indicated by the @author tags. See the copyright.txt file in the
  * distribution for a full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.as.domain.controller.transformers;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
 import static org.jboss.as.domain.controller.DomainControllerMessages.MESSAGES;
 import static org.jboss.as.domain.controller.transformers.DomainTransformers.IGNORED_SUBSYSTEMS;
 
 import java.util.Set;
 

Author(s):
Jeff Mesnil (c) 2012 Red Hat, inc
 
 
     private static final String JSF_SUBSYSTEM = "jsf";
     private static final String SLOT_ATTRIBUTE_NAME = "default-jsf-impl-slot";
     private static final String SLOT_DEFAULT_VALUE = "main";
 
     static void registerTransformers120(TransformerRegistry registryTransformersSubRegistration parent) {
             @Override
             public void transformResource(ResourceTransformationContext contextPathAddress addressResource resourcethrows OperationFailedException {
                 ModelNode model = resource.getModel();
                 if (model.hasDefined()) {
                     ModelNode slot = model.get();
                     if (!.equals(slot.asString())) {
                         context.getLogger().logAttributeWarning(address.invalidJSFSlotValue(slot.asString()), );
                     }
                 }
                 Set<Stringattributes = new HashSet<String>();
                 for (Property prop : resource.getModel().asPropertyList()) {
                     attributes.add(prop.getName());
                 }
                 attributes.remove();
                 if (!attributes.isEmpty()) {
                     context.getLogger().logAttributeWarning(address..attributesAreNotUnderstoodAndMustBeIgnored(), attributes);
                 }
             }
         });
 
         TransformersSubRegistration jsfSubsystem = parent.registerSubResource(PathElement.pathElement());
         jsfSubsystem.registerOperationTransformer(new OperationTransformer() {
 
             @Override
             public TransformedOperation transformOperation(TransformationContext contextPathAddress addressModelNode operationthrows OperationFailedException {
                 if (operation.hasDefined()) {
                     ModelNode slot = operation.get();
                     if (!.equals(slot.asString())) {
                         return new TransformedOperation(operation,
                                 new RejectionWithFailurePolicy(.invalidJSFSlotValue(slot.asString())),
                                 .);
                     }
                 }
                 Set<Stringattributes = new HashSet<String>();
                 for (Property prop : operation.asPropertyList()) {
                     attributes.add(prop.getName());
                }
                attributes.remove();
                if (!attributes.isEmpty()) {
                    return new TransformedOperation(operation,
                            new RejectionWithFailurePolicy(.unknownAttributesFromSubsystemVersion(,
                                    ,
                                    context.getTarget().getSubsystemVersion(),
                                    attributes)),
                            .);
                }
                return .transformOperation(contextaddressoperation);
            }
        });
            @Override
            public TransformedOperation transformOperation(TransformationContext contextPathAddress addressModelNode operationthrows OperationFailedException {
                final String name = operation.require().asString();
                final ModelNode value = operation.get(.);
                if (.equals(name)) {
                    if (value.isDefined() && .equals(value.asString())) {
                        return .transformOperation(contextaddressoperation);
                    } else {
                        return new TransformedOperation(operation,
                                new RejectionWithFailurePolicy(.invalidJSFSlotValue(value.asString())),
                                .);
                    }
                }
                // reject the operation for any other attribute
                return new TransformedOperation(operation,
                        new RejectionWithFailurePolicy(.unknownAttributesFromSubsystemVersion(,
                                ,
                                context.getTarget().getSubsystemVersion(),
                                Arrays.asList(name))),
                        .);
            }
        });
            @Override
            public TransformedOperation transformOperation(TransformationContext contextPathAddress addressModelNode operationthrows OperationFailedException {
                String attributeName = operation.require().asString();
                if (!.equals(attributeName)) {
                    return .transformOperation(contextaddressoperation);
                } else {
                    context.getLogger().logAttributeWarning(address..attributesAreNotUnderstoodAndMustBeIgnored(), attributeName);
                    return .transformOperation(contextaddressoperation);
                }
            }
        });
    }
    private static class RejectionWithFailurePolicy implements OperationRejectionPolicy {
        private final String failureDescription;
        public RejectionWithFailurePolicy(String failureDescription) {
            this. = failureDescription;
        }
        @Override
        public boolean rejectOperation(ModelNode preparedResult) {
            return true;
        }
        @Override
        public String getFailureDescription() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X