]> git.mxchange.org Git - jphone-core.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 09:04:06 +0000 (11:04 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 12 Oct 2015 10:09:49 +0000 (12:09 +0200)
- added named query for all SMS provider
- added validator for phone, fax and mobile numbers
- this requires the Java EE 7 API to be added
- also jcoreee is required (for abstract BaseLongValidator) class
- allow null for all numbers
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/javaee-api-7.0/javaee-api-7.0.jar [new file with mode: 0644]
lib/javaee-api-7.0/javaee-doc-api.jar [new file with mode: 0644]
lib/jcoreee.jar [new file with mode: 0644]
lib/nblibraries.properties
nbproject/project.properties
src/org/mxchange/jphone/phonenumbers/DialableNumber.java
src/org/mxchange/jphone/phonenumbers/cellphone/CellphoneNumber.java
src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java
src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java
src/org/mxchange/jphone/phonenumbers/smsprovider/CellphoneProvider.java
src/org/mxchange/jphone/validators/PhoneNumberValidator.java [new file with mode: 0644]

diff --git a/lib/javaee-api-7.0/javaee-api-7.0.jar b/lib/javaee-api-7.0/javaee-api-7.0.jar
new file mode 100644 (file)
index 0000000..9e38d4c
Binary files /dev/null and b/lib/javaee-api-7.0/javaee-api-7.0.jar differ
diff --git a/lib/javaee-api-7.0/javaee-doc-api.jar b/lib/javaee-api-7.0/javaee-doc-api.jar
new file mode 100644 (file)
index 0000000..2859e3d
Binary files /dev/null and b/lib/javaee-api-7.0/javaee-doc-api.jar differ
diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar
new file mode 100644 (file)
index 0000000..3d91b2c
Binary files /dev/null and b/lib/jcoreee.jar differ
index 7ee54123c81e4a4dddbf24b8bfb3425facc2f1e2..2e2f7c62da9e1393ccc98bfe9022256ac283cb89 100644 (file)
@@ -2,6 +2,12 @@ libs.CopyLibs.classpath=\
     ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
 libs.CopyLibs.displayName=CopyLibs Task
 libs.CopyLibs.prop-version=2.0
+libs.javaee-api-7.0.classpath=\
+    ${base}/javaee-api-7.0/javaee-api-7.0.jar
+libs.javaee-api-7.0.displayName=Java EE 7 API Library
+libs.javaee-api-7.0.javadoc=\
+    ${base}/javaee-api-7.0/javaee-doc-api.jar
+libs.javaee-api-7.0.prop-maven-dependencies=javax:javaee-api:7.0:jar
 libs.jpa20-persistence.classpath=\
     ${base}/jpa20-persistence/javax.persistence_2.1.0.v201304241213.jar
 libs.jpa20-persistence.displayName=Persistence (JPA 2.1)
index baf13afa3742ae833339ada578d7a93b7115faa0..4c915118ef0bf4946b48cd22fe435e9f72c3e104 100644 (file)
@@ -30,14 +30,17 @@ dist.jar=${dist.dir}/jphone-core.jar
 dist.javadoc.dir=${dist.dir}/javadoc
 endorsed.classpath=
 excludes=
+file.reference.jcoreee.jar=lib/jcoreee.jar
 file.reference.jcountry-core.jar=lib/jcountry-core.jar
 includes=**
 jar.archive.disabled=${jnlp.enabled}
 jar.compress=false
 jar.index=${jnlp.enabled}
 javac.classpath=\
+    ${file.reference.jcoreee.jar}:\
     ${file.reference.jcountry-core.jar}:\
-    ${libs.jpa20-persistence.classpath}
+    ${libs.jpa20-persistence.classpath}:\
+    ${libs.javaee-api-7.0.classpath}
 # Space-separated list of extra javac options
 javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
 javac.deprecation=true
@@ -89,6 +92,7 @@ run.test.classpath=\
     ${javac.test.classpath}:\
     ${build.test.classes.dir}
 source.encoding=UTF-8
+source.reference.jcoreee.jar=../jcoreee/src/
 source.reference.jcountry-core.jar=../jcountry-core/src/
 src.dir=src
 test.src.dir=test
index 2c157f6faaba4d2f7cba88a6c3e54ac54d3a3a7b..e663ebd09e24dde7fe64d87dedac49f633ce5cfc 100644 (file)
@@ -31,14 +31,14 @@ public interface DialableNumber extends Serializable {
         * <p>
         * @return Country instance
         */
-       public Country getCountry ();
+       public Country getPhoneCountry ();
 
        /**
         * Setter for country instance ('s dial data)
         * <p>
         * @param country Country instance
         */
-       public void setCountry (final Country country);
+       public void setPhoneCountry (final Country country);
 
        /**
         * Getter for id number
index d06a3bb2b6af7a21876a5498d25ae1263e9df436..a1730077f5ca8011d2ac601c2852713dcc1e983a 100644 (file)
@@ -27,7 +27,6 @@ import javax.persistence.JoinColumn;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 import org.mxchange.jcountry.data.Country;
-import org.mxchange.jcountry.data.CountryData;
 import org.mxchange.jphone.phonenumbers.smsprovider.CellphoneProvider;
 import org.mxchange.jphone.phonenumbers.smsprovider.SmsProvider;
 
@@ -68,11 +67,33 @@ public class CellphoneNumber implements DialableCellphoneNumber, Comparable<Dial
        private Long phoneNumber;
 
        /**
-        * Country instance ('s dial data)
+        * Contructor with cellphone carrier and number
+        * <p>
+        * @param cellphoneCarrier Cellphone carrier instance
+        * @param cellphoneNumber Cellphone number
         */
-       @JoinColumn (name = "cellphone_country_id", nullable = false)
-       @OneToOne (targetEntity = CountryData.class, optional = false, cascade = CascadeType.ALL)
-       private Country country;
+       public CellphoneNumber (final SmsProvider cellphoneCarrier, final Long cellphoneNumber) {
+               this.cellphoneProvider = cellphoneCarrier;
+               this.phoneNumber = cellphoneNumber;
+       }
+
+       /**
+        * Protected constructor
+        */
+       protected CellphoneNumber () {
+       }
+
+       @Override
+       @Deprecated
+       public Country getPhoneCountry () {
+               throw new UnsupportedOperationException("The country code is provided by SmsProvider."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       @Override
+       @Deprecated
+       public void setPhoneCountry (final Country country) {
+               throw new UnsupportedOperationException("The country code is provided by SmsProvider."); //To change body of generated methods, choose Tools | Templates.
+       }
 
        @Override
        public Long getPhoneId () {
@@ -105,11 +126,13 @@ public class CellphoneNumber implements DialableCellphoneNumber, Comparable<Dial
        }
 
        @Override
+       @Deprecated
        public Integer getPhoneAreaCode () {
                throw new UnsupportedOperationException("Cellphone numbers don't have area codes. Please fix your code."); //NOI18N
        }
 
        @Override
+       @Deprecated
        public void setPhoneAreaCode (final Integer phoneAreaCode) {
                throw new UnsupportedOperationException("Cellphone numbers don't have area codes. Please fix your code."); //NOI18N
        }
@@ -118,14 +141,4 @@ public class CellphoneNumber implements DialableCellphoneNumber, Comparable<Dial
        public int compareTo (final DialableCellphoneNumber dialableCellphoneNumber) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
-
-       @Override
-       public Country getCountry () {
-               return this.country;
-       }
-
-       @Override
-       public void setCountry (final Country country) {
-               this.country = country;
-       }
 }
index 16cdec03dd7a91bc065dfa1a1f6ef2d49a573d75..b5cb1b6978479393e421e71ded3739e10a78ebbb 100644 (file)
@@ -63,14 +63,33 @@ public class FaxNumber implements DialableFaxNumber, Comparable<DialableFaxNumbe
         */
        @Basic (optional = false)
        @Column (name = "fax_area_code", length = 10, nullable = false)
-       private Integer phoneAreaCode;
+       private Integer faxAreaCode;
 
        /**
         * Country instance ('s dial data)
         */
        @JoinColumn (name = "fax_country_id", nullable = false)
        @OneToOne (targetEntity = CountryData.class, optional = false, cascade = CascadeType.ALL)
-       private Country country;
+       private Country faxCountry;
+
+       /**
+        * Contructor with country, area code and number
+        * <p>
+        * @param faxCountry Country instance
+        * @param faxAreaCode Area code (without leading zeros)
+        * @param faxNumber Fax number (without area code and leading zero)
+        */
+       public FaxNumber (final Country faxCountry, final Integer faxAreaCode, final Long faxNumber) {
+               this.faxCountry = faxCountry;
+               this.faxAreaCode = faxAreaCode;
+               this.phoneNumber = faxNumber;
+       }
+
+       /**
+        * Protected constructor
+        */
+       protected FaxNumber () {
+       }
 
        @Override
        public Long getPhoneId () {
@@ -99,22 +118,22 @@ public class FaxNumber implements DialableFaxNumber, Comparable<DialableFaxNumbe
 
        @Override
        public Integer getPhoneAreaCode () {
-               return this.phoneAreaCode;
+               return this.faxAreaCode;
        }
 
        @Override
-       public void setPhoneAreaCode (final Integer phoneAreaCode) {
-               this.phoneAreaCode = phoneAreaCode;
+       public void setPhoneAreaCode (final Integer faxAreaCode) {
+               this.faxAreaCode = faxAreaCode;
        }
 
        @Override
-       public Country getCountry () {
-               return this.country;
+       public Country getPhoneCountry () {
+               return this.faxCountry;
        }
 
        @Override
-       public void setCountry (final Country country) {
-               this.country = country;
+       public void setPhoneCountry (final Country faxCountry) {
+               this.faxCountry = faxCountry;
        }
 
 }
index 73d4145e937272904e6bc8395bcba9193bb2fce9..84ae8c3a8af1b53872fa7a9490e5db9c4f9bde96 100644 (file)
@@ -70,7 +70,26 @@ public class LandLineNumber implements DialableLandLineNumber, Comparable<Dialab
         */
        @JoinColumn (name = "phone_country_id", nullable = false, updatable = false)
        @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.ALL, optional = false)
-       private Country country;
+       private Country phoneCountry;
+
+       /**
+        * Counstructor with country instance, area code and number
+        * <p>
+        * @param phoneCountry Country instance
+        * @param phoneAreaCode Phone area code
+        * @param phoneNumber Phone number
+        */
+       public LandLineNumber (final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) {
+               this.phoneCountry = phoneCountry;
+               this.phoneAreaCode = phoneAreaCode;
+               this.phoneNumber = phoneNumber;
+       }
+
+       /**
+        * Protected constructor
+        */
+       protected LandLineNumber () {
+       }
 
        @Override
        public Long getPhoneId () {
@@ -108,12 +127,12 @@ public class LandLineNumber implements DialableLandLineNumber, Comparable<Dialab
        }
 
        @Override
-       public Country getCountry () {
-               return this.country;
+       public Country getPhoneCountry () {
+               return this.phoneCountry;
        }
 
        @Override
-       public void setCountry (final Country country) {
-               this.country = country;
+       public void setPhoneCountry (final Country phoneCountry) {
+               this.phoneCountry = phoneCountry;
        }
 }
index c9a113b1612d079f20eba06694c695b64bbc260d..6007684b5762eed6847d34616ff4fa47d1282ddc 100644 (file)
@@ -24,6 +24,8 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 import org.mxchange.jcountry.data.Country;
@@ -36,6 +38,9 @@ import org.mxchange.jcountry.data.CountryData;
  */
 @Entity (name = "cellphone_provider")
 @Table (name = "cellphone_provider")
+@NamedQueries (
+               @NamedQuery (name = "AllSmsProvider", query = "SELECT p FROM cellphone_provider AS p ORDER BY p.providerId ASC")
+)
 public class CellphoneProvider implements SmsProvider {
 
        /**
diff --git a/src/org/mxchange/jphone/validators/PhoneNumberValidator.java b/src/org/mxchange/jphone/validators/PhoneNumberValidator.java
new file mode 100644 (file)
index 0000000..bc2d295
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jphone.validators;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import org.mxchange.jcoreee.validator.number.BaseLongValidator;
+
+/**
+ * A validator for phone, fax and mobile numbers
+ * <p>
+ * @author Roland Haeder
+ */
+public class PhoneNumberValidator extends BaseLongValidator implements Validator {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 186_897_817_692_786_900L;
+
+       @Override
+       public void validate (final FacesContext context, final UIComponent component, final Object value) {
+               // Trace message
+               //this.getLogger().logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
+
+               // The required field
+               String[] requiredFileds = {"phoneAreaCode", "phoneNumber", "faxAreaCode", "faxNumber", "cellphoneNumber"}; //NOI18N
+
+               // Pre-validation (example: not null, not a string, empty string ...)
+               super.preValidate(context, component, value, requiredFileds, true);
+
+               // Trace message
+               //this.getLogger().logTrace("validate: EXIT!"); //NOI18N
+       }
+}