Package org.apache.geronimo.jee.deployment

Examples of org.apache.geronimo.jee.deployment.ObjectFactory


            if (gbean == null) {
                gbean = (Gbean)getEFactory().create(Gbean.class);
                JAXBElement plan = section.getPlan();
               
                // add the JAXBElement of a GBean, not the GBean
                ObjectFactory objectFactory = new ObjectFactory();
                JAXBModelUtils.getGbeans(plan).add(objectFactory.createGbean((Gbean)gbean));
            }
            gbean.setName(textList.get(0).getText());
            gbean.setClazz(textList.get(1).getText());
            break;

        case ATTRIBUTE:
            if (isEmpty(textList.get(0).getText()) || isEmpty(textList.get(1).getText())) {
                return false;
            }
            Attribute attribute = (Attribute)eObject;
            if (attribute == null) {
                attribute = (Attribute)getEFactory().create(Attribute.class);
                gbean = (Gbean)section.getSelectedObject();
               
                // add the JAXBElement of an Attribute, not the Attribute
                ObjectFactory objectFactory = new ObjectFactory();
                gbean.getAttributeOrXmlAttributeOrReference().add(objectFactory.createGbeanAttribute(attribute));
            }
            attribute.setName(textList.get(0).getText());
            attribute.setType(textList.get(1).getText());
            attribute.setValue(textList.get(2).getText());
            break;

        case DEPENDENCY:
            if (isEmpty(textList.get(0).getText()) || isEmpty(textList.get(1).getText())) {
                return false;
            }
            Pattern dependency = (Pattern)eObject;
            if (dependency == null) {
                dependency = (Pattern)getEFactory().create(Pattern.class);
                gbean = (Gbean)section.getSelectedObject();

                // add the JAXBElement of a Dependency, not the Dependency
                ObjectFactory objectFactory = new ObjectFactory();
                gbean.getAttributeOrXmlAttributeOrReference().add(objectFactory.createGbeanDependency(dependency));
            }
            dependency.setGroupId(textList.get(0).getText());
            dependency.setArtifactId(textList.get(1).getText());
            dependency.setVersion(textList.get(2).getText());
            dependency.setModule(textList.get(3).getText());
            dependency.setType(textList.get(4).getText());
            dependency.setCustomFoo(textList.get(5).getText());
            break;

        case REFERENCE:
            if (isEmpty(textList.get(0).getText()) || isEmpty(textList.get(1).getText()) ||
                    isEmpty(textList.get(2).getText())) {
                return false;
            }
            Reference reference = (Reference)eObject;
            if (reference == null) {
                reference = (Reference)getEFactory().create(Reference.class);
                gbean = (Gbean)section.getSelectedObject();

                // add the JAXBElement of a Dependency, not the Dependency
                ObjectFactory objectFactory = new ObjectFactory();
                gbean.getAttributeOrXmlAttributeOrReference().add(objectFactory.createGbeanReference(reference));
            }
            reference.setName(textList.get(0).getText());
            reference.setGroupId(textList.get(1).getText());
            reference.setArtifactId(textList.get(2).getText());
            reference.setVersion(textList.get(3).getText());
View Full Code Here


    }

    public boolean performFinish() {
  boolean isedit = false;
  JAXBElement<?> plan = this.section.getPlan();
  ObjectFactory objectFactory = new ObjectFactory();
  // all pages
  SecurityRealmBasicPage page0 = (SecurityRealmBasicPage) this
    .getPage("SecurityRealmBasicPage");
  PropertiesFileRealmPage page1 = (PropertiesFileRealmPage) this
    .getPage("PropertiesFileRealmPage");
  SelectSQLPage page2 = (SelectSQLPage) this.getPage("SelectSQLPage");
  DBConnectionPage page3 = (DBConnectionPage) this
    .getPage("DBConnectionPage");
  LDAPConnectionPage page4 = (LDAPConnectionPage) this
    .getPage("LDAPConnectionPage");
  LDAPSearchPage page5 = (LDAPSearchPage) this.getPage("LDAPSearchPage");

  // password not match , popup a dialog
  if (!page3.textEntries[3].getText().equals(
    page3.textEntries[4].getText())) {
      Status status = new Status(IStatus.WARNING, "Login Error", 0,
        "Password provided in both fields do not match", null);
      ErrorDialog.openError(this.getShell(), "Login Error",
        "Invalid Login Details", status);
      return false;
  }

  // set a gbean according to the input from wizard
  Gbean gbean = null;
  if (eObject != null) {
      gbean = (Gbean) ((JAXBElement) eObject).getValue();
      isedit = true;
  } else {
      gbean = new Gbean();// create a new gbean
      eObject = objectFactory.createGbean(gbean);
  }

  // add the data into gbean
  String realmName = page0.textEntries[0].getText() == null ? ""
    : page0.textEntries[0].getText();
  gbean.setName(realmName);// set the gbean name the same as realm name
  gbean
    .setClazz("org.apache.geronimo.security.realm.GenericSecurityRealm");// TODO
  // message

  List<JAXBElement<?>> elelist = gbean
    .getAttributeOrXmlAttributeOrReference();

  // set the attribute
  JAXBElement<Attribute> attributeElement = getAttributeElement(elelist);
  if (attributeElement == null) {
      attributeElement = objectFactory.createGbeanAttribute(null);
      elelist.add(attributeElement);
  }
  Attribute attribute = new Attribute();
  attribute.setName("realmName");
  attribute.setValue(realmName);
  attributeElement.setValue(attribute);

  // set the reference
  JAXBElement<Reference> referenceElement = getReferenceElement(elelist);
  if (referenceElement == null) {
      referenceElement = objectFactory.createGbeanReference(null);
      elelist.add(referenceElement);
  }
  Reference ref = new Reference();
  ref.setName("ServerInfo");
  ref.setCustomFoo("ServerInfo");
  referenceElement.setValue(ref);

  // set the xml-reference
  JAXBElement<XmlAttributeType> xmlrefElement = getXmlReferenceElement(elelist);
  if (xmlrefElement == null) {
      xmlrefElement = objectFactory.createGbeanXmlReference(null);
      elelist.add(xmlrefElement);
  }
  XmlAttributeType xmlAtttribute = new XmlAttributeType();
  xmlAtttribute.setName("LoginModuleConfiguration");
  xmlrefElement.setValue(xmlAtttribute);

  LoginConfig config = new LoginConfig();
  xmlAtttribute.setAny(config);
  LoginModule loginModule = new LoginModule();
  config.getLoginModuleRefOrLoginModule().add(loginModule);
  loginModule.setControlFlag(ControlFlag.fromValue("REQUIRED"));
  loginModule.setWrapPrincipals(false);
  loginModule.setLoginDomainName(realmName);

  String realmType = page0.combo.getText().trim();
  if (realmType.equals("Properties File Realm")) {
      loginModule
        .setLoginModuleClass("org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule");

      String usersfile = page1.textEntries[0].getText().trim();
      Option usersfileopt = createOption("usersURI", usersfile);

      String groupsfile = page1.textEntries[1].getText().trim();
      Option groupsfileopt = createOption("groupsURI", groupsfile);

      String algorithm = page1.textEntries[2].getText();
      Option algorithmopt = createOption("digest", algorithm);

      String encoding = page1.textEntries[3].getText();
      Option encodingopt = createOption("encoding", encoding);

      loginModule.getOption().add(usersfileopt);
      loginModule.getOption().add(groupsfileopt);
      if (algorithm != null)
    loginModule.getOption().add(algorithmopt);
      if (encoding != null)
    loginModule.getOption().add(encodingopt);

  } else if (realmType.equals("SQL Realm")) {
      loginModule
        .setLoginModuleClass("org.apache.geronimo.security.realm.providers.SQLLoginModule");

      String selectUsers = page2.textEntries[0].getText().trim();
      Option selectUsersopt = createOption("userSelect", selectUsers);

      String selectGroups = page2.textEntries[1].getText().trim();
      Option selectGroupsopt = createOption("groupSelect", selectGroups);

      String algorithm = page2.textEntries[2].getText().trim();
      Option algorithmopt = createOption("digest", algorithm);

      String encoding = page2.textEntries[3].getText().trim();
      Option encodingopt = createOption("encoding", encoding);

      if (page3.buttons[0].getSelection()) {
    String dsname = page3.dataBasePoolCombo.getText();
    Option dsnameopt = createOption("dataSourceName", dsname);
    loginModule.getOption().add(dsnameopt);
      } else if (page3.buttons[1].getSelection()) {

    String jdbcDriverClass = page3.textEntries[0].getText().trim();
    Option jdbcDriverClassopt = createOption("jdbcDriver",
      jdbcDriverClass);

    String jdbcURL = page3.textEntries[1].getText().trim();
    Option jdbcURLopt = createOption("jdbcURL", jdbcURL);

    String userName = page3.textEntries[2].getText().trim();
    Option userNameopt = createOption("jdbcUser", userName);

    String password = page3.textEntries[3].getText().trim();
    Option passwordopt = createOption("jdbcPassword", password);

    loginModule.getOption().add(jdbcDriverClassopt);
    loginModule.getOption().add(jdbcURLopt);
    loginModule.getOption().add(userNameopt);
    loginModule.getOption().add(passwordopt);

      }

      loginModule.getOption().add(selectUsersopt);
      loginModule.getOption().add(selectGroupsopt);
      loginModule.getOption().add(algorithmopt);
      loginModule.getOption().add(encodingopt);

  } else if (realmType.equals("LDAP Realm")) {
      loginModule
        .setLoginModuleClass("org.apache.geronimo.security.realm.providers.LDAPLoginModule");
      String initialContextFactory = page4.combo[0].getText().trim();
      loginModule.getOption()
        .add(
          createOption("initialContextFactory",
            initialContextFactory));
      String connectionURL = page4.combo[1].getText();
      loginModule.getOption().add(
        createOption("connectionURL", connectionURL));
      String connectionUsername = page4.text[0].getText();
      loginModule.getOption().add(
        createOption("connectionUsername", connectionUsername));
      String connectionPassword = page4.text[1].getText();
      loginModule.getOption().add(
        createOption("connectionPassword", connectionPassword));
      String connectionProtocol = page4.text[3].getText();
      loginModule.getOption().add(
        createOption("connectionProtocol", connectionProtocol));
      String authentication = page4.combo[2].getText();
      loginModule.getOption().add(
        createOption("authentication", authentication));

      String userBase = page5.text[0].getText();
      loginModule.getOption().add(createOption("userBase", userBase));
      String userSearchMatching = page5.text[1].getText();
      loginModule.getOption().add(
        createOption("userSearchMatching", userSearchMatching));
      String userSearchSubtree = Boolean.toString(page5.userSearchSubtree
        .getSelection());
      loginModule.getOption().add(
        createOption("userSearchSubtree", userSearchSubtree));
      String roleBase = page5.text[2].getText();
      loginModule.getOption().add(createOption("roleBase", roleBase));
      String roleName = page5.text[3].getText();
      loginModule.getOption().add(createOption("roleName", roleName));
      String roleSearchMatching = page5.text[4].getText();
      loginModule.getOption().add(
        createOption("roleSearchMatching", roleSearchMatching));
      String userRoleName = page5.text[5].getText();
      loginModule.getOption().add(
        createOption("userRoleName", userRoleName));
      String roleSearchSubtree = Boolean.toString(page5.roleSearchSubtree
        .getSelection());
      loginModule.getOption().add(
        createOption("roleSearchSubtree", roleSearchSubtree));
  }

  if (isedit)
      return true;

  // is add, need to add the gbean into plan
  Object planValue = plan.getValue();
  if (Application.class.isInstance(planValue)) {
      Application application = (Application) planValue;

      // set dependency
      Environment env = application.getEnvironment();
      if (env == null) {
    env = new Environment();
    application.setEnvironment(env);
      }
      setDependency(env);

      // add the gbean into plan
      JAXBElement<Gbean> gbeanElement = objectFactory.createGbean(gbean);
      application.getService().add(gbeanElement);
  } else if (WebApp.class.isInstance(planValue)) {
      WebApp webapp = (WebApp) planValue;

      // set dependency
      Environment env = webapp.getEnvironment();
      if (env == null) {
    env = new Environment();
    webapp.setEnvironment(env);
      }
      setDependency(env);

      // add the gbean into plan
      JAXBElement<Gbean> gbeanElement = objectFactory.createGbean(gbean);
      webapp.getServiceOrPersistence().add(gbeanElement);
  } else if (OpenejbJar.class.isInstance(planValue)) {
      OpenejbJar openejbJar = (OpenejbJar) planValue;

      // set dependency
      Environment env = openejbJar.getEnvironment();
      if (env == null) {
    env = new Environment();
    openejbJar.setEnvironment(env);
      }
      setDependency(env);

      // add the gbean into plan
      JAXBElement<Gbean> gbeanElement = objectFactory.createGbean(gbean);
      openejbJar.getService().add(gbeanElement);
  }

  return true;
    }
View Full Code Here

TOP

Related Classes of org.apache.geronimo.jee.deployment.ObjectFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.